Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 1 | #include "frc971/wpilib/wpilib_interface.h" |
| 2 | |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 3 | #include "aos/common/messages/robot_state.q.h" |
| 4 | #include "aos/common/logging/queue_logging.h" |
| 5 | |
Brian Silverman | cee260a | 2015-12-24 16:27:51 -0800 | [diff] [blame] | 6 | #include "DriverStation.h" |
| 7 | #include "ControllerPower.h" |
| 8 | #undef ERROR |
| 9 | |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame^] | 10 | #ifndef WPILIB2017 |
| 11 | namespace frc { |
| 12 | using ::DriverStation; |
| 13 | } // namespace frc |
| 14 | #endif |
| 15 | |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 16 | namespace frc971 { |
| 17 | namespace wpilib { |
| 18 | |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame^] | 19 | void SendRobotState(int32_t my_pid, frc::DriverStation *ds) { |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 20 | auto new_state = ::aos::robot_state.MakeMessage(); |
| 21 | |
| 22 | new_state->reader_pid = my_pid; |
| 23 | new_state->outputs_enabled = ds->IsSysActive(); |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame^] | 24 | #ifdef WPILIB2017 |
| 25 | new_state->browned_out = ds->IsBrownedOut(); |
| 26 | #else |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 27 | new_state->browned_out = ds->IsSysBrownedOut(); |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame^] | 28 | #endif |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 29 | |
| 30 | new_state->is_3v3_active = ControllerPower::GetEnabled3V3(); |
| 31 | new_state->is_5v_active = ControllerPower::GetEnabled5V(); |
| 32 | new_state->voltage_3v3 = ControllerPower::GetVoltage3V3(); |
| 33 | new_state->voltage_5v = ControllerPower::GetVoltage5V(); |
| 34 | |
| 35 | new_state->voltage_roborio_in = ControllerPower::GetInputVoltage(); |
| 36 | new_state->voltage_battery = ds->GetBatteryVoltage(); |
| 37 | |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 38 | LOG_STRUCT(DEBUG, "robot_state", *new_state); |
| 39 | |
| 40 | new_state.Send(); |
| 41 | } |
| 42 | |
| 43 | } // namespace wpilib |
| 44 | } // namespace frc971 |