WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
CommandGamepad.hpp
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
10
11namespace wpi::cmd {
12/**
13 * A version of {@link wpi::Gamepad} with {@link Trigger} factories for
14 * command-based.
15 *
16 * @see wpi::Gamepad
17 */
19 public:
20 /**
21 * Construct an instance of a controller.
22 *
23 * @param port The port index on the Driver Station that the controller is
24 * plugged into.
25 */
26 explicit CommandGamepad(int port);
27
28 /**
29 * Get the underlying GenericHID object.
30 *
31 * @return the wrapped GenericHID object
32 */
34
35 /**
36 * Constructs an event instance around this button's digital signal.
37 *
38 * @param button the button
39 * @param loop the event loop instance to attach the event to. Defaults to the
40 * CommandScheduler's default loop.
41 * @return an event instance representing the button's digital signal attached
42 * to the given loop.
43 */
46 .GetDefaultButtonLoop()) const;
47
48 /**
49 * Constructs a Trigger instance around the South Face button's
50 * digital signal.
51 *
52 * @param loop the event loop instance to attach the event to. Defaults to the
53 * CommandScheduler's default loop.
54 * @return a Trigger instance representing the South Face button's
55 * digital signal attached to the given loop.
56 */
58 .GetDefaultButtonLoop()) const;
59
60 /**
61 * Constructs a Trigger instance around the East Face button's
62 * digital signal.
63 *
64 * @param loop the event loop instance to attach the event to. Defaults to the
65 * CommandScheduler's default loop.
66 * @return a Trigger instance representing the East Face button's
67 * digital signal attached to the given loop.
68 */
70 .GetDefaultButtonLoop()) const;
71
72 /**
73 * Constructs a Trigger instance around the West Face button's
74 * digital signal.
75 *
76 * @param loop the event loop instance to attach the event to. Defaults to the
77 * CommandScheduler's default loop.
78 * @return a Trigger instance representing the West Face button's
79 * digital signal attached to the given loop.
80 */
82 .GetDefaultButtonLoop()) const;
83
84 /**
85 * Constructs a Trigger instance around the North Face button's
86 * digital signal.
87 *
88 * @param loop the event loop instance to attach the event to. Defaults to the
89 * CommandScheduler's default loop.
90 * @return a Trigger instance representing the North Face button's
91 * digital signal attached to the given loop.
92 */
94 .GetDefaultButtonLoop()) const;
95
96 /**
97 * Constructs a Trigger instance around the Back button's
98 * digital signal.
99 *
100 * @param loop the event loop instance to attach the event to. Defaults to the
101 * CommandScheduler's default loop.
102 * @return a Trigger instance representing the Back button's
103 * digital signal attached to the given loop.
104 */
106 .GetDefaultButtonLoop()) const;
107
108 /**
109 * Constructs a Trigger instance around the Guide button's
110 * digital signal.
111 *
112 * @param loop the event loop instance to attach the event to. Defaults to the
113 * CommandScheduler's default loop.
114 * @return a Trigger instance representing the Guide button's
115 * digital signal attached to the given loop.
116 */
118 .GetDefaultButtonLoop()) const;
119
120 /**
121 * Constructs a Trigger instance around the Start button's
122 * digital signal.
123 *
124 * @param loop the event loop instance to attach the event to. Defaults to the
125 * CommandScheduler's default loop.
126 * @return a Trigger instance representing the Start button's
127 * digital signal attached to the given loop.
128 */
130 .GetDefaultButtonLoop()) const;
131
132 /**
133 * Constructs a Trigger instance around the left stick button's
134 * digital signal.
135 *
136 * @param loop the event loop instance to attach the event to. Defaults to the
137 * CommandScheduler's default loop.
138 * @return a Trigger instance representing the left stick button's
139 * digital signal attached to the given loop.
140 */
142 .GetDefaultButtonLoop()) const;
143
144 /**
145 * Constructs a Trigger instance around the right stick button's
146 * digital signal.
147 *
148 * @param loop the event loop instance to attach the event to. Defaults to the
149 * CommandScheduler's default loop.
150 * @return a Trigger instance representing the right stick button's
151 * digital signal attached to the given loop.
152 */
154 .GetDefaultButtonLoop()) const;
155
156 /**
157 * Constructs a Trigger instance around the right bumper button's
158 * digital signal.
159 *
160 * @param loop the event loop instance to attach the event to. Defaults to the
161 * CommandScheduler's default loop.
162 * @return a Trigger instance representing the right bumper button's
163 * digital signal attached to the given loop.
164 */
166 .GetDefaultButtonLoop()) const;
167
168 /**
169 * Constructs a Trigger instance around the right bumper button's
170 * digital signal.
171 *
172 * @param loop the event loop instance to attach the event to. Defaults to the
173 * CommandScheduler's default loop.
174 * @return a Trigger instance representing the right bumper button's
175 * digital signal attached to the given loop.
176 */
178 .GetDefaultButtonLoop()) const;
179
180 /**
181 * Constructs a Trigger instance around the D-pad up button's
182 * digital signal.
183 *
184 * @param loop the event loop instance to attach the event to. Defaults to the
185 * CommandScheduler's default loop.
186 * @return a Trigger instance representing the D-pad up button's
187 * digital signal attached to the given loop.
188 */
190 .GetDefaultButtonLoop()) const;
191
192 /**
193 * Constructs a Trigger instance around the D-pad down button's
194 * digital signal.
195 *
196 * @param loop the event loop instance to attach the event to. Defaults to the
197 * CommandScheduler's default loop.
198 * @return a Trigger instance representing the D-pad down button's
199 * digital signal attached to the given loop.
200 */
202 .GetDefaultButtonLoop()) const;
203
204 /**
205 * Constructs a Trigger instance around the D-pad left button's
206 * digital signal.
207 *
208 * @param loop the event loop instance to attach the event to. Defaults to the
209 * CommandScheduler's default loop.
210 * @return a Trigger instance representing the D-pad left button's
211 * digital signal attached to the given loop.
212 */
214 .GetDefaultButtonLoop()) const;
215
216 /**
217 * Constructs a Trigger instance around the D-pad right button's
218 * digital signal.
219 *
220 * @param loop the event loop instance to attach the event to. Defaults to the
221 * CommandScheduler's default loop.
222 * @return a Trigger instance representing the D-pad right button's
223 * digital signal attached to the given loop.
224 */
226 .GetDefaultButtonLoop()) const;
227
228 /**
229 * Constructs a Trigger instance around the Miscellaneous 1 button's
230 * digital signal.
231 *
232 * @param loop the event loop instance to attach the event to. Defaults to the
233 * CommandScheduler's default loop.
234 * @return a Trigger instance representing the Miscellaneous 1 button's
235 * digital signal attached to the given loop.
236 */
238 .GetDefaultButtonLoop()) const;
239
240 /**
241 * Constructs a Trigger instance around the Right Paddle 1 button's
242 * digital signal.
243 *
244 * @param loop the event loop instance to attach the event to. Defaults to the
245 * CommandScheduler's default loop.
246 * @return a Trigger instance representing the Right Paddle 1 button's
247 * digital signal attached to the given loop.
248 */
250 wpi::EventLoop* loop =
251 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
252
253 /**
254 * Constructs a Trigger instance around the Left Paddle 1 button's
255 * digital signal.
256 *
257 * @param loop the event loop instance to attach the event to. Defaults to the
258 * CommandScheduler's default loop.
259 * @return a Trigger instance representing the Left Paddle 1 button's
260 * digital signal attached to the given loop.
261 */
263 .GetDefaultButtonLoop()) const;
264
265 /**
266 * Constructs a Trigger instance around the Right Paddle 2 button's
267 * digital signal.
268 *
269 * @param loop the event loop instance to attach the event to. Defaults to the
270 * CommandScheduler's default loop.
271 * @return a Trigger instance representing the Right Paddle 2 button's
272 * digital signal attached to the given loop.
273 */
275 wpi::EventLoop* loop =
276 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
277
278 /**
279 * Constructs a Trigger instance around the Left Paddle 2 button's
280 * digital signal.
281 *
282 * @param loop the event loop instance to attach the event to. Defaults to the
283 * CommandScheduler's default loop.
284 * @return a Trigger instance representing the Left Paddle 2 button's
285 * digital signal attached to the given loop.
286 */
288 .GetDefaultButtonLoop()) const;
289
290 /**
291 * Constructs a Trigger instance around the Touchpad button's
292 * digital signal.
293 *
294 * @param loop the event loop instance to attach the event to. Defaults to the
295 * CommandScheduler's default loop.
296 * @return a Trigger instance representing the Touchpad button's
297 * digital signal attached to the given loop.
298 */
300 .GetDefaultButtonLoop()) const;
301
302 /**
303 * Constructs a Trigger instance around the Miscellaneous 2 button's
304 * digital signal.
305 *
306 * @param loop the event loop instance to attach the event to. Defaults to the
307 * CommandScheduler's default loop.
308 * @return a Trigger instance representing the Miscellaneous 2 button's
309 * digital signal attached to the given loop.
310 */
312 .GetDefaultButtonLoop()) const;
313
314 /**
315 * Constructs a Trigger instance around the Miscellaneous 3 button's
316 * digital signal.
317 *
318 * @param loop the event loop instance to attach the event to. Defaults to the
319 * CommandScheduler's default loop.
320 * @return a Trigger instance representing the Miscellaneous 3 button's
321 * digital signal attached to the given loop.
322 */
324 .GetDefaultButtonLoop()) const;
325
326 /**
327 * Constructs a Trigger instance around the Miscellaneous 4 button's
328 * digital signal.
329 *
330 * @param loop the event loop instance to attach the event to. Defaults to the
331 * CommandScheduler's default loop.
332 * @return a Trigger instance representing the Miscellaneous 4 button's
333 * digital signal attached to the given loop.
334 */
336 .GetDefaultButtonLoop()) const;
337
338 /**
339 * Constructs a Trigger instance around the Miscellaneous 5 button's
340 * digital signal.
341 *
342 * @param loop the event loop instance to attach the event to. Defaults to the
343 * CommandScheduler's default loop.
344 * @return a Trigger instance representing the Miscellaneous 5 button's
345 * digital signal attached to the given loop.
346 */
348 .GetDefaultButtonLoop()) const;
349
350 /**
351 * Constructs a Trigger instance around the Miscellaneous 6 button's
352 * digital signal.
353 *
354 * @param loop the event loop instance to attach the event to. Defaults to the
355 * CommandScheduler's default loop.
356 * @return a Trigger instance representing the Miscellaneous 6 button's
357 * digital signal attached to the given loop.
358 */
360 .GetDefaultButtonLoop()) const;
361
362 /**
363 * Constructs a Trigger instance around the axis value of the left trigger.
364 * The returned Trigger will be true when the axis value is greater than
365 * {@code threshold}.
366 *
367 * @param threshold the minimum axis value for the returned Trigger to be
368 * true. This value should be in the range [0, 1] where 0 is the unpressed
369 * state of the axis. Defaults to 0.5.
370 * @param loop the event loop instance to attach the Trigger to. Defaults to
371 * the CommandScheduler's default loop.
372 * @return a Trigger instance that is true when the left trigger's axis
373 * exceeds the provided threshold, attached to the given loop
374 */
375 Trigger LeftTrigger(double threshold = 0.5,
377 .GetDefaultButtonLoop()) const;
378
379 /**
380 * Constructs a Trigger instance around the axis value of the right trigger.
381 * The returned Trigger will be true when the axis value is greater than
382 * {@code threshold}.
383 *
384 * @param threshold the minimum axis value for the returned Trigger to be
385 * true. This value should be in the range [0, 1] where 0 is the unpressed
386 * state of the axis. Defaults to 0.5.
387 * @param loop the event loop instance to attach the Trigger to. Defaults to
388 * the CommandScheduler's default loop.
389 * @return a Trigger instance that is true when the right trigger's axis
390 * exceeds the provided threshold, attached to the given loop
391 */
393 double threshold = 0.5,
394 wpi::EventLoop* loop =
395 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
396
397 /**
398 * Constructs a Trigger instance that is true when the axis value is less than
399 * {@code threshold}, attached to {@link
400 * CommandScheduler::GetDefaultButtonLoop() the default command scheduler
401 * button loop}.
402 * @param axis The axis to read, starting at 0.
403 * @param threshold The value below which this trigger should return true.
404 * @param loop the event loop instance to attach the event to. Defaults to
405 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
406 * scheduler button loop}.
407 * @return a Trigger instance that is true when the axis value is less than
408 * the provided threshold.
409 */
411 wpi::Gamepad::Axis axis, double threshold,
412 wpi::EventLoop* loop =
413 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
414
415 /**
416 * Constructs a Trigger instance that is true when the axis value is greater
417 * than {@code threshold}, attached to {@link
418 * CommandScheduler::GetDefaultButtonLoop() the default command scheduler
419 * button loop}.
420 * @param axis The axis to read
421 * @param threshold The value below which this trigger should return true.
422 * @param loop the event loop instance to attach the event to. Defaults to
423 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
424 * scheduler button loop}.
425 * @return a Trigger instance that is true when the axis value is greater than
426 * the provided threshold.
427 */
429 wpi::Gamepad::Axis axis, double threshold,
430 wpi::EventLoop* loop =
431 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
432
433 /**
434 * Constructs a Trigger instance that is true when the axis magnitude value is
435 * greater than {@code threshold}, attached to the given loop.
436 *
437 * @param axis The axis to read
438 * @param threshold The value above which this trigger should return true.
439 * @param loop the event loop instance to attach the trigger to.
440 * @return a Trigger instance that is true when the axis magnitude value is
441 * greater than the provided threshold.
442 */
444 wpi::Gamepad::Axis axis, double threshold,
445 wpi::EventLoop* loop =
446 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
447
448 /**
449 * Get the X axis value of left side of the controller. Right is positive.
450 *
451 * @return The axis value.
452 */
453 double GetLeftX() const;
454
455 /**
456 * Get the Y axis value of left side of the controller. Back is positive.
457 *
458 * @return The axis value.
459 */
460 double GetLeftY() const;
461
462 /**
463 * Get the X axis value of right side of the controller. Right is positive.
464 *
465 * @return The axis value.
466 */
467 double GetRightX() const;
468
469 /**
470 * Get the Y axis value of right side of the controller. Back is positive.
471 *
472 * @return The axis value.
473 */
474 double GetRightY() const;
475
476 /**
477 * Get the left trigger axis value of the controller. Note that this axis is
478 * bound to the range of [0, 1] as opposed to the usual [-1, 1].
479 *
480 * @return The axis value.
481 */
482 double GetLeftTriggerAxis() const;
483
484 /**
485 * Get the right trigger axis value of the controller. Note that this axis is
486 * bound to the range of [0, 1] as opposed to the usual [-1, 1].
487 *
488 * @return The axis value.
489 */
490 double GetRightTriggerAxis() const;
491
492 private:
493 wpi::Gamepad m_hid;
494};
495} // namespace wpi::cmd
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.hpp:15
Handle input from Gamepad controllers connected to the Driver Station.
Definition Gamepad.hpp:27
Button
Represents a digital button on an Gamepad.
Definition Gamepad.hpp:30
Axis
Represents an axis on an Gamepad.
Definition Gamepad.hpp:86
Trigger EastFace(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the East Face button's digital signal.
Trigger Misc3(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 3 button's digital signal.
double GetRightTriggerAxis() const
Get the right trigger axis value of the controller.
Trigger DpadDown(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the D-pad down button's digital signal.
double GetLeftX() const
Get the X axis value of left side of the controller.
Trigger RightStick(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the right stick button's digital signal.
Trigger LeftPaddle2(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Left Paddle 2 button's digital signal.
Trigger Misc2(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 2 button's digital signal.
CommandGamepad(int port)
Construct an instance of a controller.
double GetLeftTriggerAxis() const
Get the left trigger axis value of the controller.
Trigger LeftTrigger(double threshold=0.5, wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the axis value of the left trigger.
Trigger Back(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Back button's digital signal.
double GetRightY() const
Get the Y axis value of right side of the controller.
Trigger DpadRight(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the D-pad right button's digital signal.
wpi::Gamepad & GetHID()
Get the underlying GenericHID object.
Trigger NorthFace(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the North Face button's digital signal.
Trigger Misc1(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 1 button's digital signal.
Trigger RightBumper(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the right bumper button's digital signal.
Trigger DpadLeft(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the D-pad left button's digital signal.
Trigger DpadUp(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the D-pad up button's digital signal.
Trigger RightTrigger(double threshold=0.5, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance around the axis value of the right trigger.
Trigger WestFace(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the West Face button's digital signal.
Trigger LeftPaddle1(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Left Paddle 1 button's digital signal.
Trigger SouthFace(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the South Face button's digital signal.
Trigger Guide(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Guide button's digital signal.
Trigger AxisMagnitudeGreaterThan(wpi::Gamepad::Axis axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis magnitude value is greater than threshold,...
Trigger Button(enum wpi::Gamepad::Button button, wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs an event instance around this button's digital signal.
Trigger RightPaddle2(wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Right Paddle 2 button's digital signal.
double GetRightX() const
Get the X axis value of right side of the controller.
Trigger Misc4(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 4 button's digital signal.
Trigger LeftBumper(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the right bumper button's digital signal.
Trigger Touchpad(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Touchpad button's digital signal.
double GetLeftY() const
Get the Y axis value of left side of the controller.
Trigger AxisGreaterThan(wpi::Gamepad::Axis axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis value is greater than threshold,...
Trigger AxisLessThan(wpi::Gamepad::Axis axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis value is less than threshold,...
Trigger Misc6(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 6 button's digital signal.
Trigger LeftStick(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the left stick button's digital signal.
Trigger Start(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Start button's digital signal.
Trigger Misc5(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Miscellaneous 5 button's digital signal.
Trigger RightPaddle1(wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance around the Right Paddle 1 button's digital signal.
CommandGenericHID(int port)
Construct an instance of a device.
static CommandScheduler & GetInstance()
Returns the Scheduler instance.
This class provides an easy way to link commands to conditions.
Definition Trigger.hpp:31
Definition CommandNiDsStadiaController.hpp:15