11 #include <condition_variable>
16 #include "HAL/DriverStation.h"
17 #include "HAL/cpp/priority_condition_variable.h"
18 #include "HAL/cpp/priority_mutex.h"
19 #include "RobotState.h"
20 #include "SensorBase.h"
21 #include "llvm/StringRef.h"
31 enum Alliance { kRed, kBlue, kInvalid };
37 static void ReportError(
bool is_error,
int code, llvm::StringRef error,
38 llvm::StringRef location, llvm::StringRef stack);
40 static const int kJoystickPorts = 6;
60 bool IsTest()
const override;
78 void InDisabled(
bool entering) { m_userInDisabled = entering; }
83 void InAutonomous(
bool entering) { m_userInAutonomous = entering; }
92 void InTest(
bool entering) { m_userInTest = entering; }
99 void ReportJoystickUnpluggedError(llvm::StringRef message);
100 void ReportJoystickUnpluggedWarning(llvm::StringRef message);
102 void UpdateControlWord(
bool force,
HAL_ControlWord& controlWord)
const;
105 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
106 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
107 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
108 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
111 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
112 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
113 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
114 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
117 std::thread m_dsThread;
118 std::atomic<bool> m_isRunning{
false};
121 bool m_waitForDataPredicate =
false;
122 std::condition_variable_any m_waitForDataCond;
125 mutable std::atomic<bool> m_newControlData{
false};
130 bool m_userInDisabled =
false;
131 bool m_userInAutonomous =
false;
132 bool m_userInTeleop =
false;
133 bool m_userInTest =
false;
137 mutable std::chrono::steady_clock::time_point m_lastControlWordUpdate;
140 double m_nextMessageTime = 0;
static void ReportError(llvm::StringRef error)
Report an error to the DriverStation messages window.
Definition: DriverStation.cpp:48
int GetStickPOV(int stick, int pov)
Get the state of a POV on the joystick.
Definition: DriverStation.cpp:113
Base class for all sensors.
Definition: SensorBase.h:22
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:88
int GetJoystickType(int stick) const
Returns the type of joystick at a given port.
Definition: DriverStation.cpp:244
int GetStickAxisCount(int stick) const
Returns the number of axes on a given joystick port.
Definition: DriverStation.cpp:184
void GetData()
Copy data from the DS task for the user.
Definition: DriverStation.cpp:540
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:29
int GetStickPOVCount(int stick) const
Returns the number of POVs on a given joystick port.
Definition: DriverStation.cpp:199
int GetStickButtons(int stick) const
The state of the buttons on the joystick.
Definition: DriverStation.cpp:139
bool IsAutonomous() const override
Check if the DS is commanding autonomous mode.
Definition: DriverStation.cpp:310
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:78
static DriverStation & GetInstance()
Return a pointer to the singleton DriverStation.
Definition: DriverStation.cpp:38
bool IsEnabled() const override
Check if the DS has enabled the robot.
Definition: DriverStation.cpp:288
double GetStickAxis(int stick, int axis)
Get the value of the axis on a joystick.
Definition: DriverStation.cpp:87
Definition: priority_mutex.h:53
void WaitForData()
Wait until a new packet comes from the driver station.
Definition: DriverStation.cpp:458
double GetBatteryVoltage() const
Read the battery voltage.
Definition: DriverStation.cpp:526
bool IsNewControlData() const
Has a new control packet from the driver station arrived since the last time this function was called...
Definition: DriverStation.cpp:358
bool IsBrownedOut() const
Check if the system is browned out.
Definition: DriverStation.cpp:394
bool IsTest() const override
Check if the DS is commanding test mode.
Definition: DriverStation.cpp:332
bool GetJoystickIsXbox(int stick) const
Returns a boolean indicating if the controller is an xbox controller.
Definition: DriverStation.cpp:229
bool GetStickButton(int stick, int button)
The state of one joystick button.
Definition: DriverStation.cpp:155
Definition: RobotState.h:14
Alliance GetAlliance() const
Return the alliance that the driver station says it is on.
Definition: DriverStation.cpp:408
int GetStickButtonCount(int stick) const
Returns the number of buttons on a given joystick port.
Definition: DriverStation.cpp:214
bool IsDSAttached() const
Check if the DS is attached.
Definition: DriverStation.cpp:343
bool IsDisabled() const override
Check if the robot is disabled.
Definition: DriverStation.cpp:299
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:92
int GetLocation() const
Return the driver station location on the field.
Definition: DriverStation.cpp:432
std::string GetJoystickName(int stick) const
Returns the name of the joystick at the given port.
Definition: DriverStation.cpp:259
static void ReportWarning(llvm::StringRef error)
Report a warning to the DriverStation messages window.
Definition: DriverStation.cpp:58
Definition: DriverStation.h:31
int GetJoystickAxisType(int stick, int axis) const
Returns the types of Axes on a given joystick port.
Definition: DriverStation.cpp:274
bool IsSysActive() const
Check if the FPGA outputs are enabled.
Definition: DriverStation.cpp:382
double GetMatchTime() const
Return the approximate match time.
Definition: DriverStation.cpp:516
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
bool IsFMSAttached() const
Is the driver station attached to a Field Management System?
Definition: DriverStation.cpp:368
bool IsOperatorControl() const override
Check if the DS is commanding teleop mode.
Definition: DriverStation.cpp:321