For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

RobotContainer.java
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

  1. Start by setting gyroInvert in swervedrive.json to false AND drive.inverted to false in every module JSON.

  2. THEN set gyroInvert to true.

  3. THEN invert all of the drive motors in the module JSONs by setting inverted.drive to true.

  4. THEN set gyroInvert back to false.

  5. THEN flip the modules.\

    Depiction of flipping the modules correctly.
  6. THEN un-invert all of the drive motors (inverted.drive back to false).

  7. THEN set gyroInvert to true.

  8. THEN set your drive motors' inverted.drive back to true.

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.

How to swap module configurations

For the examples, we label modules with numbers to reduce confusion; when changing module files around, we assign the numbers to the respective initial module configuration names. For the example above:

  1. frontleft.json

  2. frontright.json

  3. backleft.json

  4. backright.json

Swapping frontleft.json with backright.json

Swap the device IDs and offsets between the two files (keep each file's own location) and you've swapped the module configurations correctly.

The easy way

  1. Change the location negations to the desired module side.

  2. Rename the files without overwriting each other.

Last updated

Was this helpful?