Need Help Tuning WPILib Based Swerve Autonomous

Our team is using SDS Mk4i serve modules with the SDS swerve-lib and using WPILib’s swerve trajectory follower and trajectory generation. My question is: How do you go about tuning the trajectory following to make the path following smoother? We characterized the drivetrain with SysId, this is the second swerve drivetrain we characterized. Based on the similarities of the values for both and another team that posted here on CD we’re reasonably sure they’re good constants.

// This kP worked for the DriveWithSetRotation command
public static final double kPThetaController = 1.5;
public static final double kIThetaController = 0.0;
public static final double kDThetaController = 0.0;

// Feed Forward and PID values from SysId
public static final double kP = 2.2941; // test bot = 2.3055;
public static final double kI = 0;
public static final double kD = 0;
public static final double kA = 0.43516; // test bot = 0.12817;
public static final double kV = 2.344;   // test bot = 2.3423;
public static final double kS = 0.62811; // test bot = 0.53114;

Our theta controller settings are copied from our teleop code that works well.

Our robot does a good job of following the trajectory, just not as smoothly as we see other swerve bots do in auton.

The behavior we’re seeing is that the modules “chatter” throughout the autonomous path, as if they’re trying to make many micro adjustments at each corner as it follows the trajectory.

Maybe we’re driving too slowly? Our test trajectories are with tame limits with a max velocity of 1.5 m/s and a max acceleration of 0.75 m/s^2.

Should I be messing with the drive motor PID? the thetaController PID? what other tuning parameters do I have?

Side question, how do you characterize swerve?

Check this thread:

Short answer is use SysId and some hacking of the swerve drivetrain to make it drive straight.

1 Like

Slow velocity/acceleration can worsen unsmooth movements. Try increasing these values to match your real robot capabilities.

Just as important as characterizing is the paths themselves. What are you using to create the paths (pathweaver, pathplanner, etc.)? If it isn’t smooth in the preview or conceptually, it definitely won’t be smooth in real life. If you’d like, you can send a path file and I can give you some tips to improve it.

We’re using the WPILib Trajectory creation classes.

We’ll be testing with faster V and A later today.

We did a deep dive into what scheduler loop overruns. We cleanwd out 50 or more Smartdashboard putNumbers, removed the drivetrain layout object that SDS swerve-lib includes by default, and eventually the Field2d object and that got the SmartDashboard update below 1ms and got rid of the all the loop overruns.

That left a couple of subsystems triggering the few remaining loop overruns, so we moved all the subsystems we don’t use during autonomous to be initialized in teleop.

Between eliminating the loop overuns and increasing the robot velocity and acceleration the robot was much smoother. Acceptable, but not super. That’ll have to do for now.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.