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!
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
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.
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);
}
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());
}
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?
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!
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.