Skip to content

Commit ce75329

Browse files
author
NewtonCrosby
committed
Fixed formatting with Black.
1 parent 0faf2c0 commit ce75329

File tree

2 files changed

+49
-39
lines changed

2 files changed

+49
-39
lines changed

commands2/ramsetecommand.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
from __future__ import annotations
55

66
from typing import Callable, Union
7-
from wpimath.controller import PIDController, RamseteController, SimpleMotorFeedforwardMeters
7+
from wpimath.controller import (
8+
PIDController,
9+
RamseteController,
10+
SimpleMotorFeedforwardMeters,
11+
)
812
from wpimath.geometry import Pose2d
9-
from wpimath.kinematics import ChassisSpeeds, DifferentialDriveKinematics, DifferentialDriveWheelSpeeds
13+
from wpimath.kinematics import (
14+
ChassisSpeeds,
15+
DifferentialDriveKinematics,
16+
DifferentialDriveWheelSpeeds,
17+
)
1018
from wpimath.trajectory import Trajectory
1119
from wpiutil import SendableBuilder
1220
from wpilib import Timer
@@ -15,6 +23,7 @@
1523
from .command import Command
1624
from .subsystem import Subsystem
1725

26+
1827
class RamseteCommand(Command):
1928
"""
2029
A command that uses a RAMSETE controller (RamseteController) to follow a trajectory
@@ -62,7 +71,7 @@ def __init__(
6271
6372
OPTIONAL PARAMETERS
6473
When the following optional parameters are provided, when executed, the RamseteCommand will follow
65-
provided trajectory. PID control and feedforward are handled internally, and the outputs are scaled
74+
provided trajectory. PID control and feedforward are handled internally, and the outputs are scaled
6675
from -12 to 12 representing units of volts. If any one of the optional parameters are provided, each
6776
other optional parameter becomes required.
6877
:param feedforward The feedforward to use for the drive
@@ -90,11 +99,11 @@ def __init__(
9099
# requirements become required.
91100
if feedforward or leftController or rightController or wheelSpeeds is not None:
92101
if feedforward or leftController or rightController or wheelSpeeds is None:
93-
raise RuntimeError(f'Failed to instantiate RamseteCommand, not all optional arguments were provided.\n \
94-
Feedforward - {feedforward}, LeftController - {leftController}, RightController - {rightController}, WheelSpeeds - {wheelSpeeds} '
102+
raise RuntimeError(
103+
f"Failed to instantiate RamseteCommand, not all optional arguments were provided.\n \
104+
Feedforward - {feedforward}, LeftController - {leftController}, RightController - {rightController}, WheelSpeeds - {wheelSpeeds} "
95105
)
96-
97-
106+
98107
self.leftController: PIDController = leftController
99108
self.rightController: PIDController = rightController
100109
self.wheelspeeds: Callable[[], DifferentialDriveWheelSpeeds] = wheelSpeeds
@@ -109,7 +118,11 @@ def initialize(self):
109118
self.prevTime = -1
110119
initial_state = self.trajectory.sample(0)
111120
initial_speeds = self.kinematics.toWheelSpeeds(
112-
ChassisSpeeds( initial_state.velocity, 0, initial_state.curvature * initial_state.velocity )
121+
ChassisSpeeds(
122+
initial_state.velocity,
123+
0,
124+
initial_state.curvature * initial_state.velocity,
125+
)
113126
)
114127
self.prevSpeeds = initial_speeds
115128
self.timer.restart()
@@ -135,29 +148,20 @@ def execute(self):
135148

136149
if self.usePID:
137150
left_feedforward = self.feedforward.calculate(
138-
left_speed_setpoint,
139-
(left_speed_setpoint - self.prevSpeeds.left) / dt
151+
left_speed_setpoint, (left_speed_setpoint - self.prevSpeeds.left) / dt
140152
)
141153

142154
right_feedforward = self.feedforward.calculate(
143155
right_speed_setpoint,
144-
(right_speed_setpoint - self.prevSpeeds.right) / dt
156+
(right_speed_setpoint - self.prevSpeeds.right) / dt,
145157
)
146158

147-
left_output = (
148-
left_feedforward
149-
+ self.leftController.calculate(
150-
self.wheelspeeds().left,
151-
left_speed_setpoint
152-
)
159+
left_output = left_feedforward + self.leftController.calculate(
160+
self.wheelspeeds().left, left_speed_setpoint
153161
)
154162

155-
right_output = (
156-
right_feedforward
157-
+ self.rightController.calculate(
158-
self.wheelspeeds().right,
159-
right_speed_setpoint
160-
)
163+
right_output = right_feedforward + self.rightController.calculate(
164+
self.wheelspeeds().right, right_speed_setpoint
161165
)
162166
else:
163167
left_output = left_speed_setpoint

tests/test_ramsetecommand.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,31 @@ def __init__(self):
4848
self.kMaxMetersPerSecond = 3.0
4949
self.kMaxAccelerationMetersPerSecondSquared = 1.0
5050
self.kEncoderCPR = 1024
51-
self.kEncoderDistancePerPulse = (self.kWheelDiameterMeters * math.pi) / self.kEncoderCPR
51+
self.kEncoderDistancePerPulse = (
52+
self.kWheelDiameterMeters * math.pi
53+
) / self.kEncoderCPR
5254

5355
self.command_kinematics: kinematics.DifferentialDriveKinematics = (
5456
kinematics.DifferentialDriveKinematics(self.kTrackWidth)
5557
)
5658

5759
self.command_voltage_constraint: constraints.DifferentialDriveVoltageConstraint = constraints.DifferentialDriveVoltageConstraint(
5860
controller.SimpleMotorFeedforwardMeters(
59-
self.ksVolts,
61+
self.ksVolts,
6062
self.kvVoltSecondsPerMeter,
61-
self.kaVoltSecondsSquaredPerMeter
62-
),
63-
self.command_kinematics,
64-
10
63+
self.kaVoltSecondsSquaredPerMeter,
64+
),
65+
self.command_kinematics,
66+
10,
6567
)
6668

67-
self.command_odometry: kinematics.DifferentialDriveOdometry = kinematics.DifferentialDriveOdometry(
68-
self.angle,
69-
self.leftDistance,
70-
self.rightDistance,
71-
geometry.Pose2d(0, 0, geometry.Rotation2d(0))
69+
self.command_odometry: kinematics.DifferentialDriveOdometry = (
70+
kinematics.DifferentialDriveOdometry(
71+
self.angle,
72+
self.leftDistance,
73+
self.rightDistance,
74+
geometry.Pose2d(0, 0, geometry.Rotation2d(0)),
75+
)
7276
)
7377

7478
def setWheelSpeeds(self, leftspeed: float, rightspeed: float) -> None:
@@ -84,7 +88,7 @@ def getCurrentWheelDistances(self) -> kinematics.DifferentialDriveWheelPositions
8488

8589
def getRobotPose(self) -> geometry.Pose2d:
8690
positions = self.getCurrentWheelDistances()
87-
self.command_odometry.update(self.angle, positions.left,positions.right)
91+
self.command_odometry.update(self.angle, positions.left, positions.right)
8892
return self.command_odometry.getPose()
8993

9094

@@ -111,12 +115,14 @@ def test_ramseteCommand(
111115
end_state = new_trajectory.sample(new_trajectory.totalTime())
112116

113117
command = commands2.RamseteCommand(
114-
new_trajectory,
118+
new_trajectory,
115119
fixture_data.getRobotPose,
116-
controller.RamseteController(fixture_data.kRamseteB, fixture_data.kRamseteZeta),
120+
controller.RamseteController(
121+
fixture_data.kRamseteB, fixture_data.kRamseteZeta
122+
),
117123
fixture_data.command_kinematics,
118124
fixture_data.setWheelSpeeds,
119-
subsystem
125+
subsystem,
120126
)
121127

122128
fixture_data.timer.restart()
@@ -139,4 +145,4 @@ def test_ramseteCommand(
139145
)
140146
assert end_state.pose.Y() == pytest.approx(
141147
fixture_data.getRobotPose().Y(), fixture_data.kyTolerance
142-
)
148+
)

0 commit comments

Comments
 (0)