blob: 8d67cf05b97bb75dc3876caf3dfaa515a0d9776c [file] [log] [blame]
Brian Silverman811f8ec2015-12-06 01:29:42 -05001#include "frc971/wpilib/wpilib_interface.h"
2
Brian Silverman811f8ec2015-12-06 01:29:42 -05003#include "aos/common/messages/robot_state.q.h"
4#include "aos/common/logging/queue_logging.h"
5
Brian Silverman425492b2015-12-30 15:23:55 -08006#include "frc971/wpilib/pdp_fetcher.h"
7
Brian Silvermancee260a2015-12-24 16:27:51 -08008#include "DriverStation.h"
9#include "ControllerPower.h"
10#undef ERROR
11
Brian Silverman811f8ec2015-12-06 01:29:42 -050012namespace frc971 {
13namespace wpilib {
14
Brian Silvermanc7e8fdd2015-12-06 02:48:27 -050015void SendRobotState(int32_t my_pid, DriverStation *ds,
Brian Silverman425492b2015-12-30 15:23:55 -080016 PDPFetcher *pdp_fetcher) {
Brian Silverman811f8ec2015-12-06 01:29:42 -050017 auto new_state = ::aos::robot_state.MakeMessage();
18
19 new_state->reader_pid = my_pid;
20 new_state->outputs_enabled = ds->IsSysActive();
21 new_state->browned_out = ds->IsSysBrownedOut();
22
23 new_state->is_3v3_active = ControllerPower::GetEnabled3V3();
24 new_state->is_5v_active = ControllerPower::GetEnabled5V();
25 new_state->voltage_3v3 = ControllerPower::GetVoltage3V3();
26 new_state->voltage_5v = ControllerPower::GetVoltage5V();
27
28 new_state->voltage_roborio_in = ControllerPower::GetInputVoltage();
29 new_state->voltage_battery = ds->GetBatteryVoltage();
30
Brian Silverman1fa98372016-01-01 13:42:17 -080031 if (pdp_fetcher) {
32 pdp_fetcher->GetValues(&new_state->pdp);
33 }
Brian Silvermanc7e8fdd2015-12-06 02:48:27 -050034
Brian Silverman811f8ec2015-12-06 01:29:42 -050035 LOG_STRUCT(DEBUG, "robot_state", *new_state);
36
37 new_state.Send();
38}
39
40} // namespace wpilib
41} // namespace frc971