Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 1 | #include "frc971/wpilib/joystick_sender.h" |
| 2 | |
| 3 | #include "aos/common/messages/robot_state.q.h" |
| 4 | #include "aos/linux_code/init.h" |
| 5 | #include "aos/common/network/team_number.h" |
| 6 | #include "aos/common/logging/queue_logging.h" |
| 7 | |
| 8 | #include "DriverStation.h" |
| 9 | |
| 10 | namespace frc971 { |
| 11 | namespace wpilib { |
| 12 | |
| 13 | void JoystickSender::operator()() { |
| 14 | DriverStation *ds = DriverStation::GetInstance(); |
Brian Silverman | bd925f9 | 2014-12-31 14:28:06 -0800 | [diff] [blame^] | 15 | ::aos::SetCurrentThreadName("DSReader"); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 16 | uint16_t team_id = ::aos::network::GetTeamNumber(); |
| 17 | |
Brian Silverman | bd925f9 | 2014-12-31 14:28:06 -0800 | [diff] [blame^] | 18 | ::aos::SetCurrentThreadRealtimePriority(29); |
| 19 | |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 20 | while (run_) { |
| 21 | ds->WaitForData(); |
| 22 | auto new_state = ::aos::robot_state.MakeMessage(); |
| 23 | |
| 24 | new_state->test_mode = ds->IsAutonomous(); |
| 25 | new_state->fms_attached = ds->IsFMSAttached(); |
| 26 | new_state->enabled = ds->IsEnabled(); |
| 27 | new_state->autonomous = ds->IsAutonomous(); |
| 28 | new_state->team_id = team_id; |
| 29 | new_state->fake = false; |
| 30 | |
| 31 | for (int i = 0; i < 4; ++i) { |
| 32 | new_state->joysticks[i].buttons = 0; |
| 33 | for (int button = 0; button < 16; ++button) { |
| 34 | new_state->joysticks[i].buttons |= ds->GetStickButton(i, button + 1) |
| 35 | << button; |
| 36 | } |
| 37 | for (int j = 0; j < 4; ++j) { |
| 38 | new_state->joysticks[i].axis[j] = ds->GetStickAxis(i, j); |
| 39 | } |
| 40 | } |
| 41 | LOG_STRUCT(DEBUG, "robot_state", *new_state); |
| 42 | |
| 43 | if (!new_state.Send()) { |
| 44 | LOG(WARNING, "sending robot_state failed\n"); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } // namespace wpilib |
| 50 | } // namespace frc971 |