WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
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 <stddef.h>
8#include <stdint.h>
9
11#include "wpi/hal/Types.h"
13#include "wpi/util/string.h"
14
15/**
16 * @defgroup hal_driverstation Driver Station Functions
17 * @ingroup hal_capi
18 * @{
19 */
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/**
26 * Sends an error to the driver station.
27 *
28 * @param isError true for error, false for warning
29 * @param errorCode the error code
30 * @param isLVCode true for a LV error code, false for a standard error code
31 * @param details the details of the error
32 * @param location the file location of the error
33 * @param callStack the callstack of the error
34 * @param printMsg true to print the error message to stdout as well as to the
35 * DS
36 * @return the error code, or 0 for success
37 */
38int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
39 const char* details, const char* location,
40 const char* callStack, HAL_Bool printMsg);
41
42/**
43 * Set the print function used by HAL_SendError
44 *
45 * @param func Function called by HAL_SendError when stderr is printed
46 */
47void HAL_SetPrintErrorImpl(void (*func)(const char* line, size_t size));
48
49/**
50 * Sends a line to the driver station console.
51 *
52 * @param line the line to send (null terminated)
53 * @return the error code, or 0 for success
54 */
55int32_t HAL_SendConsoleLine(const char* line);
56
57/**
58 * Gets the current control word of the driver station.
59 *
60 * The control word contains the robot state.
61 *
62 * @param controlWord the control word (out)
63 * @return the error code, or 0 for success
64 */
65int32_t HAL_GetControlWord(HAL_ControlWord* controlWord);
66
67/**
68 * Gets the current control word of the driver station. Unlike
69 * HAL_GetControlWord, this function gets the latest value rather than using the
70 * value cached by HAL_RefreshDSData().
71 *
72 * The control word contains the robot state.
73 *
74 * @param controlWord the control word (out)
75 * @return the error code, or 0 for success
76 */
78
79/**
80 * Sets operating mode options.
81 *
82 * @param options array of operating mode options
83 * @param count number of options in the array
84 * @return the error code, or 0 for success
85 */
86int32_t HAL_SetOpModeOptions(const struct HAL_OpModeOption* options,
87 int32_t count);
88
89/**
90 * Gets the current alliance station ID.
91 *
92 * @param[out] status the error code, or 0 for success
93 * @return the alliance station ID
94 */
96
97/**
98 * Gets the axes of a specific joystick.
99 *
100 * @param joystickNum the joystick number
101 * @param axes the axes values (output)
102 * @return the error code, or 0 for success
103 */
104int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
105
106/**
107 * Gets the POVs of a specific joystick.
108 *
109 * @param joystickNum the joystick number
110 * @param povs the POV values (output)
111 * @return the error code, or 0 for success
112 */
113int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
114
115/**
116 * Gets the buttons of a specific joystick.
117 *
118 * @param joystickNum the joystick number
119 * @param buttons the button values (output)
120 * @return the error code, or 0 for success
121 */
122int32_t HAL_GetJoystickButtons(int32_t joystickNum,
123 HAL_JoystickButtons* buttons);
124
125/**
126 * Gets the touchpads of a specific joystick.
127 * @param joystickNum the joystick number
128 * @param touchpads the touchpad values (output)
129 * @return the error code, or 0 for success
130 */
131int32_t HAL_GetJoystickTouchpads(int32_t joystickNum,
132 HAL_JoystickTouchpads* touchpads);
133
134/**
135 * Gets all the data of a specific joystick.
136 *
137 * @param joystickNum the joystick number
138 * @param axes the axes values (output)
139 * @param povs the POV values (output)
140 * @param buttons the button values (output)
141 * @param touchpads the touchpad values (output)
142 */
143void HAL_GetAllJoystickData(int32_t joystickNum, HAL_JoystickAxes* axes,
144 HAL_JoystickPOVs* povs,
145 HAL_JoystickButtons* buttons,
146 HAL_JoystickTouchpads* touchpads);
147
148/**
149 * Retrieves the Joystick Descriptor for particular slot.
150 *
151 * @param joystickNum the joystick number
152 * @param[out] desc descriptor (data transfer object) to fill in. desc is
153 * filled in regardless of success. In other words, if
154 * descriptor is not available, desc is filled in with
155 * default values matching the init-values in Java and C++
156 * Driver Station for when caller requests a too-large
157 * joystick index.
158 * @return error code reported from Network Comm back-end. Zero is good,
159 * nonzero is bad.
160 */
161int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
163
164/**
165 * Gets whether a specific joystick is considered to be an Gamepad.
166 *
167 * @param joystickNum the joystick number
168 * @return true if gamepad, false otherwise
169 */
171
172/**
173 * Gets the type of joystick connected.
174 *
175 * This maps to SDL_GamepadType
176 *
177 * @param joystickNum the joystick number
178 * @return the enumerated gamepad type
179 */
180int32_t HAL_GetJoystickGamepadType(int32_t joystickNum);
181
182/**
183 * Gets the game-specific message for the current match.
184 *
185 * @param gameData the game-specific message (output)
186 * @return the error code, or 0 for success
187 */
188int32_t HAL_GetGameData(HAL_GameData* gameData);
189
190/**
191 * Gets the supported outputs of a specific joystick.
192 *
193 * @param joystickNum the joystick number
194 * @return bitmask of supported outputs
195 */
196int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum);
197
198/**
199 * Gets the name of a joystick.
200 *
201 * The returned string must be freed with WPI_FreeString
202 *
203 * @param name the joystick name string
204 * @param joystickNum the joystick number
205 */
206void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum);
207
208/**
209 * Set joystick rumbles.
210 *
211 * @param joystickNum the joystick number
212 * @param leftRumble the left rumble value (0-FFFF)
213 * @param rightRumble the right rumble value (0-FFFF)
214 * @param leftTriggerRumble the left trigger rumble value (0-FFFF)
215 * @param rightTriggerRumble the right trigger rumble value (0-FFFF)
216 * @return the error code, or 0 for success
217 */
218int32_t HAL_SetJoystickRumble(int32_t joystickNum, int32_t leftRumble,
219 int32_t rightRumble, int32_t leftTriggerRumble,
220 int32_t rightTriggerRumble);
221
222/**
223 * Set joystick LEDs.
224 * @param joystickNum the joystick number
225 * @param leds the rgb led color value (0xRRGGBB)
226 * @return the error code, or 0 for success
227 */
228int32_t HAL_SetJoystickLeds(int32_t joystickNum, int32_t leds);
229
230/**
231 * Return the approximate match time. The FMS does not send an official match
232 * time to the robots, but does send an approximate match time. The value will
233 * count down the time remaining in the current period (auto or teleop).
234 * Warning: This is not an official time (so it cannot be used to dispute ref
235 * calls or guarantee that a function will trigger before the match ends).
236 *
237 * <p>When connected to the real field, this number only changes in full integer
238 * increments, and always counts down.
239 *
240 * <p>When the DS is in practice mode, this number is a floating point number,
241 * and counts down.
242 *
243 * <p>When the DS is in teleop or autonomous mode, this number returns -1.0.
244 *
245 * <p>Simulation matches DS behavior without an FMS connected.
246 *
247 * @param[out] status the error code, or 0 for success
248 * @return Time remaining in current match period (auto or teleop) in seconds
249 */
250double HAL_GetMatchTime(int32_t* status);
251
252/**
253 * Gets if outputs are enabled by the control system.
254 *
255 * @return true if outputs are enabled
256 */
258
259/**
260 * Gets info about a specific match.
261 *
262 * @param[in] info the match info (output)
263 * @return the error code, or 0 for success
264 */
266
267/**
268 * Refresh the DS control word.
269 *
270 * @return true if updated
271 */
273
274/**
275 * Adds an event handle to be signalled when new data arrives.
276 *
277 * @param handle the event handle to be signalled
278 */
280
281/**
282 * Removes the event handle from being signalled when new data arrives.
283 *
284 * @param handle the event handle to remove
285 */
287
288/**
289 * Sets the program starting flag in the DS.
290 *
291 * This is what changes the DS to showing robot code ready.
292 */
294
295/**
296 * Sets the control word state returned to the DS.
297 *
298 * This is used for the DS to ensure the robot is properly responding to its
299 * state request. Ensure this gets called about every 50ms, or the robot will be
300 * disabled by the DS.
301 *
302 * @param word control word returned by HAL_GetControlWord
303 */
305
306#ifdef __cplusplus
307} // extern "C"
308#endif
309/** @} */
WPI_Handle WPI_EventHandle
An event handle.
Definition Synchronization.h:18
@ name
Definition base.h:690
int32_t HAL_GetUncachedControlWord(HAL_ControlWord *controlWord)
Gets the current control word of the driver station.
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_SetJoystickRumble(int32_t joystickNum, int32_t leftRumble, int32_t rightRumble, int32_t leftTriggerRumble, int32_t rightTriggerRumble)
Set joystick rumbles.
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.
int32_t HAL_SetJoystickLeds(int32_t joystickNum, int32_t leds)
Set joystick LEDs.
int32_t HAL_SendConsoleLine(const char *line)
Sends a line to the driver station console.
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.
int32_t HAL_GetJoystickGamepadType(int32_t joystickNum)
Gets the type of joystick connected.
void HAL_ProvideNewDataEventHandle(WPI_EventHandle handle)
Adds an event handle to be signalled when new data arrives.
int32_t HAL_GetGameData(HAL_GameData *gameData)
Gets the game-specific message for the current match.
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.
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_GetAllJoystickData(int32_t joystickNum, HAL_JoystickAxes *axes, HAL_JoystickPOVs *povs, HAL_JoystickButtons *buttons, HAL_JoystickTouchpads *touchpads)
Gets all the data of a specific joystick.
void HAL_ObserveUserProgramStarting(void)
Sets the program starting flag in the DS.
HAL_Bool HAL_GetJoystickIsGamepad(int32_t joystickNum)
Gets whether a specific joystick is considered to be an Gamepad.
int32_t HAL_GetJoystickTouchpads(int32_t joystickNum, HAL_JoystickTouchpads *touchpads)
Gets the touchpads of a specific joystick.
int32_t HAL_GetMatchInfo(HAL_MatchInfo *info)
Gets info about a specific match.
HAL_AllianceStationID
Definition DriverStationTypes.h:31
int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum)
Gets the supported outputs of a specific joystick.
void HAL_RemoveNewDataEventHandle(WPI_EventHandle handle)
Removes the event handle from being signalled when new data arrives.
int32_t HAL_SetOpModeOptions(const struct HAL_OpModeOption *options, int32_t count)
Sets operating mode options.
void HAL_ObserveUserProgram(HAL_ControlWord word)
Sets the control word state returned to the DS.
HAL_Bool HAL_GetOutputsEnabled(void)
Gets if outputs are enabled by the control system.
int32_t HAL_Bool
Definition Types.h:75
Definition DriverStationTypes.h:26
Definition DriverStationTypes.h:152
Definition DriverStationTypes.h:93
Definition DriverStationTypes.h:127
Definition DriverStationTypes.h:157
Definition DriverStationTypes.h:121
Definition DriverStationTypes.h:146
Definition DriverStationTypes.h:165
Definition DriverStationTypes.h:177
A const UTF8 string.
Definition string.h:12