Skip to content

Commit 3463a23

Browse files
authored
Merge pull request #46 from robotpy/review
Commands QA review
2 parents 27a3071 + 20f9aca commit 3463a23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1312
-957
lines changed

.gittrack

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[git-source-track]
2+
upstream_root = ../allwpilib/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command
3+
upstream_branch = main
4+
upstream_commit = 4595f84719759d71491e11e8df55d60ce2a6154c
5+
validation_root = commands2

commands2/__init__.py

+3-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
1-
from .button import Trigger
21
from .command import Command, InterruptionBehavior
32

3+
from . import button
44
from . import cmd
55

6-
# from .cmd import (
7-
# deadline,
8-
# either,
9-
# none,
10-
# parallel,
11-
# print_,
12-
# race,
13-
# repeatingSequence,
14-
# run,
15-
# runEnd,
16-
# runOnce,
17-
# select,
18-
# sequence,
19-
# startEnd,
20-
# waitSeconds,
21-
# waitUntil,
22-
# )
23-
from .commandgroup import CommandGroup, IllegalCommandUse
246
from .commandscheduler import CommandScheduler
257
from .conditionalcommand import ConditionalCommand
8+
from .exceptions import IllegalCommandUse
269
from .functionalcommand import FunctionalCommand
2710
from .instantcommand import InstantCommand
2811
from .notifiercommand import NotifierCommand
2912
from .parallelcommandgroup import ParallelCommandGroup
3013
from .paralleldeadlinegroup import ParallelDeadlineGroup
3114
from .parallelracegroup import ParallelRaceGroup
32-
from .perpetualcommand import PerpetualCommand
3315
from .pidcommand import PIDCommand
3416
from .pidsubsystem import PIDSubsystem
3517
from .printcommand import PrintCommand
3618
from .proxycommand import ProxyCommand
37-
from .proxyschedulecommand import ProxyScheduleCommand
3819
from .repeatcommand import RepeatCommand
3920
from .runcommand import RunCommand
4021
from .schedulecommand import ScheduleCommand
@@ -52,9 +33,9 @@
5233
from typing import TYPE_CHECKING
5334

5435
__all__ = [
36+
"button",
5537
"cmd",
5638
"Command",
57-
"CommandGroup",
5839
"CommandScheduler",
5940
"ConditionalCommand",
6041
"FunctionalCommand",
@@ -65,12 +46,10 @@
6546
"ParallelCommandGroup",
6647
"ParallelDeadlineGroup",
6748
"ParallelRaceGroup",
68-
"PerpetualCommand",
6949
"PIDCommand",
7050
"PIDSubsystem",
7151
"PrintCommand",
7252
"ProxyCommand",
73-
"ProxyScheduleCommand",
7453
"RepeatCommand",
7554
"RunCommand",
7655
"ScheduleCommand",
@@ -84,22 +63,6 @@
8463
"WaitCommand",
8564
"WaitUntilCommand",
8665
"WrapperCommand",
87-
# "none",
88-
# "runOnce",
89-
# "run",
90-
# "startEnd",
91-
# "runEnd",
92-
# "print_",
93-
# "waitSeconds",
94-
# "waitUntil",
95-
# "either",
96-
# "select",
97-
# "sequence",
98-
# "repeatingSequence",
99-
# "parallel",
100-
# "race",
101-
# "deadline",
102-
"Trigger", # was here in 2023
10366
]
10467

10568
if not TYPE_CHECKING:

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)