Skip to content

Commit

Permalink
joystick buttons accessible via APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed May 3, 2017
1 parent 298169f commit f79fa19
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion AirLib/include/controllers/DroneCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ struct RCData {
//pitch, roll, yaw should be in range -1 to 1
//switches should be integer value indicating its state, 0=on, 1=off for example.
float pitch = 0, roll = 0, throttle = 0, yaw = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0, switch5 = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0,
switch5 = 0, switch6 = 0, switch7 = 0, switch8 = 0;
bool is_connected = false; //must be true for data to be valid

void add(const RCData& other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ class RosFlightDroneController : public DroneControllerBase {
board_->setInputChannel(5, switchToPwm(rcData.switch2));
board_->setInputChannel(6, switchToPwm(rcData.switch3));
board_->setInputChannel(7, switchToPwm(rcData.switch4));
board_->setInputChannel(8, switchToPwm(rcData.switch5)); //arm/disarm
board_->setInputChannel(8, switchToPwm(rcData.switch5));
board_->setInputChannel(9, switchToPwm(rcData.switch6));
board_->setInputChannel(10, switchToPwm(rcData.switch7));
board_->setInputChannel(11, switchToPwm(rcData.switch8));
}
//else we don't have RC data
}
Expand Down
14 changes: 11 additions & 3 deletions AirLib/include/rpc/RpcLibAdapators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ class RpcLibAdapators {
struct RCData {
uint64_t timestamp = 0;
float pitch = 0, roll = 0, throttle = 0, yaw = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0, switch5 = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0,
switch5 = 0, switch6 = 0, switch7 = 0, switch8 = 0;

MSGPACK_DEFINE_ARRAY(timestamp, pitch, roll, throttle, yaw, switch1, switch2, switch3, switch4, switch5);
MSGPACK_DEFINE_ARRAY(timestamp, pitch, roll, throttle, yaw, switch1, switch2, switch3, switch4, switch5, switch6, switch7, switch8);

RCData()
{}
Expand All @@ -133,6 +134,10 @@ class RpcLibAdapators {
switch3 = s.switch3;
switch4 = s.switch4;
switch5 = s.switch5;
switch6 = s.switch6;
switch7 = s.switch7;
switch8 = s.switch8;

}
msr::airlib::RCData to() const
{
Expand All @@ -147,7 +152,10 @@ class RpcLibAdapators {
d.switch3 = switch3;
d.switch4 = switch4;
d.switch5 = switch5;

d.switch6 = switch6;
d.switch7 = switch7;
d.switch8 = switch8;

return d;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
o9x3�M����I Quad X4zd�I ��������d�I�����d�I������d�I����d�\Q �d�]Q
�d�^Q �d�_Q �d�`Q�d�aQ�d�bQ�d�cvM�d�I�N��d�I�L��d�I�K��d�I�WWWWWWWo������������_
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void UAirBlueprintLib::LogMessage(const FString &prefix, const FString &suffix,

FColor color;
switch (level) {
case LogDebugLevel::Informational: color = FColor::Blue; break;
case LogDebugLevel::Informational: color = FColor(5, 5, 100);; break;
case LogDebugLevel::Success: color = FColor::Green; break;
case LogDebugLevel::Failure: color = FColor::Red; break;
case LogDebugLevel::Unimportant: color = FColor::Silver; break;
Expand Down
10 changes: 8 additions & 2 deletions Unreal/Plugins/AirSim/Source/MultiRotorConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ const msr::airlib::RCData& MultiRotorConnector::getRCData()

rc_data_.switch1 = joystick_state_.left_trigger ? 1 : 0;
rc_data_.switch2 = joystick_state_.right_trigger ? 1 : 0;

rc_data_.switch3 = joystick_state_.buttons & 0x100 ? 1 : 0; //front-upper-left
rc_data_.switch4 = joystick_state_.buttons & 0x200 ? 1 : 0; //front-upper-right
rc_data_.switch5 = joystick_state_.buttons & 0x1000 ? 1 : 0; //top-left-right
rc_data_.switch6 = joystick_state_.buttons & 0x2000 ? 1 : 0; //top-right-right
rc_data_.switch7 = joystick_state_.buttons & 0x4000 ? 1 : 0; //top-left-left
rc_data_.switch8 = joystick_state_.buttons & 0x8000 ? 1 : 0; //top-right-left

UAirBlueprintLib::LogMessage(FString("Joystick (T,R,P,Y): "),
FString::SanitizeFloat(rc_data_.throttle) + ", " + FString::SanitizeFloat(rc_data_.roll) + ", " + FString::SanitizeFloat(rc_data_.pitch) + ", " + FString::SanitizeFloat(rc_data_.yaw),
LogDebugLevel::Informational);
UAirBlueprintLib::LogMessage(FString("Joystick (Switches): "), FString::FromInt(joystick_state_.buttons) + ", " +
FString::FromInt(rc_data_.switch1) + ", " + FString::FromInt(rc_data_.switch2) + ", " + FString::FromInt(rc_data_.switch3) + ", " + FString::FromInt(rc_data_.switch4)
+ ", " + FString::FromInt(rc_data_.switch5),
+ ", " + FString::FromInt(rc_data_.switch5)+ ", " + FString::FromInt(rc_data_.switch6)+ ", " + FString::FromInt(rc_data_.switch7)+ ", " + FString::FromInt(rc_data_.switch8),
LogDebugLevel::Informational);
}
//else don't waste time
Expand Down

0 comments on commit f79fa19

Please sign in to comment.