blob: 2a590194d32ab554a1ea63fcac006fa55c5acbf3 [file] [log] [blame]
Brian Silverman811f8ec2015-12-06 01:29:42 -05001#include "frc971/wpilib/wpilib_interface.h"
2
Alex Perrycb7da4b2019-08-28 19:35:56 -07003#include "aos/events/event_loop.h"
4#include "aos/logging/logging.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07005#include "frc971/input/robot_state_generated.h"
Austin Schuhf6b94632019-02-02 22:11:27 -08006#include "hal/HAL.h"
Brian Silvermane48dbc12017-02-04 20:06:29 -08007
Brian Silverman811f8ec2015-12-06 01:29:42 -05008namespace frc971 {
9namespace wpilib {
10
Alex Perrycb7da4b2019-08-28 19:35:56 -070011flatbuffers::Offset<aos::RobotState> PopulateRobotState(
12 aos::Sender<::aos::RobotState>::Builder *builder, int32_t my_pid) {
Austin Schuh94f51e92017-10-30 19:25:32 -070013 int32_t status = 0;
14
Alex Perrycb7da4b2019-08-28 19:35:56 -070015 aos::RobotState::Builder robot_state_builder =
16 builder->MakeBuilder<aos::RobotState>();
Brian Silverman811f8ec2015-12-06 01:29:42 -050017
Alex Perrycb7da4b2019-08-28 19:35:56 -070018 robot_state_builder.add_reader_pid(my_pid);
19 robot_state_builder.add_outputs_enabled(HAL_GetSystemActive(&status));
20 robot_state_builder.add_browned_out(HAL_GetBrownedOut(&status));
Brian Silverman811f8ec2015-12-06 01:29:42 -050021
Alex Perrycb7da4b2019-08-28 19:35:56 -070022 robot_state_builder.add_is_3v3_active(HAL_GetUserActive3V3(&status));
23 robot_state_builder.add_is_5v_active(HAL_GetUserActive5V(&status));
24 robot_state_builder.add_voltage_3v3(HAL_GetUserVoltage3V3(&status));
25 robot_state_builder.add_voltage_5v(HAL_GetUserVoltage5V(&status));
26
27 robot_state_builder.add_voltage_roborio_in(HAL_GetVinVoltage(&status));
28 robot_state_builder.add_voltage_battery(HAL_GetVinVoltage(&status));
Brian Silverman811f8ec2015-12-06 01:29:42 -050029
Austin Schuhdf6cbb12019-02-02 13:46:52 -080030 if (status != 0) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070031 AOS_LOG(FATAL, "Failed to get robot state: %d\n", status);
Austin Schuhdf6cbb12019-02-02 13:46:52 -080032 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070033
34 return robot_state_builder.Finish();
Brian Silverman811f8ec2015-12-06 01:29:42 -050035}
36
37} // namespace wpilib
38} // namespace frc971