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" |
Austin Schuh | 94f51e9 | 2017-10-30 19:25:32 -0700 | [diff] [blame^] | 9 | #if defined(WPILIB2017) || defined(WPILIB2018) |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 10 | #include "HAL/HAL.h" |
| 11 | #else |
Brian Silverman | 6f7d5fe | 2015-01-01 15:45:41 -0800 | [diff] [blame] | 12 | #include "HAL/HAL.hpp" |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 13 | #endif |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 14 | |
| 15 | namespace frc971 { |
| 16 | namespace wpilib { |
| 17 | |
| 18 | void JoystickSender::operator()() { |
Austin Schuh | 3b5b69b | 2015-10-31 18:55:47 -0700 | [diff] [blame] | 19 | DriverStation *ds = |
| 20 | #ifdef WPILIB2015 |
| 21 | DriverStation::GetInstance(); |
| 22 | #else |
| 23 | &DriverStation::GetInstance(); |
| 24 | #endif |
Brian Silverman | bd925f9 | 2014-12-31 14:28:06 -0800 | [diff] [blame] | 25 | ::aos::SetCurrentThreadName("DSReader"); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 26 | uint16_t team_id = ::aos::network::GetTeamNumber(); |
| 27 | |
Brian Silverman | bd925f9 | 2014-12-31 14:28:06 -0800 | [diff] [blame] | 28 | ::aos::SetCurrentThreadRealtimePriority(29); |
| 29 | |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 30 | while (run_) { |
| 31 | ds->WaitForData(); |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 32 | auto new_state = ::aos::joystick_state.MakeMessage(); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 33 | |
Austin Schuh | 94f51e9 | 2017-10-30 19:25:32 -0700 | [diff] [blame^] | 34 | #if defined(WPILIB2017) || defined(WPILIB2018) |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 35 | HAL_ControlWord control_word; |
| 36 | HAL_GetControlWord(&control_word); |
| 37 | #else |
Brian Silverman | 6f7d5fe | 2015-01-01 15:45:41 -0800 | [diff] [blame] | 38 | HALControlWord control_word; |
| 39 | HALGetControlWord(&control_word); |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 40 | #endif |
Brian Silverman | 6f7d5fe | 2015-01-01 15:45:41 -0800 | [diff] [blame] | 41 | new_state->test_mode = control_word.test; |
| 42 | new_state->fms_attached = control_word.fmsAttached; |
| 43 | new_state->enabled = control_word.enabled; |
| 44 | new_state->autonomous = control_word.autonomous; |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 45 | new_state->team_id = team_id; |
| 46 | new_state->fake = false; |
| 47 | |
| 48 | for (int i = 0; i < 4; ++i) { |
Brian Silverman | 5e23377 | 2015-01-01 13:25:44 -0800 | [diff] [blame] | 49 | new_state->joysticks[i].buttons = ds->GetStickButtons(i); |
Austin Schuh | 4ee6042 | 2017-02-05 16:49:52 -0800 | [diff] [blame] | 50 | for (int j = 0; j < 6; ++j) { |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 51 | new_state->joysticks[i].axis[j] = ds->GetStickAxis(i, j); |
| 52 | } |
Austin Schuh | fee2e60 | 2015-03-08 18:26:05 -0700 | [diff] [blame] | 53 | new_state->joysticks[i].pov = ds->GetStickPOV(i, 0); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 54 | } |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 55 | LOG_STRUCT(DEBUG, "joystick_state", *new_state); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 56 | |
| 57 | if (!new_state.Send()) { |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 58 | LOG(WARNING, "sending joystick_state failed\n"); |
Brian Silverman | da45b6c | 2014-12-28 11:36:50 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | } // namespace wpilib |
| 64 | } // namespace frc971 |