Class AutoRoutine

java.lang.Object
com.crossbotics.ftchelper.auto.AutoRoutine

public class AutoRoutine extends Object
An autonomous written as a list of named steps. (Last season's AutoSequence, made general.)

 routine.move("Leave the wall", 6, 0, 0.4)
        .step("Lift to HIGH", lift.startStep("HIGH"))        // starts; keeps moving during the next steps
        .move("Drive to basket", 24, 0, 0.6)
        .turn("Face basket", 45, 0.5)                        // written for BLUE, mirrored for RED
        .waitUntil("Lift up", lift::isAtTarget, 2.0)
        .run("Drop", claw::open)
        .waitFor("Let it fall", 0.3)
        .thenPark()                                         // steps below run even if time is short
        .move("Park", 30, 180, 0.8)
        .runAll();
 

Two stages: first you ADD steps (the methods below only write each step onto the list, nothing moves yet). Then runAll() RUNS the list, one step after another.

EasyAuto makes and runs one of these for you. Docs: docs/modules/auto.md, docs/guides/easy-autos.md. The signs (which way is left) are in docs/conventions.md.

  • Constructor Details

    • AutoRoutine

      public AutoRoutine(com.qualcomm.robotcore.eventloop.opmode.LinearOpMode opMode)
      Makes a routine for your OpMode.
      Parameters:
      opMode - your autonomous OpMode (this)
    • AutoRoutine

      public AutoRoutine(BooleanSupplier isActive, Runnable idle, org.firstinspires.ftc.robotcore.external.Telemetry telemetry)
      For tests and simulations: what "running" and "idle" mean, and the telemetry.
  • Method Details

    • drive

      public AutoRoutine drive(AutoDrive autoDrive)
      The drivetrain for move and turn steps.
    • subsystems

      public AutoRoutine subsystems(Subsystem mechanisms)
      The mechanisms to keep updated during every step (a Subsystems group, or one Subsystem).
    • telemetry

      public AutoRoutine telemetry(RobotTelemetry t)
      The telemetry to show steps on (made for you if you do not give one).
    • timer

      public AutoRoutine timer(MatchTimer matchTimer)
      A match timer already started at START (made and started by runAll() if not given).
    • mirrorFor

      public AutoRoutine mirrorFor(Alliance alliance)
      Flips turns, headings and sideways directions when alliance is RED. Write routes for BLUE. For a field that is ROTATED (not mirrored) between alliances, do not call this: robot-relative moves and turns are then the same for both alliances. Pass null to turn mirroring off. See match/Alliance.java and docs/modules/match.md.
    • mirrorsX

      public boolean mirrorsX()
      True when routes are mirrored now (RED with mirrorFor(com.crossbotics.ftchelper.match.Alliance)): x and headings flip.
    • reserveForPark

      public AutoRoutine reserveForPark(double seconds)
      Main steps stop when this many seconds are left, so the park steps have time. Default 0 (off).
    • move

      public AutoRoutine move(String label, double distanceIn, double directionDeg, double maxPower)
      Drives a distance: direction 0 forward, 90 right, 180 back, -90 left (robot-relative).
      Parameters:
      label - the name shown on the Driver Station and in the report
      distanceIn - inches
      directionDeg - degrees, clockwise from forward (mirrored for RED)
      maxPower - 0 to 1
    • turn

      public AutoRoutine turn(String label, double degrees, double maxPower)
      Turns by an amount, in degrees: positive = left (mirrored for RED).
    • turnTo

      public AutoRoutine turnTo(String label, double headingDeg, double maxPower)
      Turns to a heading (0 = the direction at the start, positive = left; mirrored for RED).
    • moveWithTurn

      public AutoRoutine moveWithTurn(String label, double distanceIn, double fieldDirectionDeg, double headingDeg, double maxPower, double maxTurnPower)
      Drives in a field direction while turning to a heading (mecanum only). Both angles are mirrored for RED.
    • driveTo

      public AutoRoutine driveTo(String label, Supplier<FieldPose> pose, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn)
      Drives to a field point with odometry and ends at a heading (mecanum). Written for BLUE: for RED with mirroring on, x and the heading are mirrored.
      Parameters:
      pose - the odometry's pose (x right, y away, heading CCW from "away")
    • driveTo

      public AutoRoutine driveTo(String label, Supplier<FieldPose> pose, BooleanSupplier ready, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn)
    • followPath

      public AutoRoutine followPath(String label, PathJob job, double timeoutSec)
      Follows a path driven by another library (see PathJob) and waits until it is at the end, at most timeoutSec. The report says timed out, STALLED (the distance left stopped going down for 1.5 s, more than 3 in from the end) or NO_ODOMETRY (the pose was not ready at the start, or for 0.2 s on the way). BLOCKS until then, keeping the mechanisms updated.
    • rememberHeading

      public AutoRoutine rememberHeading(String label)
      Remembers the heading now, for returnToHeading(java.lang.String, double).
    • returnToHeading

      public AutoRoutine returnToHeading(String label, double maxPower)
      Turns back to the heading saved by rememberHeading(java.lang.String).
    • run

      public AutoRoutine run(String label, Runnable action)
      Runs some code at once and goes on (e.g. claw::open, () -> lift.goTo("HIGH")).
    • waitFor

      public AutoRoutine waitFor(String label, double seconds)
      Waits (mechanisms keep working).
    • waitUntil

      public AutoRoutine waitUntil(String label, BooleanSupplier condition, double timeoutSec)
      Waits until something is true, at most timeoutSec. The report says if it timed out.
    • step

      public AutoRoutine step(String label, AutoStep step)
      Any step: a mechanism's step (e.g. lift.goToStep("HIGH")) or your own lambda.
    • thenPark

      public AutoRoutine thenPark()
      The steps after this are PARK steps: they run even when the main steps ran out of time.
    • runAll

      public void runAll()
      Runs every step in order. Call after waitForStart(). BLOCKS (on purpose): returns when the routine is done or stopped. Autonomous only. Mechanisms are updated every loop the whole time.
    • getReport

      public List<String> getReport()
      What happened to each step, e.g. "Drive to basket: STALLED". Read-only.
    • size

      public int size()
      Number of steps added.
    • beforeDriving

      public AutoRoutine beforeDriving(Runnable hook)
      Code to run when a step starts driving the wheels (move, turn, driveTo...). The robot layer uses it to end a path follower's hold at the end of a path, so the two never drive the wheels at once. Each call adds one more; they run in order.
    • reportText

      public String reportText()
      Formats the report for telemetry: one line per step.