blob: af72f7d1af083dd1a60601cfa7b29e04416a590a [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 Silvermancee260a2015-12-24 16:27:51 -08006#include "DriverStation.h"
7#include "ControllerPower.h"
8#undef ERROR
9
Brian Silvermane48dbc12017-02-04 20:06:29 -080010#ifndef WPILIB2017
11namespace frc {
12using ::DriverStation;
13} // namespace frc
14#endif
15
Brian Silverman811f8ec2015-12-06 01:29:42 -050016namespace frc971 {
17namespace wpilib {
18
Brian Silvermane48dbc12017-02-04 20:06:29 -080019void SendRobotState(int32_t my_pid, frc::DriverStation *ds) {
Brian Silverman811f8ec2015-12-06 01:29:42 -050020 auto new_state = ::aos::robot_state.MakeMessage();
21
22 new_state->reader_pid = my_pid;
23 new_state->outputs_enabled = ds->IsSysActive();
Brian Silvermane48dbc12017-02-04 20:06:29 -080024#ifdef WPILIB2017
25 new_state->browned_out = ds->IsBrownedOut();
26#else
Brian Silverman811f8ec2015-12-06 01:29:42 -050027 new_state->browned_out = ds->IsSysBrownedOut();
Brian Silvermane48dbc12017-02-04 20:06:29 -080028#endif
Brian Silverman811f8ec2015-12-06 01:29:42 -050029
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 Silverman811f8ec2015-12-06 01:29:42 -050038 LOG_STRUCT(DEBUG, "robot_state", *new_state);
39
40 new_state.Send();
41}
42
43} // namespace wpilib
44} // namespace frc971