I am trying to implement pathplanner to our swerve drive code. Predefined trajectory code works fine with the Simulation however when I try to use imported pathplanner trajectory Sim Gui crashes due to an overrun. Any suggestions?
PathPlannerTrajectory examplePath = PathPlanner.loadPath("ay", new PathConstraints(4, 3));
var thetaController = new ProfiledPIDController(
AutoConstants.kPThetaController, 0, 0, AutoConstants.kThetaControllerConstraints);
thetaController.enableContinuousInput(-Math.PI, Math.PI);
SwerveControllerCommand swerveControllerCommand = new SwerveControllerCommand(
examplePath,
m_robotDrive::getPose, // Functional interface to feed supplier
DriveConstants.kDriveKinematics,
// Position controllers
new PIDController(AutoConstants.kPXController, 0, 0),
new PIDController(AutoConstants.kPYController, 0, 0),
thetaController,
m_robotDrive::setModuleStates,
m_robotDrive);
Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373): The robot program quit unexpectedly. This is usually due to a code error.
The above stacktrace can help determine where the error occurred.
See Reading Stacktraces — FIRST Robotics Competition documentation for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:380): The startCompetition() method (or methods called by it) should have handled the exception above.
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:387): Loop time of 0.02s overrun
Above that output block there should be a full stack trace which looks something like this:
Error at frc.robot.Robot.robotInit(Robot.java:23): Unhandled exception: java.lang.NullPointerException
at frc.robot.Robot.robotInit(Robot.java:23)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463)
at frc.robot.Main.main(Main.java:23)
Error at java.base/java.util.Objects.requireNonNull(Objects.java:233): Unhandled exception: java.lang.NullPointerException: Parameter trajectory in method SwerveControllerCommand was null when it should not have been! Check the stacktrace to find the responsible line of code - usually, it is the first line of user-written code indicated in the stacktrace. Make sure all objects passed to the method in question were properly initialized - note that this may not be obvious if it is being called under dynamically-changing conditions! Please do not seek additional technical assistance without doing this first!
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at edu.wpi.first.util.ErrorMessages.requireNonNullParam(ErrorMessages.java:27)
at edu.wpi.first.wpilibj2.command.SwerveControllerCommand.(SwerveControllerCommand.java:197)
at edu.wpi.first.wpilibj2.command.SwerveControllerCommand.(SwerveControllerCommand.java:74)
at edu.wpi.first.wpilibj2.command.SwerveControllerCommand.(SwerveControllerCommand.java:119)
at frc.robot.RobotContainer.getAutonomousCommand(RobotContainer.java:118)
at frc.robot.Robot.autonomousInit(Robot.java:88)
at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:320)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:130)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:431)
at java.base/java.lang.Thread.run(Thread.java:833)
In this case, the file in the deploy directory is blueRight1.wpilib.json not blueRight.wpilib.json. For PathPlanner, you have a deploy nested inside the main deploy. You need to move the pathplanner directory up one level to get the paths to be recognized. It should look like this:
(Ignore the apriltag directory)