Need assistance with pathplanner for swerve drive

Our team is in our second year of using swerve drive. We are attempting to use pathplanner for our autonomous for this upcoming season. When attempting to configure the AutoBuilder, we are experiencing trouble with the robot relative speeds component. The code is linked here. Any help would be much appreciated.

Have you tried YAGSL? It has PathPlanner built-in to the Example project?

2 Likes

Thank you for the suggestion. That resource looks like it has what’s we need.

1 Like

If you still want to stick to your code base, you would have to modify the code for the swerve subsystem.

public void drive(Translation2d translation, double rotation, boolean fieldRelative, boolean isOpenLoop) {
    drive(
            new ChassisSpeeds(translation.getX(), translation.getY(), rotation),
            fieldRelative, isOpenLoop
    );
}
public void drive(ChassisSpeeds speeds, boolean fieldRelative, boolean isOpenLoop) {
    SwerveModuleState[] swerveModuleStates = Constants.Swerve.swerveKinematics.toSwerveModuleStates(
            fieldRelative
                    ? ChassisSpeeds.fromFieldRelativeSpeeds(speeds, getYaw())
                    : speeds);

    SwerveDriveKinematics.desaturateWheelSpeeds(swerveModuleStates, Constants.Swerve.maxSpeed);

    for (frc.robot.subsystems.SwerveModule mod : mSwerveMods) {
        mod.setDesiredState(swerveModuleStates[mod.moduleNumber], isOpenLoop);
    }
}

Now you can configure your AutoBuilder like this:

AutoBuilder.configureHolonomic(
  this::getPose,
  this::resetOdometry,
  this::getRobotRelativeSpeeds,
  (speeds) -> drive(speeds, false, false),
  new HolonomicPathFollowerConfig(...), // your robot's config
  () -> DriverStation.getAlliance().isPresent()
      && DriverStation.getAlliance().get() == Alliance.Red,
 this
);

Also, you might want to upgrade to PathPlanner 2025 Beta for the new season.
This is how you configure it for the new version:

AutoBuilder.configure(
  this::getPose,
  this::resetOdometry,
  this::getRobotRelativeSpeeds,
  (speeds) -> drive(speeds, false, false),
  new PPHolonomicDriveController(...), // PID configs of your robt
  new RobotConfig(...),
  () -> DriverStation.getAlliance().isPresent()
      && DriverStation.getAlliance().get() == Alliance.Red,
 this
);
1 Like

I tried what you suggested but I am getting errors and it doesn’t look like the software is recognizing the auto builder configure method. Is there anything else I can try?

Oh, that’s the new API since PP2025 beta if you haven’t upgraded to that yet:

I believe I have upgraded to the 2025 Beta. Is there any other reason it would be causing an error?

That’s strange, when you type in “AutoBuilder.c” what are the options that pop up in the IDE?