Assistance with Path Planner

Our team was trying to implement Path planner to run autonomous route on our swerve robot. We were trying to implement the following code based on the path planner github:

return new SequentialCommandGroup(
new InstantCommand(() → {
// Reset odometry for the first path you run during auto
if(isFirstPath){
this.resetOdometry(traj.getInitialHolonomicPose());
}
}),
new PPSwerveControllerCommand(
traj,
this::getPose, // Pose supplier
this.kinematics, // SwerveDriveKinematics
new PIDController(0, 0, 0), // X controller. Tune these values for your robot. Leaving them 0 will only use feedforwards.
new PIDController(0, 0, 0), // Y controller (usually the same values as X controller)
new PIDController(0, 0, 0), // Rotation controller. Tune these values for your robot. Leaving them 0 will only use feedforwards.
this::setModuleStates, // Module states consumer
eventMap, // This argument is optional if you don’t use event markers
this // Requires this drive subsystem
)
);

In specific we were trying to figure out out how to implement the setModuleStates method. We have tried looking at other teams code but we struggled to understand the code and only ended up more confused. If anybody knows how to implement the setModuleStates method in Java for pathplanner that would be greatly appreciated.

Our full code is here: https://github.com/FRC5549Robotics/BunnyBots_2022

Thank you!

Not the same library, obviously, but you might find it instructive to look at this example.

public void setModuleStates(SwerveModuleState[] desiredStates) {
    SwerveDriveKinematics.desaturateWheelSpeeds(
        desiredStates, DriveConstants.kMaxSpeedMetersPerSecond);
    m_frontLeft.setDesiredState(desiredStates[0]);
    m_frontRight.setDesiredState(desiredStates[1]);
    m_rearLeft.setDesiredState(desiredStates[2]);
    m_rearRight.setDesiredState(desiredStates[3]);
  }
1 Like

My teams looks like this: public void updateAutoDemand (SwerveModuleState[] states) { drive(m_kinematics.toChassisSpeeds(states)); }
Basically all it is a method that takes the “demand” from path planners motion controller and hands it to your drive train. Assuming you already have a functioning drivetrain in teleop all the method should do is take path planners output, an array of swerve module states, and translate it into whatever input your drive method takes. Hope this helps!

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