Skip to content

Commit e7fc50f

Browse files
committed
Validate various commands with minor adjustments
- Update docs - Change member variables to be prefixed with _ - Add initSendable
1 parent 8669305 commit e7fc50f

36 files changed

+526
-228
lines changed

commands2/button/commandgenerichid.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# validated: 2024-01-20 DS 92149efa11fa button/CommandGenericHID.java
12
from typing import Optional
23

34
from wpilib.event import EventLoop
@@ -9,7 +10,7 @@
910

1011
class CommandGenericHID:
1112
"""
12-
A version of GenericHID with Trigger factories for command-based.
13+
A version of :class:`wpilib.interfaces.GenericHID` with :class:`.Trigger` factories for command-based.
1314
"""
1415

1516
def __init__(self, port: int):
@@ -31,7 +32,10 @@ def button(self, button: int, loop: Optional[EventLoop] = None) -> Trigger:
3132
Constructs an event instance around this button's digital signal.
3233
3334
:param button: The button index
34-
:param loop: the event loop instance to attache the event to.
35+
:param loop: the event loop instance to attach the event to, defaults
36+
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
37+
38+
:returns: A trigger instance attached to the event loop
3539
"""
3640
if loop is None:
3741
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
@@ -48,8 +52,9 @@ def pov(
4852
4953
:param angle: POV angle in degrees, or -1 for the center / not pressed.
5054
:param pov: index of the POV to read (starting at 0). Defaults to 0.
51-
:param loop: the event loop instance to attach the event to. Defaults to {@link
52-
CommandScheduler#getDefaultButtonLoop() the default command scheduler button loop}.
55+
:param loop: the event loop instance to attach the event to, defaults
56+
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
57+
5358
:returns: a Trigger instance based around this angle of a POV on the HID.
5459
"""
5560
if loop is None:
@@ -59,8 +64,7 @@ def pov(
5964
def povUp(self) -> Trigger:
6065
"""
6166
Constructs a Trigger instance based around the 0 degree angle (up) of the default (index 0) POV
62-
on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
63-
scheduler button loop}.
67+
on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
6468
6569
:returns: a Trigger instance based around the 0 degree angle of a POV on the HID.
6670
"""
@@ -69,8 +73,7 @@ def povUp(self) -> Trigger:
6973
def povUpRight(self) -> Trigger:
7074
"""
7175
Constructs a Trigger instance based around the 45 degree angle (right up) of the default (index
72-
0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default
73-
command scheduler button loop}.
76+
0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
7477
7578
:returns: a Trigger instance based around the 45 degree angle of a POV on the HID.
7679
"""
@@ -79,8 +82,7 @@ def povUpRight(self) -> Trigger:
7982
def povRight(self) -> Trigger:
8083
"""
8184
Constructs a Trigger instance based around the 90 degree angle (right) of the default (index 0)
82-
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
83-
scheduler button loop}.
85+
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
8486
8587
:returns: a Trigger instance based around the 90 degree angle of a POV on the HID.
8688
"""
@@ -89,8 +91,7 @@ def povRight(self) -> Trigger:
8991
def povDownRight(self) -> Trigger:
9092
"""
9193
Constructs a Trigger instance based around the 135 degree angle (right down) of the default
92-
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
93-
default command scheduler button loop}.
94+
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
9495
9596
:returns: a Trigger instance based around the 135 degree angle of a POV on the HID.
9697
"""
@@ -99,8 +100,7 @@ def povDownRight(self) -> Trigger:
99100
def povDown(self) -> Trigger:
100101
"""
101102
Constructs a Trigger instance based around the 180 degree angle (down) of the default (index 0)
102-
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
103-
scheduler button loop}.
103+
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
104104
105105
:returns: a Trigger instance based around the 180 degree angle of a POV on the HID.
106106
"""
@@ -109,8 +109,7 @@ def povDown(self) -> Trigger:
109109
def povDownLeft(self) -> Trigger:
110110
"""
111111
Constructs a Trigger instance based around the 225 degree angle (down left) of the default
112-
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
113-
default command scheduler button loop}.
112+
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
114113
115114
:returns: a Trigger instance based around the 225 degree angle of a POV on the HID.
116115
"""
@@ -119,8 +118,7 @@ def povDownLeft(self) -> Trigger:
119118
def povLeft(self) -> Trigger:
120119
"""
121120
Constructs a Trigger instance based around the 270 degree angle (left) of the default (index 0)
122-
POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
123-
scheduler button loop}.
121+
POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
124122
125123
:returns: a Trigger instance based around the 270 degree angle of a POV on the HID.
126124
"""
@@ -129,8 +127,7 @@ def povLeft(self) -> Trigger:
129127
def povUpLeft(self) -> Trigger:
130128
"""
131129
Constructs a Trigger instance based around the 315 degree angle (left up) of the default (index
132-
0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the default
133-
command scheduler button loop}.
130+
0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
134131
135132
:returns: a Trigger instance based around the 315 degree angle of a POV on the HID.
136133
"""
@@ -139,8 +136,7 @@ def povUpLeft(self) -> Trigger:
139136
def povCenter(self) -> Trigger:
140137
"""
141138
Constructs a Trigger instance based around the center (not pressed) position of the default
142-
(index 0) POV on the HID, attached to {@link CommandScheduler#getDefaultButtonLoop() the
143-
default command scheduler button loop}.
139+
(index 0) POV on the HID, attached to :func:`commands2.CommandScheduler.getDefaultButtonLoop`.
144140
145141
:returns: a Trigger instance based around the center position of a POV on the HID.
146142
"""
@@ -150,14 +146,15 @@ def axisLessThan(
150146
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
151147
) -> Trigger:
152148
"""
153-
Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
149+
Constructs a Trigger instance that is true when the axis value is less than ``threshold``,
154150
attached to the given loop.
155151
156152
:param axis: The axis to read, starting at 0
157153
:param threshold: The value below which this trigger should return true.
158154
:param loop: the event loop instance to attach the trigger to
155+
159156
:returns: a Trigger instance that is true when the axis value is less than the provided
160-
threshold.
157+
threshold.
161158
"""
162159
if loop is None:
163160
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
@@ -167,14 +164,15 @@ def axisGreaterThan(
167164
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
168165
) -> Trigger:
169166
"""
170-
Constructs a Trigger instance that is true when the axis value is greater than {@code
171-
threshold}, attached to the given loop.
167+
Constructs a Trigger instance that is true when the axis value is greater than
168+
``threshold``, attached to the given loop.
172169
173170
:param axis: The axis to read, starting at 0
174171
:param threshold: The value above which this trigger should return true.
175172
:param loop: the event loop instance to attach the trigger to.
173+
176174
:returns: a Trigger instance that is true when the axis value is greater than the provided
177-
threshold.
175+
threshold.
178176
"""
179177
if loop is None:
180178
loop = CommandScheduler.getInstance().getDefaultButtonLoop()

commands2/button/commandjoystick.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# validated: 2024-01-20 DS 92aecab2ef05 button/CommandJoystick.java
12
from typing import Optional
23

34
from wpilib import Joystick
@@ -10,7 +11,7 @@
1011

1112
class CommandJoystick(CommandGenericHID):
1213
"""
13-
A version of Joystick with Trigger factories for command-based.
14+
A version of :class:`wpilib.Joystick` with :class:`.Trigger` factories for command-based.
1415
"""
1516

1617
_hid: Joystick
@@ -25,7 +26,7 @@ def __init__(self, port: int):
2526
super().__init__(port)
2627
self._hid = Joystick(port)
2728

28-
def getHID(self):
29+
def getHID(self) -> Joystick:
2930
"""
3031
Get the underlying GenericHID object.
3132
@@ -37,7 +38,9 @@ def trigger(self, loop: Optional[EventLoop] = None) -> Trigger:
3738
"""
3839
Constructs an event instance around the trigger button's digital signal.
3940
40-
:param loop: the event loop instance to attach the event to.
41+
:param loop: the event loop instance to attach the event to, defaults
42+
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
43+
4144
:returns: an event instance representing the trigger button's digital signal attached to the
4245
given loop.
4346
"""
@@ -49,9 +52,11 @@ def top(self, loop: Optional[EventLoop] = None) -> Trigger:
4952
"""
5053
Constructs an event instance around the top button's digital signal.
5154
52-
:param loop: the event loop instance to attach the event to.
55+
:param loop: the event loop instance to attach the event to, defaults
56+
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
57+
5358
:returns: an event instance representing the top button's digital signal attached to the given
54-
loop.
59+
loop.
5560
"""
5661
if loop is None:
5762
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
@@ -121,21 +126,21 @@ def getZChannel(self) -> int:
121126
"""
122127
return self._hid.getZChannel()
123128

124-
def getThrottleChannel(self) -> int:
129+
def getTwistChannel(self) -> int:
125130
"""
126-
Get the channel currently associated with the throttle axis.
131+
Get the channel currently associated with the twist axis.
127132
128133
:returns: The channel for the axis.
129134
"""
130-
return self._hid.getThrottleChannel()
135+
return self._hid.getTwistChannel()
131136

132-
def getTwistChannel(self) -> int:
137+
def getThrottleChannel(self) -> int:
133138
"""
134-
Get the channel currently associated with the twist axis.
139+
Get the channel currently associated with the throttle axis.
135140
136141
:returns: The channel for the axis.
137142
"""
138-
return self._hid.getTwistChannel()
143+
return self._hid.getThrottleChannel()
139144

140145
def getX(self) -> float:
141146
"""

0 commit comments

Comments
 (0)