Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swerve Driving Out of Control #906

Closed
Kouyang07 opened this issue Nov 14, 2024 · 1 comment
Closed

Swerve Driving Out of Control #906

Kouyang07 opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Kouyang07
Copy link

Bug Description
This might not be a PP issue because I can't see how PP directly causes it but everything is fine after reverting version
On enabling after a deploy, the robot's swerve module for some reason drive uncontrollably straight. This started occurring after we updated to PP 2025 beta "version": "2025.0.0-beta-2.2". Here is what it looks like
image
The following image contains raw input chassis speed (I apologize for naming but ChassisSpeed is the ChassisSpeed generated from the controller input and RunVelocity/ are the values that the robot is setting the velocity to).

public void runVelocity(ChassisSpeeds speeds) {
    Logger.recordOutput(
        "RunVelocity/StackTrace", Arrays.toString(Thread.currentThread().getStackTrace()));
    Logger.recordOutput("RunVelocity/Speeds", speeds);
    // Calculate module setpoints
    ChassisSpeeds discreteSpeeds = ChassisSpeeds.discretize(speeds, 0.02);
    SwerveModuleState[] setpointStates = kinematics.toSwerveModuleStates(discreteSpeeds);
    SwerveDriveKinematics.desaturateWheelSpeeds(setpointStates, MAX_LINEAR_SPEED);

    // Send setpoints to modules
    SwerveModuleState[] optimizedSetpointStates = new SwerveModuleState[4];
    for (int i = 0; i < 4; i++) {
      // The module returns the optimized state, useful for logging
      optimizedSetpointStates[i] = modules[i].runSetpoint(setpointStates[i]);
    }

    // Log setpoint states
    Logger.recordOutput("SwerveStates/Setpoints", setpointStates);
    Logger.recordOutput("SwerveStates/SetpointsOptimized", optimizedSetpointStates);
  }
image

The controller input is essentially 0, but the modules are running which I find bizarre.

Here is the code that have this problem https://github.com/WheatleyRobotics/Reefscape/tree/bug/swerve-out-of-control
Here is the old code with 2024 PP that does not have this problem https://github.com/WheatleyRobotics/Reefscape/tree/master

Note: The code is mostly forked from 6328's Advanced Swerve Examples with minor changes to control and no big changes to math for swerve. This code served us very well the previous season with no instance of this problem.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy (There are no problems)
  2. Redeploy (The modules will run in teleop without any controller input)

To Fix
Fully power cycle the robot and on the first deploy it will be fine

Versions: (please complete the following information):

  • OS: MacOS Sequoia 15.1
  • PPLib Version: 2025.0.0-beta-2.2
  • PPLib Language: Java

Additional context
I made a ChiefDelphi post regarding this problem https://www.chiefdelphi.com/t/swerve-modules-driving-out-of-control/474561/2. I was suggested to reset the controllers because the motor controllers might have the previous input.

    driveSparkFlex.set(0);
    turnSparkMax.set(0);

I added this right after object initialization but unfortunately the problem still persists

@Kouyang07 Kouyang07 added the bug Something isn't working label Nov 14, 2024
@mjansen4857
Copy link
Owner

So from my understanding this isn't happening in anything that uses PPLib code. So, this is definitely not a PPLib issue.

I think your SwerveStates/Measured log entry gives a clue to what the issue could be. Your code thinks that the measured speed of your modules is in the thousands of meters/sec. This indicates that your unit conversions from the motor to meters/sec is wrong. So, it is likely wrong in the other direction as well, causing very small outputs to make the motor drive very fast. I can't really debug this for you, but hopefully that gives you an idea of where to look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants