WPILibC++ 2025.0.0-alpha-1-9-ga2beb75
DriverStation.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <stddef.h> //NOLINT
10
11#include <wpi/Synchronization.h>
12#include <wpi/string.h>
13
15#include "hal/Types.h"
16
17/**
18 * @defgroup hal_driverstation Driver Station Functions
19 * @ingroup hal_capi
20 * @{
21 */
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * Sends an error to the driver station.
29 *
30 * @param isError true for error, false for warning
31 * @param errorCode the error code
32 * @param isLVCode true for a LV error code, false for a standard error code
33 * @param details the details of the error
34 * @param location the file location of the error
35 * @param callStack the callstack of the error
36 * @param printMsg true to print the error message to stdout as well as to the
37 * DS
38 * @return the error code, or 0 for success
39 */
40int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
41 const char* details, const char* location,
42 const char* callStack, HAL_Bool printMsg);
43
44/**
45 * Set the print function used by HAL_SendError
46 *
47 * @param func Function called by HAL_SendError when stderr is printed
48 */
49void HAL_SetPrintErrorImpl(void (*func)(const char* line, size_t size));
50
51/**
52 * Sends a line to the driver station console.
53 *
54 * @param line the line to send (null terminated)
55 * @return the error code, or 0 for success
56 */
57int32_t HAL_SendConsoleLine(const char* line);
58
59/**
60 * Gets the current control word of the driver station.
61 *
62 * The control word contains the robot state.
63 *
64 * @param controlWord the control word (out)
65 * @return the error code, or 0 for success
66 */
67int32_t HAL_GetControlWord(HAL_ControlWord* controlWord);
68
69/**
70 * Gets the current alliance station ID.
71 *
72 * @param[out] status the error code, or 0 for success
73 * @return the alliance station ID
74 */
76
77/**
78 * Gets the axes of a specific joystick.
79 *
80 * @param joystickNum the joystick number
81 * @param axes the axes values (output)
82 * @return the error code, or 0 for success
83 */
84int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
85
86/**
87 * Gets the POVs of a specific joystick.
88 *
89 * @param joystickNum the joystick number
90 * @param povs the POV values (output)
91 * @return the error code, or 0 for success
92 */
93int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
94
95/**
96 * Gets the buttons of a specific joystick.
97 *
98 * @param joystickNum the joystick number
99 * @param buttons the button values (output)
100 * @return the error code, or 0 for success
101 */
102int32_t HAL_GetJoystickButtons(int32_t joystickNum,
103 HAL_JoystickButtons* buttons);
104
106 HAL_JoystickButtons* buttons);
107
108/**
109 * Retrieves the Joystick Descriptor for particular slot.
110 *
111 * @param joystickNum the joystick number
112 * @param[out] desc descriptor (data transfer object) to fill in. desc is
113 * filled in regardless of success. In other words, if
114 * descriptor is not available, desc is filled in with
115 * default values matching the init-values in Java and C++
116 * Driver Station for when caller requests a too-large
117 * joystick index.
118 * @return error code reported from Network Comm back-end. Zero is good,
119 * nonzero is bad.
120 */
121int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
123
124/**
125 * Gets whether a specific joystick is considered to be an XBox controller.
126 *
127 * @param joystickNum the joystick number
128 * @return true if xbox, false otherwise
129 */
130HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum);
131
132/**
133 * Gets the type of joystick connected.
134 *
135 * This is device specific, and different depending on what system input type
136 * the joystick uses.
137 *
138 * @param joystickNum the joystick number
139 * @return the enumerated joystick type
140 */
141int32_t HAL_GetJoystickType(int32_t joystickNum);
142
143/**
144 * Gets the name of a joystick.
145 *
146 * The returned string must be freed with WPI_FreeString
147 *
148 * @param name the joystick name string
149 * @param joystickNum the joystick number
150 */
151void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum);
152
153/**
154 * Gets the type of a specific joystick axis.
155 *
156 * This is device specific, and different depending on what system input type
157 * the joystick uses.
158 *
159 * @param joystickNum the joystick number
160 * @param axis the axis number
161 * @return the enumerated axis type
162 */
163int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis);
164
165/**
166 * Set joystick outputs.
167 *
168 * @param joystickNum the joystick number
169 * @param outputs bitmask of outputs, 1 for on 0 for off
170 * @param leftRumble the left rumble value (0-FFFF)
171 * @param rightRumble the right rumble value (0-FFFF)
172 * @return the error code, or 0 for success
173 */
174int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
175 int32_t leftRumble, int32_t rightRumble);
176
177/**
178 * Return the approximate match time. The FMS does not send an official match
179 * time to the robots, but does send an approximate match time. The value will
180 * count down the time remaining in the current period (auto or teleop).
181 * Warning: This is not an official time (so it cannot be used to dispute ref
182 * calls or guarantee that a function will trigger before the match ends).
183 *
184 * <p>When connected to the real field, this number only changes in full integer
185 * increments, and always counts down.
186 *
187 * <p>When the DS is in practice mode, this number is a floating point number,
188 * and counts down.
189 *
190 * <p>When the DS is in teleop or autonomous mode, this number is a floating
191 * point number, and counts up.
192 *
193 * <p>Simulation matches DS behavior without an FMS connected.
194 *
195 * @param[out] status the error code, or 0 for success
196 * @return Time remaining in current match period (auto or teleop) in seconds
197 */
198double HAL_GetMatchTime(int32_t* status);
199
200/**
201 * Gets if outputs are enabled by the control system.
202 *
203 * @return true if outputs are enabled
204 */
206
207/**
208 * Gets info about a specific match.
209 *
210 * @param[in] info the match info (output)
211 * @return the error code, or 0 for success
212 */
214
215/**
216 * Refresh the DS control word.
217 *
218 * @return true if updated
219 */
221
224
225/**
226 * Sets the program starting flag in the DS.
227 *
228 * This is what changes the DS to showing robot code ready.
229 */
231
232/**
233 * Sets the disabled flag in the DS.
234 *
235 * This is used for the DS to ensure the robot is properly responding to its
236 * state request. Ensure this gets called about every 50ms, or the robot will be
237 * disabled by the DS.
238 */
240
241/**
242 * Sets the autonomous enabled flag in the DS.
243 *
244 * This is used for the DS to ensure the robot is properly responding to its
245 * state request. Ensure this gets called about every 50ms, or the robot will be
246 * disabled by the DS.
247 */
249
250/**
251 * Sets the teleoperated enabled flag in the DS.
252 *
253 * This is used for the DS to ensure the robot is properly responding to its
254 * state request. Ensure this gets called about every 50ms, or the robot will be
255 * disabled by the DS.
256 */
258
259/**
260 * Sets the test mode flag in the DS.
261 *
262 * This is used for the DS to ensure the robot is properly responding to its
263 * state request. Ensure this gets called about every 50ms, or the robot will be
264 * disabled by the DS.
265 */
267
268#ifdef __cplusplus
269} // extern "C"
270#endif
271/** @} */
WPI_Handle WPI_EventHandle
An event handle.
Definition: Synchronization.h:25
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis)
Gets the type of a specific joystick axis.
HAL_AllianceStationID HAL_GetAllianceStation(int32_t *status)
Gets the current alliance station ID.
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode, const char *details, const char *location, const char *callStack, HAL_Bool printMsg)
Sends an error to the driver station.
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes *axes)
Gets the axes of a specific joystick.
void HAL_GetJoystickName(struct WPI_String *name, int32_t joystickNum)
Gets the name of a joystick.
void HAL_ObserveUserProgramDisabled(void)
Sets the disabled flag in the DS.
int32_t HAL_SendConsoleLine(const char *line)
Sends a line to the driver station console.
void HAL_ObserveUserProgramTeleop(void)
Sets the teleoperated enabled flag in the DS.
void HAL_SetPrintErrorImpl(void(*func)(const char *line, size_t size))
Set the print function used by HAL_SendError.
int32_t HAL_GetControlWord(HAL_ControlWord *controlWord)
Gets the current control word of the driver station.
void HAL_ProvideNewDataEventHandle(WPI_EventHandle handle)
HAL_Bool HAL_RefreshDSData(void)
Refresh the DS control word.
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum, HAL_JoystickDescriptor *desc)
Retrieves the Joystick Descriptor for particular slot.
int32_t HAL_GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons *buttons)
Gets the buttons of a specific joystick.
void HAL_ObserveUserProgramAutonomous(void)
Sets the autonomous enabled flag in the DS.
double HAL_GetMatchTime(int32_t *status)
Return the approximate match time.
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs *povs)
Gets the POVs of a specific joystick.
void HAL_ObserveUserProgramTest(void)
Sets the test mode flag in the DS.
void HAL_ObserveUserProgramStarting(void)
Sets the program starting flag in the DS.
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs, int32_t leftRumble, int32_t rightRumble)
Set joystick outputs.
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum)
Gets whether a specific joystick is considered to be an XBox controller.
int32_t HAL_GetMatchInfo(HAL_MatchInfo *info)
Gets info about a specific match.
HAL_AllianceStationID
Definition: DriverStationTypes.h:43
void HAL_RemoveNewDataEventHandle(WPI_EventHandle handle)
HAL_Bool HAL_GetOutputsEnabled(void)
Gets if outputs are enabled by the control system.
void HAL_GetAllJoystickData(HAL_JoystickAxes *axes, HAL_JoystickPOVs *povs, HAL_JoystickButtons *buttons)
int32_t HAL_GetJoystickType(int32_t joystickNum)
Gets the type of joystick connected.
int32_t HAL_Bool
Definition: Types.h:73
constexpr const char * name(const T &)
Definition: DriverStationTypes.h:32
Definition: DriverStationTypes.h:68
Definition: DriverStationTypes.h:81
Definition: DriverStationTypes.h:87
Definition: DriverStationTypes.h:75
Definition: DriverStationTypes.h:98
A const UTF8 string.
Definition: string.h:14