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