WPILibC++ 2024.3.2
DriverStationSim.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 <memory>
8
10
11#include "frc/DriverStation.h"
13
14namespace frc::sim {
15
16/**
17 * Class to control a simulated driver station.
18 */
20 public:
21 /**
22 * Register a callback on whether the DS is enabled.
23 *
24 * @param callback the callback that will be called whenever the enabled
25 * state is changed
26 * @param initialNotify if true, the callback will be run on the initial value
27 * @return the CallbackStore object associated with this callback
28 */
29 [[nodiscard]]
30 static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
31 NotifyCallback callback, bool initialNotify);
32
33 /**
34 * Check if the DS is enabled.
35 *
36 * @return true if enabled
37 */
38 static bool GetEnabled();
39
40 /**
41 * Change whether the DS is enabled.
42 *
43 * @param enabled the new value
44 */
45 static void SetEnabled(bool enabled);
46
47 /**
48 * Register a callback on whether the DS is in autonomous mode.
49 *
50 * @param callback the callback that will be called on autonomous mode
51 * entrance/exit
52 * @param initialNotify if true, the callback will be run on the initial value
53 * @return the CallbackStore object associated with this callback
54 */
55 [[nodiscard]]
56 static std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
57 NotifyCallback callback, bool initialNotify);
58
59 /**
60 * Check if the DS is in autonomous.
61 *
62 * @return true if autonomous
63 */
64 static bool GetAutonomous();
65
66 /**
67 * Change whether the DS is in autonomous.
68 *
69 * @param autonomous the new value
70 */
71 static void SetAutonomous(bool autonomous);
72
73 /**
74 * Register a callback on whether the DS is in test mode.
75 *
76 * @param callback the callback that will be called whenever the test mode
77 * is entered or left
78 * @param initialNotify if true, the callback will be run on the initial value
79 * @return the CallbackStore object associated with this callback
80 */
81 [[nodiscard]]
82 static std::unique_ptr<CallbackStore> RegisterTestCallback(
83 NotifyCallback callback, bool initialNotify);
84
85 /**
86 * Check if the DS is in test.
87 *
88 * @return true if test
89 */
90 static bool GetTest();
91
92 /**
93 * Change whether the DS is in test.
94 *
95 * @param test the new value
96 */
97 static void SetTest(bool test);
98
99 /**
100 * Register a callback on the eStop state.
101 *
102 * @param callback the callback that will be called whenever the eStop state
103 * changes
104 * @param initialNotify if true, the callback will be run on the initial value
105 * @return the CallbackStore object associated with this callback
106 */
107 [[nodiscard]]
108 static std::unique_ptr<CallbackStore> RegisterEStopCallback(
109 NotifyCallback callback, bool initialNotify);
110
111 /**
112 * Check if eStop has been activated.
113 *
114 * @return true if eStopped
115 */
116 static bool GetEStop();
117
118 /**
119 * Set whether eStop is active.
120 *
121 * @param eStop true to activate
122 */
123 static void SetEStop(bool eStop);
124
125 /**
126 * Register a callback on whether the FMS is connected.
127 *
128 * @param callback the callback that will be called whenever the FMS
129 * connection changes
130 * @param initialNotify if true, the callback will be run on the initial value
131 * @return the CallbackStore object associated with this callback
132 */
133 [[nodiscard]]
134 static std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
135 NotifyCallback callback, bool initialNotify);
136
137 /**
138 * Check if the FMS is connected.
139 *
140 * @return true if FMS is connected
141 */
142 static bool GetFmsAttached();
143
144 /**
145 * Change whether the FMS is connected.
146 *
147 * @param fmsAttached the new value
148 */
149 static void SetFmsAttached(bool fmsAttached);
150
151 /**
152 * Register a callback on whether the DS is connected.
153 *
154 * @param callback the callback that will be called whenever the DS
155 * connection changes
156 * @param initialNotify if true, the callback will be run on the initial value
157 * @return the CallbackStore object associated with this callback
158 */
159 [[nodiscard]]
160 static std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
161 NotifyCallback callback, bool initialNotify);
162
163 /**
164 * Check if the DS is attached.
165 *
166 * @return true if attached
167 */
168 static bool GetDsAttached();
169
170 /**
171 * Change whether the DS is attached.
172 *
173 * @param dsAttached the new value
174 */
175 static void SetDsAttached(bool dsAttached);
176
177 /**
178 * Register a callback on the alliance station ID.
179 *
180 * @param callback the callback that will be called whenever the alliance
181 * station changes
182 * @param initialNotify if true, the callback will be run on the initial value
183 * @return the CallbackStore object associated with this callback
184 */
185 [[nodiscard]]
186 static std::unique_ptr<CallbackStore> RegisterAllianceStationIdCallback(
187 NotifyCallback callback, bool initialNotify);
188
189 /**
190 * Get the alliance station ID (color + number).
191 *
192 * @return the alliance station color and number
193 */
195
196 /**
197 * Change the alliance station.
198 *
199 * @param allianceStationId the new alliance station
200 */
201 static void SetAllianceStationId(HAL_AllianceStationID allianceStationId);
202
203 /**
204 * Register a callback on match time.
205 *
206 * @param callback the callback that will be called whenever match time
207 * changes
208 * @param initialNotify if true, the callback will be run on the initial value
209 * @return the CallbackStore object associated with this callback
210 */
211 [[nodiscard]]
212 static std::unique_ptr<CallbackStore> RegisterMatchTimeCallback(
213 NotifyCallback callback, bool initialNotify);
214
215 /**
216 * Get the current value of the match timer.
217 *
218 * @return the current match time
219 */
220 static double GetMatchTime();
221
222 /**
223 * Sets the match timer.
224 *
225 * @param matchTime the new match time
226 */
227 static void SetMatchTime(double matchTime);
228
229 /**
230 * Updates DriverStation data so that new values are visible to the user
231 * program.
232 */
233 static void NotifyNewData();
234
235 /**
236 * Sets suppression of DriverStation::ReportError and ReportWarning messages.
237 *
238 * @param shouldSend If false then messages will be suppressed.
239 */
240 static void SetSendError(bool shouldSend);
241
242 /**
243 * Sets suppression of DriverStation::SendConsoleLine messages.
244 *
245 * @param shouldSend If false then messages will be suppressed.
246 */
247 static void SetSendConsoleLine(bool shouldSend);
248
249 /**
250 * Gets the joystick outputs.
251 *
252 * @param stick The joystick number
253 * @return The joystick outputs
254 */
255 static int64_t GetJoystickOutputs(int stick);
256
257 /**
258 * Gets the joystick rumble.
259 *
260 * @param stick The joystick number
261 * @param rumbleNum Rumble to get (0=left, 1=right)
262 * @return The joystick rumble value
263 */
264 static int GetJoystickRumble(int stick, int rumbleNum);
265
266 /**
267 * Sets the state of one joystick button. %Button indexes begin at 1.
268 *
269 * @param stick The joystick number
270 * @param button The button index, beginning at 1
271 * @param state The state of the joystick button
272 */
273 static void SetJoystickButton(int stick, int button, bool state);
274
275 /**
276 * Gets the value of the axis on a joystick.
277 *
278 * @param stick The joystick number
279 * @param axis The analog axis number
280 * @param value The value of the axis on the joystick
281 */
282 static void SetJoystickAxis(int stick, int axis, double value);
283
284 /**
285 * Gets the state of a POV on a joystick.
286 *
287 * @param stick The joystick number
288 * @param pov The POV number
289 * @param value the angle of the POV in degrees, or -1 for not pressed
290 */
291 static void SetJoystickPOV(int stick, int pov, int value);
292
293 /**
294 * Sets the state of all the buttons on a joystick.
295 *
296 * @param stick The joystick number
297 * @param buttons The bitmap state of the buttons on the joystick
298 */
299 static void SetJoystickButtons(int stick, uint32_t buttons);
300
301 /**
302 * Sets the number of axes for a joystick.
303 *
304 * @param stick The joystick number
305 * @param count The number of axes on the indicated joystick
306 */
307 static void SetJoystickAxisCount(int stick, int count);
308
309 /**
310 * Sets the number of POVs for a joystick.
311 *
312 * @param stick The joystick number
313 * @param count The number of POVs on the indicated joystick
314 */
315 static void SetJoystickPOVCount(int stick, int count);
316
317 /**
318 * Sets the number of buttons for a joystick.
319 *
320 * @param stick The joystick number
321 * @param count The number of buttons on the indicated joystick
322 */
323 static void SetJoystickButtonCount(int stick, int count);
324
325 /**
326 * Sets the value of isXbox for a joystick.
327 *
328 * @param stick The joystick number
329 * @param isXbox The value of isXbox
330 */
331 static void SetJoystickIsXbox(int stick, bool isXbox);
332
333 /**
334 * Sets the value of type for a joystick.
335 *
336 * @param stick The joystick number
337 * @param type The value of type
338 */
339 static void SetJoystickType(int stick, int type);
340
341 /**
342 * Sets the name of a joystick.
343 *
344 * @param stick The joystick number
345 * @param name The value of name
346 */
347 static void SetJoystickName(int stick, std::string_view name);
348
349 /**
350 * Sets the types of Axes for a joystick.
351 *
352 * @param stick The joystick number
353 * @param axis The target axis
354 * @param type The type of axis
355 */
356 static void SetJoystickAxisType(int stick, int axis, int type);
357
358 /**
359 * Sets the game specific message.
360 *
361 * @param message the game specific message
362 */
364
365 /**
366 * Sets the event name.
367 *
368 * @param name the event name
369 */
371
372 /**
373 * Sets the match type.
374 *
375 * @param type the match type
376 */
378
379 /**
380 * Sets the match number.
381 *
382 * @param matchNumber the match number
383 */
384 static void SetMatchNumber(int matchNumber);
385
386 /**
387 * Sets the replay number.
388 *
389 * @param replayNumber the replay number
390 */
391 static void SetReplayNumber(int replayNumber);
392
393 /**
394 * Reset all simulation data for the Driver Station.
395 */
396 static void ResetData();
397};
398} // namespace frc::sim
MatchType
The type of robot match that the robot is part of.
Definition: DriverStation.h:38
Class to control a simulated driver station.
Definition: DriverStationSim.h:19
static double GetMatchTime()
Get the current value of the match timer.
static void SetJoystickButton(int stick, int button, bool state)
Sets the state of one joystick button.
static std::unique_ptr< CallbackStore > RegisterEStopCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the eStop state.
static void SetDsAttached(bool dsAttached)
Change whether the DS is attached.
static void SetAllianceStationId(HAL_AllianceStationID allianceStationId)
Change the alliance station.
static std::unique_ptr< CallbackStore > RegisterFmsAttachedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the FMS is connected.
static void SetEventName(std::string_view name)
Sets the event name.
static void SetSendError(bool shouldSend)
Sets suppression of DriverStation::ReportError and ReportWarning messages.
static std::unique_ptr< CallbackStore > RegisterMatchTimeCallback(NotifyCallback callback, bool initialNotify)
Register a callback on match time.
static void SetJoystickAxisCount(int stick, int count)
Sets the number of axes for a joystick.
static void SetEnabled(bool enabled)
Change whether the DS is enabled.
static void SetMatchType(DriverStation::MatchType type)
Sets the match type.
static bool GetFmsAttached()
Check if the FMS is connected.
static std::unique_ptr< CallbackStore > RegisterTestCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the DS is in test mode.
static void SetReplayNumber(int replayNumber)
Sets the replay number.
static bool GetDsAttached()
Check if the DS is attached.
static std::unique_ptr< CallbackStore > RegisterAutonomousCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the DS is in autonomous mode.
static std::unique_ptr< CallbackStore > RegisterDsAttachedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the DS is connected.
static void SetMatchTime(double matchTime)
Sets the match timer.
static void SetGameSpecificMessage(std::string_view message)
Sets the game specific message.
static void SetSendConsoleLine(bool shouldSend)
Sets suppression of DriverStation::SendConsoleLine messages.
static std::unique_ptr< CallbackStore > RegisterAllianceStationIdCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the alliance station ID.
static std::unique_ptr< CallbackStore > RegisterEnabledCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the DS is enabled.
static void SetAutonomous(bool autonomous)
Change whether the DS is in autonomous.
static bool GetEStop()
Check if eStop has been activated.
static void SetEStop(bool eStop)
Set whether eStop is active.
static void SetJoystickType(int stick, int type)
Sets the value of type for a joystick.
static void SetMatchNumber(int matchNumber)
Sets the match number.
static int GetJoystickRumble(int stick, int rumbleNum)
Gets the joystick rumble.
static void SetJoystickIsXbox(int stick, bool isXbox)
Sets the value of isXbox for a joystick.
static void SetJoystickButtons(int stick, uint32_t buttons)
Sets the state of all the buttons on a joystick.
static void SetTest(bool test)
Change whether the DS is in test.
static HAL_AllianceStationID GetAllianceStationId()
Get the alliance station ID (color + number).
static void SetJoystickAxis(int stick, int axis, double value)
Gets the value of the axis on a joystick.
static void SetJoystickButtonCount(int stick, int count)
Sets the number of buttons for a joystick.
static void NotifyNewData()
Updates DriverStation data so that new values are visible to the user program.
static void SetFmsAttached(bool fmsAttached)
Change whether the FMS is connected.
static void SetJoystickPOV(int stick, int pov, int value)
Gets the state of a POV on a joystick.
static bool GetAutonomous()
Check if the DS is in autonomous.
static int64_t GetJoystickOutputs(int stick)
Gets the joystick outputs.
static void SetJoystickAxisType(int stick, int axis, int type)
Sets the types of Axes for a joystick.
static bool GetEnabled()
Check if the DS is enabled.
static bool GetTest()
Check if the DS is in test.
static void ResetData()
Reset all simulation data for the Driver Station.
static void SetJoystickName(int stick, std::string_view name)
Sets the name of a joystick.
static void SetJoystickPOVCount(int stick, int count)
Sets the number of POVs for a joystick.
basic_string_view< char > string_view
Definition: core.h:501
HAL_AllianceStationID
Definition: DriverStationTypes.h:43
constexpr auto count() -> size_t
Definition: core.h:1203
state
Definition: core.h:2271
type
Definition: core.h:556
Definition: XboxControllerSim.h:13
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14