Exporting Code
Exporting Code
Section titled “Exporting Code”Turn your visualized paths into runnable robot code or shareable animations.
How to Export
Section titled “How to Export”Every export starts from the Export menu in the top-right corner of the navigation bar.

- Open the Export menu: Click Export, then choose a format: Java Code, Kotlin Code, Points Array, Sequential Command, .turt File, Export as Image, Export Animated, or Strategy Sheet. You can also use a shortcut, such as Ctrl + Shift + J (or Cmd + Shift + J on macOS) for Java code. See Controls & Shortcuts for the rest.
- Adjust Options: Each format opens a dialog with its own options. The ones you change often, such as Language, Target Library, and Class Name, stay in view. The dialog also shows whether the project mirrors for the alliance, which you set in the Field tab. Click Options to reach the set-once ones: Package Name, Command Registrar (OpMode exports), Code Units (imperial or metric), and Generate Full Class or Embed Pose Data in Code. The code preview updates as you change them.
- Copy or Save:
- Click Copy Code to paste the generated code into Android Studio.
- Click Save to File to download it as a
.javafile (.ktif you export Kotlin), or a.txtfile for a points array. The .turt File dialog has a Download as .turt button instead.
OpMode (Standard)
Section titled “OpMode (Standard)”Generates a complete, standalone OpMode for your autonomous routine, in Java or Kotlin. This does not support all the functionality of the program due to current limitations.

- Full Class: Creates a ready-to-run file including the
OpModestructure, state machine, and path definitions. - Snippets: Uncheck "Generate Full Class" to get just the path construction code for copy-pasting into your own classes.
- Hardcoded Paths: The geometry is baked into the generated file. You do not need to put the
.turtfile on the robot. - Event Markers: Each marker becomes a
ProgressTrackerregistration that runs the command you registered withNamedCommandsunder the marker's name. - Command Registrar (optional): Name a method of yours, such as
org.firstinspires.ftc.teamcode.RobotCommands.register, and the generatedinit()calls it withhardwareMapso your named commands exist before the first path starts. It's written only when the path has event markers. You set it under Options.
Example Output
Section titled “Example Output”This is the OpMode generated for a three-path routine with a wait, a SpinUp event marker on the first path, and an Intake marker on the last. The paths are built in a Paths class, and a state machine follows them in order:
package org.firstinspires.ftc.teamcode;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.bylazar.configurables.annotations.Configurable;import com.bylazar.telemetry.PanelsTelemetry;import com.bylazar.telemetry.TelemetryManager;import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.eventloop.opmode.Autonomous;import com.qualcomm.robotcore.eventloop.opmode.OpMode;import com.qualcomm.robotcore.util.ElapsedTime;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import org.firstinspires.ftc.teamcode.pedro.Constants;
@Autonomous(name = "Turtle Tracer Autonomous", group = "Autonomous")@Configurable // Panelspublic class TurtleTracerAutonomous extends OpMode {
private TelemetryManager panelsTelemetry; // Panels Telemetry instance public Follower follower; // Pathing follower instance private final PoseFactory p = PoseFactory.degrees(); private ProgressTracker tracker; // Progress tracker instance for event markers private int pathState; // Current autonomous path state (state machine) private ElapsedTime pathTimer; // Timer for path state machine private Paths paths; // Paths defined in the Paths class
@Override public void init() { panelsTelemetry = PanelsTelemetry.INSTANCE.getTelemetry(); // ... panelsTelemetry.debug("Status", "Initialized"); panelsTelemetry.update(telemetry);
follower = Constants.create(hardwareMap); follower.setPose(p.of(9.000, 25.000, 0.000));
pathTimer = new ElapsedTime(); paths = new Paths(follower); // Build paths
tracker = new ProgressTracker(follower, telemetry); }
@Override public void loop() { follower.update(); // Update follower tracker.update(); // Update tracker pathState = autonomousPathUpdate(); // Update autonomous state machine
// Log values to Panels and Driver Station panelsTelemetry.debug("Path State", pathState); panelsTelemetry.debug("X", follower.pose().x()); panelsTelemetry.debug("Y", follower.pose().y()); panelsTelemetry.debug("Heading", follower.pose().heading()); panelsTelemetry.update(telemetry); }
public static class Paths {
private static final PoseFactory p = PoseFactory.degrees(); public Path DriveToShoot; public Path CollectRow1; public Path ReturnToShoot;
public Paths(Follower follower) { DriveToShoot = curve( p.of(9.000, 25.000, 0.0), p.of(28.000, 22.000, 0.0), p.of(48.000, 48.000, 0.0) ).linear(Math.toRadians(0), Math.toRadians(45));
CollectRow1 = curve( p.of(48.000, 48.000, 0.0), p.of(30.000, 58.000, 0.0), p.of(34.000, 78.000, 0.0) ).tangent();
ReturnToShoot = line( p.of(34.000, 78.000, 0.0), p.of(48.000, 48.000, 0.0) ).linear(Math.toRadians(90), Math.toRadians(45)); } }
public int autonomousPathUpdate() { switch (pathState) { case 0: follower.follow(paths.DriveToShoot); tracker.clearPathEvents(); tracker.onParametric(0, 0.400, NamedCommands.getCommand("SpinUp")); tracker.setCurrentPath(paths.DriveToShoot); setPathState(1); break; case 1: if (!follower.isBusy()) { setPathState(2); } break; case 2: setPathState(3); break; case 3: if (pathTimer.milliseconds() > 1500) { setPathState(4); } break; case 4: follower.follow(paths.CollectRow1); tracker.clearPathEvents(); tracker.setCurrentPath(paths.CollectRow1); setPathState(5); break; case 5: if (!follower.isBusy()) { setPathState(6); } break; case 6: follower.follow(paths.ReturnToShoot); tracker.clearPathEvents(); tracker.onParametric(0, 0.500, NamedCommands.getCommand("Intake")); tracker.setCurrentPath(paths.ReturnToShoot); setPathState(7); break; case 7: if (!follower.isBusy()) { setPathState(8); } break; case 8: requestOpModeStop(); pathState = -1; break; } return pathState; }
public void setPathState(int pState) { pathState = pState; pathTimer.reset(); }}package org.firstinspires.ftc.teamcode
import com.qualcomm.robotcore.eventloop.opmode.OpModeimport com.qualcomm.robotcore.eventloop.opmode.Autonomousimport com.qualcomm.robotcore.util.ElapsedTimeimport org.firstinspires.ftc.teamcode.pedro.Constantsimport com.turtletracerlib.pathing.NamedCommandsimport com.turtletracerlib.pathing.ProgressTracker
import com.bylazar.configurables.annotations.Configurableimport com.bylazar.telemetry.TelemetryManagerimport com.bylazar.telemetry.PanelsTelemetryimport com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolator
@Autonomous(name = "Turtle Tracer Autonomous", group = "Autonomous")@Configurable // Panelsclass TurtleTracerAutonomous : OpMode() { private lateinit var panelsTelemetry: TelemetryManager // Panels Telemetry instance lateinit var follower: Follower // Pathing follower instance private val p = PoseFactory.degrees() private lateinit var tracker: ProgressTracker // Progress tracker instance for event markers private var pathState = 0 // Current autonomous path state (state machine) private lateinit var pathTimer: ElapsedTime // Timer for path state machine private lateinit var paths: Paths // Paths defined in the Paths class
override fun init() { panelsTelemetry = PanelsTelemetry.telemetry // ... panelsTelemetry.debug("Status", "Initialized") panelsTelemetry.update(telemetry)
follower = Constants.create(hardwareMap) follower.setPose(p.of(9.000, 25.000, 0.000))
pathTimer = ElapsedTime() paths = Paths() // Build paths
tracker = ProgressTracker(follower, telemetry) }
override fun loop() { follower.update() // Update follower tracker.update() // Update tracker pathState = autonomousPathUpdate() // Update autonomous state machine
// Log values to Panels and Driver Station panelsTelemetry.debug("Path State", pathState) panelsTelemetry.debug("X", follower.pose().x()) panelsTelemetry.debug("Y", follower.pose().y()) panelsTelemetry.debug("Heading", follower.pose().heading()) panelsTelemetry.update(telemetry) }
class Paths { val DriveToShoot: Path val CollectRow1: Path val ReturnToShoot: Path
init { DriveToShoot = curve( p.of(9.000, 25.000, 0.0), p.of(28.000, 22.000, 0.0), p.of(48.000, 48.000, 0.0) ).linear(Math.toRadians(0.0), Math.toRadians(45.0))
CollectRow1 = curve( p.of(48.000, 48.000, 0.0), p.of(30.000, 58.000, 0.0), p.of(34.000, 78.000, 0.0) ).tangent()
ReturnToShoot = line( p.of(34.000, 78.000, 0.0), p.of(48.000, 48.000, 0.0) ).linear(Math.toRadians(90.0), Math.toRadians(45.0)) }
companion object { private val p = PoseFactory.degrees() } }
fun autonomousPathUpdate(): Int { when (pathState) { 0 -> { follower.follow(paths.DriveToShoot) tracker.clearPathEvents() tracker.onParametric(0, 0.400, NamedCommands.getCommand("SpinUp")) tracker.setCurrentPath(paths.DriveToShoot) setPathState(1) } 1 -> { if(!follower.isBusy()) { setPathState(2) } } 2 -> { setPathState(3) } 3 -> { if(pathTimer.milliseconds() > 1500) { setPathState(4) } } 4 -> { follower.follow(paths.CollectRow1) tracker.clearPathEvents() tracker.setCurrentPath(paths.CollectRow1) setPathState(5) } 5 -> { if(!follower.isBusy()) { setPathState(6) } } 6 -> { follower.follow(paths.ReturnToShoot) tracker.clearPathEvents() tracker.onParametric(0, 0.500, NamedCommands.getCommand("Intake")) tracker.setCurrentPath(paths.ReturnToShoot) setPathState(7) } 7 -> { if(!follower.isBusy()) { setPathState(8) } } 8 -> { requestOpModeStop() pathState = -1 } } return pathState }
fun setPathState(pState: Int) { pathState = pState pathTimer.reset() }}Register the SpinUp and Intake commands before the routine runs. Without a Command Registrar, that means editing the generated init(), which the next export overwrites. With one, the export writes the call for you:
follower = Constants.create(hardwareMap);follower.setPose(p.of(9.000, 25.000, 0.000));
org.firstinspires.ftc.teamcode.RobotCommands.register(hardwareMap); // Team's named commands
pathTimer = new ElapsedTime();paths = new Paths(follower); // Build pathsSee Named Commands & Events for the registration class and a step-by-step setup.
Command-Based (Recommended, Advanced)
Section titled “Command-Based (Recommended, Advanced)”Generates a command group for use with command-based frameworks.

- Supported Libraries: Pick one with the library tabs in the export dialog, or with Target Library in Settings.
- SolversLib: Standard integration.
- NextFTC: Experimental support.
- Ivy: Experimental support for Pedro Pathing's Ivy. Ivy builds commands with static factories, so the generated class hands back a
Commandfromcommand()instead of extending one. CallScheduler.reset()ininit(), start the routine withnew AutoPath(follower, hardwareMap).command().schedule(), and callfollower.update()andScheduler.execute()every loop.
- Pose data: Embed Pose Data in Code is on by default, so the poses are written into the class and you don't need the
.turtfile on the robot. Turn it off and the class usesTurtleTracerReaderto load path data from the.turtfile at runtime. You must put your.turtfile on the robot for that to work. See TurtleTracerReader. - Features: Automatically handles
FollowPath,Wait,Turn, and event triggers. Event markers use TurtleTracerLib events, and each path registers only its own markers, so they trigger on the right path in a chain. - Named commands: Register your commands in your own code (a
RobotContainerworks well) before you create the class. The Command Registrar isn't offered here. See Sequential Command Exports.
Example Output
Section titled “Example Output”The same routine exported for each library. Without Embed Pose Data, the class reads its poses from AutoPath.turt and registers each path's event markers just before that path runs:
package org.firstinspires.ftc.teamcode.Commands.AutoCommands;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.hardware.HardwareMap;import com.seattlesolvers.solverslib.command.InstantCommand;import com.seattlesolvers.solverslib.command.ParallelRaceGroup;import com.seattlesolvers.solverslib.command.RunCommand;import com.seattlesolvers.solverslib.command.SequentialCommandGroup;import com.seattlesolvers.solverslib.command.WaitCommand;import com.seattlesolvers.solverslib.command.WaitUntilCommand;import com.seattlesolvers.solverslib.pedroCommand.FollowPathCommand;import com.turtletracerlib.TurtleTracerReader;import com.turtletracerlib.auto.TurtleAuto;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import java.io.IOException;import org.firstinspires.ftc.robotcore.external.Telemetry;
@TurtleAuto(name = "AutoPath")public class AutoPath extends SequentialCommandGroup {
private final Follower follower; private final PoseFactory p = PoseFactory.degrees(); private TurtleTracerReader pp; private ProgressTracker tracker;
// Poses private Pose startPoint; private Pose DriveToShoot; private Pose DriveToShoot_line0_control1; private Pose CollectRow1; private Pose CollectRow1_line1_control1; private Pose ReturnToShoot;
// Path chains private Path startPointTODriveToShoot; private Path DriveToShootTOCollectRow1; private Path CollectRow1TOReturnToShoot;
public AutoPath(final Follower follower, HardwareMap hw, Telemetry telemetry) throws IOException { this.follower = follower;
pp = new TurtleTracerReader("AutoPath.turt", hw.appContext); pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")).onEvent( "Intake", NamedCommands.getCommand("Intake") );
tracker = new ProgressTracker(follower, telemetry);
// Load poses startPoint = pp.get("startPoint"); DriveToShoot = pp.get("DriveToShoot"); DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1"); CollectRow1 = pp.get("CollectRow1"); CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1"); ReturnToShoot = pp.get("ReturnToShoot");
follower.setPose(startPoint);
buildPaths();
addCommands( new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 0, 0); tracker.setCurrentPath(startPointTODriveToShoot); }), new ParallelRaceGroup( new FollowPathCommand(follower, startPointTODriveToShoot), new RunCommand(() -> tracker.update()) ), new WaitCommand(1500), new FollowPathCommand(follower, DriveToShootTOCollectRow1), new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 2, 0); tracker.setCurrentPath(CollectRow1TOReturnToShoot); }), new ParallelRaceGroup( new FollowPathCommand(follower, CollectRow1TOReturnToShoot), new RunCommand(() -> tracker.update()) ) ); }
public void buildPaths() { startPointTODriveToShoot = curve( startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot ).linear(Math.toRadians(0), Math.toRadians(45));
DriveToShootTOCollectRow1 = curve( DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1 ).tangent();
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot).linear( Math.toRadians(90), Math.toRadians(45) ); }}package org.firstinspires.ftc.teamcode.Commands.AutoCommands
import com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolatorimport com.qualcomm.robotcore.hardware.HardwareMapimport com.turtletracerlib.auto.TurtleAuto
import com.seattlesolvers.solverslib.command.SequentialCommandGroupimport com.seattlesolvers.solverslib.command.ParallelRaceGroupimport com.seattlesolvers.solverslib.command.WaitCommandimport com.seattlesolvers.solverslib.command.WaitUntilCommandimport com.seattlesolvers.solverslib.command.InstantCommandimport com.seattlesolvers.solverslib.command.RunCommandimport com.seattlesolvers.solverslib.pedroCommand.FollowPathCommand
import org.firstinspires.ftc.robotcore.external.Telemetryimport com.turtletracerlib.TurtleTracerReaderimport com.turtletracerlib.pathing.ProgressTrackerimport com.turtletracerlib.pathing.NamedCommands
@TurtleAuto(name = "AutoPath")class AutoPath( private val follower: Follower, hw: HardwareMap, telemetry: Telemetry,) : SequentialCommandGroup() { private val p = PoseFactory.degrees() private val pp: TurtleTracerReader private val tracker: ProgressTracker
// Poses private val startPoint: Pose private val DriveToShoot: Pose private val DriveToShoot_line0_control1: Pose private val CollectRow1: Pose private val CollectRow1_line1_control1: Pose private val ReturnToShoot: Pose
// Path chains private lateinit var startPointTODriveToShoot: Path private lateinit var DriveToShootTOCollectRow1: Path private lateinit var CollectRow1TOReturnToShoot: Path
init { pp = TurtleTracerReader("AutoPath.turt", hw.appContext) pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")) .onEvent("Intake", NamedCommands.getCommand("Intake"))
tracker = ProgressTracker(follower, telemetry)
// Load poses startPoint = pp.get("startPoint") DriveToShoot = pp.get("DriveToShoot") DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1") CollectRow1 = pp.get("CollectRow1") CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1") ReturnToShoot = pp.get("ReturnToShoot")
follower.setPose(startPoint)
buildPaths()
addCommands( InstantCommand({ tracker.clearPathEvents() pp.registerLineEvents(tracker, 0, 0) tracker.setCurrentPath(startPointTODriveToShoot) }), ParallelRaceGroup( FollowPathCommand(follower, startPointTODriveToShoot), RunCommand({ tracker.update() }) ), WaitCommand(1500), FollowPathCommand(follower, DriveToShootTOCollectRow1), InstantCommand({ tracker.clearPathEvents() pp.registerLineEvents(tracker, 2, 0) tracker.setCurrentPath(CollectRow1TOReturnToShoot) }), ParallelRaceGroup( FollowPathCommand(follower, CollectRow1TOReturnToShoot), RunCommand({ tracker.update() }) ) ) }
fun buildPaths() { startPointTODriveToShoot = curve(startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot) .linear(Math.toRadians(0.0), Math.toRadians(45.0))
DriveToShootTOCollectRow1 = curve(DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1) .tangent()
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot) .linear(Math.toRadians(90.0), Math.toRadians(45.0)) }}package org.firstinspires.ftc.teamcode.Commands.AutoCommands;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.hardware.HardwareMap;import com.turtletracerlib.TurtleTracerReader;import com.turtletracerlib.auto.TurtleAuto;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import dev.nextftc.core.commands.Command;import dev.nextftc.core.commands.delays.Delay;import dev.nextftc.core.commands.delays.WaitUntil;import dev.nextftc.core.commands.groups.ParallelRaceGroup;import dev.nextftc.core.commands.groups.SequentialGroup;import dev.nextftc.core.commands.utility.InstantCommand;import dev.nextftc.core.commands.utility.LambdaCommand;import java.io.IOException;
@TurtleAuto(name = "AutoPath")public class AutoPath extends Command {
private final Follower follower; private final PoseFactory p = PoseFactory.degrees(); private TurtleTracerReader pp; private ProgressTracker tracker; private Command group;
// Poses private Pose startPoint; private Pose DriveToShoot; private Pose DriveToShoot_line0_control1; private Pose CollectRow1; private Pose CollectRow1_line1_control1; private Pose ReturnToShoot;
// Path chains private Path startPointTODriveToShoot; private Path DriveToShootTOCollectRow1; private Path CollectRow1TOReturnToShoot;
public AutoPath(final Follower follower, HardwareMap hw) throws IOException { this.follower = follower;
pp = new TurtleTracerReader("AutoPath.turt", hw.appContext); pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")).onEvent( "Intake", NamedCommands.getCommand("Intake") );
tracker = new ProgressTracker(follower, null);
// Load poses startPoint = pp.get("startPoint"); DriveToShoot = pp.get("DriveToShoot"); DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1"); CollectRow1 = pp.get("CollectRow1"); CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1"); ReturnToShoot = pp.get("ReturnToShoot");
follower.setPose(startPoint); }
public void buildPaths() { startPointTODriveToShoot = curve( startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot ).linear(Math.toRadians(0), Math.toRadians(45));
DriveToShootTOCollectRow1 = curve( DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1 ).tangent();
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot).linear( Math.toRadians(90), Math.toRadians(45) ); }
@Override public void start() { buildPaths(); group = new SequentialGroup( new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 0, 0); tracker.setCurrentPath(startPointTODriveToShoot); }), new ParallelRaceGroup( new LambdaCommand("FollowPath") .setStart(() -> follower.follow(startPointTODriveToShoot)) .setIsDone(() -> !follower.isBusy()), new LambdaCommand("Update") .setUpdate(() -> tracker.update()) .setIsDone(() -> false) ), new Delay(1.500), new LambdaCommand("FollowPath") .setStart(() -> follower.follow(DriveToShootTOCollectRow1)) .setIsDone(() -> !follower.isBusy()), new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 2, 0); tracker.setCurrentPath(CollectRow1TOReturnToShoot); }), new ParallelRaceGroup( new LambdaCommand("FollowPath") .setStart(() -> follower.follow(CollectRow1TOReturnToShoot)) .setIsDone(() -> !follower.isBusy()), new LambdaCommand("Update") .setUpdate(() -> tracker.update()) .setIsDone(() -> false) ) ); group.start(); }
@Override public void update() { if (group != null) group.update(); }
@Override public void stop(boolean interrupted) { if (group != null) group.stop(interrupted); }
@Override public boolean isDone() { return group != null && group.isDone(); }}package org.firstinspires.ftc.teamcode.Commands.AutoCommands
import com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolatorimport com.qualcomm.robotcore.hardware.HardwareMapimport com.turtletracerlib.auto.TurtleAuto
import dev.nextftc.core.commands.Commandimport dev.nextftc.core.commands.groups.SequentialGroupimport dev.nextftc.core.commands.groups.ParallelRaceGroupimport dev.nextftc.core.commands.delays.Delayimport dev.nextftc.core.commands.delays.WaitUntilimport dev.nextftc.core.commands.utility.InstantCommandimport dev.nextftc.core.commands.utility.LambdaCommand
import com.turtletracerlib.pathing.ProgressTrackerimport com.turtletracerlib.pathing.NamedCommandsimport com.turtletracerlib.TurtleTracerReader
@TurtleAuto(name = "AutoPath")class AutoPath( private val follower: Follower, hw: HardwareMap,) : Command() { private val p = PoseFactory.degrees() private val pp: TurtleTracerReader private val tracker: ProgressTracker private var group: Command? = null
// Poses private val startPoint: Pose private val DriveToShoot: Pose private val DriveToShoot_line0_control1: Pose private val CollectRow1: Pose private val CollectRow1_line1_control1: Pose private val ReturnToShoot: Pose
// Path chains private lateinit var startPointTODriveToShoot: Path private lateinit var DriveToShootTOCollectRow1: Path private lateinit var CollectRow1TOReturnToShoot: Path
init { pp = TurtleTracerReader("AutoPath.turt", hw.appContext) pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")) .onEvent("Intake", NamedCommands.getCommand("Intake"))
tracker = ProgressTracker(follower, null)
// Load poses startPoint = pp.get("startPoint") DriveToShoot = pp.get("DriveToShoot") DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1") CollectRow1 = pp.get("CollectRow1") CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1") ReturnToShoot = pp.get("ReturnToShoot")
follower.setPose(startPoint) }
fun buildPaths() { startPointTODriveToShoot = curve(startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot) .linear(Math.toRadians(0.0), Math.toRadians(45.0))
DriveToShootTOCollectRow1 = curve(DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1) .tangent()
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot) .linear(Math.toRadians(90.0), Math.toRadians(45.0)) }
override fun start() { buildPaths() val sequence = SequentialGroup( InstantCommand { tracker.clearPathEvents() pp.registerLineEvents(tracker, 0, 0) tracker.setCurrentPath(startPointTODriveToShoot) }, ParallelRaceGroup( LambdaCommand("FollowPath").setStart { follower.follow(startPointTODriveToShoot) }.setIsDone { !follower.isBusy() }, LambdaCommand("Update").setUpdate { tracker.update() }.setIsDone { false } ), Delay(1.500), LambdaCommand("FollowPath").setStart { follower.follow(DriveToShootTOCollectRow1) }.setIsDone { !follower.isBusy() }, InstantCommand { tracker.clearPathEvents() pp.registerLineEvents(tracker, 2, 0) tracker.setCurrentPath(CollectRow1TOReturnToShoot) }, ParallelRaceGroup( LambdaCommand("FollowPath").setStart { follower.follow(CollectRow1TOReturnToShoot) }.setIsDone { !follower.isBusy() }, LambdaCommand("Update").setUpdate { tracker.update() }.setIsDone { false } ) ) group = sequence sequence.start() }
override fun update() { group?.update() }
override fun stop(interrupted: Boolean) { group?.stop(interrupted) }
override val isDone: Boolean get() = group?.isDone ?: false}package org.firstinspires.ftc.teamcode.Commands.AutoCommands;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.ivy.Command;import com.pedropathing.ivy.commands.Commands;import com.pedropathing.ivy.groups.Groups;import com.pedropathing.ivy.pedro.PedroCommands;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.hardware.HardwareMap;import com.turtletracerlib.TurtleTracerReader;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import java.io.IOException;
/** * Call {@code Scheduler.reset();} in init(), start it with * {@code new AutoPath(follower, hardwareMap).command().schedule();}, and call * {@code follower.update();} and {@code Scheduler.execute();} every loop. */public class AutoPath {
private final Follower follower; private final PoseFactory p = PoseFactory.degrees(); private TurtleTracerReader pp; private ProgressTracker tracker;
// Poses private Pose startPoint; private Pose DriveToShoot; private Pose DriveToShoot_line0_control1; private Pose CollectRow1; private Pose CollectRow1_line1_control1; private Pose ReturnToShoot;
// Path chains private Path startPointTODriveToShoot; private Path DriveToShootTOCollectRow1; private Path CollectRow1TOReturnToShoot;
public AutoPath(final Follower follower, HardwareMap hw) throws IOException { this.follower = follower;
pp = new TurtleTracerReader("AutoPath.turt", hw.appContext); pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")).onEvent( "Intake", NamedCommands.getCommand("Intake") );
tracker = new ProgressTracker(follower, null);
// Load poses startPoint = pp.get("startPoint"); DriveToShoot = pp.get("DriveToShoot"); DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1"); CollectRow1 = pp.get("CollectRow1"); CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1"); ReturnToShoot = pp.get("ReturnToShoot");
follower.setPose(startPoint); }
public void buildPaths() { startPointTODriveToShoot = curve( startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot ).linear(Math.toRadians(0), Math.toRadians(45));
DriveToShootTOCollectRow1 = curve( DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1 ).tangent();
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot).linear( Math.toRadians(90), Math.toRadians(45) ); }
public Command command() { buildPaths(); return Groups.sequential( Commands.instant(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 0, 0); tracker.setCurrentPath(startPointTODriveToShoot); }), Groups.race( PedroCommands.follow(follower, startPointTODriveToShoot), Commands.infinite(() -> tracker.update()) ), Commands.waitMs(1500), PedroCommands.follow(follower, DriveToShootTOCollectRow1), Commands.instant(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 2, 0); tracker.setCurrentPath(CollectRow1TOReturnToShoot); }), Groups.race( PedroCommands.follow(follower, CollectRow1TOReturnToShoot), Commands.infinite(() -> tracker.update()) ) ); }}package org.firstinspires.ftc.teamcode.Commands.AutoCommands
import com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolatorimport com.qualcomm.robotcore.hardware.HardwareMap
import com.pedropathing.ivy.Commandimport com.pedropathing.ivy.commands.Commandsimport com.pedropathing.ivy.groups.Groupsimport com.pedropathing.ivy.pedro.PedroCommands
import com.turtletracerlib.pathing.ProgressTrackerimport com.turtletracerlib.pathing.NamedCommandsimport com.turtletracerlib.TurtleTracerReader
/** * Call `Scheduler.reset()` in init(), start it with * `AutoPath(follower, hardwareMap).command().schedule()`, and call * `follower.update()` and `Scheduler.execute()` every loop. */class AutoPath( private val follower: Follower, hw: HardwareMap,) { private val p = PoseFactory.degrees() private val pp: TurtleTracerReader private val tracker: ProgressTracker
// Poses private val startPoint: Pose private val DriveToShoot: Pose private val DriveToShoot_line0_control1: Pose private val CollectRow1: Pose private val CollectRow1_line1_control1: Pose private val ReturnToShoot: Pose
// Path chains private lateinit var startPointTODriveToShoot: Path private lateinit var DriveToShootTOCollectRow1: Path private lateinit var CollectRow1TOReturnToShoot: Path
init { pp = TurtleTracerReader("AutoPath.turt", hw.appContext) pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")) .onEvent("Intake", NamedCommands.getCommand("Intake"))
tracker = ProgressTracker(follower, null)
// Load poses startPoint = pp.get("startPoint") DriveToShoot = pp.get("DriveToShoot") DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1") CollectRow1 = pp.get("CollectRow1") CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1") ReturnToShoot = pp.get("ReturnToShoot")
follower.setPose(startPoint) }
fun buildPaths() { startPointTODriveToShoot = curve(startPoint, p.of(28.000, 22.000, 0.0), DriveToShoot) .linear(Math.toRadians(0.0), Math.toRadians(45.0))
DriveToShootTOCollectRow1 = curve(DriveToShoot, p.of(30.000, 58.000, 0.0), CollectRow1) .tangent()
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot) .linear(Math.toRadians(90.0), Math.toRadians(45.0)) }
fun command(): Command { buildPaths() return Groups.sequential( Commands.instant { tracker.clearPathEvents() pp.registerLineEvents(tracker, 0, 0) tracker.setCurrentPath(startPointTODriveToShoot) }, Groups.race( PedroCommands.follow(follower, startPointTODriveToShoot), Commands.infinite { tracker.update() } ), Commands.waitMs(1500.0), PedroCommands.follow(follower, DriveToShootTOCollectRow1), Commands.instant { tracker.clearPathEvents() pp.registerLineEvents(tracker, 2, 0) tracker.setCurrentPath(CollectRow1TOReturnToShoot) }, Groups.race( PedroCommands.follow(follower, CollectRow1TOReturnToShoot), Commands.infinite { tracker.update() } ) ) }}The .turt file has to be on the robot for the TurtleTracerReader lines to work. See TurtleTracerReader.
Gradle setup
Section titled “Gradle setup”To use the command-based exports you need to add the JitPack repository and the TurtleTracerLib dependency to your teamcode Gradle configuration (for example, build.gradle):
repositories { maven { url 'https://jitpack.io' }}And add the dependency (use the newest release instead of the version shown):
implementation 'com.github.Mallen220:TurtleTracerLib:v3.0.3'Exported code is written for Pedro Pathing 3.x. See the TurtleTracerLib installation guide for the Pedro dependencies.
Kotlin
Section titled “Kotlin”The OpMode and Sequential Command exports can be written in Kotlin as well as Java. The other formats (Points Array, .turt File, image, animation, and strategy sheet) don't depend on the language.
- Choosing the language: Java Code and Kotlin Code in the Export menu open the OpMode export in that language. Every OpMode and Sequential Command dialog also has a Language switch above the code preview. The choice is a setting, so it carries over to the other dialogs, the Code tab, and auto export. You can also change it in Settings.
- Command libraries: SolversLib, NextFTC, and Ivy can all write Kotlin. The Target Library, Embed Pose Data, Package Name, and Code Units options work the same as for Java. For Ivy, start the routine with
AutoPath(follower, hardwareMap).command().schedule(), withoutnew. - Saving: Save to File writes a
.ktfile named after the class. - Plugin actions: A step that comes from a plugin that can't write Kotlin yet is left as a
// TODOcomment, and the dialog warns you. See Plugins.
Every example on this page has a Kotlin tab next to Java. The tab you pick is remembered across the docs.
Mirroring for the Other Alliance
Section titled “Mirroring for the Other Alliance”In most FTC games the red and blue halves of the field are copies of each other, so a path drawn for one alliance can run on the other if every point and heading is moved to the matching spot. The Alliance Selection & Path Mirroring section of the Field tab sets this up for each project. Its heading, and the Event Markers heading, have an info icon: both features need TurtleTracerLib on the robot, and the icon links to their docs. It works with TurtleTracerLib's auto selector: the code reads the driver's choice from an AutoContext and passes every pose and heading through it, so nothing changes when no mirroring is needed.
-
Drawn For: the alliance the project's paths are written for, Red or Blue. A new project has none (NONE), and clicking the selected alliance again clears it. With no alliance, exported code runs as drawn and doesn't use TurtleTracerLib for it.
-
Mirror to Blue (or Mirror to Red): the code says so explicitly either way, so it does what the project says whatever your selector's config is.
- On: the code tells its context to mirror when the driver picks the other alliance (
autoContext.drawnFor(Alliance.RED).mirroring(MirrorPolicy.FOLLOW_ALLIANCE)), then records the alliance it ran for and whether it mirrored (AutoSelection.record(ctx)). The driver's mirror override on the gamepad still applies. - Off: the code runs as drawn whichever alliance the driver picks, and records that with
AutoSelection.record(Alliance.RED, false).
Either way your TeleOp can read the alliance with
AutoSelection.alliance()and whether the auto mirrored withAutoSelection.isMirrored(). The class's@TurtleAutonames the same policy (FOLLOW_ALLIANCEorNEVER), so the selector's menu shows what the code will do. - On: the code tells its context to mirror when the driver picks the other alliance (
-
Preview on Blue (or Red): shows the path and the robot on the field as they will run for the other alliance, by the season's Field Mirror. A banner across the top of the field says you're previewing, with a Stop button. You can edit the path while you preview, just as on its own side: dragging a point on the mirrored path moves the matching point of the project's path, and the field shows positions on the side you're looking at. Obstacles stay where they are, so their handles are hidden during the preview. Turning the preview on or off doesn't change the project.
These are saved in the project's .turt file, so each path can be drawn for a different alliance, and changing one project doesn't change the others. The export dialog shows the project's choice above the code, and the Code tab and auto export use it too.
Everything the export writes is mirrored: poses, Bézier control points, heading angles, facing-point targets, Rotate steps and pose event markers. Steps added by plugins are mirrored only if the plugin supports it (see Plugins).
TurtleTracerLib is optional. Exported code only imports it for what the project uses: event markers, reading poses from the .turt file (when Embed Pose Data is off), or an alliance. A project with none of these exports code that builds without TurtleTracerLib installed. Command classes that do use it (SolversLib and NextFTC) also get @TurtleAuto(...), so your auto selector can find them with scan.
OpMode
Section titled “OpMode”The OpMode shows an alliance menu on the Driver Station during init. The driver picks red or blue with D-pad left and right, and when Start is pressed the OpMode builds its paths for that alliance. Picking the alliance the project is drawn for runs the paths as drawn; picking the other mirrors them.
How the field mirrors depends on the season, not the path, so it's a setting shared by every project: Field Mirror in Settings, under Code Export. The preview uses it too. Choose Turn field 180° (the default), Flip left/right (X) or Flip top/bottom (Y).
package org.firstinspires.ftc.teamcode;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.bylazar.configurables.annotations.Configurable;import com.bylazar.telemetry.PanelsTelemetry;import com.bylazar.telemetry.TelemetryManager;import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.eventloop.opmode.Autonomous;import com.qualcomm.robotcore.eventloop.opmode.OpMode;import com.qualcomm.robotcore.util.ElapsedTime;import com.turtletracerlib.auto.Alliance;import com.turtletracerlib.auto.AutoConfig;import com.turtletracerlib.auto.AutoContext;import com.turtletracerlib.auto.AutoRegistry;import com.turtletracerlib.auto.AutoSelector;import com.turtletracerlib.auto.MirrorAxes;import com.turtletracerlib.auto.MirrorPolicy;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import org.firstinspires.ftc.teamcode.pedro.Constants;
@Autonomous(name = "Turtle Tracer Autonomous", group = "Autonomous")@Configurable // Panelspublic class TurtleTracerAutonomous extends OpMode {
private TelemetryManager panelsTelemetry; // Panels Telemetry instance public Follower follower; // Pathing follower instance private final PoseFactory p = PoseFactory.degrees(); private ProgressTracker tracker; // Progress tracker instance for event markers private int pathState; // Current autonomous path state (state machine) private ElapsedTime pathTimer; // Timer for path state machine private Paths paths; // Paths defined in the Paths class private AutoSelector<AutoContext> selector; // Alliance menu shown during init private AutoContext ctx; // The alliance picked, to mirror the paths for
@Override public void init() { panelsTelemetry = PanelsTelemetry.INSTANCE.getTelemetry(); // ... panelsTelemetry.debug("Status", "Initialized"); panelsTelemetry.update(telemetry);
follower = Constants.create(hardwareMap);
pathTimer = new ElapsedTime(); // Alliance menu: D-pad left/right picks the alliance before Start. selector = new AutoSelector<>( new AutoRegistry<AutoContext>().add("Turtle Tracer Autonomous", c -> c), AutoConfig.builder() .baseAlliance(Alliance.RED) // The side these paths are drawn for .mirrorPolicy(MirrorPolicy.FOLLOW_ALLIANCE) // Mirrored when the driver picks the other one .mirrorAxes(MirrorAxes.BOTH) .build() );
tracker = new ProgressTracker(follower, telemetry); }
@Override public void init_loop() { selector.update(gamepad1, telemetry); // Draw the alliance menu }
@Override public void start() { ctx = selector.buildSelected(); // The alliance picked, and whether to mirror follower.setPose(ctx.pose(p.of(9.000, 25.000, 0.000))); paths = new Paths(follower, ctx); // Build paths for that alliance }
@Override public void loop() { follower.update(); // Update follower tracker.update(); // Update tracker pathState = autonomousPathUpdate(); // Update autonomous state machine
// Log values to Panels and Driver Station panelsTelemetry.debug("Path State", pathState); panelsTelemetry.debug("X", follower.pose().x()); panelsTelemetry.debug("Y", follower.pose().y()); panelsTelemetry.debug("Heading", follower.pose().heading()); panelsTelemetry.update(telemetry); }
public static class Paths {
private static final PoseFactory p = PoseFactory.degrees(); public Path DriveToShoot; public Path CollectRow1; public Path ReturnToShoot;
public Paths(Follower follower, AutoContext ctx) { DriveToShoot = curve( ctx.pose(p.of(9.000, 25.000, 0.0)), ctx.pose(p.of(28.000, 22.000, 0.0)), ctx.pose(p.of(48.000, 48.000, 0.0)) ).linear(ctx.heading(Math.toRadians(0)), ctx.heading(Math.toRadians(45)));
CollectRow1 = curve( ctx.pose(p.of(48.000, 48.000, 0.0)), ctx.pose(p.of(30.000, 58.000, 0.0)), ctx.pose(p.of(34.000, 78.000, 0.0)) ).tangent();
ReturnToShoot = line( ctx.pose(p.of(34.000, 78.000, 0.0)), ctx.pose(p.of(48.000, 48.000, 0.0)) ).linear( ctx.heading(Math.toRadians(90)), ctx.heading(Math.toRadians(45)) ); } }
public int autonomousPathUpdate() { switch (pathState) { case 0: follower.follow(paths.DriveToShoot); tracker.clearPathEvents(); tracker.onParametric(0, 0.400, NamedCommands.getCommand("SpinUp")); tracker.setCurrentPath(paths.DriveToShoot); setPathState(1); break; case 1: if (!follower.isBusy()) { setPathState(2); } break; case 2: setPathState(3); break; case 3: if (pathTimer.milliseconds() > 1500) { setPathState(4); } break; case 4: follower.follow(paths.CollectRow1); tracker.clearPathEvents(); tracker.setCurrentPath(paths.CollectRow1); setPathState(5); break; case 5: if (!follower.isBusy()) { setPathState(6); } break; case 6: follower.follow(paths.ReturnToShoot); tracker.clearPathEvents(); tracker.onParametric(0, 0.500, NamedCommands.getCommand("Intake")); tracker.setCurrentPath(paths.ReturnToShoot); setPathState(7); break; case 7: if (!follower.isBusy()) { setPathState(8); } break; case 8: requestOpModeStop(); pathState = -1; break; } return pathState; }
public void setPathState(int pState) { pathState = pState; pathTimer.reset(); }}package org.firstinspires.ftc.teamcode
import com.qualcomm.robotcore.eventloop.opmode.OpModeimport com.qualcomm.robotcore.eventloop.opmode.Autonomousimport com.qualcomm.robotcore.util.ElapsedTimeimport org.firstinspires.ftc.teamcode.pedro.Constantsimport com.turtletracerlib.pathing.NamedCommandsimport com.turtletracerlib.pathing.ProgressTracker
import com.bylazar.configurables.annotations.Configurableimport com.bylazar.telemetry.TelemetryManagerimport com.bylazar.telemetry.PanelsTelemetryimport com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolatorimport com.turtletracerlib.auto.Allianceimport com.turtletracerlib.auto.AutoConfigimport com.turtletracerlib.auto.AutoContextimport com.turtletracerlib.auto.AutoRegistryimport com.turtletracerlib.auto.AutoSelectorimport com.turtletracerlib.auto.MirrorAxesimport com.turtletracerlib.auto.MirrorPolicy
@Autonomous(name = "Turtle Tracer Autonomous", group = "Autonomous")@Configurable // Panelsclass TurtleTracerAutonomous : OpMode() { private lateinit var panelsTelemetry: TelemetryManager // Panels Telemetry instance lateinit var follower: Follower // Pathing follower instance private val p = PoseFactory.degrees() private lateinit var tracker: ProgressTracker // Progress tracker instance for event markers private var pathState = 0 // Current autonomous path state (state machine) private lateinit var pathTimer: ElapsedTime // Timer for path state machine private lateinit var paths: Paths // Paths defined in the Paths class private lateinit var selector: AutoSelector<AutoContext> // Alliance menu shown during init private lateinit var ctx: AutoContext // The alliance picked, to mirror the paths for
override fun init() { panelsTelemetry = PanelsTelemetry.telemetry // ... panelsTelemetry.debug("Status", "Initialized") panelsTelemetry.update(telemetry)
follower = Constants.create(hardwareMap)
pathTimer = ElapsedTime() // Alliance menu: D-pad left/right picks the alliance before Start. selector = AutoSelector( AutoRegistry<AutoContext>().add("Turtle Tracer Autonomous") { it }, AutoConfig.builder() .baseAlliance(Alliance.RED) // The side these paths are drawn for .mirrorPolicy(MirrorPolicy.FOLLOW_ALLIANCE) // Mirrored when the driver picks the other one .mirrorAxes(MirrorAxes.BOTH) .build(), )
tracker = ProgressTracker(follower, telemetry) }
override fun init_loop() { selector.update(gamepad1, telemetry) // Draw the alliance menu }
override fun start() { ctx = selector.buildSelected() // The alliance picked, and whether to mirror follower.setPose(ctx.pose(p.of(9.000, 25.000, 0.000))) paths = Paths(ctx) // Build paths for that alliance }
override fun loop() { follower.update() // Update follower tracker.update() // Update tracker pathState = autonomousPathUpdate() // Update autonomous state machine
// Log values to Panels and Driver Station panelsTelemetry.debug("Path State", pathState) panelsTelemetry.debug("X", follower.pose().x()) panelsTelemetry.debug("Y", follower.pose().y()) panelsTelemetry.debug("Heading", follower.pose().heading()) panelsTelemetry.update(telemetry) }
class Paths(ctx: AutoContext) { val DriveToShoot: Path val CollectRow1: Path val ReturnToShoot: Path
init { DriveToShoot = curve( ctx.pose(p.of(9.000, 25.000, 0.0)), ctx.pose(p.of(28.000, 22.000, 0.0)), ctx.pose(p.of(48.000, 48.000, 0.0)) ).linear(ctx.heading(Math.toRadians(0.0)), ctx.heading(Math.toRadians(45.0)))
CollectRow1 = curve( ctx.pose(p.of(48.000, 48.000, 0.0)), ctx.pose(p.of(30.000, 58.000, 0.0)), ctx.pose(p.of(34.000, 78.000, 0.0)) ).tangent()
ReturnToShoot = line( ctx.pose(p.of(34.000, 78.000, 0.0)), ctx.pose(p.of(48.000, 48.000, 0.0)) ).linear(ctx.heading(Math.toRadians(90.0)), ctx.heading(Math.toRadians(45.0))) }
companion object { private val p = PoseFactory.degrees() } }
fun autonomousPathUpdate(): Int { when (pathState) { 0 -> { follower.follow(paths.DriveToShoot) tracker.clearPathEvents() tracker.onParametric(0, 0.400, NamedCommands.getCommand("SpinUp")) tracker.setCurrentPath(paths.DriveToShoot) setPathState(1) } 1 -> { if(!follower.isBusy()) { setPathState(2) } } 2 -> { setPathState(3) } 3 -> { if(pathTimer.milliseconds() > 1500) { setPathState(4) } } 4 -> { follower.follow(paths.CollectRow1) tracker.clearPathEvents() tracker.setCurrentPath(paths.CollectRow1) setPathState(5) } 5 -> { if(!follower.isBusy()) { setPathState(6) } } 6 -> { follower.follow(paths.ReturnToShoot) tracker.clearPathEvents() tracker.onParametric(0, 0.500, NamedCommands.getCommand("Intake")) tracker.setCurrentPath(paths.ReturnToShoot) setPathState(7) } 7 -> { if(!follower.isBusy()) { setPathState(8) } } 8 -> { requestOpModeStop() pathState = -1 } } return pathState }
fun setPathState(pState: Int) { pathState = pState pathTimer.reset() }}Command-Based
Section titled “Command-Based”The class takes an AutoContext as its last constructor argument and calls drawnFor(...) on it with the project's alliance, so it decides for itself whether to mirror. Get the context from an AutoSelector and pass it in when the routine is built. Adding the routine with the same alliance keeps the selector's menu right:
autos.add("Routine", ctx -> new AutoPath(follower, hardwareMap, telemetry, ctx), Alliance.RED);That's the SolversLib constructor. NextFTC and Ivy classes take (follower, hardwareMap, ctx). How the field mirrors comes from your selector's AutoConfig, so the Field Mirror setting isn't used here. Without a selector, pass AutoContext.unmirrored() and the routine runs as drawn.
When the class reads a .turt file, the reader mirrors the poses and the curves' control points come from the file too. With Embed Pose Data, each pose in the code is wrapped in ctx.pose(...) instead.
package org.firstinspires.ftc.teamcode.Commands.AutoCommands;
import static com.pedropathing.api.Paths.curve;import static com.pedropathing.api.Paths.line;import static com.pedropathing.api.Paths.path;
import com.pedropathing.api.PoseFactory;import com.pedropathing.follower.Follower;import com.pedropathing.math.Pose;import com.pedropathing.paths.Path;import com.pedropathing.paths.interpolator.Interpolator;import com.qualcomm.robotcore.hardware.HardwareMap;import com.seattlesolvers.solverslib.command.InstantCommand;import com.seattlesolvers.solverslib.command.ParallelRaceGroup;import com.seattlesolvers.solverslib.command.RunCommand;import com.seattlesolvers.solverslib.command.SequentialCommandGroup;import com.seattlesolvers.solverslib.command.WaitCommand;import com.seattlesolvers.solverslib.command.WaitUntilCommand;import com.seattlesolvers.solverslib.pedroCommand.FollowPathCommand;import com.turtletracerlib.TurtleTracerReader;import com.turtletracerlib.auto.Alliance;import com.turtletracerlib.auto.AutoContext;import com.turtletracerlib.auto.AutoSelection;import com.turtletracerlib.auto.MirrorPolicy;import com.turtletracerlib.auto.TurtleAuto;import com.turtletracerlib.pathing.NamedCommands;import com.turtletracerlib.pathing.ProgressTracker;import java.io.IOException;import org.firstinspires.ftc.robotcore.external.Telemetry;
@TurtleAuto( name = "AutoPath", drawnFor = Alliance.RED, mirror = MirrorPolicy.FOLLOW_ALLIANCE, overrideMirror = true)public class AutoPath extends SequentialCommandGroup {
private final Follower follower; private final AutoContext ctx; // The driver's alliance, for paths drawn for RED private final PoseFactory p = PoseFactory.degrees(); private TurtleTracerReader pp; private ProgressTracker tracker;
// Poses private Pose startPoint; private Pose DriveToShoot; private Pose DriveToShoot_line0_control1; private Pose CollectRow1; private Pose CollectRow1_line1_control1; private Pose ReturnToShoot;
// Path chains private Path startPointTODriveToShoot; private Path DriveToShootTOCollectRow1; private Path CollectRow1TOReturnToShoot;
public AutoPath( final Follower follower, HardwareMap hw, Telemetry telemetry, AutoContext autoContext ) throws IOException { this.follower = follower; // Drawn for the red alliance, and mirrored when the driver picks the other one. this.ctx = autoContext .drawnFor(Alliance.RED) .mirroring(MirrorPolicy.FOLLOW_ALLIANCE); AutoSelection.record(ctx); // The alliance it runs for, and whether it's mirrored, for TeleOp
pp = new TurtleTracerReader("AutoPath.turt", hw.appContext).mirrored( ctx.mirror() ); pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")).onEvent( "Intake", NamedCommands.getCommand("Intake") );
tracker = new ProgressTracker(follower, telemetry);
// Load poses startPoint = pp.get("startPoint"); DriveToShoot = pp.get("DriveToShoot"); DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1"); CollectRow1 = pp.get("CollectRow1"); CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1"); ReturnToShoot = pp.get("ReturnToShoot");
follower.setPose(startPoint);
buildPaths();
addCommands( new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 0, 0); tracker.setCurrentPath(startPointTODriveToShoot); }), new ParallelRaceGroup( new FollowPathCommand(follower, startPointTODriveToShoot), new RunCommand(() -> tracker.update()) ), new WaitCommand(1500), new FollowPathCommand(follower, DriveToShootTOCollectRow1), new InstantCommand(() -> { tracker.clearPathEvents(); pp.registerLineEvents(tracker, 2, 0); tracker.setCurrentPath(CollectRow1TOReturnToShoot); }), new ParallelRaceGroup( new FollowPathCommand(follower, CollectRow1TOReturnToShoot), new RunCommand(() -> tracker.update()) ) ); }
public void buildPaths() { startPointTODriveToShoot = curve( startPoint, DriveToShoot_line0_control1, DriveToShoot ).linear(ctx.heading(Math.toRadians(0)), ctx.heading(Math.toRadians(45)));
DriveToShootTOCollectRow1 = curve( DriveToShoot, CollectRow1_line1_control1, CollectRow1 ).tangent();
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot).linear( ctx.heading(Math.toRadians(90)), ctx.heading(Math.toRadians(45)) ); }}package org.firstinspires.ftc.teamcode.Commands.AutoCommands
import com.pedropathing.api.PoseFactoryimport com.pedropathing.follower.Followerimport com.pedropathing.paths.Pathimport com.pedropathing.api.Paths.curveimport com.pedropathing.api.Paths.lineimport com.pedropathing.api.Paths.pathimport com.pedropathing.math.Poseimport com.pedropathing.paths.interpolator.Interpolatorimport com.qualcomm.robotcore.hardware.HardwareMapimport com.turtletracerlib.auto.Allianceimport com.turtletracerlib.auto.AutoContextimport com.turtletracerlib.auto.AutoSelectionimport com.turtletracerlib.auto.MirrorPolicyimport com.turtletracerlib.auto.TurtleAuto
import com.seattlesolvers.solverslib.command.SequentialCommandGroupimport com.seattlesolvers.solverslib.command.ParallelRaceGroupimport com.seattlesolvers.solverslib.command.WaitCommandimport com.seattlesolvers.solverslib.command.WaitUntilCommandimport com.seattlesolvers.solverslib.command.InstantCommandimport com.seattlesolvers.solverslib.command.RunCommandimport com.seattlesolvers.solverslib.pedroCommand.FollowPathCommand
import org.firstinspires.ftc.robotcore.external.Telemetryimport com.turtletracerlib.TurtleTracerReaderimport com.turtletracerlib.pathing.ProgressTrackerimport com.turtletracerlib.pathing.NamedCommands
@TurtleAuto(name = "AutoPath", drawnFor = Alliance.RED, mirror = MirrorPolicy.FOLLOW_ALLIANCE, overrideMirror = true)class AutoPath( private val follower: Follower, hw: HardwareMap, telemetry: Telemetry, autoContext: AutoContext,) : SequentialCommandGroup() { // The driver's alliance, for paths drawn for RED: mirrored when the // driver picks the other one. private val ctx = autoContext.drawnFor(Alliance.RED).mirroring(MirrorPolicy.FOLLOW_ALLIANCE) private val p = PoseFactory.degrees() private val pp: TurtleTracerReader private val tracker: ProgressTracker
// Poses private val startPoint: Pose private val DriveToShoot: Pose private val DriveToShoot_line0_control1: Pose private val CollectRow1: Pose private val CollectRow1_line1_control1: Pose private val ReturnToShoot: Pose
// Path chains private lateinit var startPointTODriveToShoot: Path private lateinit var DriveToShootTOCollectRow1: Path private lateinit var CollectRow1TOReturnToShoot: Path
init { AutoSelection.record(ctx) // The alliance it runs for, and whether it's mirrored, for TeleOp
pp = TurtleTracerReader("AutoPath.turt", hw.appContext).mirrored(ctx.mirror()) pp.onEvent("SpinUp", NamedCommands.getCommand("SpinUp")) .onEvent("Intake", NamedCommands.getCommand("Intake"))
tracker = ProgressTracker(follower, telemetry)
// Load poses startPoint = pp.get("startPoint") DriveToShoot = pp.get("DriveToShoot") DriveToShoot_line0_control1 = pp.get("DriveToShoot_line0_control1") CollectRow1 = pp.get("CollectRow1") CollectRow1_line1_control1 = pp.get("CollectRow1_line1_control1") ReturnToShoot = pp.get("ReturnToShoot")
follower.setPose(startPoint)
buildPaths()
addCommands( InstantCommand({ tracker.clearPathEvents() pp.registerLineEvents(tracker, 0, 0) tracker.setCurrentPath(startPointTODriveToShoot) }), ParallelRaceGroup( FollowPathCommand(follower, startPointTODriveToShoot), RunCommand({ tracker.update() }) ), WaitCommand(1500), FollowPathCommand(follower, DriveToShootTOCollectRow1), InstantCommand({ tracker.clearPathEvents() pp.registerLineEvents(tracker, 2, 0) tracker.setCurrentPath(CollectRow1TOReturnToShoot) }), ParallelRaceGroup( FollowPathCommand(follower, CollectRow1TOReturnToShoot), RunCommand({ tracker.update() }) ) ) }
fun buildPaths() { startPointTODriveToShoot = curve(startPoint, DriveToShoot_line0_control1, DriveToShoot) .linear(ctx.heading(Math.toRadians(0.0)), ctx.heading(Math.toRadians(45.0)))
DriveToShootTOCollectRow1 = curve(DriveToShoot, CollectRow1_line1_control1, CollectRow1) .tangent()
CollectRow1TOReturnToShoot = line(CollectRow1, ReturnToShoot) .linear(ctx.heading(Math.toRadians(90.0)), ctx.heading(Math.toRadians(45.0))) }}Other Formats
Section titled “Other Formats”- Points List: A raw array of coordinates (e.g.,
[(10, 10), (20, 20)]) for custom processing or debugging. - Project File (.turt): Download the source file to share with teammates or back up your work. The project data preview shows exactly what saving will write, including unsaved changes. Older
.ppfiles can still be opened.
Animation Export
Section titled “Animation Export”Create high-quality visualizers to share your strategy.
- Formats:
- GIF: Best for compatibility (Discord, Slack).
- APNG: Higher quality with transparency support, and smaller file sizes.
- Quality Controls: Adjust FPS, Scale, and Quality to balance file size and visual fidelity.
Dialog Tools
Section titled “Dialog Tools”- Search (Ctrl+F): Quickly find specific lines or markers in the generated code.
- Package Name: Set your team's package (e.g.,
org.firstinspires.ftc.teamcode) to fix imports automatically. - Command Registrar (OpMode exports only): The class and method that registers your named commands, for example
org.firstinspires.ftc.teamcode.RobotCommands.register. A line under the field shows what will be added toinit(). See Named Commands & Events. - Code Units: Generate the code in imperial (inches) or metric (cm). For sequential commands, metric code generation requires Embed Pose Data in Code, and the dialog warns you if it's off.
- Save to File: Directly save
.javaor.txtfiles to your computer.