Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughTwo swerve module files were modified. SwerveModuleConstants adds a new COUPLED_RATIO constant and updates DRIVE_MOTOR_GEAR_RATIO from 7.03 to 6.03. SwerveModule re-enables three imports and modifies getDriveWheelPositionRadians to apply steering angle coupling by subtracting steering rotation scaled by COUPLED_RATIO before converting to radians. In setTargetClosedLoopDriveVelocity, a local velocityToSet variable is calculated using COUPLED_RATIO but remains unused in the subsequent motor control call, which continues using the original targetDriveVelocityRotationsPerSecond value. 🚥 Pre-merge checks | ✅ 1 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| public double getDriveWheelPositionRadians() { | ||
| return edu.wpi.first.math.util.Units.rotationsToRadians(driveMotor.getSignal(TalonFXSignal.POSITION)); | ||
| final double driveWheelPositionRotations = driveMotor.getSignal(TalonFXSignal.POSITION); | ||
| final double wheelAngleRotations = getCurrentSteerAngle().getRotations(); | ||
| final double driveWheelPositionWithCouplingRatioRotations = driveWheelPositionRotations - (wheelAngleRotations * SwerveModuleConstants.COUPLED_RATIO); | ||
| return edu.wpi.first.math.util.Units.rotationsToRadians(driveWheelPositionWithCouplingRatioRotations); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, let's locate and examine the SwerveModule.java file
find . -name "SwerveModule.java" -type fRepository: Programming-TRIGON/RobotCode2026
Length of output: 157
🏁 Script executed:
#!/bin/bash
# Read the relevant section of the file (around lines 117-136)
sed -n '110,145p' ./src/main/java/frc/trigon/robot/subsystems/swerve/swervemodule/SwerveModule.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 1939
🏁 Script executed:
#!/bin/bash
# Search for calls to getDriveWheelPositionRadians and getOdometryPosition
rg -n --type=java 'getDriveWheelPositionRadians|getOdometryPosition' --max-count=30Repository: Programming-TRIGON/RobotCode2026
Length of output: 690
🏁 Script executed:
#!/bin/bash
# Search for where latestOdometryDrivePositions is populated
rg -n --type=java 'latestOdometryDrivePositions\s*=' -B2 -A2Repository: Programming-TRIGON/RobotCode2026
Length of output: 714
🏁 Script executed:
#!/bin/bash
# Look at the full SwerveModule class to understand the context better
wc -l ./src/main/java/frc/trigon/robot/subsystems/swerve/swervemodule/SwerveModule.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 161
🏁 Script executed:
#!/bin/bash
# Look at the context around where latestOdometryDrivePositions and latestOdometrySteerPositions are populated
sed -n '75,95p' ./src/main/java/frc/trigon/robot/subsystems/swerve/swervemodule/SwerveModule.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 896
🏁 Script executed:
#!/bin/bash
# Check the whole update method and surrounding context
sed -n '70,100p' ./src/main/java/frc/trigon/robot/subsystems/swerve/swervemodule/SwerveModule.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 1272
🏁 Script executed:
#!/bin/bash
# Search for any comments or documentation about coupling correction in odometry
rg -n --type=java 'coupling|COUPLED_RATIO' -B2 -A2Repository: Programming-TRIGON/RobotCode2026
Length of output: 2406
🏁 Script executed:
#!/bin/bash
# Check how driveWheelRotationsToMeters is implemented to understand the conversion
rg -n --type=java 'driveWheelRotationsToMeters' -A5Repository: Programming-TRIGON/RobotCode2026
Length of output: 2309
🏁 Script executed:
#!/bin/bash
# Look at the broader context of where these methods are called to understand intent
sed -n '145,160p' ./src/main/java/frc/trigon/robot/subsystems/swerve/Swerve.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 824
🏁 Script executed:
#!/bin/bash
# Check around line 326 in Swerve.java to see how getOdometryPosition is used
sed -n '320,335p' ./src/main/java/frc/trigon/robot/subsystems/swerve/Swerve.javaRepository: Programming-TRIGON/RobotCode2026
Length of output: 1022
Apply coupling correction in getOdometryPosition for consistency with getDriveWheelPositionRadians.
getDriveWheelPositionRadians compensates for steering coupling, but getOdometryPosition calls driveWheelRotationsToMeters on the raw odometry drive position without any correction. This inconsistency means pose estimates from odometry will diverge from the coupling-corrected position used elsewhere.
Apply the same correction in getOdometryPosition using the odometry steer angle snapshot (latestOdometrySteerPositions[odometryUpdateIndex]) to maintain temporal consistency:
final double drivePositionWithCouplingCorrected = latestOdometryDrivePositions[odometryUpdateIndex] -
(Rotation2d.fromRotations(latestOdometrySteerPositions[odometryUpdateIndex]).getRotations() * SwerveModuleConstants.COUPLED_RATIO);
return new SwerveModulePosition(
driveWheelRotationsToMeters(drivePositionWithCouplingCorrected),
Rotation2d.fromRotations(latestOdometrySteerPositions[odometryUpdateIndex])
);
| private void setTargetClosedLoopDriveVelocity(double targetVelocityMetersPerSecond) { | ||
| final double targetDriveVelocityRotationsPerSecond = metersToDriveWheelRotations(targetVelocityMetersPerSecond); | ||
| final double driveRateBackOut = targetDriveVelocityRotationsPerSecond * SwerveModuleConstants.COUPLED_RATIO; | ||
| final double velocityToSet = driveRateBackOut; | ||
|
|
||
| driveMotor.setControl(driveVelocityRequest.withVelocity(targetDriveVelocityRotationsPerSecond)); | ||
| } |
There was a problem hiding this comment.
velocityToSet is computed but never used—the motor still receives the uncorrected velocity.
Line 163 passes targetDriveVelocityRotationsPerSecond to the motor instead of velocityToSet. The coupling compensation has no effect.
Additionally, the formula itself looks incorrect. Coupling compensation for velocity should involve the steer velocity, not the drive velocity. The typical pattern is:
velocityToSet = targetDriveVelocityRotationsPerSecond + steerVelocityRotationsPerSecond * COUPLED_RATIO
This adds a feed-forward term to counteract the parasitic drive caused by steering motion. Right now driveRateBackOut = targetDriveVelocityRotationsPerSecond * COUPLED_RATIO scales the drive velocity by the coupling ratio, which doesn't model the physical coupling.
Proposed fix (verify the coupling direction sign for your module)
private void setTargetClosedLoopDriveVelocity(double targetVelocityMetersPerSecond) {
final double targetDriveVelocityRotationsPerSecond = metersToDriveWheelRotations(targetVelocityMetersPerSecond);
- final double driveRateBackOut = targetDriveVelocityRotationsPerSecond * SwerveModuleConstants.COUPLED_RATIO;
- final double velocityToSet = driveRateBackOut;
+ final double steerVelocityRotationsPerSecond = steerMotor.getSignal(TalonFXSignal.VELOCITY);
+ final double couplingCompensation = steerVelocityRotationsPerSecond * SwerveModuleConstants.COUPLED_RATIO;
+ final double velocityToSet = targetDriveVelocityRotationsPerSecond + couplingCompensation;
- driveMotor.setControl(driveVelocityRequest.withVelocity(targetDriveVelocityRotationsPerSecond));
+ driveMotor.setControl(driveVelocityRequest.withVelocity(velocityToSet));
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private void setTargetClosedLoopDriveVelocity(double targetVelocityMetersPerSecond) { | |
| final double targetDriveVelocityRotationsPerSecond = metersToDriveWheelRotations(targetVelocityMetersPerSecond); | |
| final double driveRateBackOut = targetDriveVelocityRotationsPerSecond * SwerveModuleConstants.COUPLED_RATIO; | |
| final double velocityToSet = driveRateBackOut; | |
| driveMotor.setControl(driveVelocityRequest.withVelocity(targetDriveVelocityRotationsPerSecond)); | |
| } | |
| private void setTargetClosedLoopDriveVelocity(double targetVelocityMetersPerSecond) { | |
| final double targetDriveVelocityRotationsPerSecond = metersToDriveWheelRotations(targetVelocityMetersPerSecond); | |
| final double steerVelocityRotationsPerSecond = steerMotor.getSignal(TalonFXSignal.VELOCITY); | |
| final double couplingCompensation = steerVelocityRotationsPerSecond * SwerveModuleConstants.COUPLED_RATIO; | |
| final double velocityToSet = targetDriveVelocityRotationsPerSecond + couplingCompensation; | |
| driveMotor.setControl(driveVelocityRequest.withVelocity(velocityToSet)); | |
| } |
| import frc.trigon.robot.constants.AutonomousConstants; | ||
|
|
||
| public class SwerveModuleConstants { | ||
| static final double COUPLED_RATIO = 3; |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Add a brief comment explaining what COUPLED_RATIO represents physically.
The other gear ratios have clarifying comments (e.g., R1: 7.03, R2: 6.03, R3: 5.27). A similar note here—e.g., the bevel gear teeth ratio or the mechanical source of this value—would help future readers understand why it's 3 and when it should change.
No description provided.