WPILibC++ 2024.3.2
StadiaController.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 "frc/GenericHID.h"
8
9namespace frc {
10
11/**
12 * Handle input from Stadia controllers connected to the Driver
13 * Station.
14 *
15 * This class handles Stadia input that comes from the Driver Station. Each time
16 * a value is requested the most recent value is returned. There is a single
17 * class instance for each controller and the mapping of ports to hardware
18 * buttons depends on the code in the Driver Station.
19 */
21 public:
22 /**
23 * Construct an instance of a Stadia controller.
24 *
25 * The controller index is the USB port on the Driver Station.
26 *
27 * @param port The port on the Driver Station that the controller is plugged
28 * into (0-5).
29 */
30 explicit StadiaController(int port);
31
32 ~StadiaController() override = default;
33
36
37 /**
38 * Get the X axis value of left side of the controller.
39 *
40 * @return the axis value
41 */
42 double GetLeftX() const;
43
44 /**
45 * Get the X axis value of right side of the controller.
46 *
47 * @return the axis value
48 */
49 double GetRightX() const;
50
51 /**
52 * Get the Y axis value of left side of the controller.
53 *
54 * @return the axis value
55 */
56 double GetLeftY() const;
57
58 /**
59 * Get the Y axis value of right side of the controller.
60 *
61 * @return the axis value
62 */
63 double GetRightY() const;
64
65 /**
66 * Read the value of the left bumper (LB) button on the controller.
67 *
68 * @return the state of the button
69 */
70 bool GetLeftBumper() const;
71
72 /**
73 * Read the value of the right bumper (RB) button on the controller.
74 *
75 * @return the state of the button
76 */
77 bool GetRightBumper() const;
78
79 /**
80 * Whether the left bumper (LB) was pressed since the last check.
81 *
82 * @return Whether the button was pressed since the last check
83 */
85
86 /**
87 * Whether the right bumper (RB) was pressed since the last check.
88 *
89 * @return Whether the button was pressed since the last check
90 */
92
93 /**
94 * Whether the left bumper (LB) was released since the last check.
95 *
96 * @return Whether the button was released since the last check.
97 */
99
100 /**
101 * Whether the right bumper (RB) was released since the last check.
102 *
103 * @return Whether the button was released since the last check.
104 */
106
107 /**
108 * Constructs an event instance around the left bumper's digital signal.
109 *
110 * @param loop the event loop instance to attach the event to.
111 * @return an event instance representing the left bumper's digital signal
112 * attached to the given loop.
113 */
115
116 /**
117 * Constructs an event instance around the right bumper's digital signal.
118 *
119 * @param loop the event loop instance to attach the event to.
120 * @return an event instance representing the right bumper's digital signal
121 * attached to the given loop.
122 */
124
125 /**
126 * Read the value of the left stick button (LSB) on the controller.
127 *
128 * @return the state of the button
129 */
130 bool GetLeftStickButton() const;
131
132 /**
133 * Read the value of the right stick button (RSB) on the controller.
134 *
135 * @return the state of the button
136 */
138
139 /**
140 * Whether the left stick button (LSB) was pressed since the last check.
141 *
142 * @return Whether the button was pressed since the last check.
143 */
145
146 /**
147 * Whether the right stick button (RSB) was pressed since the last check.
148 *
149 * @return Whether the button was pressed since the last check
150 */
152
153 /**
154 * Whether the left stick button (LSB) was released since the last check.
155 *
156 * @return Whether the button was released since the last check.
157 */
159
160 /**
161 * Whether the right stick button (RSB) was released since the last check.
162 *
163 * @return Whether the button was released since the last check.
164 */
166
167 /**
168 * Constructs an event instance around the left stick's digital signal.
169 *
170 * @param loop the event loop instance to attach the event to.
171 * @return an event instance representing the left stick's digital signal
172 * attached to the given loop.
173 */
175
176 /**
177 * Constructs an event instance around the right stick's digital signal.
178 *
179 * @param loop the event loop instance to attach the event to.
180 * @return an event instance representing the right stick's digital signal
181 * attached to the given loop.
182 */
184
185 /**
186 * Read the value of the A button on the controller.
187 *
188 * @return The state of the button.
189 */
190 bool GetAButton() const;
191
192 /**
193 * Whether the A button was pressed since the last check.
194 *
195 * @return Whether the button was pressed since the last check.
196 */
198
199 /**
200 * Whether the A button was released since the last check.
201 *
202 * @return Whether the button was released since the last check.
203 */
205
206 /**
207 * Constructs an event instance around the A button's digital signal.
208 *
209 * @param loop the event loop instance to attach the event to.
210 * @return an event instance representing the A button's digital signal
211 * attached to the given loop.
212 */
214
215 /**
216 * Read the value of the B button on the controller.
217 *
218 * @return The state of the button.
219 */
220 bool GetBButton() const;
221
222 /**
223 * Whether the B button was pressed since the last check.
224 *
225 * @return Whether the button was pressed since the last check.
226 */
228
229 /**
230 * Whether the B button was released since the last check.
231 *
232 * @return Whether the button was released since the last check.
233 */
235
236 /**
237 * Constructs an event instance around the B button's digital signal.
238 *
239 * @param loop the event loop instance to attach the event to.
240 * @return an event instance representing the B button's digital signal
241 * attached to the given loop.
242 */
244
245 /**
246 * Read the value of the X button on the controller.
247 *
248 * @return The state of the button.
249 */
250 bool GetXButton() const;
251
252 /**
253 * Whether the X button was pressed since the last check.
254 *
255 * @return Whether the button was pressed since the last check.
256 */
258
259 /**
260 * Whether the X button was released since the last check.
261 *
262 * @return Whether the button was released since the last check.
263 */
265
266 /**
267 * Constructs an event instance around the X button's digital signal.
268 *
269 * @param loop the event loop instance to attach the event to.
270 * @return an event instance representing the X button's digital signal
271 * attached to the given loop.
272 */
274
275 /**
276 * Read the value of the Y button on the controller.
277 *
278 * @return The state of the button.
279 */
280 bool GetYButton() const;
281
282 /**
283 * Whether the Y button was pressed since the last check.
284 *
285 * @return Whether the button was pressed since the last check.
286 */
288
289 /**
290 * Whether the Y button was released since the last check.
291 *
292 * @return Whether the button was released since the last check.
293 */
295
296 /**
297 * Constructs an event instance around the Y button's digital signal.
298 *
299 * @param loop the event loop instance to attach the event to.
300 * @return an event instance representing the Y button's digital signal
301 * attached to the given loop.
302 */
304
305 /**
306 * Read the value of the ellipses button on the controller.
307 *
308 * @return The state of the button.
309 */
310 bool GetEllipsesButton() const;
311
312 /**
313 * Whether the ellipses button was pressed since the last check.
314 *
315 * @return Whether the button was pressed since the last check.
316 */
318
319 /**
320 * Whether the ellipses button was released since the last check.
321 *
322 * @return Whether the button was released since the last check.
323 */
325
326 /**
327 * Constructs an event instance around the ellipses button's digital signal.
328 *
329 * @param loop the event loop instance to attach the event to.
330 * @return an event instance representing the ellipses button's digital signal
331 * attached to the given loop.
332 */
334
335 /**
336 * Read the value of the hamburger button on the controller.
337 *
338 * @return The state of the button.
339 */
340 bool GetHamburgerButton() const;
341
342 /**
343 * Whether the hamburger button was pressed since the last check.
344 *
345 * @return Whether the button was pressed since the last check.
346 */
348
349 /**
350 * Whether the hamburger button was released since the last check.
351 *
352 * @return Whether the button was released since the last check.
353 */
355
356 /**
357 * Constructs an event instance around the hamburger button's digital signal.
358 *
359 * @param loop the event loop instance to attach the event to.
360 * @return an event instance representing the hamburger button's digital
361 * signal attached to the given loop.
362 */
364
365 /**
366 * Read the value of the stadia button on the controller.
367 *
368 * @return The state of the button.
369 */
370 bool GetStadiaButton() const;
371
372 /**
373 * Whether the stadia button was pressed since the last check.
374 *
375 * @return Whether the button was pressed since the last check.
376 */
378
379 /**
380 * Whether the stadia button was released since the last check.
381 *
382 * @return Whether the button was released since the last check.
383 */
385
386 /**
387 * Constructs an event instance around the stadia button's digital signal.
388 *
389 * @param loop the event loop instance to attach the event to.
390 * @return an event instance representing the stadia button's digital signal
391 * attached to the given loop.
392 */
394
395 /**
396 * Read the value of the google button on the controller.
397 *
398 * @return The state of the button.
399 */
400 bool GetGoogleButton() const;
401
402 /**
403 * Whether the google button was pressed since the last check.
404 *
405 * @return Whether the button was pressed since the last check.
406 */
408
409 /**
410 * Whether the google button was released since the last check.
411 *
412 * @return Whether the button was released since the last check.
413 */
415
416 /**
417 * Constructs an event instance around the google button's digital signal.
418 *
419 * @param loop the event loop instance to attach the event to.
420 * @return an event instance representing the google button's digital signal
421 * attached to the given loop.
422 */
424
425 /**
426 * Read the value of the frame button on the controller.
427 *
428 * @return The state of the button.
429 */
430 bool GetFrameButton() const;
431
432 /**
433 * Whether the frame button was pressed since the last check.
434 *
435 * @return Whether the button was pressed since the last check.
436 */
438
439 /**
440 * Whether the frame button was released since the last check.
441 *
442 * @return Whether the button was released since the last check.
443 */
445
446 /**
447 * Constructs an event instance around the frame button's digital signal.
448 *
449 * @param loop the event loop instance to attach the event to.
450 * @return an event instance representing the frame button's digital signal
451 * attached to the given loop.
452 */
454
455 /**
456 * Read the value of the left trigger button on the controller.
457 *
458 * @return The state of the button.
459 */
461
462 /**
463 * Whether the left trigger button was pressed since the last check.
464 *
465 * @return Whether the button was pressed since the last check.
466 */
468
469 /**
470 * Whether the left trigger button was released since the last check.
471 *
472 * @return Whether the button was released since the last check.
473 */
475
476 /**
477 * Constructs an event instance around the left trigger button's digital
478 * signal.
479 *
480 * @param loop the event loop instance to attach the event to.
481 * @return an event instance representing the left trigger button's digital
482 * signal attached to the given loop.
483 */
485
486 /**
487 * Read the value of the right trigger button on the controller.
488 *
489 * @return The state of the button.
490 */
492
493 /**
494 * Whether the right trigger button was pressed since the last check.
495 *
496 * @return Whether the button was pressed since the last check.
497 */
499
500 /**
501 * Whether the right trigger button was released since the last check.
502 *
503 * @return Whether the button was released since the last check.
504 */
506
507 /**
508 * Constructs an event instance around the right trigger button's digital
509 * signal.
510 *
511 * @param loop the event loop instance to attach the event to.
512 * @return an event instance representing the right trigger button's digital
513 * signal attached to the given loop.
514 */
516
517 /**
518 * Represents a digital button on a StadiaController.
519 */
520 struct Button {
521 /// A button.
522 static constexpr int kA = 1;
523 /// B button.
524 static constexpr int kB = 2;
525 /// X button.
526 static constexpr int kX = 3;
527 /// Y button.
528 static constexpr int kY = 4;
529 /// Left bumper button.
530 static constexpr int kLeftBumper = 5;
531 /// Right bumper button.
532 static constexpr int kRightBumper = 6;
533 /// Left stick button.
534 static constexpr int kLeftStick = 7;
535 /// Right stick button.
536 static constexpr int kRightStick = 8;
537 /// Ellipses button.
538 static constexpr int kEllipses = 9;
539 /// Hamburger button.
540 static constexpr int kHamburger = 10;
541 /// Stadia button.
542 static constexpr int kStadia = 11;
543 /// Right trigger button.
544 static constexpr int kRightTrigger = 12;
545 /// Left trigger button.
546 static constexpr int kLeftTrigger = 13;
547 /// Google button.
548 static constexpr int kGoogle = 14;
549 /// Frame button.
550 static constexpr int kFrame = 15;
551 };
552
553 /**
554 * Represents an axis on a StadiaController.
555 */
556 struct Axis {
557 /// Left X axis.
558 static constexpr int kLeftX = 0;
559 /// Right X axis.
560 static constexpr int kRightX = 4;
561 /// Left Y axis.
562 static constexpr int kLeftY = 1;
563 /// Right Y axis.
564 static constexpr int kRightY = 5;
565 };
566};
567
568} // namespace frc
This class provides an easy way to link actions to inputs.
Definition: BooleanEvent.h:31
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition: EventLoop.h:15
Handle input from standard HID devices connected to the Driver Station.
Definition: GenericHID.h:24
Handle input from Stadia controllers connected to the Driver Station.
Definition: StadiaController.h:20
bool GetStadiaButtonPressed()
Whether the stadia button was pressed since the last check.
BooleanEvent RightStick(EventLoop *loop) const
Constructs an event instance around the right stick's digital signal.
BooleanEvent LeftTrigger(EventLoop *loop) const
Constructs an event instance around the left trigger button's digital signal.
BooleanEvent X(EventLoop *loop) const
Constructs an event instance around the X button's digital signal.
bool GetXButtonPressed()
Whether the X button was pressed since the last check.
bool GetYButton() const
Read the value of the Y button on the controller.
bool GetStadiaButtonReleased()
Whether the stadia button was released since the last check.
bool GetRightBumperReleased()
Whether the right bumper (RB) was released since the last check.
bool GetEllipsesButtonPressed()
Whether the ellipses button was pressed since the last check.
bool GetGoogleButtonReleased()
Whether the google button was released since the last check.
bool GetLeftBumperPressed()
Whether the left bumper (LB) was pressed since the last check.
bool GetLeftTriggerButtonReleased()
Whether the left trigger button was released since the last check.
bool GetBButtonReleased()
Whether the B button was released since the last check.
bool GetHamburgerButton() const
Read the value of the hamburger button on the controller.
bool GetLeftTriggerButtonPressed()
Whether the left trigger button was pressed since the last check.
double GetLeftX() const
Get the X axis value of left side of the controller.
bool GetBButtonPressed()
Whether the B button was pressed since the last check.
bool GetYButtonPressed()
Whether the Y button was pressed since the last check.
bool GetLeftStickButtonPressed()
Whether the left stick button (LSB) was pressed since the last check.
bool GetEllipsesButtonReleased()
Whether the ellipses button was released since the last check.
BooleanEvent LeftBumper(EventLoop *loop) const
Constructs an event instance around the left bumper's digital signal.
bool GetStadiaButton() const
Read the value of the stadia button on the controller.
bool GetGoogleButtonPressed()
Whether the google button was pressed since the last check.
BooleanEvent Y(EventLoop *loop) const
Constructs an event instance around the Y button's digital signal.
bool GetHamburgerButtonReleased()
Whether the hamburger button was released since the last check.
bool GetAButton() const
Read the value of the A button on the controller.
bool GetRightTriggerButton() const
Read the value of the right trigger button on the controller.
bool GetHamburgerButtonPressed()
Whether the hamburger button was pressed since the last check.
bool GetLeftStickButtonReleased()
Whether the left stick button (LSB) was released since the last check.
bool GetGoogleButton() const
Read the value of the google button on the controller.
BooleanEvent Ellipses(EventLoop *loop) const
Constructs an event instance around the ellipses button's digital signal.
BooleanEvent B(EventLoop *loop) const
Constructs an event instance around the B button's digital signal.
BooleanEvent Hamburger(EventLoop *loop) const
Constructs an event instance around the hamburger button's digital signal.
bool GetRightStickButtonReleased()
Whether the right stick button (RSB) was released since the last check.
BooleanEvent Frame(EventLoop *loop) const
Constructs an event instance around the frame button's digital signal.
bool GetLeftTriggerButton() const
Read the value of the left trigger button on the controller.
bool GetXButtonReleased()
Whether the X button was released since the last check.
double GetLeftY() const
Get the Y axis value of left side of the controller.
bool GetAButtonReleased()
Whether the A button was released since the last check.
bool GetRightBumperPressed()
Whether the right bumper (RB) was pressed since the last check.
BooleanEvent Stadia(EventLoop *loop) const
Constructs an event instance around the stadia button's digital signal.
double GetRightY() const
Get the Y axis value of right side of the controller.
BooleanEvent A(EventLoop *loop) const
Constructs an event instance around the A button's digital signal.
bool GetRightBumper() const
Read the value of the right bumper (RB) button on the controller.
double GetRightX() const
Get the X axis value of right side of the controller.
bool GetFrameButtonPressed()
Whether the frame button was pressed since the last check.
bool GetRightStickButtonPressed()
Whether the right stick button (RSB) was pressed since the last check.
bool GetRightTriggerButtonPressed()
Whether the right trigger button was pressed since the last check.
BooleanEvent Google(EventLoop *loop) const
Constructs an event instance around the google button's digital signal.
bool GetLeftStickButton() const
Read the value of the left stick button (LSB) on the controller.
bool GetAButtonPressed()
Whether the A button was pressed since the last check.
bool GetBButton() const
Read the value of the B button on the controller.
BooleanEvent RightTrigger(EventLoop *loop) const
Constructs an event instance around the right trigger button's digital signal.
bool GetRightStickButton() const
Read the value of the right stick button (RSB) on the controller.
bool GetYButtonReleased()
Whether the Y button was released since the last check.
StadiaController(int port)
Construct an instance of a Stadia controller.
bool GetRightTriggerButtonReleased()
Whether the right trigger button was released since the last check.
bool GetFrameButtonReleased()
Whether the frame button was released since the last check.
BooleanEvent LeftStick(EventLoop *loop) const
Constructs an event instance around the left stick's digital signal.
StadiaController & operator=(StadiaController &&)=default
bool GetLeftBumperReleased()
Whether the left bumper (LB) was released since the last check.
bool GetXButton() const
Read the value of the X button on the controller.
StadiaController(StadiaController &&)=default
bool GetEllipsesButton() const
Read the value of the ellipses button on the controller.
~StadiaController() override=default
bool GetLeftBumper() const
Read the value of the left bumper (LB) button on the controller.
BooleanEvent RightBumper(EventLoop *loop) const
Constructs an event instance around the right bumper's digital signal.
bool GetFrameButton() const
Read the value of the frame button on the controller.
Definition: AprilTagPoseEstimator.h:15
Represents an axis on a StadiaController.
Definition: StadiaController.h:556
static constexpr int kLeftY
Left Y axis.
Definition: StadiaController.h:562
static constexpr int kLeftX
Left X axis.
Definition: StadiaController.h:558
static constexpr int kRightY
Right Y axis.
Definition: StadiaController.h:564
static constexpr int kRightX
Right X axis.
Definition: StadiaController.h:560
Represents a digital button on a StadiaController.
Definition: StadiaController.h:520
static constexpr int kLeftStick
Left stick button.
Definition: StadiaController.h:534
static constexpr int kGoogle
Google button.
Definition: StadiaController.h:548
static constexpr int kLeftBumper
Left bumper button.
Definition: StadiaController.h:530
static constexpr int kHamburger
Hamburger button.
Definition: StadiaController.h:540
static constexpr int kY
Y button.
Definition: StadiaController.h:528
static constexpr int kLeftTrigger
Left trigger button.
Definition: StadiaController.h:546
static constexpr int kRightTrigger
Right trigger button.
Definition: StadiaController.h:544
static constexpr int kEllipses
Ellipses button.
Definition: StadiaController.h:538
static constexpr int kX
X button.
Definition: StadiaController.h:526
static constexpr int kRightBumper
Right bumper button.
Definition: StadiaController.h:532
static constexpr int kStadia
Stadia button.
Definition: StadiaController.h:542
static constexpr int kFrame
Frame button.
Definition: StadiaController.h:550
static constexpr int kB
B button.
Definition: StadiaController.h:524
static constexpr int kA
A button.
Definition: StadiaController.h:522
static constexpr int kRightStick
Right stick button.
Definition: StadiaController.h:536