Skip to content

Commit 3a29515

Browse files
Transfered commands from constants.py to robotcontainer.py
1 parent d39f755 commit 3a29515

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

examples/maxswerve/constants.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +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
17-
from wpimath.controller import HolonomicDriveController, PIDController, ProfiledPIDControllerRadians
18-
from wpimath.trajectory import TrapezoidProfileRadians
1916

2017
from rev import CANSparkMax
2118

@@ -132,15 +129,3 @@ class AutoConstants:
132129
kMaxAccelerationMetersPerSecondSquared = 3
133130
kMaxAngularSpeedRadiansPerSecond = math.pi
134131
kMaxAngularSpeedRadiansPerSecondSquared = math.pi
135-
136-
# Constraint for the motion profiled robot angle controller
137-
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
138-
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared
139-
)
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-
kPThetaController.enableContinuousInput(-math.pi, math.pi)
145-
146-
kPIDController = HolonomicDriveController(kPXController, kPYController, kPThetaController)

examples/maxswerve/robotcontainer.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
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
11-
from wpimath.controller import HolonomicDriveController
10+
from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator, TrapezoidProfileRadians
11+
from wpimath.controller import HolonomicDriveController, PIDController, ProfiledPIDControllerRadians
1212

1313
from constants import AutoConstants, DriveConstants, OIConstants
1414
from subsystems.drivesubsystem import DriveSubsystem
@@ -89,12 +89,27 @@ def getAutonomousCommand(self) -> commands2.Command:
8989
config,
9090
)
9191

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+
92107
swerveControllerCommand = commands2.SwerveControllerCommand(
93108
exampleTrajectory,
94109
self.robotDrive.getPose, # Functional interface to feed supplier
95110
DriveConstants.kDriveKinematics,
96111
# Position controllers
97-
AutoConstants.kPIDController,
112+
kPIDController,
98113
self.robotDrive.setModuleStates,
99114
(self.robotDrive,)
100115
)

0 commit comments

Comments
 (0)