|
7 | 7 | from commands2 import cmd |
8 | 8 | from wpimath.controller import PIDController, ProfiledPIDControllerRadians |
9 | 9 | from wpimath.geometry import Pose2d, Rotation2d, Translation2d |
10 | | -from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator |
11 | | -from wpimath.controller import HolonomicDriveController |
| 10 | +from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator, TrapezoidProfileRadians |
| 11 | +from wpimath.controller import HolonomicDriveController, PIDController, ProfiledPIDControllerRadians |
12 | 12 |
|
13 | 13 | from constants import AutoConstants, DriveConstants, OIConstants |
14 | 14 | from subsystems.drivesubsystem import DriveSubsystem |
@@ -89,12 +89,27 @@ def getAutonomousCommand(self) -> commands2.Command: |
89 | 89 | config, |
90 | 90 | ) |
91 | 91 |
|
| 92 | + # Constraint for the motion profiled robot angle controller |
| 93 | + kThetaControllerConstraints = TrapezoidProfileRadians.Constraints( |
| 94 | + AutoConstants.kMaxAngularSpeedRadiansPerSecond, AutoConstants.kMaxAngularSpeedRadiansPerSecondSquared |
| 95 | + ) |
| 96 | + |
| 97 | + kPXController = PIDController(1.0, 0.0, 0.0) |
| 98 | + kPYController = PIDController(1.0, 0.0, 0.0) |
| 99 | + kPThetaController = ProfiledPIDControllerRadians(1.0, 0.0, 0.0, kThetaControllerConstraints) |
| 100 | + kPThetaController.enableContinuousInput(-math.pi, math.pi) |
| 101 | + |
| 102 | + kPIDController = HolonomicDriveController( |
| 103 | + kPXController, |
| 104 | + kPYController, |
| 105 | + kPThetaController) |
| 106 | + |
92 | 107 | swerveControllerCommand = commands2.SwerveControllerCommand( |
93 | 108 | exampleTrajectory, |
94 | 109 | self.robotDrive.getPose, # Functional interface to feed supplier |
95 | 110 | DriveConstants.kDriveKinematics, |
96 | 111 | # Position controllers |
97 | | - AutoConstants.kPIDController, |
| 112 | + kPIDController, |
98 | 113 | self.robotDrive.setModuleStates, |
99 | 114 | (self.robotDrive,) |
100 | 115 | ) |
|
0 commit comments