Skip to content

Commit 1e9c9e0

Browse files
Updated robotcontainer.py and constants.py for the maxswerve example to match updates to the commands2 class.
1 parent d5cc79e commit 1e9c9e0

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

examples/maxswerve/constants.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from wpimath.geometry import Translation2d
1515
from wpimath.kinematics import SwerveDrive4Kinematics
1616
from wpimath.trajectory import TrapezoidProfileRadians
17+
from wpimath.controller import HolonomicDriveController, PIDController, ProfiledPIDControllerRadians
18+
from wpimath.trajectory import TrapezoidProfileRadians
1719

1820
from rev import CANSparkMax
1921

@@ -131,11 +133,13 @@ class AutoConstants:
131133
kMaxAngularSpeedRadiansPerSecond = math.pi
132134
kMaxAngularSpeedRadiansPerSecondSquared = math.pi
133135

134-
kPXController = 1
135-
kPYController = 1
136-
kPThetaController = 1
137-
138136
# Constraint for the motion profiled robot angle controller
139137
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
140138
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared
141139
)
140+
141+
kPXController = PIDController(1.0, 0.0, 0.0)
142+
kPYController = PIDController(1.0, 0.0, 0.0)
143+
kPThetaController = ProfiledPIDControllerRadians(1.0, 0.0, 0.0, kThetaControllerConstraints)
144+
145+
kPIDController = HolonomicDriveController(kPXController, kPYController, kPThetaController)

examples/maxswerve/robotcontainer.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from wpimath.controller import PIDController, ProfiledPIDControllerRadians
99
from wpimath.geometry import Pose2d, Rotation2d, Translation2d
1010
from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator
11+
from wpimath.controller import HolonomicDriveController
1112

1213
from constants import AutoConstants, DriveConstants, OIConstants
1314
from subsystems.drivesubsystem import DriveSubsystem
@@ -88,24 +89,14 @@ def getAutonomousCommand(self) -> commands2.Command:
8889
config,
8990
)
9091

91-
thetaController = ProfiledPIDControllerRadians(
92-
AutoConstants.kPThetaController,
93-
0,
94-
0,
95-
AutoConstants.kThetaControllerConstraints,
96-
)
97-
thetaController.enableContinuousInput(-math.pi, math.pi)
98-
9992
swerveControllerCommand = commands2.SwerveControllerCommand(
10093
exampleTrajectory,
10194
self.robotDrive.getPose, # Functional interface to feed supplier
10295
DriveConstants.kDriveKinematics,
10396
# Position controllers
104-
PIDController(AutoConstants.kPXController, 0, 0),
105-
PIDController(AutoConstants.kPYController, 0, 0),
106-
thetaController,
97+
AutoConstants.kPIDController,
10798
self.robotDrive.setModuleStates,
108-
(self.robotDrive,),
99+
(self.robotDrive,)
109100
)
110101

111102
# Reset odometry to the starting pose of the trajectory.
@@ -117,4 +108,4 @@ def getAutonomousCommand(self) -> commands2.Command:
117108
lambda: self.robotDrive.drive(0, 0, 0, False, False),
118109
self.robotDrive,
119110
)
120-
)
111+
)

0 commit comments

Comments
 (0)