Skip to content

Commit d0791ff

Browse files
virtualdauscompgeek
andcommitted
Apply suggestions from code review
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
1 parent 481b640 commit d0791ff

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

examples/maxswerve/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DriveConstants:
2626
# Driving Parameters - Note that these are not the maximum capable speeds of
2727
# the robot, rather the allowed maximum speeds
2828
kMaxSpeedMetersPerSecond = 4.8
29-
kMaxAngularSpeed = 2 * math.pi # radians per second
29+
kMaxAngularSpeed = math.tau # radians per second
3030

3131
kDirectionSlewRate = 1.2 # radians per second
3232
kMagnitudeSlewRate = 1.8 # percent per second (1 = 100%)
@@ -93,8 +93,8 @@ class ModuleConstants:
9393
(kWheelDiameterMeters * math.pi) / kDrivingMotorReduction
9494
) / 60.0 # meters per second
9595

96-
kTurningEncoderPositionFactor = 2 * math.pi # radian
97-
kTurningEncoderVelocityFactor = (2 * math.pi) / 60.0 # radians per second
96+
kTurningEncoderPositionFactor = math.tau # radian
97+
kTurningEncoderVelocityFactor = math.tau / 60.0 # radians per second
9898

9999
kTurningEncoderPositionPIDMinInput = 0 # radian
100100
kTurningEncoderPositionPIDMaxInput = kTurningEncoderPositionFactor # radian

examples/maxswerve/subsystems/drivesubsystem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def drive(
127127
if rateLimit:
128128
# Convert XY to polar for rate limiting
129129
inputTranslationDir = math.atan2(ySpeed, xSpeed)
130-
inputTranslationMag = math.sqrt(math.pow(xSpeed, 2) + math.pow(ySpeed, 2))
130+
inputTranslationMag = math.hypot(xSpeed, ySpeed)
131131

132132
# Calculate the direction slew rate based on an estimate of the lateral acceleration
133133
if self.currentTranslationMag != 0.0:
@@ -202,7 +202,7 @@ def drive(
202202
if fieldRelative
203203
else ChassisSpeeds(xSpeedDelivered, ySpeedDelivered, rotDelivered)
204204
)
205-
SwerveDrive4Kinematics.desaturateWheelSpeeds(
205+
swerveModuleStates = SwerveDrive4Kinematics.desaturateWheelSpeeds(
206206
swerveModuleStates, DriveConstants.kMaxSpeedMetersPerSecond
207207
)
208208
self.frontLeft.setDesiredState(swerveModuleStates[0])
@@ -224,7 +224,7 @@ def setModuleStates(self, desiredStates: typing.Tuple[SwerveModuleState]) -> Non
224224
225225
:param desiredStates: The desired SwerveModule states.
226226
"""
227-
SwerveDrive4Kinematics.desaturateWheelSpeeds(
227+
desiredStates = SwerveDrive4Kinematics.desaturateWheelSpeeds(
228228
desiredStates, DriveConstants.kMaxSpeedMetersPerSecond
229229
)
230230
self.frontLeft.setDesiredState(desiredStates[0])

examples/maxswerve/swerveutils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def stepTowardsCircular(current: float, target: float, stepsize: float) -> float
4343
elif difference > math.pi: # does the system need to wrap over eventually?
4444
# handle the special case where you can reach the target in one step while also wrapping
4545
if (
46-
current + 2 * math.pi - target < stepsize
47-
or target + 2 * math.pi - current < stepsize
46+
current + math.tau - target < stepsize
47+
or target + math.tau - current < stepsize
4848
):
4949
return target
5050
else:
@@ -63,7 +63,7 @@ def angleDifference(angleA: float, angleB: float) -> float:
6363
:returns: The (unsigned) minimum difference between the two angles (in radians).
6464
"""
6565
difference = abs(angleA - angleB)
66-
return (2 * math.pi) - difference if difference > math.pi else difference
66+
return math.tau - difference if difference > math.pi else difference
6767

6868

6969
def wrapAngle(angle: float) -> float:
@@ -74,7 +74,7 @@ def wrapAngle(angle: float) -> float:
7474
:returns: An angle (in radians) from 0 and 2*PI (exclusive).
7575
"""
7676

77-
twoPi = math.pi * 2
77+
twoPi = math.tau
7878

7979
# Handle this case separately to avoid floating point errors with the floor after the division in the case below
8080
if angle == twoPi:

0 commit comments

Comments
 (0)