10 #include "SensorBase.h"
11 #include "RobotState.h"
13 #include "HAL/HAL.hpp"
14 #include "HAL/cpp/Semaphore.hpp"
15 #include "HAL/cpp/priority_mutex.h"
16 #include "HAL/cpp/priority_condition_variable.h"
17 #include <condition_variable>
29 enum Alliance { kRed, kBlue, kInvalid };
35 static void ReportError(
bool is_error, int32_t code,
const std::string& error,
36 const std::string& location,
37 const std::string& stack);
39 static const uint32_t kJoystickPorts = 6;
59 bool IsTest()
const override;
77 void InDisabled(
bool entering) { m_userInDisabled = entering; }
83 void InAutonomous(
bool entering) { m_userInAutonomous = entering; }
94 void InTest(
bool entering) { m_userInTest = entering; }
103 void ReportJoystickUnpluggedError(std::string message);
104 void ReportJoystickUnpluggedWarning(std::string message);
112 std::atomic<bool> m_isRunning{
false};
113 mutable Semaphore m_newControlData{Semaphore::kEmpty};
116 std::condition_variable_any m_waitForDataCond;
118 bool m_userInDisabled =
false;
119 bool m_userInAutonomous =
false;
120 bool m_userInTeleop =
false;
121 bool m_userInTest =
false;
122 double m_nextMessageTime = 0;
void InDisabled(bool entering)
Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purpose...
Definition: DriverStation.h:77
bool IsNewControlData() const
Has a new control packet from the driver station arrived since the last time this function was called...
Definition: DriverStation.cpp:444
static void ReportWarning(std::string error)
Report a warning to the DriverStation messages window.
Definition: DriverStation.cpp:546
bool IsSysActive() const
Check if the FPGA outputs are enabled.
Definition: DriverStation.cpp:419
Definition: Semaphore.hpp:8
int GetStickPOVCount(uint32_t stick) const
Returns the number of POVs on a given joystick port.
Definition: DriverStation.cpp:226
float GetStickAxis(uint32_t stick, uint32_t axis)
Get the value of the axis on a joystick.
Definition: DriverStation.cpp:260
int GetStickPOV(uint32_t stick, uint32_t pov)
Get the state of a POV on the joystick.
Definition: DriverStation.cpp:289
uint32_t GetLocation() const
Return the driver station location on the field This could return 1, 2, or 3.
Definition: DriverStation.cpp:486
bool IsSysBrownedOut() const
Check if the system is browned out.
Definition: DriverStation.cpp:430
static void ReportError(std::string error)
Report an error to the DriverStation messages window.
Definition: DriverStation.cpp:538
void InAutonomous(bool entering)
Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purpose...
Definition: DriverStation.h:83
int GetStickAxisCount(uint32_t stick) const
Returns the number of axes on a given joystick port.
Definition: DriverStation.cpp:154
int GetJoystickAxisType(uint32_t stick, uint8_t axis) const
Returns the types of Axes on a given joystick port.
Definition: DriverStation.cpp:212
Base class for all sensors.
Definition: SensorBase.h:20
bool IsEnabled() const override
Check if the DS has enabled the robot.
Definition: DriverStation.cpp:352
bool IsOperatorControl() const override
Check if the DS is commanding teleop mode.
Definition: DriverStation.cpp:385
Definition: priority_condition_variable.h:23
bool IsDSAttached() const
Check if the DS is attached.
Definition: DriverStation.cpp:406
void GetData()
Copy data from the DS task for the user.
Definition: DriverStation.cpp:100
static DriverStation & GetInstance()
Return a pointer to the singleton DriverStation.
Definition: DriverStation.cpp:90
Definition: RobotState.h:12
Definition: priority_mutex.h:53
uint32_t GetStickButtons(uint32_t stick) const
The state of the buttons on the joystick.
Definition: DriverStation.cpp:313
bool GetStickButton(uint32_t stick, uint8_t button)
The state of one joystick button.
Definition: DriverStation.cpp:329
bool IsAutonomous() const override
Check if the DS is commanding autonomous mode.
Definition: DriverStation.cpp:374
double GetMatchTime() const
Return the approximate match time The FMS does not send an official match time to the robots...
Definition: DriverStation.cpp:528
bool IsTest() const override
Check if the DS is commanding test mode.
Definition: DriverStation.cpp:396
int GetJoystickType(uint32_t stick) const
Returns the type of joystick at a given port.
Definition: DriverStation.cpp:184
void WaitForData()
Wait until a new packet comes from the driver station This blocks on a semaphore, so the waiting is e...
Definition: DriverStation.cpp:510
std::string GetJoystickName(uint32_t stick) const
Returns the name of the joystick at the given port.
Definition: DriverStation.cpp:170
Alliance GetAlliance() const
Return the alliance that the driver station says it is on.
Definition: DriverStation.cpp:464
bool GetJoystickIsXbox(uint32_t stick) const
Returns a boolean indicating if the controller is an xbox controller.
Definition: DriverStation.cpp:198
bool IsFMSAttached() const
Is the driver station attached to a Field Management System?
Definition: DriverStation.cpp:453
void InTest(bool entering)
Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purpose...
Definition: DriverStation.h:94
void InOperatorControl(bool entering)
Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purpose...
Definition: DriverStation.h:89
Wrapper class around std::thread that allows changing thread priority.
Definition: Task.h:19
DriverStation()
DriverStation constructor.
Definition: DriverStation.cpp:35
float GetBatteryVoltage() const
Read the battery voltage.
Definition: DriverStation.cpp:116
int GetStickButtonCount(uint32_t stick) const
Returns the number of buttons on a given joystick port.
Definition: DriverStation.cpp:242
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:27
bool IsDisabled() const override
Check if the robot is disabled.
Definition: DriverStation.cpp:363