Skip to content

Commit d181ad1

Browse files
TheTripleVvirtuald
authored andcommitted
Port Commands to Pure Python
1 parent 28428ed commit d181ad1

File tree

223 files changed

+6551
-13449
lines changed

Some content is hidden

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

223 files changed

+6551
-13449
lines changed

.github/workflows/dist.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ on:
1111

1212
jobs:
1313
ci:
14-
uses: robotpy/build-actions/.github/workflows/package-ci.yml@v2023
14+
uses: robotpy/build-actions/.github/workflows/package-pure.yml@v2024-alpha
1515
with:
1616
enable_sphinx_check: false
1717
secrets:
18-
SSH_USER: ${{ secrets.SSH_USER }}
19-
SSH_KEY: ${{ secrets.SSH_KEY }}
20-
SSH_PASSPHRASE: ${{ secrets.SSH_PASSPHRASE }}
2118
META_REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
22-
RTD_TOKEN: ${{ secrets.RTD_TOKEN }}
23-
RTD_WEBHOOK: ${{ secrets.RTD_WEBHOOK }}
2419
PYPI_API_TOKEN: ${{ secrets.PYPI_PASSWORD }}

commands2/__init__.py

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,93 @@
1-
from . import _init_impl
1+
from .button import Trigger
2+
from .command import Command, InterruptionBehavior
23

3-
from .version import version as __version__
4+
from . import cmd
45

5-
# autogenerated by 'robotpy-build create-imports commands2 commands2._impl'
6-
from ._impl import (
7-
Command,
8-
CommandBase,
9-
CommandGroupBase,
10-
CommandScheduler,
11-
ConditionalCommand,
12-
FunctionalCommand,
13-
InstantCommand,
14-
MecanumControllerCommand,
15-
NotifierCommand,
16-
PIDCommand,
17-
PIDSubsystem,
18-
ParallelCommandGroup,
19-
ParallelDeadlineGroup,
20-
ParallelRaceGroup,
21-
PerpetualCommand,
22-
PrintCommand,
23-
ProfiledPIDCommand,
24-
ProfiledPIDSubsystem,
25-
ProxyScheduleCommand,
26-
RamseteCommand,
27-
RepeatCommand,
28-
RunCommand,
29-
ScheduleCommand,
30-
SelectCommand,
31-
SequentialCommandGroup,
32-
StartEndCommand,
33-
Subsystem,
34-
SubsystemBase,
35-
Swerve2ControllerCommand,
36-
Swerve3ControllerCommand,
37-
Swerve4ControllerCommand,
38-
Swerve6ControllerCommand,
39-
TimedCommandRobot,
40-
TrapezoidProfileCommand,
41-
TrapezoidProfileCommandRadians,
42-
TrapezoidProfileSubsystem,
43-
TrapezoidProfileSubsystemRadians,
44-
Trigger,
45-
WaitCommand,
46-
WaitUntilCommand,
47-
# button,
48-
# cmd,
49-
requirementsDisjoint,
50-
)
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
24+
from .commandscheduler import CommandScheduler
25+
from .conditionalcommand import ConditionalCommand
26+
from .functionalcommand import FunctionalCommand
27+
from .instantcommand import InstantCommand
28+
from .notifiercommand import NotifierCommand
29+
from .parallelcommandgroup import ParallelCommandGroup
30+
from .paralleldeadlinegroup import ParallelDeadlineGroup
31+
from .parallelracegroup import ParallelRaceGroup
32+
from .perpetualcommand import PerpetualCommand
33+
from .printcommand import PrintCommand
34+
from .proxycommand import ProxyCommand
35+
from .proxyschedulecommand import ProxyScheduleCommand
36+
from .repeatcommand import RepeatCommand
37+
from .runcommand import RunCommand
38+
from .schedulecommand import ScheduleCommand
39+
from .selectcommand import SelectCommand
40+
from .sequentialcommandgroup import SequentialCommandGroup
41+
from .startendcommand import StartEndCommand
42+
from .subsystem import Subsystem
43+
from .timedcommandrobot import TimedCommandRobot
44+
from .waitcommand import WaitCommand
45+
from .waituntilcommand import WaitUntilCommand
46+
from .wrappercommand import WrapperCommand
5147

5248
__all__ = [
49+
"cmd",
5350
"Command",
54-
"CommandBase",
55-
"CommandGroupBase",
51+
"CommandGroup",
5652
"CommandScheduler",
5753
"ConditionalCommand",
58-
"SelectCommand",
5954
"FunctionalCommand",
55+
"IllegalCommandUse",
6056
"InstantCommand",
61-
"MecanumControllerCommand",
57+
"InterruptionBehavior",
6258
"NotifierCommand",
63-
"PIDCommand",
64-
"PIDSubsystem",
6559
"ParallelCommandGroup",
6660
"ParallelDeadlineGroup",
6761
"ParallelRaceGroup",
6862
"PerpetualCommand",
6963
"PrintCommand",
70-
"ProfiledPIDCommand",
71-
"ProfiledPIDSubsystem",
64+
"ProxyCommand",
7265
"ProxyScheduleCommand",
73-
"RamseteCommand",
7466
"RepeatCommand",
7567
"RunCommand",
7668
"ScheduleCommand",
69+
"SelectCommand",
7770
"SequentialCommandGroup",
7871
"StartEndCommand",
7972
"Subsystem",
80-
"SubsystemBase",
81-
"Swerve2ControllerCommand",
82-
"Swerve3ControllerCommand",
83-
"Swerve4ControllerCommand",
84-
"Swerve6ControllerCommand",
8573
"TimedCommandRobot",
86-
"TrapezoidProfileCommand",
87-
"TrapezoidProfileCommandRadians",
88-
"TrapezoidProfileSubsystem",
89-
"TrapezoidProfileSubsystemRadians",
90-
"Trigger",
9174
"WaitCommand",
9275
"WaitUntilCommand",
93-
# "button",
94-
# "cmd",
95-
"requirementsDisjoint",
76+
"WrapperCommand",
77+
# "none",
78+
# "runOnce",
79+
# "run",
80+
# "startEnd",
81+
# "runEnd",
82+
# "print_",
83+
# "waitSeconds",
84+
# "waitUntil",
85+
# "either",
86+
# "select",
87+
# "sequence",
88+
# "repeatingSequence",
89+
# "parallel",
90+
# "race",
91+
# "deadline",
92+
"Trigger", # was here in 2023
9693
]

commands2/button/__init__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# autogenerated by 'robotpy-build create-imports commands2.button commands2._impl.button'
2-
from .._impl.button import (
3-
Button,
4-
CommandGenericHID,
5-
CommandJoystick,
6-
CommandPS4Controller,
7-
CommandXboxController,
8-
JoystickButton,
9-
NetworkButton,
10-
POVButton,
11-
)
1+
from .commandgenerichid import CommandGenericHID
2+
from .commandjoystick import CommandJoystick
3+
from .commandps4controller import CommandPS4Controller
4+
from .commandxboxcontroller import CommandXboxController
5+
from .joystickbutton import JoystickButton
6+
from .networkbutton import NetworkButton
7+
from .povbutton import POVButton
8+
from .trigger import Trigger
129

1310
__all__ = [
14-
"Button",
11+
"Trigger",
1512
"CommandGenericHID",
1613
"CommandJoystick",
1714
"CommandPS4Controller",
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
from typing import Optional
2+
3+
from wpilib.event import EventLoop
4+
from wpilib.interfaces import GenericHID
5+
6+
from ..commandscheduler import CommandScheduler
7+
from .trigger import Trigger
8+
9+
10+
class CommandGenericHID:
11+
"""
12+
A version of GenericHID with Trigger factories for command-based.
13+
"""
14+
15+
def __init__(self, port: int):
16+
"""
17+
Construct an instance of a device.
18+
19+
:param port: The port on the Driver Station that the device is plugged into.
20+
"""
21+
self._hid = GenericHID(port)
22+
23+
def getHID(self) -> GenericHID:
24+
"""
25+
Get the underlying GenericHID object.
26+
"""
27+
return self._hid
28+
29+
def button(self, button: int, loop: Optional[EventLoop] = None) -> Trigger:
30+
"""
31+
Constructs an event instance around this button's digital signal.
32+
33+
:param button: The button index
34+
:param loop: the event loop instance to attache the event to.
35+
"""
36+
if loop is None:
37+
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
38+
return Trigger(loop, lambda: self._hid.getRawButtonPressed(button))
39+
40+
def pov(
41+
self, angle: int, *, pov: int = 0, loop: Optional[EventLoop] = None
42+
) -> Trigger:
43+
"""
44+
Constructs a Trigger instance based around this angle of a POV on the HID.
45+
46+
The POV angles start at 0 in the up direction, and increase clockwise (e.g. right is 90,
47+
upper-left is 315).
48+
49+
:param angle: POV angle in degrees, or -1 for the center / not pressed.
50+
: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}.
53+
:returns: a Trigger instance based around this angle of a POV on the HID.
54+
"""
55+
if loop is None:
56+
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
57+
return Trigger(loop, lambda: self._hid.getPOV(pov) == angle)
58+
59+
def povUp(self) -> Trigger:
60+
"""
61+
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}.
64+
65+
:returns: a Trigger instance based around the 0 degree angle of a POV on the HID.
66+
"""
67+
return self.pov(0)
68+
69+
def povUpRight(self) -> Trigger:
70+
"""
71+
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}.
74+
75+
:returns: a Trigger instance based around the 45 degree angle of a POV on the HID.
76+
"""
77+
return self.pov(45)
78+
79+
def povRight(self) -> Trigger:
80+
"""
81+
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}.
84+
85+
:returns: a Trigger instance based around the 90 degree angle of a POV on the HID.
86+
"""
87+
return self.pov(90)
88+
89+
def povDownRight(self) -> Trigger:
90+
"""
91+
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+
95+
:returns: a Trigger instance based around the 135 degree angle of a POV on the HID.
96+
"""
97+
return self.pov(135)
98+
99+
def povDown(self) -> Trigger:
100+
"""
101+
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}.
104+
105+
:returns: a Trigger instance based around the 180 degree angle of a POV on the HID.
106+
"""
107+
return self.pov(180)
108+
109+
def povDownLeft(self) -> Trigger:
110+
"""
111+
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}.
114+
115+
:returns: a Trigger instance based around the 225 degree angle of a POV on the HID.
116+
"""
117+
return self.pov(225)
118+
119+
def povLeft(self) -> Trigger:
120+
"""
121+
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}.
124+
125+
:returns: a Trigger instance based around the 270 degree angle of a POV on the HID.
126+
"""
127+
return self.pov(270)
128+
129+
def povUpLeft(self) -> Trigger:
130+
"""
131+
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}.
134+
135+
:returns: a Trigger instance based around the 315 degree angle of a POV on the HID.
136+
"""
137+
return self.pov(315)
138+
139+
def povCenter(self) -> Trigger:
140+
"""
141+
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}.
144+
145+
:returns: a Trigger instance based around the center position of a POV on the HID.
146+
"""
147+
return self.pov(-1)
148+
149+
def axisLessThan(
150+
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
151+
) -> Trigger:
152+
"""
153+
Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
154+
attached to the given loop.
155+
156+
:param axis: The axis to read, starting at 0
157+
:param threshold: The value below which this trigger should return true.
158+
:param loop: the event loop instance to attach the trigger to
159+
:returns: a Trigger instance that is true when the axis value is less than the provided
160+
threshold.
161+
"""
162+
if loop is None:
163+
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
164+
return Trigger(loop, lambda: self._hid.getRawAxis(axis) < threshold)
165+
166+
def axisGreaterThan(
167+
self, axis: int, threshold: float, loop: Optional[EventLoop] = None
168+
) -> Trigger:
169+
"""
170+
Constructs a Trigger instance that is true when the axis value is greater than {@code
171+
threshold}, attached to the given loop.
172+
173+
:param axis: The axis to read, starting at 0
174+
:param threshold: The value above which this trigger should return true.
175+
:param loop: the event loop instance to attach the trigger to.
176+
:returns: a Trigger instance that is true when the axis value is greater than the provided
177+
threshold.
178+
"""
179+
if loop is None:
180+
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
181+
return Trigger(loop, lambda: self._hid.getRawAxis(axis) > threshold)
182+
183+
def getRawAxis(self, axis: int) -> float:
184+
"""
185+
Get the value of the axis.
186+
187+
:param axis: The axis to read, starting at 0.
188+
:returns: The value of the axis.
189+
"""
190+
return self._hid.getRawAxis(axis)

0 commit comments

Comments
 (0)