Skip to content

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.

The system consists of two main components:

  1. NamedCommands: A central registry that maps string names (e.g., “OpenClaw”) to executable Command objects.
  2. ProgressTracker: A utility that monitors the robot’s progress along the path and automatically triggers these named commands at the correct position.

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");
}

The NamedCommands system exclusively uses standard Java Runnable interfaces, making it highly compatible:

  • Basic Java / FTC SDK: Pass any Runnable or lambda directly.
  • NextFTC: Supported using Runnables.
  • SolversLib: Supported using Runnables.

The ProgressTracker is responsible for “watching” the path follower and firing events.

Create a ProgressTracker instance, passing it your Follower and (optionally) Telemetry.

ProgressTracker progressTracker = new ProgressTracker(follower, telemetry);

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 path
progressTracker.registerEvent("OpenClaw", 0.5);

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);

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"))

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");

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.