WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
PS5Controller.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// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY
6
7#pragma once
8
11
12#include "frc/GenericHID.h"
13
14namespace frc {
15
16/**
17 * Handle input from PS5 controllers connected to the Driver Station.
18 *
19 * This class handles PS5 input that comes from the Driver Station. Each
20 * time a value is requested the most recent value is returned. There is a
21 * single class instance for each controller and the mapping of ports to
22 * hardware buttons depends on the code in the Driver Station.
23 *
24 * Only first party controllers from Sony are guaranteed to have the
25 * correct mapping, and only through the official NI DS. Sim is not guaranteed
26 * to have the same mapping, as well as any 3rd party controllers.
27 */
29 public wpi::Sendable,
30 public wpi::SendableHelper<PS5Controller> {
31 public:
32 /**
33 * Construct an instance of a controller.
34 *
35 * The controller index is the USB port on the Driver Station.
36 *
37 * @param port The port on the Driver Station that the controller is plugged
38 * into (0-5).
39 */
40 explicit PS5Controller(int port);
41
42 ~PS5Controller() override = default;
43
46
47 /**
48 * Get the X axis value of left side of the controller. Right is positive.
49 *
50 * @return the axis value.
51 */
52 double GetLeftX() const;
53
54 /**
55 * Get the Y axis value of left side of the controller. Back is positive.
56 *
57 * @return the axis value.
58 */
59 double GetLeftY() const;
60
61 /**
62 * Get the X axis value of right side of the controller. Right is positive.
63 *
64 * @return the axis value.
65 */
66 double GetRightX() const;
67
68 /**
69 * Get the Y axis value of right side of the controller. Back is positive.
70 *
71 * @return the axis value.
72 */
73 double GetRightY() const;
74
75 /**
76 * Get the left trigger 2 axis value of the controller. Note that this axis
77 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
78 *
79 * @return the axis value.
80 */
81 double GetL2Axis() const;
82
83 /**
84 * Get the right trigger 2 axis value of the controller. Note that this axis
85 * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
86 *
87 * @return the axis value.
88 */
89 double GetR2Axis() const;
90
91 /**
92 * Read the value of the square button on the controller.
93 *
94 * @return The state of the button.
95 */
96 bool GetSquareButton() const;
97
98 /**
99 * Whether the square button was pressed since the last check.
100 *
101 * @return Whether the button was pressed since the last check.
102 */
104
105 /**
106 * Whether the square button was released since the last check.
107 *
108 * @return Whether the button was released since the last check.
109 */
111
112 /**
113 * Constructs an event instance around the square button's
114 * digital signal.
115 *
116 * @param loop the event loop instance to attach the event to.
117 * @return an event instance representing the square button's
118 * digital signal attached to the given loop.
119 */
121
122 /**
123 * Read the value of the cross button on the controller.
124 *
125 * @return The state of the button.
126 */
127 bool GetCrossButton() const;
128
129 /**
130 * Whether the cross button was pressed since the last check.
131 *
132 * @return Whether the button was pressed since the last check.
133 */
135
136 /**
137 * Whether the cross button was released since the last check.
138 *
139 * @return Whether the button was released since the last check.
140 */
142
143 /**
144 * Constructs an event instance around the cross button's
145 * digital signal.
146 *
147 * @param loop the event loop instance to attach the event to.
148 * @return an event instance representing the cross button's
149 * digital signal attached to the given loop.
150 */
152
153 /**
154 * Read the value of the circle button on the controller.
155 *
156 * @return The state of the button.
157 */
158 bool GetCircleButton() const;
159
160 /**
161 * Whether the circle button was pressed since the last check.
162 *
163 * @return Whether the button was pressed since the last check.
164 */
166
167 /**
168 * Whether the circle button was released since the last check.
169 *
170 * @return Whether the button was released since the last check.
171 */
173
174 /**
175 * Constructs an event instance around the circle button's
176 * digital signal.
177 *
178 * @param loop the event loop instance to attach the event to.
179 * @return an event instance representing the circle button's
180 * digital signal attached to the given loop.
181 */
183
184 /**
185 * Read the value of the triangle button on the controller.
186 *
187 * @return The state of the button.
188 */
189 bool GetTriangleButton() const;
190
191 /**
192 * Whether the triangle button was pressed since the last check.
193 *
194 * @return Whether the button was pressed since the last check.
195 */
197
198 /**
199 * Whether the triangle button was released since the last check.
200 *
201 * @return Whether the button was released since the last check.
202 */
204
205 /**
206 * Constructs an event instance around the triangle button's
207 * digital signal.
208 *
209 * @param loop the event loop instance to attach the event to.
210 * @return an event instance representing the triangle button's
211 * digital signal attached to the given loop.
212 */
214
215 /**
216 * Read the value of the left trigger 1 button on the controller.
217 *
218 * @return The state of the button.
219 */
220 bool GetL1Button() const;
221
222 /**
223 * Whether the left trigger 1 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 left trigger 1 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 left trigger 1 button's
238 * digital signal.
239 *
240 * @param loop the event loop instance to attach the event to.
241 * @return an event instance representing the left trigger 1 button's
242 * digital signal attached to the given loop.
243 */
245
246 /**
247 * Read the value of the right trigger 1 button on the controller.
248 *
249 * @return The state of the button.
250 */
251 bool GetR1Button() const;
252
253 /**
254 * Whether the right trigger 1 button was pressed since the last check.
255 *
256 * @return Whether the button was pressed since the last check.
257 */
259
260 /**
261 * Whether the right trigger 1 button was released since the last check.
262 *
263 * @return Whether the button was released since the last check.
264 */
266
267 /**
268 * Constructs an event instance around the right trigger 1 button's
269 * digital signal.
270 *
271 * @param loop the event loop instance to attach the event to.
272 * @return an event instance representing the right trigger 1 button's
273 * digital signal attached to the given loop.
274 */
276
277 /**
278 * Read the value of the left trigger 2 button on the controller.
279 *
280 * @return The state of the button.
281 */
282 bool GetL2Button() const;
283
284 /**
285 * Whether the left trigger 2 button was pressed since the last check.
286 *
287 * @return Whether the button was pressed since the last check.
288 */
290
291 /**
292 * Whether the left trigger 2 button was released since the last check.
293 *
294 * @return Whether the button was released since the last check.
295 */
297
298 /**
299 * Constructs an event instance around the left trigger 2 button's
300 * digital signal.
301 *
302 * @param loop the event loop instance to attach the event to.
303 * @return an event instance representing the left trigger 2 button's
304 * digital signal attached to the given loop.
305 */
307
308 /**
309 * Read the value of the right trigger 2 button on the controller.
310 *
311 * @return The state of the button.
312 */
313 bool GetR2Button() const;
314
315 /**
316 * Whether the right trigger 2 button was pressed since the last check.
317 *
318 * @return Whether the button was pressed since the last check.
319 */
321
322 /**
323 * Whether the right trigger 2 button was released since the last check.
324 *
325 * @return Whether the button was released since the last check.
326 */
328
329 /**
330 * Constructs an event instance around the right trigger 2 button's
331 * digital signal.
332 *
333 * @param loop the event loop instance to attach the event to.
334 * @return an event instance representing the right trigger 2 button's
335 * digital signal attached to the given loop.
336 */
338
339 /**
340 * Read the value of the create button on the controller.
341 *
342 * @return The state of the button.
343 */
344 bool GetCreateButton() const;
345
346 /**
347 * Whether the create button was pressed since the last check.
348 *
349 * @return Whether the button was pressed since the last check.
350 */
352
353 /**
354 * Whether the create button was released since the last check.
355 *
356 * @return Whether the button was released since the last check.
357 */
359
360 /**
361 * Constructs an event instance around the create button's
362 * digital signal.
363 *
364 * @param loop the event loop instance to attach the event to.
365 * @return an event instance representing the create button's
366 * digital signal attached to the given loop.
367 */
369
370 /**
371 * Read the value of the options button on the controller.
372 *
373 * @return The state of the button.
374 */
375 bool GetOptionsButton() const;
376
377 /**
378 * Whether the options button was pressed since the last check.
379 *
380 * @return Whether the button was pressed since the last check.
381 */
383
384 /**
385 * Whether the options button was released since the last check.
386 *
387 * @return Whether the button was released since the last check.
388 */
390
391 /**
392 * Constructs an event instance around the options button's
393 * digital signal.
394 *
395 * @param loop the event loop instance to attach the event to.
396 * @return an event instance representing the options button's
397 * digital signal attached to the given loop.
398 */
400
401 /**
402 * Read the value of the L3 (left stick) button on the controller.
403 *
404 * @return The state of the button.
405 */
406 bool GetL3Button() const;
407
408 /**
409 * Whether the L3 (left stick) button was pressed since the last check.
410 *
411 * @return Whether the button was pressed since the last check.
412 */
414
415 /**
416 * Whether the L3 (left stick) button was released since the last check.
417 *
418 * @return Whether the button was released since the last check.
419 */
421
422 /**
423 * Constructs an event instance around the L3 (left stick) button's
424 * digital signal.
425 *
426 * @param loop the event loop instance to attach the event to.
427 * @return an event instance representing the L3 (left stick) button's
428 * digital signal attached to the given loop.
429 */
431
432 /**
433 * Read the value of the R3 (right stick) button on the controller.
434 *
435 * @return The state of the button.
436 */
437 bool GetR3Button() const;
438
439 /**
440 * Whether the R3 (right stick) button was pressed since the last check.
441 *
442 * @return Whether the button was pressed since the last check.
443 */
445
446 /**
447 * Whether the R3 (right stick) button was released since the last check.
448 *
449 * @return Whether the button was released since the last check.
450 */
452
453 /**
454 * Constructs an event instance around the R3 (right stick) button's
455 * digital signal.
456 *
457 * @param loop the event loop instance to attach the event to.
458 * @return an event instance representing the R3 (right stick) button's
459 * digital signal attached to the given loop.
460 */
462
463 /**
464 * Read the value of the PlayStation button on the controller.
465 *
466 * @return The state of the button.
467 */
468 bool GetPSButton() const;
469
470 /**
471 * Whether the PlayStation button was pressed since the last check.
472 *
473 * @return Whether the button was pressed since the last check.
474 */
476
477 /**
478 * Whether the PlayStation button was released since the last check.
479 *
480 * @return Whether the button was released since the last check.
481 */
483
484 /**
485 * Constructs an event instance around the PlayStation button's
486 * digital signal.
487 *
488 * @param loop the event loop instance to attach the event to.
489 * @return an event instance representing the PlayStation button's
490 * digital signal attached to the given loop.
491 */
493
494 /**
495 * Read the value of the touchpad button on the controller.
496 *
497 * @return The state of the button.
498 */
499 bool GetTouchpadButton() const;
500
501 /**
502 * Whether the touchpad button was pressed since the last check.
503 *
504 * @return Whether the button was pressed since the last check.
505 */
507
508 /**
509 * Whether the touchpad button was released since the last check.
510 *
511 * @return Whether the button was released since the last check.
512 */
514
515 /**
516 * Constructs an event instance around the touchpad button's
517 * digital signal.
518 *
519 * @param loop the event loop instance to attach the event to.
520 * @return an event instance representing the touchpad button's
521 * digital signal attached to the given loop.
522 */
524
525 /**
526 * Read the value of the touchpad button on the controller.
527 *
528 * @return The state of the button.
529 * @deprecated Use GetTouchpadButton instead. This function is deprecated for
530 * removal to make function names consistent to allow the HID classes to be
531 * automatically generated.
532 */
533 [[deprecated("Use GetTouchpadButton instead")]]
534 bool GetTouchpad() const;
535 /**
536 * Whether the touchpad was pressed since the last check.
537 *
538 * @return Whether the touchpad was pressed since the last check.
539 * @deprecated Use GetTouchpadButtonPressed instead. This function is
540 * deprecated for removal to make function names consistent to allow the HID
541 * classes to be automatically generated.
542 */
543 [[deprecated("Use GetTouchpadButtonPressed instead")]]
545
546 /**
547 * Whether the touchpad was released since the last check.
548 *
549 * @return Whether the touchpad was released since the last check.
550 * @deprecated Use GetLeftBumperButton instead. This function is deprecated
551 * for removal to make function names consistent to allow the HID classes to
552 * be automatically generated.
553 */
554 [[deprecated("Use GetTouchpadButtonReleased instead")]]
556
557 /** Represents a digital button on an PS5Controller. */
558 struct Button {
559 /// Square button.
560 static constexpr int kSquare = 1;
561 /// Cross button.
562 static constexpr int kCross = 2;
563 /// Circle button.
564 static constexpr int kCircle = 3;
565 /// Triangle button.
566 static constexpr int kTriangle = 4;
567 /// Left trigger 1 button.
568 static constexpr int kL1 = 5;
569 /// Right trigger 1 button.
570 static constexpr int kR1 = 6;
571 /// Left trigger 2 button.
572 static constexpr int kL2 = 7;
573 /// Right trigger 2 button.
574 static constexpr int kR2 = 8;
575 /// Create button.
576 static constexpr int kCreate = 9;
577 /// Options button.
578 static constexpr int kOptions = 10;
579 /// L3 (left stick) button.
580 static constexpr int kL3 = 11;
581 /// R3 (right stick) button.
582 static constexpr int kR3 = 12;
583 /// PlayStation button.
584 static constexpr int kPS = 13;
585 /// Touchpad button.
586 static constexpr int kTouchpad = 14;
587 };
588
589 /** Represents an axis on an PS5Controller. */
590 struct Axis {
591 /// Left X axis.
592 static constexpr int kLeftX = 0;
593 /// Left Y axis.
594 static constexpr int kLeftY = 1;
595 /// Right X axis.
596 static constexpr int kRightX = 2;
597 /// Right Y axis.
598 static constexpr int kRightY = 5;
599 /// Left trigger 2.
600 static constexpr int kL2 = 3;
601 /// Right trigger 2.
602 static constexpr int kR2 = 4;
603 };
604
605 void InitSendable(wpi::SendableBuilder& builder) override;
606};
607
608} // namespace frc
This class provides an easy way to link actions to active high logic signals.
Definition BooleanEvent.h:30
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 PS5 controllers connected to the Driver Station.
Definition PS5Controller.h:30
bool GetOptionsButtonReleased()
Whether the options button was released since the last check.
bool GetSquareButtonPressed()
Whether the square button was pressed since the last check.
BooleanEvent PS(EventLoop *loop) const
Constructs an event instance around the PlayStation button's digital signal.
bool GetL3ButtonPressed()
Whether the L3 (left stick) button was pressed since the last check.
bool GetCrossButtonPressed()
Whether the cross button was pressed since the last check.
bool GetSquareButtonReleased()
Whether the square button was released since the last check.
bool GetTouchpadButtonReleased()
Whether the touchpad button was released since the last check.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
bool GetCircleButtonReleased()
Whether the circle button was released since the last check.
bool GetCircleButtonPressed()
Whether the circle button was pressed since the last check.
bool GetL3ButtonReleased()
Whether the L3 (left stick) button was released since the last check.
bool GetTouchpadButtonPressed()
Whether the touchpad button was pressed since the last check.
~PS5Controller() override=default
bool GetPSButtonReleased()
Whether the PlayStation button was released since the last check.
BooleanEvent R2(EventLoop *loop) const
Constructs an event instance around the right trigger 2 button's digital signal.
BooleanEvent R1(EventLoop *loop) const
Constructs an event instance around the right trigger 1 button's digital signal.
bool GetL1ButtonReleased()
Whether the left trigger 1 button was released since the last check.
bool GetR1ButtonReleased()
Whether the right trigger 1 button was released since the last check.
BooleanEvent L2(EventLoop *loop) const
Constructs an event instance around the left trigger 2 button's digital signal.
PS5Controller & operator=(PS5Controller &&)=default
bool GetCircleButton() const
Read the value of the circle button on the controller.
bool GetTouchpadButton() const
Read the value of the touchpad button on the controller.
bool GetPSButtonPressed()
Whether the PlayStation button was pressed since the last check.
BooleanEvent Touchpad(EventLoop *loop) const
Constructs an event instance around the touchpad button's digital signal.
bool GetPSButton() const
Read the value of the PlayStation button on the controller.
PS5Controller(PS5Controller &&)=default
BooleanEvent L1(EventLoop *loop) const
Constructs an event instance around the left trigger 1 button's digital signal.
double GetLeftY() const
Get the Y axis value of left side of the controller.
bool GetSquareButton() const
Read the value of the square button on the controller.
bool GetR3ButtonReleased()
Whether the R3 (right stick) button was released since the last check.
bool GetL2ButtonReleased()
Whether the left trigger 2 button was released since the last check.
double GetR2Axis() const
Get the right trigger 2 axis value of the controller.
double GetRightY() const
Get the Y axis value of right side of the controller.
bool GetR3Button() const
Read the value of the R3 (right stick) button on the controller.
bool GetL2Button() const
Read the value of the left trigger 2 button on the controller.
BooleanEvent Circle(EventLoop *loop) const
Constructs an event instance around the circle button's digital signal.
BooleanEvent Square(EventLoop *loop) const
Constructs an event instance around the square button's digital signal.
double GetLeftX() const
Get the X axis value of left side of the controller.
bool GetR2Button() const
Read the value of the right trigger 2 button on the controller.
bool GetOptionsButton() const
Read the value of the options button on the controller.
BooleanEvent Create(EventLoop *loop) const
Constructs an event instance around the create button's digital signal.
bool GetTouchpad() const
Read the value of the touchpad button on the controller.
BooleanEvent R3(EventLoop *loop) const
Constructs an event instance around the R3 (right stick) button's digital signal.
bool GetL3Button() const
Read the value of the L3 (left stick) button on the controller.
bool GetTriangleButton() const
Read the value of the triangle button on the controller.
bool GetR2ButtonReleased()
Whether the right trigger 2 button was released since the last check.
bool GetL1Button() const
Read the value of the left trigger 1 button on the controller.
bool GetR2ButtonPressed()
Whether the right trigger 2 button was pressed since the last check.
bool GetTouchpadReleased()
Whether the touchpad was released since the last check.
bool GetOptionsButtonPressed()
Whether the options button was pressed since the last check.
bool GetTouchpadPressed()
Whether the touchpad was pressed since the last check.
double GetRightX() const
Get the X axis value of right side of the controller.
PS5Controller(int port)
Construct an instance of a controller.
BooleanEvent Cross(EventLoop *loop) const
Constructs an event instance around the cross button's digital signal.
bool GetL2ButtonPressed()
Whether the left trigger 2 button was pressed since the last check.
bool GetCrossButtonReleased()
Whether the cross button was released since the last check.
bool GetCreateButton() const
Read the value of the create button on the controller.
bool GetL1ButtonPressed()
Whether the left trigger 1 button was pressed since the last check.
bool GetCreateButtonPressed()
Whether the create button was pressed since the last check.
double GetL2Axis() const
Get the left trigger 2 axis value of the controller.
bool GetCreateButtonReleased()
Whether the create button was released since the last check.
bool GetTriangleButtonPressed()
Whether the triangle button was pressed since the last check.
bool GetR3ButtonPressed()
Whether the R3 (right stick) button was pressed since the last check.
bool GetTriangleButtonReleased()
Whether the triangle button was released since the last check.
bool GetR1ButtonPressed()
Whether the right trigger 1 button was pressed since the last check.
bool GetR1Button() const
Read the value of the right trigger 1 button on the controller.
bool GetCrossButton() const
Read the value of the cross button on the controller.
BooleanEvent Triangle(EventLoop *loop) const
Constructs an event instance around the triangle button's digital signal.
BooleanEvent L3(EventLoop *loop) const
Constructs an event instance around the L3 (left stick) button's digital signal.
BooleanEvent Options(EventLoop *loop) const
Constructs an event instance around the options button's digital signal.
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.h:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.h:21
Interface for Sendable objects.
Definition Sendable.h:16
Definition CAN.h:11
Represents an axis on an PS5Controller.
Definition PS5Controller.h:590
static constexpr int kRightY
Right Y axis.
Definition PS5Controller.h:598
static constexpr int kLeftY
Left Y axis.
Definition PS5Controller.h:594
static constexpr int kL2
Left trigger 2.
Definition PS5Controller.h:600
static constexpr int kLeftX
Left X axis.
Definition PS5Controller.h:592
static constexpr int kRightX
Right X axis.
Definition PS5Controller.h:596
static constexpr int kR2
Right trigger 2.
Definition PS5Controller.h:602
Represents a digital button on an PS5Controller.
Definition PS5Controller.h:558
static constexpr int kPS
PlayStation button.
Definition PS5Controller.h:584
static constexpr int kCross
Cross button.
Definition PS5Controller.h:562
static constexpr int kL1
Left trigger 1 button.
Definition PS5Controller.h:568
static constexpr int kTriangle
Triangle button.
Definition PS5Controller.h:566
static constexpr int kR1
Right trigger 1 button.
Definition PS5Controller.h:570
static constexpr int kL2
Left trigger 2 button.
Definition PS5Controller.h:572
static constexpr int kL3
L3 (left stick) button.
Definition PS5Controller.h:580
static constexpr int kCreate
Create button.
Definition PS5Controller.h:576
static constexpr int kCircle
Circle button.
Definition PS5Controller.h:564
static constexpr int kSquare
Square button.
Definition PS5Controller.h:560
static constexpr int kR2
Right trigger 2 button.
Definition PS5Controller.h:574
static constexpr int kR3
R3 (right stick) button.
Definition PS5Controller.h:582
static constexpr int kTouchpad
Touchpad button.
Definition PS5Controller.h:586
static constexpr int kOptions
Options button.
Definition PS5Controller.h:578