Path Planner Programming Help

Hi, I’m trying to get started with path planner for my autos, and I am having errors when trying to set up my code to be able to run paths. I am having errors in the DriverSubsystem where I initialize the AutoBuilder stuff. I am using mostly the REV swerve code. Any help is appreciated! Thanks in advance!

GitHub Repository:
https://github.com/6175-EVW-Mystery-Machine/M1_2024-Imported

1 Like

We are doing some similar things and I’m happy to take a look but I’m getting a 404 error when I follow that link.

1 Like

https://github.com/6175-EVW-Mystery-Machine/M1_2024-Imported

Does this link work for you?

1 Like

It does not. The repo must be private.

1 Like

I’m so sorry. I thought I had changed it earlier, but it must not have saved or I just did it wrong. I believe I have made it public now.

1 Like

I am not seeing methods for the following calls in your auto builder for the subsystem. I believe once those methods are created that the errors with the drive subsystem will be resolved.

            this::getRobotRelativeSpeeds, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
            this::driveRobotRelative, // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds
1 Like

Would you have any insight into how to do that. I used a good portion of the REV swerve example. I’m not sure what the major differences between the field relative code and the robot relative code look like.

1 Like

Here is what they look like in C++. Should be similar for you since I also started from the Rev Swerve Code, you just need to port over to Java.

   /* This function gets the current robot relative chassis speeds.     */
frc::ChassisSpeeds DriveSubsystem::GetRobotRelativeChassisSpeeds()
{
   return(kDriveKinematics.ToChassisSpeeds(GetModuleStates()));
}

   /* This function drive the robot using the specified robot relative  */
   /* speeds.                                                           */
void DriveSubsystem::DriveRobotRelative(frc::ChassisSpeeds RobotRelativeSpeeds)
{
   /* Next calculate the drive kinematics to get the required swerve    */
   /* module states based on the specified Chassis Speeds.              */
   auto setpointStates = kDriveKinematics.ToSwerveModuleStates(RobotRelativeSpeeds);

   /* Renormalizes the wheel speeds if any individual speed is above the*/
   /* specified maximum.                                                */
   /* ** NOTE ** Sometimes, after inverse kinematics, the requested     */
   /*            speed from one or more modules may be above the max    */
   /*            attainable speed for the driving motor on that module. */
   /*            To fix this issue, one can reduce all the wheel speeds */
   /*            to make sure that all requested module speeds are      */
   /*            at-or-below the absolute threshold, while maintaining  */
   /*            the ratio of speeds between modules.                   */
   /* ** NOTE ** Since this function isn't typically used for teleops,  */
   /*            we are setting the max speed to use in desaturation to */
   /*            the default maximum speed.                             */
   kDriveKinematics.DesaturateWheelSpeeds(&setpointStates, kDefaultMaxSpeed);

   /* Break up the states into the individual swerve components.        */
   auto [fl, fr, rl, rr] = setpointStates;

   /* Set the desired state for each of the swerve modules and save the */
   /* return value to the optimized desired state.                      */
   m_frontLeft.SetDesiredState(fl);
   m_frontRight.SetDesiredState(fr);
   m_rearLeft.SetDesiredState(rl);
   m_rearRight.SetDesiredState(rr);
}
1 Like

You just need methods to use your kinematics to go between chassis speeds and module states. Assuming everything is already in the correct units, it would be something like this:

public void driveRobotRelative(ChassisSpeeds chassisSpeeds) {
  var swerveModuleStates = 
      DriveConstants.kDriveKinematics.toSwerveModuleStates(chassisSpeeds);

  SwerveDriveKinematics.desaturateWheelSpeeds(
      swerveModuleStates, DriveConstants.kMaxSpeedMetersPerSecond);

  m_frontLeft.setDesiredState(swerveModuleStates[0]);
  m_frontRight.setDesiredState(swerveModuleStates[1]);
  m_rearLeft.setDesiredState(swerveModuleStates[2]);
  m_rearRight.setDesiredState(swerveModuleStates[3]);
}

public ChassisSpeeds getRobotRelativeSpeeds() {
  return DriveConstants.kDriveKinematics.toChassisSpeeds(
      m_frontLeft.getState(),
      m_frontRight.getState(),
      m_rearLeft.getState(),
      m_rearRight.getState());
}

EDIT: corrected code typo

1 Like

Thank you! I think this fixed a good portion of the issues. Im still having a slight issue with the rest of the set up. Specifically in the RobotContainer part. Do you know what im doing wrong, or why the AutoBuilder is erroring out?

1 Like

Specifically lines ~60-75 and ~150-170

1 Like

Your getAutonomousCommand() method is using WPILib trajectories, not PathPlanner. I think you can remove everything you have in there.

If you’re going to run autonomous with PathPlanner, I recommend just following the instructions to create a SendableChooser with all autos.

  1. Create a SendableChooser field in RobotContainer.
  2. In RobotContainer’s constructor, call AutoBuilder.buildAutoChooser() to create the chooser, then add it to your dashboard.
  3. Return the selected command from getAutonomousCommand().
3 Likes

Oh wow! Thank you so much! That seemed to have worked. Hopefully I can get some time to run a test path or something on the bot tonight just to confirm but thank you so much! Is there anything I should know about bringing paths from pathplanner to my code or is fairly simple? Thanks again for all the help, it would’ve taken me ages to figure out on my own!

2 Likes

That code will automatically populate your dashboard with all of the autonomous routines you create in PathPlanner. So, you’ll need to create a path AND an auto for it to show up.

Other than that, you’ll have to tune your PID values, but it should work.

1 Like

I just wanted to point out that m_frontRight is being used twice in getRobotRelativeSpeeds(), just in case op didnt catch the typo

2 Likes

Thanks for catching that :dizzy_face: I edited the post.

1 Like