package frc.robot.subsystems;
import java.io.IOException;
import java.nio.file.Path;
import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.math.trajectory.TrajectoryUtil;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Filesystem;
public class GetTrajectory {
public static Trajectory get(String trajectoryJSON){
Trajectory trajectory = new Trajectory();
try {
Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
} catch (IOException ex) {
DriverStation.reportError("Unable to open trajectory: " + trajectoryJSON, ex.getStackTrace());
}
return trajectory;
}
}
What is the problem you’re having? What have you tried and what errors have you gotten / issues are you seeing?
I get an error Unable to open trajectory then the path to the trajectory. I have tried manually making the trajectory and it worked but it will not get the json file created by pathweaver.
Is the JSON file in the deploy/ directory of the project?
/SWERVE-2024-1.0/deploy/paths/output
This is the directory for all JSON files.
What string are you passing as TrajectoryJSON in your code? Something like "paths/output/my.json"
? The trajectoryPath being generated in your get() function is relative to the top-level deploy directory.
It is …\\Swerve-2024-1.0\\deploy\\paths\\output\\my.wpilib.json
This is because we are on windows.
Have you compared your code to the code here? Importing a PathWeaver JSON — FIRST Robotics Competition documentation Compare the string you’re providing to the one in that example.
Yes. This is the code I copied and then used it to make a method that we can call when we want.
here is all of our code. Github
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.