Add more FMS data to JoystickState
Specifically:
-Add a more generica game-data string so that we don't have to add new
fields every year.
-Add the current alliance color.
Change-Id: Ic422ccaf1cddd448176dc59618e9f9a3d008ea23
diff --git a/aos/robot_state/joystick_state.fbs b/aos/robot_state/joystick_state.fbs
index f21b211..1deaa06 100644
--- a/aos/robot_state/joystick_state.fbs
+++ b/aos/robot_state/joystick_state.fbs
@@ -12,6 +12,8 @@
pov:int;
}
+enum Alliance : byte { kRed, kBlue, kInvalid }
+
// This message is checked by all control loops to make sure that the
// joystick code hasn't died. It is published on "/aos"
table JoystickState {
@@ -36,6 +38,12 @@
// useful for testing. The only difference in behavior should be motors not
// actually turning on.
fake:bool;
+
+ // Color of our current alliance.
+ alliance:Alliance;
+
+ // String corresponding to the game data string
+ game_data:string;
}
root_type JoystickState;
diff --git a/frc971/wpilib/joystick_sender.cc b/frc971/wpilib/joystick_sender.cc
index c614cfe..d31d4a5 100644
--- a/frc971/wpilib/joystick_sender.cc
+++ b/frc971/wpilib/joystick_sender.cc
@@ -67,6 +67,18 @@
joysticks_offset = builder.fbb()->CreateVector(joysticks.begin(),
joysticks.size());
+ flatbuffers::Offset<flatbuffers::String> game_data_offset;
+ if (status == 0) {
+ static_assert(sizeof(match_info.gameSpecificMessage) == 64,
+ "Check that the match info game specific message size "
+ "hasn't changed and is still sane.");
+ CHECK_LE(match_info.gameSpecificMessageSize,
+ sizeof(match_info.gameSpecificMessage));
+ game_data_offset = builder.fbb()->CreateString(
+ reinterpret_cast<const char *>(match_info.gameSpecificMessage),
+ match_info.gameSpecificMessageSize);
+ }
+
aos::JoystickState::Builder joystick_state_builder =
builder.MakeBuilder<aos::JoystickState>();
@@ -79,12 +91,24 @@
joystick_state_builder.add_scale_left(
match_info.gameSpecificMessage[1] == 'L' ||
match_info.gameSpecificMessage[1] == 'l');
+ joystick_state_builder.add_game_data(game_data_offset);
}
joystick_state_builder.add_test_mode(ds->IsTestMode());
joystick_state_builder.add_fms_attached(ds->IsFmsAttached());
joystick_state_builder.add_enabled(ds->IsEnabled());
joystick_state_builder.add_autonomous(ds->IsAutonomous());
+ switch (ds->GetAlliance()) {
+ case frc::DriverStation::kRed:
+ joystick_state_builder.add_alliance(aos::Alliance::kRed);
+ break;
+ case frc::DriverStation::kBlue:
+ joystick_state_builder.add_alliance(aos::Alliance::kBlue);
+ break;
+ case frc::DriverStation::kInvalid:
+ joystick_state_builder.add_alliance(aos::Alliance::kInvalid);
+ break;
+ }
joystick_state_builder.add_team_id(team_id_);
if (!builder.Send(joystick_state_builder.Finish())) {