Skip to content

Commit 8300e6f

Browse files
committed
Update examples for 2024
- Some of the command based examples don't work because the command framework is incomplete. See robotpy/robotpy-commands-v2#28
1 parent bab2e0d commit 8300e6f

File tree

34 files changed

+96
-96
lines changed

34 files changed

+96
-96
lines changed

Diff for: .github/workflows/test.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@ jobs:
1313
check:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- uses: psf/black@stable
1818

1919
test:
2020
runs-on: ${{ matrix.os }}
2121
strategy:
2222
matrix:
23-
os: [windows-latest, macos-latest, ubuntu-22.04]
24-
python_version: [3.7, 3.8, 3.9, "3.10", "3.11"]
23+
os: ["ubuntu-22.04", "macos-12", "windows-2022"]
24+
python_version:
25+
- '3.8'
26+
- '3.9'
27+
- '3.10'
28+
- '3.11'
29+
- '3.12'
2530

2631
steps:
27-
- uses: actions/checkout@v3
32+
- uses: actions/checkout@v4
2833
- uses: actions/setup-python@v4
2934
with:
3035
python-version: ${{ matrix.python_version }}
3136
architecture: ${{ matrix.architecture }}
3237
- name: Install deps
3338
run: |
34-
pip install numpy
3539
pip install -U pip
36-
pip install 'robotpy[commands2]<2024.0.0,>=2023.1.1.0' pytest
37-
#pip install 'robotpy[commands2,romi]<2024.0.0,>=2023.0.0b3' pytest
40+
pip install 'robotpy[commands2]<2025.0.0,>=2024.0.0b3' numpy pytest
3841
- name: Run tests
3942
run: bash run_tests.sh
4043
shell: bash

Diff for: arm-simulation/physics.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, physics_controller: PhysicsInterface, robot: "MyRobot"):
5454
math.radians(-75),
5555
math.radians(255),
5656
True,
57+
0,
5758
)
5859
self.encoderSim = wpilib.simulation.EncoderSim(robot.encoder)
5960
self.motorSim = wpilib.simulation.PWMSim(robot.motor.getChannel())

Diff for: commands-v2/armbot/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import constants
1010

1111

12-
class DriveSubsystem(commands2.SubsystemBase):
12+
class DriveSubsystem(commands2.Subsystem):
1313
# Creates a new DriveSubsystem
1414
def __init__(self) -> None:
1515
super().__init__()

Diff for: commands-v2/armbotoffboard/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import typing
1111

1212

13-
class DriveSubsystem(commands2.SubsystemBase):
13+
class DriveSubsystem(commands2.Subsystem):
1414
def __init__(self) -> None:
1515
super().__init__()
1616

Diff for: commands-v2/drive-distance-offboard/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import examplesmartmotorcontroller
1414

1515

16-
class DriveSubsystem(commands2.SubsystemBase):
16+
class DriveSubsystem(commands2.Subsystem):
1717
def __init__(self) -> None:
1818
"""Creates a new DriveSubsystem"""
1919
super().__init__()

Diff for: commands-v2/frisbee-bot/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import constants
1111

1212

13-
class DriveSubsystem(commands2.SubsystemBase):
13+
class DriveSubsystem(commands2.Subsystem):
1414
def __init__(self) -> None:
1515
"""Creates a new DriveSubsystem"""
1616
super().__init__()

Diff for: commands-v2/gyro-drive-commands/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import constants
1212

1313

14-
class DriveSubsystem(commands2.SubsystemBase):
14+
class DriveSubsystem(commands2.Subsystem):
1515
def __init__(self) -> None:
1616
"""Creates a new DriveSubsystem"""
1717
super().__init__()

Diff for: commands-v2/hatchbot-inlined/commands/autos.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Autos:
2020
def __init__(self) -> None:
2121
raise Exception("This is a utility class!")
2222

23+
@staticmethod
2324
def simpleAuto(drive: subsystems.drivesubsystem.DriveSubsystem):
2425
"""A simple auto routine that drives forward a specified distance, and then stops."""
2526
return commands2.FunctionalCommand(
@@ -35,42 +36,41 @@ def simpleAuto(drive: subsystems.drivesubsystem.DriveSubsystem):
3536
# Require the drive subsystem
3637
)
3738

39+
@staticmethod
3840
def complexAuto(
3941
driveSubsystem: subsystems.drivesubsystem.DriveSubsystem,
4042
hatchSubsystem: subsystems.hatchsubsystem.HatchSubsystem,
4143
):
4244
"""A complex auto routine that drives forward, drops a hatch, and then drives backward."""
4345
return commands2.cmd.sequence(
44-
[
45-
# Drive forward up to the front of the cargo ship
46-
commands2.FunctionalCommand(
47-
# Reset encoders on command start
48-
driveSubsystem.resetEncoders,
49-
# Drive forward while the command is executing
50-
lambda: driveSubsystem.arcadeDrive(constants.kAutoDriveSpeed, 0),
51-
# Stop driving at the end of the command
52-
lambda interrupt: driveSubsystem.arcadeDrive(0, 0),
53-
# End the command when the robot's driven distance exceeds the desired value
54-
lambda: driveSubsystem.getAverageEncoderDistance()
55-
>= constants.kAutoDriveDistanceInches,
56-
# Require the drive subsystem
57-
[driveSubsystem],
58-
),
59-
# Release the hatch
60-
hatchSubsystem.releaseHatch(),
61-
# Drive backward the specified distance
62-
commands2.FunctionalCommand(
63-
# Reset encoders on command start
64-
driveSubsystem.resetEncoders,
65-
# Drive backwards while the command is executing
66-
lambda: driveSubsystem.arcadeDrive(-constants.kAutoDriveSpeed, 0),
67-
# Stop driving at the end of the command
68-
lambda interrupt: driveSubsystem.arcadeDrive(0, 0),
69-
# End the command when the robot's driven distance exceeds the desired value
70-
lambda: abs(driveSubsystem.getAverageEncoderDistance())
71-
>= constants.kAutoBackupDistanceInches,
72-
# Require the drive subsystem
73-
[driveSubsystem],
74-
),
75-
]
46+
# Drive forward up to the front of the cargo ship
47+
commands2.FunctionalCommand(
48+
# Reset encoders on command start
49+
driveSubsystem.resetEncoders,
50+
# Drive forward while the command is executing
51+
lambda: driveSubsystem.arcadeDrive(constants.kAutoDriveSpeed, 0),
52+
# Stop driving at the end of the command
53+
lambda interrupt: driveSubsystem.arcadeDrive(0, 0),
54+
# End the command when the robot's driven distance exceeds the desired value
55+
lambda: driveSubsystem.getAverageEncoderDistance()
56+
>= constants.kAutoDriveDistanceInches,
57+
# Require the drive subsystem
58+
driveSubsystem,
59+
),
60+
# Release the hatch
61+
hatchSubsystem.releaseHatch(),
62+
# Drive backward the specified distance
63+
commands2.FunctionalCommand(
64+
# Reset encoders on command start
65+
driveSubsystem.resetEncoders,
66+
# Drive backwards while the command is executing
67+
lambda: driveSubsystem.arcadeDrive(-constants.kAutoDriveSpeed, 0),
68+
# Stop driving at the end of the command
69+
lambda interrupt: driveSubsystem.arcadeDrive(0, 0),
70+
# End the command when the robot's driven distance exceeds the desired value
71+
lambda: abs(driveSubsystem.getAverageEncoderDistance())
72+
>= constants.kAutoBackupDistanceInches,
73+
# Require the drive subsystem
74+
driveSubsystem,
75+
),
7676
)

Diff for: commands-v2/hatchbot-inlined/physics.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
import wpilib
1313
import wpilib.simulation
14-
from wpimath.system import LinearSystemId
15-
from wpimath.system.plant import DCMotor
14+
from wpimath.system.plant import DCMotor, LinearSystemId
1615

1716
import constants
1817

Diff for: commands-v2/hatchbot-inlined/robotcontainer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self) -> None:
5454
-self.driverController.getLeftY(),
5555
-self.driverController.getRightX(),
5656
),
57-
[self.driveSubsystem],
57+
self.driveSubsystem,
5858
)
5959
)
6060

Diff for: commands-v2/hatchbot-inlined/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import constants
66

77

8-
class DriveSubsystem(commands2.SubsystemBase):
8+
class DriveSubsystem(commands2.Subsystem):
99
def __init__(self) -> None:
1010
super().__init__()
1111

Diff for: commands-v2/hatchbot-inlined/subsystems/hatchsubsystem.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import constants
66

77

8-
class HatchSubsystem(commands2.SubsystemBase):
8+
class HatchSubsystem(commands2.Subsystem):
99
def __init__(self) -> None:
1010
super().__init__()
1111

@@ -18,11 +18,11 @@ def __init__(self) -> None:
1818
def grabHatch(self) -> commands2.Command:
1919
"""Grabs the hatch"""
2020
return commands2.cmd.runOnce(
21-
lambda: self.hatchSolenoid.set(wpilib.DoubleSolenoid.Value.kForward), [self]
21+
lambda: self.hatchSolenoid.set(wpilib.DoubleSolenoid.Value.kForward), self
2222
)
2323

2424
def releaseHatch(self) -> commands2.Command:
2525
"""Releases the hatch"""
2626
return commands2.cmd.runOnce(
27-
lambda: self.hatchSolenoid.set(wpilib.DoubleSolenoid.Value.kReverse), [self]
27+
lambda: self.hatchSolenoid.set(wpilib.DoubleSolenoid.Value.kReverse), self
2828
)

Diff for: commands-v2/hatchbot/commands/defaultdrive.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from subsystems.drivesubsystem import DriveSubsystem
44

55

6-
class DefaultDrive(commands2.CommandBase):
6+
class DefaultDrive(commands2.Command):
77
def __init__(
88
self,
99
drive: DriveSubsystem,
@@ -16,7 +16,7 @@ def __init__(
1616
self.forward = forward
1717
self.rotation = rotation
1818

19-
self.addRequirements([self.drive])
19+
self.addRequirements(self.drive)
2020

2121
def execute(self) -> None:
2222
self.drive.arcadeDrive(self.forward(), self.rotation())

Diff for: commands-v2/hatchbot/commands/drivedistance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from subsystems.drivesubsystem import DriveSubsystem
44

55

6-
class DriveDistance(commands2.CommandBase):
6+
class DriveDistance(commands2.Command):
77
def __init__(self, inches: float, speed: float, drive: DriveSubsystem) -> None:
88
super().__init__()
99
self.distance = inches

Diff for: commands-v2/hatchbot/commands/grabhatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from subsystems.hatchsubsystem import HatchSubsystem
33

44

5-
class GrabHatch(commands2.CommandBase):
5+
class GrabHatch(commands2.Command):
66
def __init__(self, hatch: HatchSubsystem) -> None:
77
super().__init__()
88
self.hatch = hatch

Diff for: commands-v2/hatchbot/commands/halvedrivespeed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from subsystems.drivesubsystem import DriveSubsystem
44

55

6-
class HalveDriveSpeed(commands2.CommandBase):
6+
class HalveDriveSpeed(commands2.Command):
77
def __init__(self, drive: DriveSubsystem) -> None:
88
super().__init__()
99
self.drive = drive

Diff for: commands-v2/hatchbot/physics.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
import wpilib
1313
import wpilib.simulation
14-
from wpimath.system import LinearSystemId
15-
from wpimath.system.plant import DCMotor
14+
from wpimath.system.plant import DCMotor, LinearSystemId
1615

1716
import constants
1817

Diff for: commands-v2/hatchbot/robotcontainer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ def configureButtonBindings(self):
7272
and then passing it to a JoystickButton.
7373
"""
7474

75-
commands2.button.JoystickButton(self.driverController, 1).whenPressed(
75+
commands2.button.JoystickButton(self.driverController, 1).onTrue(
7676
GrabHatch(self.hatch)
7777
)
7878

79-
commands2.button.JoystickButton(self.driverController, 2).whenPressed(
79+
commands2.button.JoystickButton(self.driverController, 2).onTrue(
8080
ReleaseHatch(self.hatch)
8181
)
8282

83-
commands2.button.JoystickButton(self.driverController, 3).whenHeld(
83+
commands2.button.JoystickButton(self.driverController, 3).whileTrue(
8484
HalveDriveSpeed(self.drive)
8585
)
8686

Diff for: commands-v2/hatchbot/subsystems/drivesubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import constants
66

77

8-
class DriveSubsystem(commands2.SubsystemBase):
8+
class DriveSubsystem(commands2.Subsystem):
99
def __init__(self) -> None:
1010
super().__init__()
1111

Diff for: commands-v2/hatchbot/subsystems/hatchsubsystem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import constants
55

66

7-
class HatchSubsystem(commands2.SubsystemBase):
7+
class HatchSubsystem(commands2.Subsystem):
88
def __init__(self) -> None:
99
super().__init__()
1010

Diff for: commands-v2/ramsete/subsystems/drivetrain.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from commands2 import SubsystemBase
1+
from commands2 import Subsystem
22

33
from wpilib import MotorControllerGroup, PWMSparkMax, Encoder, AnalogGyro
44
from wpilib.drive import DifferentialDrive
@@ -9,7 +9,7 @@
99
import constants
1010

1111

12-
class Drivetrain(SubsystemBase):
12+
class Drivetrain(Subsystem):
1313
def __init__(self):
1414
super().__init__()
1515

Diff for: commands-v2/romi/commands/arcadedrive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from subsystems.drivetrain import Drivetrain
88

99

10-
class ArcadeDrive(commands2.CommandBase):
10+
class ArcadeDrive(commands2.Command):
1111
def __init__(
1212
self,
1313
drive: Drivetrain,

Diff for: commands-v2/romi/commands/drivedistance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from subsystems.drivetrain import Drivetrain
88

99

10-
class DriveDistance(commands2.CommandBase):
10+
class DriveDistance(commands2.Command):
1111
def __init__(self, speed: float, inches: float, drive: Drivetrain) -> None:
1212
"""Creates a new DriveDistance. This command will drive your your robot for a desired distance at
1313
a desired speed.

Diff for: commands-v2/romi/commands/drivetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from subsystems.drivetrain import Drivetrain
99

1010

11-
class DriveTime(commands2.CommandBase):
11+
class DriveTime(commands2.Command):
1212
"""Creates a new DriveTime. This command will drive your robot for a desired speed and time."""
1313

1414
def __init__(self, speed: float, time: float, drive: Drivetrain) -> None:

Diff for: commands-v2/romi/commands/turndegrees.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from subsystems.drivetrain import Drivetrain
99

1010

11-
class TurnDegrees(commands2.CommandBase):
11+
class TurnDegrees(commands2.Command):
1212
def __init__(self, speed: float, degrees: float, drive: Drivetrain) -> None:
1313
"""Creates a new TurnDegrees. This command will turn your robot for a desired rotation (in
1414
degrees) and rotational speed.

Diff for: commands-v2/romi/commands/turntime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from subsystems.drivetrain import Drivetrain
99

1010

11-
class TurnTime(commands2.CommandBase):
11+
class TurnTime(commands2.Command):
1212
"""Creates a new TurnTime command. This command will turn your robot for a
1313
desired rotational speed and time.
1414
"""

Diff for: commands-v2/romi/robotcontainer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _configureButtonBindings(self):
7373
self.chooser.addOption("Auto Routine Time", AutonomousTime(self.drivetrain))
7474
wpilib.SmartDashboard.putData(self.chooser)
7575

76-
def getAutonomousCommand(self) -> typing.Optional[commands2.CommandBase]:
76+
def getAutonomousCommand(self) -> typing.Optional[commands2.Command]:
7777
return self.chooser.getSelected()
7878

7979
def getArcadeDriveCommand(self) -> ArcadeDrive:

Diff for: commands-v2/romi/subsystems/drivetrain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import romi
1111

1212

13-
class Drivetrain(commands2.SubsystemBase):
13+
class Drivetrain(commands2.Subsystem):
1414
kCountsPerRevolution = 1440.0
1515
kWheelDiameterInch = 2.75591
1616

0 commit comments

Comments
 (0)