Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 1 | #include "frc971/wpilib/wpilib_interface.h" |
| 2 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 3 | #include "aos/events/event_loop.h" |
| 4 | #include "aos/logging/logging.h" |
| 5 | #include "aos/robot_state/robot_state_generated.h" |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 6 | |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 7 | #include "hal/HAL.h" |
Brian Silverman | e48dbc1 | 2017-02-04 20:06:29 -0800 | [diff] [blame] | 8 | |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 9 | namespace frc971 { |
| 10 | namespace wpilib { |
| 11 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 12 | flatbuffers::Offset<aos::RobotState> PopulateRobotState( |
| 13 | aos::Sender<::aos::RobotState>::Builder *builder, int32_t my_pid) { |
Austin Schuh | 94f51e9 | 2017-10-30 19:25:32 -0700 | [diff] [blame] | 14 | int32_t status = 0; |
| 15 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 16 | aos::RobotState::Builder robot_state_builder = |
| 17 | builder->MakeBuilder<aos::RobotState>(); |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 18 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 19 | robot_state_builder.add_reader_pid(my_pid); |
| 20 | robot_state_builder.add_outputs_enabled(HAL_GetSystemActive(&status)); |
| 21 | robot_state_builder.add_browned_out(HAL_GetBrownedOut(&status)); |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 22 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 23 | robot_state_builder.add_is_3v3_active(HAL_GetUserActive3V3(&status)); |
| 24 | robot_state_builder.add_is_5v_active(HAL_GetUserActive5V(&status)); |
| 25 | robot_state_builder.add_voltage_3v3(HAL_GetUserVoltage3V3(&status)); |
| 26 | robot_state_builder.add_voltage_5v(HAL_GetUserVoltage5V(&status)); |
| 27 | |
| 28 | robot_state_builder.add_voltage_roborio_in(HAL_GetVinVoltage(&status)); |
| 29 | robot_state_builder.add_voltage_battery(HAL_GetVinVoltage(&status)); |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 30 | |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 31 | if (status != 0) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 32 | AOS_LOG(FATAL, "Failed to get robot state: %d\n", status); |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 33 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 34 | |
| 35 | return robot_state_builder.Finish(); |
Brian Silverman | 811f8ec | 2015-12-06 01:29:42 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | } // namespace wpilib |
| 39 | } // namespace frc971 |