Trajectory Following

I am attempting to use a ramsete controller to follow a trajectory and I cannot parse through the trajectory. I’ve noticed that it gives an IOException so I attempted to add a throws IOException and now the command in Robot.java says unhandled exception type IOException. I’ve attempted to use a try-catch exception and then it cannot find the variable or if I place the variable in a try-catch it says that the trajectory isn’t initialized.

https://github.com/djpgamer7/FRC4012-Infinite-Recharge

Please show the actual exception/stacktrace.

Sorry Accidentally posted it without finishing the message, its there. There is no stack trace but just an error with the code.

Take a look at the driver station logs. There likely is a stacktrace, but broken into multiple lines so you’re not seeing it.

Either way, please share the exact output that you’re seeing. Copy/paste or a screenshot will do.

There is no driver station logs because the code wont deploy in the first place because of the exception. I’m attempting to implement a pathweaver trajectory if that makes more sense. The error is in RobotContainer/Robot.java

Here’s how we have been doing it. Then we check for null before scheduling the command in autonomous.

   public Command getAutonomousCommand() {
        var autoVoltageConstraint = new DifferentialDriveVoltageConstraint(
                new SimpleMotorFeedforward(Const.Ks, Const.Kv, Const.Ka), drive.getDifferentialDriveKinematics(), 10);

    TrajectoryConfig config = new TrajectoryConfig(2, 2);

    config.addConstraint(autoVoltageConstraint);
    config.setKinematics(drive.getDifferentialDriveKinematics());

    String trajectoryJSON = "paths/collect.wpilib.json";

    try {
        Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
        Trajectory trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);

        RamseteCommand command = new RamseteCommand(trajectory, drive::getPosition, new RamseteController(2.0, .7),
                drive.getFeedFoward(), drive.getDifferentialDriveKinematics(), drive::getWheelSpeeds,
                drive.getLeftPIDController(), drive.getRightPIDController(), drive::setVolts, drive);

        return command.andThen(() -> drive.setVolts(0, 0));
    } catch (IOException ex) {
        System.out.println("Unable to open trajectory: " + trajectoryJSON);
    }

    // TODO: return empty command to set motors to 0, 0
    return null;
}
3 Likes

That’s what I had but thought it would return null, Thanks!

Ah, didn’t realize it was a deployment error. In that case, you almost certainly have a stacktrace somewhere. Can you copy/paste the FULL console output?

I think the path has to be in the deploy directory that goes to the reo (e.g. src/main/deploy) based on the name of the method (getDeployDirectory)

I believe you’re correct, however I was waiting for the console output to be posted before suggesting that. If it’s truly an error at deployment time, then this is likely unrelated, since the code doesn’t execute until it’s on the robot, meaning nothing is referencing that file until then.

o I missed that, thank you

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