|
17 | 17 | class Drivetrain: |
18 | 18 | """Represents a differential drive style drivetrain.""" |
19 | 19 |
|
20 | | - kMaxSpeed = 3.0 # meters per second |
21 | | - kMaxAngularSpeed = math.tau # one rotation per second |
| 20 | + kMaxVelocity = 3.0 # meters per second |
| 21 | + kMaxAngularVelocity = math.tau # one rotation per second |
22 | 22 |
|
23 | 23 | kTrackwidth = 0.381 * 2 # meters |
24 | 24 | kWheelRadius = 0.0508 # meters |
@@ -111,33 +111,35 @@ def __init__(self, cameraToObjectTopic: ntcore.DoubleArrayTopic) -> None: |
111 | 111 | wpilib.SmartDashboard.putData("Field", self.fieldSim) |
112 | 112 | wpilib.SmartDashboard.putData("FieldEstimation", self.fieldApproximation) |
113 | 113 |
|
114 | | - def setSpeeds(self, speeds: wpimath.DifferentialDriveWheelSpeeds) -> None: |
115 | | - """Sets the desired wheel speeds. |
| 114 | + def setVelocities( |
| 115 | + self, velocities: wpimath.DifferentialDriveWheelVelocities |
| 116 | + ) -> None: |
| 117 | + """Sets the desired wheel velocities. |
116 | 118 |
|
117 | | - :param speeds: The desired wheel speeds. |
| 119 | + :param velocities: The desired wheel velocities. |
118 | 120 | """ |
119 | | - leftFeedforward = self.feedforward.calculate(speeds.left) |
120 | | - rightFeedforward = self.feedforward.calculate(speeds.right) |
| 121 | + leftFeedforward = self.feedforward.calculate(velocities.left) |
| 122 | + rightFeedforward = self.feedforward.calculate(velocities.right) |
121 | 123 |
|
122 | 124 | leftOutput = self.leftPIDController.calculate( |
123 | | - self.leftEncoder.getRate(), speeds.left |
| 125 | + self.leftEncoder.getRate(), velocities.left |
124 | 126 | ) |
125 | 127 | rightOutput = self.rightPIDController.calculate( |
126 | | - self.rightEncoder.getRate(), speeds.right |
| 128 | + self.rightEncoder.getRate(), velocities.right |
127 | 129 | ) |
128 | 130 | self.leftLeader.setVoltage(leftOutput + leftFeedforward) |
129 | 131 | self.rightLeader.setVoltage(rightOutput + rightFeedforward) |
130 | 132 |
|
131 | | - def drive(self, xSpeed: float, rot: float) -> None: |
| 133 | + def drive(self, xVelocity: float, rot: float) -> None: |
132 | 134 | """Drives the robot with the given linear velocity and angular velocity. |
133 | 135 |
|
134 | | - :param xSpeed: Linear velocity in m/s. |
| 136 | + :param xVelocity: Linear velocity in m/s. |
135 | 137 | :param rot: Angular velocity in rad/s. |
136 | 138 | """ |
137 | | - wheelSpeeds = self.kinematics.toWheelSpeeds( |
138 | | - wpimath.ChassisSpeeds(xSpeed, 0.0, rot) |
| 139 | + wheelVelocities = self.kinematics.toWheelVelocities( |
| 140 | + wpimath.ChassisVelocities(xVelocity, 0.0, rot) |
139 | 141 | ) |
140 | | - self.setSpeeds(wheelSpeeds) |
| 142 | + self.setVelocities(wheelVelocities) |
141 | 143 |
|
142 | 144 | def publishCameraToObject( |
143 | 145 | self, |
@@ -242,8 +244,8 @@ def simulationPeriodic(self) -> None: |
242 | 244 | # simulation, and write the simulated positions and velocities to our |
243 | 245 | # simulated encoder and gyro. |
244 | 246 | self.drivetrainSimulator.setInputs( |
245 | | - self.leftLeader.get() * wpilib.RobotController.getInputVoltage(), |
246 | | - self.rightLeader.get() * wpilib.RobotController.getInputVoltage(), |
| 247 | + self.leftLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(), |
| 248 | + self.rightLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(), |
247 | 249 | ) |
248 | 250 | self.drivetrainSimulator.update(0.02) |
249 | 251 |
|
|
0 commit comments