导入路径编织器 JSON

可以使用 ``TrajectoryUtil’’ 将路径编织器 JSON导入机器人代码以跟随它。本文将介绍如何导入轨迹。请访问: ref:end-to-end trajectory tutorial <docs/software/examples-tutorials/trajectory-tutorial/index:Trajectory Tutorial> 以获取有关跟踪轨迹的更多信息。

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.

注解

路径编织者将 JSON 文件放置在 src/main/deploy/paths  中,该文件将自动放置在 roboRIO 文件系统上的 /home/lvuser/deploy/paths 中,并可以使用 getDeployDirectory 进行访问,如下所示。

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.