Skip to content

Commit 47df42c

Browse files
Updated robotcontainer.py and constants.py for the maxswerve example … (#65)
* Updated robotcontainer.py and constants.py for the maxswerve example to match updates to the commands2 class. * Update constants.py Added the line to enable continuous inputs on the ProfiledPIDController. * Update constants.py Oops, changed the wrong PID controller. * Transfered commands from constants.py to robotcontainer.py * Added new line to end of robotcontainer.py * Fixed Formatting * Fixed some formatting issues to comply with ci. * Fixed some spacing
1 parent d5cc79e commit 47df42c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

examples/maxswerve/constants.py

-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from wpimath import units
1414
from wpimath.geometry import Translation2d
1515
from wpimath.kinematics import SwerveDrive4Kinematics
16-
from wpimath.trajectory import TrapezoidProfileRadians
1716

1817
from rev import CANSparkMax
1918

@@ -130,12 +129,3 @@ class AutoConstants:
130129
kMaxAccelerationMetersPerSecondSquared = 3
131130
kMaxAngularSpeedRadiansPerSecond = math.pi
132131
kMaxAngularSpeedRadiansPerSecondSquared = math.pi
133-
134-
kPXController = 1
135-
kPYController = 1
136-
kPThetaController = 1
137-
138-
# Constraint for the motion profiled robot angle controller
139-
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
140-
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared
141-
)

examples/maxswerve/robotcontainer.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
from commands2 import cmd
88
from wpimath.controller import PIDController, ProfiledPIDControllerRadians
99
from wpimath.geometry import Pose2d, Rotation2d, Translation2d
10-
from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator
10+
from wpimath.trajectory import (
11+
TrajectoryConfig,
12+
TrajectoryGenerator,
13+
TrapezoidProfileRadians,
14+
)
15+
from wpimath.controller import (
16+
HolonomicDriveController,
17+
PIDController,
18+
ProfiledPIDControllerRadians,
19+
)
1120

1221
from constants import AutoConstants, DriveConstants, OIConstants
1322
from subsystems.drivesubsystem import DriveSubsystem
@@ -88,22 +97,29 @@ def getAutonomousCommand(self) -> commands2.Command:
8897
config,
8998
)
9099

91-
thetaController = ProfiledPIDControllerRadians(
92-
AutoConstants.kPThetaController,
93-
0,
94-
0,
95-
AutoConstants.kThetaControllerConstraints,
100+
# Constraint for the motion profiled robot angle controller
101+
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
102+
AutoConstants.kMaxAngularSpeedRadiansPerSecond,
103+
AutoConstants.kMaxAngularSpeedRadiansPerSecondSquared,
104+
)
105+
106+
kPXController = PIDController(1.0, 0.0, 0.0)
107+
kPYController = PIDController(1.0, 0.0, 0.0)
108+
kPThetaController = ProfiledPIDControllerRadians(
109+
1.0, 0.0, 0.0, kThetaControllerConstraints
110+
)
111+
kPThetaController.enableContinuousInput(-math.pi, math.pi)
112+
113+
kPIDController = HolonomicDriveController(
114+
kPXController, kPYController, kPThetaController
96115
)
97-
thetaController.enableContinuousInput(-math.pi, math.pi)
98116

99117
swerveControllerCommand = commands2.SwerveControllerCommand(
100118
exampleTrajectory,
101119
self.robotDrive.getPose, # Functional interface to feed supplier
102120
DriveConstants.kDriveKinematics,
103121
# Position controllers
104-
PIDController(AutoConstants.kPXController, 0, 0),
105-
PIDController(AutoConstants.kPYController, 0, 0),
106-
thetaController,
122+
kPIDController,
107123
self.robotDrive.setModuleStates,
108124
(self.robotDrive,),
109125
)

0 commit comments

Comments
 (0)