Named Commands & Events
TurtleTracerLib provides a robust system for synchronizing robot actions with your path traversal. This system bridges the gap between the strings defined in the Event Markers in TurtleTracer and the Java code running on your robot.
Overview
Section titled “Overview”The system consists of two main components:
NamedCommands: A central registry that maps string names (e.g., “OpenClaw”) to executableCommandobjects.ProgressTracker: A utility that monitors the robot’s progress along the path and automatically triggers these named commands at the correct position.
Registering Commands
Section titled “Registering Commands”Before your autonomous routine runs, you must register the commands you intend to use. This is typically done in your OpMode’s init() method or a RobotContainer constructor.
import com.turtletracerlib.pathing.NamedCommands;
public void init() { // Registering a simple Runnable NamedCommands.registerCommand("OpenClaw", () -> robot.claw.open());
// Registering a custom Runnable for a sequence NamedCommands.registerCommand("ScoreSpecimen", () -> robot.scoreSpecimen());
// Registering with a description (useful for debugging) NamedCommands.registerCommand("Intake", () -> robot.intake.start(), "Starts the intake motor");}Supported Platforms
Section titled “Supported Platforms”The NamedCommands system exclusively uses standard Java Runnable interfaces, making it highly compatible:
- Basic Java / FTC SDK: Pass any
Runnableor lambda directly. - NextFTC: Supported using Runnables.
- SolversLib: Supported using Runnables.
Using ProgressTracker
Section titled “Using ProgressTracker”The ProgressTracker is responsible for “watching” the path follower and firing events.
1. Initialization
Section titled “1. Initialization”Create a ProgressTracker instance, passing it your Follower and (optionally) Telemetry.
ProgressTracker progressTracker = new ProgressTracker(follower, telemetry);2. Loading Events
Section titled “2. Loading Events”When using the Command-Based export from TurtleTracer, the generated code automatically handles event registration. If you are writing custom code, you can register events manually:
// Register "OpenClaw" to trigger at 50% (0.5) of the pathprogressTracker.registerEvent("OpenClaw", 0.5);3. Setting the Path
Section titled “3. Setting the Path”Whenever you start a new Path, you must inform the tracker. This resets the internal event state and prepares it for the new trajectory.
progressTracker.setCurrentPath(myPath);4. Updating
Section titled “4. Updating”In your OpMode loop, calling progressTracker.update() alongside follower.update() evaluates all registered event markers and executes triggered actions automatically and safely.
Alternatively, if you are using a generated SequentialCommandGroup, you can query whether an event has triggered:
// Example usage in generated code:new WaitUntilCommand(() -> progressTracker.shouldTriggerEvent("OpenClaw")),new InstantCommand(() -> progressTracker.executeEvent("OpenClaw"))Manual Execution
Section titled “Manual Execution”You can manually trigger a named command at any time using the tracker. This ensures it only runs once per registration cycle (preventing double-firing).
progressTracker.executeEvent("OpenClaw");Debugging
Section titled “Debugging”You can list all registered commands to the Driver Station telemetry to verify your setup.
NamedCommands.listAllCommands(telemetry);telemetry.update();This will print a table of Command Name, Class Type, and Description.