导入路径编织器 JSON¶

TrajectoryUtil 中的 fromPathweaverJson（Java）/ FromPathweaverJson（C ++）静态方式可用于根据 roboRIO 文件系统上存储的 JSON 文件创建轨迹。

To be compatible with the Field2d view in the simulator GUI, the coordinates for the exported JSON have changed. Previously (before 2021), the range of the y-coordinate was from -27 feet to 0 feet whereas now, the range of the y-coordinate is from 0 feet to 27 feet (with 0 being at the bottom of the screen and 27 feet being at the top). This should not affect teams who are correctly resetting their odometry to the starting pose of the trajectory before path following.

String trajectoryJSON = "paths/YourPath.wpilib.json";
Trajectory trajectory = new Trajectory();

@Override
public void robotInit() {
try {
Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
} catch (IOException ex) {
DriverStation.reportError("Unable to open trajectory: " + trajectoryJSON, ex.getStackTrace());
}
}


In the examples above, YourPath should be replaced with the name of your path.

Loading a PathWeaver JSON from file in Java can take more than one loop iteration so it is highly recommended that the robot load these paths on startup.