WPILibC++ 2027.0.0-alpha-4
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 a Trigger instance around the South Face button's
37 * digital signal.
38 *
39 * @param loop the event loop instance to attach the event to. Defaults to the
40 * CommandScheduler's default loop.
41 * @return a Trigger instance representing the South Face button's
42 * digital signal attached to the given loop.
43 */
45 .GetDefaultButtonLoop()) const;
46
47 /**
48 * Constructs a Trigger instance around the East Face button's
49 * digital signal.
50 *
51 * @param loop the event loop instance to attach the event to. Defaults to the
52 * CommandScheduler's default loop.
53 * @return a Trigger instance representing the East Face button's
54 * digital signal attached to the given loop.
55 */
57 .GetDefaultButtonLoop()) const;
58
59 /**
60 * Constructs a Trigger instance around the West Face button's
61 * digital signal.
62 *
63 * @param loop the event loop instance to attach the event to. Defaults to the
64 * CommandScheduler's default loop.
65 * @return a Trigger instance representing the West Face button's
66 * digital signal attached to the given loop.
67 */
69 .GetDefaultButtonLoop()) const;
70
71 /**
72 * Constructs a Trigger instance around the North Face button's
73 * digital signal.
74 *
75 * @param loop the event loop instance to attach the event to. Defaults to the
76 * CommandScheduler's default loop.
77 * @return a Trigger instance representing the North Face button's
78 * digital signal attached to the given loop.
79 */
81 .GetDefaultButtonLoop()) const;
82
83 /**
84 * Constructs a Trigger instance around the Back button's
85 * digital signal.
86 *
87 * @param loop the event loop instance to attach the event to. Defaults to the
88 * CommandScheduler's default loop.
89 * @return a Trigger instance representing the Back button's
90 * digital signal attached to the given loop.
91 */
93 .GetDefaultButtonLoop()) const;
94
95 /**
96 * Constructs a Trigger instance around the Guide button's
97 * digital signal.
98 *
99 * @param loop the event loop instance to attach the event to. Defaults to the
100 * CommandScheduler's default loop.
101 * @return a Trigger instance representing the Guide button's
102 * digital signal attached to the given loop.
103 */
105 .GetDefaultButtonLoop()) const;
106
107 /**
108 * Constructs a Trigger instance around the Start button's
109 * digital signal.
110 *
111 * @param loop the event loop instance to attach the event to. Defaults to the
112 * CommandScheduler's default loop.
113 * @return a Trigger instance representing the Start button's
114 * digital signal attached to the given loop.
115 */
117 .GetDefaultButtonLoop()) const;
118
119 /**
120 * Constructs a Trigger instance around the left stick button's
121 * digital signal.
122 *
123 * @param loop the event loop instance to attach the event to. Defaults to the
124 * CommandScheduler's default loop.
125 * @return a Trigger instance representing the left stick button's
126 * digital signal attached to the given loop.
127 */
129 .GetDefaultButtonLoop()) const;
130
131 /**
132 * Constructs a Trigger instance around the right stick button's
133 * digital signal.
134 *
135 * @param loop the event loop instance to attach the event to. Defaults to the
136 * CommandScheduler's default loop.
137 * @return a Trigger instance representing the right stick button's
138 * digital signal attached to the given loop.
139 */
141 .GetDefaultButtonLoop()) const;
142
143 /**
144 * Constructs a Trigger instance around the right bumper button's
145 * digital signal.
146 *
147 * @param loop the event loop instance to attach the event to. Defaults to the
148 * CommandScheduler's default loop.
149 * @return a Trigger instance representing the right bumper button's
150 * digital signal attached to the given loop.
151 */
153 .GetDefaultButtonLoop()) const;
154
155 /**
156 * Constructs a Trigger instance around the right bumper button's
157 * digital signal.
158 *
159 * @param loop the event loop instance to attach the event to. Defaults to the
160 * CommandScheduler's default loop.
161 * @return a Trigger instance representing the right bumper button's
162 * digital signal attached to the given loop.
163 */
165 .GetDefaultButtonLoop()) const;
166
167 /**
168 * Constructs a Trigger instance around the D-pad up button's
169 * digital signal.
170 *
171 * @param loop the event loop instance to attach the event to. Defaults to the
172 * CommandScheduler's default loop.
173 * @return a Trigger instance representing the D-pad up button's
174 * digital signal attached to the given loop.
175 */
177 .GetDefaultButtonLoop()) const;
178
179 /**
180 * Constructs a Trigger instance around the D-pad down button's
181 * digital signal.
182 *
183 * @param loop the event loop instance to attach the event to. Defaults to the
184 * CommandScheduler's default loop.
185 * @return a Trigger instance representing the D-pad down button's
186 * digital signal attached to the given loop.
187 */
189 .GetDefaultButtonLoop()) const;
190
191 /**
192 * Constructs a Trigger instance around the D-pad left button's
193 * digital signal.
194 *
195 * @param loop the event loop instance to attach the event to. Defaults to the
196 * CommandScheduler's default loop.
197 * @return a Trigger instance representing the D-pad left button's
198 * digital signal attached to the given loop.
199 */
201 .GetDefaultButtonLoop()) const;
202
203 /**
204 * Constructs a Trigger instance around the D-pad right button's
205 * digital signal.
206 *
207 * @param loop the event loop instance to attach the event to. Defaults to the
208 * CommandScheduler's default loop.
209 * @return a Trigger instance representing the D-pad right button's
210 * digital signal attached to the given loop.
211 */
213 .GetDefaultButtonLoop()) const;
214
215 /**
216 * Constructs a Trigger instance around the Miscellaneous 1 button's
217 * digital signal.
218 *
219 * @param loop the event loop instance to attach the event to. Defaults to the
220 * CommandScheduler's default loop.
221 * @return a Trigger instance representing the Miscellaneous 1 button's
222 * digital signal attached to the given loop.
223 */
225 .GetDefaultButtonLoop()) const;
226
227 /**
228 * Constructs a Trigger instance around the Right Paddle 1 button's
229 * digital signal.
230 *
231 * @param loop the event loop instance to attach the event to. Defaults to the
232 * CommandScheduler's default loop.
233 * @return a Trigger instance representing the Right Paddle 1 button's
234 * digital signal attached to the given loop.
235 */
238 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
239
240 /**
241 * Constructs a Trigger instance around the Left 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 Left Paddle 1 button's
247 * digital signal attached to the given loop.
248 */
250 .GetDefaultButtonLoop()) const;
251
252 /**
253 * Constructs a Trigger instance around the Right Paddle 2 button's
254 * digital signal.
255 *
256 * @param loop the event loop instance to attach the event to. Defaults to the
257 * CommandScheduler's default loop.
258 * @return a Trigger instance representing the Right Paddle 2 button's
259 * digital signal attached to the given loop.
260 */
263 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
264
265 /**
266 * Constructs a Trigger instance around the Left 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 Left Paddle 2 button's
272 * digital signal attached to the given loop.
273 */
275 .GetDefaultButtonLoop()) const;
276
277 /**
278 * Constructs a Trigger instance around the Touchpad button's
279 * digital signal.
280 *
281 * @param loop the event loop instance to attach the event to. Defaults to the
282 * CommandScheduler's default loop.
283 * @return a Trigger instance representing the Touchpad button's
284 * digital signal attached to the given loop.
285 */
287 .GetDefaultButtonLoop()) const;
288
289 /**
290 * Constructs a Trigger instance around the Miscellaneous 2 button's
291 * digital signal.
292 *
293 * @param loop the event loop instance to attach the event to. Defaults to the
294 * CommandScheduler's default loop.
295 * @return a Trigger instance representing the Miscellaneous 2 button's
296 * digital signal attached to the given loop.
297 */
299 .GetDefaultButtonLoop()) const;
300
301 /**
302 * Constructs a Trigger instance around the Miscellaneous 3 button's
303 * digital signal.
304 *
305 * @param loop the event loop instance to attach the event to. Defaults to the
306 * CommandScheduler's default loop.
307 * @return a Trigger instance representing the Miscellaneous 3 button's
308 * digital signal attached to the given loop.
309 */
311 .GetDefaultButtonLoop()) const;
312
313 /**
314 * Constructs a Trigger instance around the Miscellaneous 4 button's
315 * digital signal.
316 *
317 * @param loop the event loop instance to attach the event to. Defaults to the
318 * CommandScheduler's default loop.
319 * @return a Trigger instance representing the Miscellaneous 4 button's
320 * digital signal attached to the given loop.
321 */
323 .GetDefaultButtonLoop()) const;
324
325 /**
326 * Constructs a Trigger instance around the Miscellaneous 5 button's
327 * digital signal.
328 *
329 * @param loop the event loop instance to attach the event to. Defaults to the
330 * CommandScheduler's default loop.
331 * @return a Trigger instance representing the Miscellaneous 5 button's
332 * digital signal attached to the given loop.
333 */
335 .GetDefaultButtonLoop()) const;
336
337 /**
338 * Constructs a Trigger instance around the Miscellaneous 6 button's
339 * digital signal.
340 *
341 * @param loop the event loop instance to attach the event to. Defaults to the
342 * CommandScheduler's default loop.
343 * @return a Trigger instance representing the Miscellaneous 6 button's
344 * digital signal attached to the given loop.
345 */
347 .GetDefaultButtonLoop()) const;
348
349 /**
350 * Constructs a Trigger instance around the axis value of the left trigger.
351 * The returned Trigger will be true when the axis value is greater than
352 * {@code threshold}.
353 *
354 * @param threshold the minimum axis value for the returned Trigger to be
355 * true. This value should be in the range [0, 1] where 0 is the unpressed
356 * state of the axis. Defaults to 0.5.
357 * @param loop the event loop instance to attach the Trigger to. Defaults to
358 * the CommandScheduler's default loop.
359 * @return a Trigger instance that is true when the left trigger's axis
360 * exceeds the provided threshold, attached to the given loop
361 */
362 Trigger LeftTrigger(double threshold = 0.5,
364 .GetDefaultButtonLoop()) const;
365
366 /**
367 * Constructs a Trigger instance around the axis value of the right trigger.
368 * The returned Trigger will be true when the axis value is greater than
369 * {@code threshold}.
370 *
371 * @param threshold the minimum axis value for the returned Trigger to be
372 * true. This value should be in the range [0, 1] where 0 is the unpressed
373 * state of the axis. Defaults to 0.5.
374 * @param loop the event loop instance to attach the Trigger to. Defaults to
375 * the CommandScheduler's default loop.
376 * @return a Trigger instance that is true when the right trigger's axis
377 * exceeds the provided threshold, attached to the given loop
378 */
380 double threshold = 0.5,
382 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
383
384 /**
385 * Get the X axis value of left side of the controller. Right is positive.
386 *
387 * @return The axis value.
388 */
389 double GetLeftX() const;
390
391 /**
392 * Get the Y axis value of left side of the controller. Back is positive.
393 *
394 * @return The axis value.
395 */
396 double GetLeftY() const;
397
398 /**
399 * Get the X axis value of right side of the controller. Right is positive.
400 *
401 * @return The axis value.
402 */
403 double GetRightX() const;
404
405 /**
406 * Get the Y axis value of right side of the controller. Back is positive.
407 *
408 * @return The axis value.
409 */
410 double GetRightY() const;
411
412 /**
413 * Get the left trigger axis value of the controller. Note that this axis is
414 * bound to the range of [0, 1] as opposed to the usual [-1, 1].
415 *
416 * @return The axis value.
417 */
418 double GetLeftTriggerAxis() const;
419
420 /**
421 * Get the right trigger axis value of the controller. Note that this axis is
422 * bound to the range of [0, 1] as opposed to the usual [-1, 1].
423 *
424 * @return The axis value.
425 */
426 double GetRightTriggerAxis() const;
427
428 private:
429 wpi::Gamepad m_hid;
430};
431} // 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
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 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 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