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 PathChain, you must inform the tracker. This resets the internal state and prepares it for the new segment.

progressTracker.setCurrentChain(myPathChain);

If you are not using the FollowPathCommand (which handles updates internally via the scheduler if integrated properly, or needs manual calls), you might need to check triggers in your loop.

However, typically the ProgressTracker is used within a generated SequentialCommandGroup or a custom command structure where checks are performed.

Note: If you are using the Command-Based Export from TurtleTracer, the generated SequentialCommandGroup uses WaitUntilCommand or similar structures that query progressTracker.shouldTriggerEvent("Name").

// 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.