The 8 steps
Something is wrong but it's driving-ish?
When changing inversion states doesn't work and nothing else you know of fixes the issue, debugging can be painful and arduous. Here are the eight steps that are unfortunately necessary to work through it.
Affectionately known as "Translational Axis change based off of the robot heading" (the X and Y axis change in field-oriented control based on your robot turning), these steps will resolve it somewhere along the way.
Prepare your robot code
To run these tests quickly and effectively, use the following (or a variation of it) as your drive code. You may need to port it to your joystick or negate axis data, but this will help you debug faster.
SwerveDriveSubsystem drivebase;
CommandXboxController driverXbox;
// Applies deadbands and inverts controls because joysticks
// are back-right positive while robot controls are front-left positive.
// Left stick controls translation, right stick controls the desired
// heading directly (NOT angular rotation).
SwerveInputStream driveDirectAngle =
new SwerveInputStream(drivebase.getSwerveDrive(),
() -> -driverXbox.getLeftY(),
() -> -driverXbox.getLeftX(),
() -> -driverXbox.getRightX(),
() -> -driverXbox.getRightY())
.withAllianceRelativeControl();
drivebase.setDefaultCommand(drivebase.drive(driveDirectAngle));This uses the four-argument SwerveInputStream(drive, x, y, headingX, headingY) constructor, which drives directly to a heading computed from the right stick instead of an angular velocity — the same "point the stick where you want the robot to face" behavior the old SwerveController.getTargetSpeeds() heading-hold path provided. If you're using the two-argument angular-velocity constructor instead, the steps below are identical; only the exact symptom description changes slightly.
The eight steps
The steps are dangerous!
6 of them will cause your robot to spin out of control.
1 of them will be correct.
1 of them will appear to be correct but have the translational axis change based on the robot's heading.
You are not expected to complete all of these steps to get a functioning swerve drive — somewhere along the way your issue should disappear.
Start by setting
gyroInvertinswervedrive.jsontofalseANDdrive.invertedtofalsein every module JSON.THEN set
gyroInverttotrue.THEN invert all of the drive motors in the module JSONs by setting
inverted.drivetotrue.THEN set
gyroInvertback tofalse.THEN flip the modules.\

Depiction of flipping the modules correctly. THEN un-invert all of the drive motors (
inverted.driveback tofalse).THEN set
gyroInverttotrue.THEN set your drive motors'
inverted.driveback totrue.
IF none of these work, you most likely have an incorrect hardware configuration, something is not working as expected, or something is wired incorrectly.
Verifying behavior
Sometimes the eight steps don't look done when they really are. Here's an example where the robot is actually tuned correctly, but the desired front of the robot is really the back of the robot.
Last updated
Was this helpful?