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 left, 180 back, -90 right (robot-relative, counterclockwise).
      Parameters:
      label - the name shown on the Driver Station and in the report
      distanceIn - inches
      directionDeg - degrees from forward, counterclockwise like a heading: 90 = left (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).
    • forward

      public AutoRoutine forward(String label, double inches, double maxPower)
      Drives forward: move(label, inches, 0, maxPower). A plus number of inches (minus goes back).
    • back

      public AutoRoutine back(String label, double inches, double maxPower)
      Drives backward: move(label, inches, 180, maxPower). A plus number of inches (minus goes forward).
    • left

      public AutoRoutine left(String label, double inches, double maxPower)
      Slides left, still facing the same way (mecanum only): move(label, inches, 90, maxPower). Mirrored for RED.
    • right

      public AutoRoutine right(String label, double inches, double maxPower)
      Slides right, still facing the same way (mecanum only): move(label, inches, -90, maxPower). Mirrored for RED.
    • turnLeft

      public AutoRoutine turnLeft(String label, double degrees, double maxPower)
      Turns left by this many degrees: turn(label, degrees, maxPower). A plus number (minus turns right).
    • turnRight

      public AutoRoutine turnRight(String label, double degrees, double maxPower)
      Turns right by this many degrees: turn(label, -degrees, maxPower). A plus number (minus turns left).
    • 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).
    • turnTowardWithSweep

      public AutoRoutine turnTowardWithSweep(String label, DoubleSupplier bearingDeg, double toleranceDeg, double maxPower, double timeoutSec, double sweepDeg, double stepDeg, double sweepPower)
      turnToward(java.lang.String, java.util.function.DoubleSupplier, double, double, double) with a sweep: when nothing is seen at the start, the robot turns slowly, in steps of stepDeg, up to sweepDeg to the left, then up to sweepDeg to the right of where it started, and looks after each step. As soon as it sees the target it turns toward it as turnToward(java.lang.String, java.util.function.DoubleSupplier, double, double, double) does. Never seen: it turns back to where it started, and the report notes "not seen (swept)". It never turns farther than sweepDeg either way.
    • sweepStops

      public static List<Double> sweepStops(double sweepDeg, double stepDeg)
      The sweep's stops, degrees from the start (+ = left): left in steps up to sweepDeg, then right in steps down to -sweepDeg; both ends always included. None for a sweep of 0. Public for tests.
    • turnToward

      public AutoRoutine turnToward(String label, DoubleSupplier bearingDeg, double toleranceDeg, double maxPower, double timeoutSec)
      Turns toward something the robot measures, like the goal from the camera: bearingDeg says how far to turn (positive = left, NaN = not seen). Up to 4 turns (a fresh reading after each), until it is within toleranceDeg, or timeoutSec has passed. Not mirrored for RED: the bearing is measured, not written. The report notes "not seen" or "not within" if it did not get there.
    • 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)
    • driveTo

      public AutoRoutine driveTo(String label, Supplier<FieldPose> pose, BooleanSupplier ready, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn, List<PathEvent> events)
      driveTo(String, java.util.function.Supplier, BooleanSupplier, double, double, double, double, double) that also does things on the way (PathEvent): the "path" is the straight line from where the robot is at the start of the step to the point. Its distance left is the distance to the point.
    • 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.
    • followPath

      public AutoRoutine followPath(String label, PathJob job, double timeoutSec, List<PathEvent> events)
      followPath(String, PathJob, double) that also does things along the path: each PathEvent fires once, when the robot gets far enough along (checked every loop, in the order given). At the end of the path the ones reached there fire; if the path ends early, the report lists the ones that did not fire (STALLED, not fired: Spin up).
    • 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.
    • driveRoute

      public AutoRoutine driveRoute(String label, Supplier<FieldPose> pose, BooleanSupplier ready, BooleanSupplier poseKnown, FieldMap map, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn)
      Drives to a field point around the boxes of a FieldMap. The route is worked out when the step starts, from where the robot is THEN, so it works after a step was cut short at any place. It slows down at each corner of the route, and does not stop there (AutoDrive.followRoute(java.util.function.Supplier<com.crossbotics.ftchelper.util.FieldPose>, java.util.function.BooleanSupplier, java.util.List<double[]>, com.crossbotics.ftchelper.drive.RouteDriver.LineCheck, double, double, double)). The report words are driveTo's. "no route" in the report: the robot stayed where it was.

      BLOCKS (on purpose), like every driving step. Mirrored for RED like driveTo: the map and the point are written for BLUE.

      Parameters:
      pose - where the robot is now
      ready - false while the odometry cannot be trusted
      poseKnown - false if nothing set the pose (no start spot): the pose is only "where it stood", so a route from it would be wrong, and the robot stays
      map - the boxes
    • 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.