Skip to content

TurtleTracerReader

The TurtleTracerReader class is great utility in TurtleTracerLib for teams that utilize the Command-Based code export from TurtleTracer. It allows your robot to dynamically read poses (Points) directly from a .pp file saved on the robot’s control hub, decoupling the path geometry from your Java code.

In traditional path generation (Standard OpMode export), every X, Y, and Heading coordinate is hardcoded into your Java file. This means any minor tweak to a curve requires re-exporting the Java code, copy-pasting it into Android Studio, and recompiling the entire app to the robot.

TurtleTracerReader changes this workflow:

  1. You export a .pp (JSON) file from TurtleTracer.
  2. You upload this .pp file directly to your robot’s internal storage.
  3. Your Java code uses TurtleTracerReader to read the named points.

Benefit: If you need to adjust a path at a competition, you just tweak it in the visualizer, save the new .pp file, upload it to the robot via the FTC Dashboard or File Manager, and run the robot. No recompiling required!

Before you can read a file, it must be on the robot. It is recommended to upload .pp files to TeamCode/src/main/assets/AutoPaths for the easiest implementation.

When you use the Command-Based (SolversLib/NextFTC) export option in TurtleTracer, the generated code already includes TurtleTracerReader.

You initialize the reader by passing the name of the uploaded file and the hardware map’s application context. This operation can throw an IOException if the file isn’t found, so it must be handled or declared.

import com.turtletracerlib.TurtleTracerReader;
import com.qualcomm.robotcore.hardware.HardwareMap;
import java.io.IOException;
// Inside your OpMode or CommandGroup constructor:
public AutoPath(HardwareMap hw) throws IOException {
// Look for "AutoPath.pp" on the robot's storage
TurtleTracerReader pp = new TurtleTracerReader("AutoPath.pp", hw.appContext);
}

Once initialized, you can retrieve any Pose by the name you gave the point or path segment in TurtleTracer.

import com.pedropathing.math.Pose;
// ...
TurtleTracerReader pp = new TurtleTracerReader("AutoPath.turt", hw.appContext);
// Retrieve points by their string names
Pose startPoint = pp.get("startPoint");
Pose point1 = pp.get("point1");
Pose scoringPosition = pp.get("scoringPosition");

After retrieving the poses, you can build your path using Pedro Pathing:

import com.pedropathing.api.Paths;
import com.pedropathing.paths.Path;
// ...
follower.setStartingPose(startPoint);
Path startPointTOpoint1 = Paths.line(startPoint, point1)
.linear(startPoint.heading(), point1.heading());

You can bind Java actions directly to event markers defined in the visualizer:

import com.turtletracerlib.pathing.ProgressTracker;
pp.onEvent("IntakeMarker", () -> intake.start())
.onEvent("ScoreMarker", () -> outtake.score());
// Registers markers and binds their actions to the tracker automatically:
pp.registerEvents(progressTracker);
  • Naming Conventions: Give your points clear, descriptive names in TurtleTracer (e.g., preloadDrop, samplePickup1). TurtleTracerReader relies entirely on these string keys.
  • File Updates: Remember that if you change the structure of your path (e.g., adding entirely new segments or renaming points), you will need to re-export the Java code. TurtleTracerReader is meant for tweaking existing geometry.
  • Error Handling: The visualizer’s generated code simply throws IOException up the chain. In a robust competition setup, you might want to catch this error and output a telemetry message so drivers know the file is missing before they press Start.