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.
Why Use TurtleTracerReader?
Section titled “Why Use TurtleTracerReader?”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:
- You export a
.pp(JSON) file from TurtleTracer. - You upload this
.ppfile directly to your robot’s internal storage. - Your Java code uses
TurtleTracerReaderto 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!
Uploading the File
Section titled “Uploading the File”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.
Usage in Code
Section titled “Usage in Code”When you use the Command-Based (SolversLib/NextFTC) export option in TurtleTracer, the generated code already includes TurtleTracerReader.
1. Initialization
Section titled “1. Initialization”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);}2. Retrieving Poses
Section titled “2. Retrieving Poses”Once initialized, you can retrieve any Pose by the name you gave the point or path segment in TurtleTracer.
import com.turtletracer.geometry.Pose;
// ...TurtleTracerReader pp = new TurtleTracerReader("AutoPath.pp", hw.appContext);
// Retrieve points by their string namesPose startPoint = pp.get("startPoint");Pose point1 = pp.get("point1");Pose scoringPosition = pp.get("scoringPosition");3. Building PathChains
Section titled “3. Building PathChains”After retrieving the poses, you use them in your Follower path builder just as you would with hardcoded poses.
import com.turtletracer.geometry.BezierLine;import com.turtletracer.paths.PathChain;
// ...follower.setStartingPose(startPoint);
PathChain startPointTOpoint1 = follower .pathBuilder() .addPath(new BezierLine(startPoint, point1)) .setLinearHeadingInterpolation(startPoint.getHeading(), point1.getHeading()) .build();Best Practices
Section titled “Best Practices”- Naming Conventions: Give your points clear, descriptive names in TurtleTracer (e.g.,
preloadDrop,samplePickup1).TurtleTracerReaderrelies 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.
TurtleTracerReaderis meant for tweaking existing geometry. - Error Handling: The visualizer’s generated code simply throws
IOExceptionup 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.