Package com.crossbotics.ftchelper.auto
Class AutoRoutine
java.lang.Object
com.crossbotics.ftchelper.auto.AutoRoutine
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();
- Every step has a name. It shows on the Driver Station while it runs, and in the report at the end.
- Mechanisms (a
Subsystemgroup) are updated every loop, during every step. mirrorFor(com.crossbotics.ftchelper.match.Alliance)flips turns and sideways moves for RED: write the route once, for BLUE.reserveForPark(double): the main steps stop early so the park steps always have time.
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 Summary
ConstructorsConstructorDescriptionAutoRoutine(com.qualcomm.robotcore.eventloop.opmode.LinearOpMode opMode) Makes a routine for your OpMode.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 Summary
Modifier and TypeMethodDescriptionbeforeDriving(Runnable hook) Code to run when a step starts driving the wheels (move, turn, driveTo...).The drivetrain for move and turn steps.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).driveTo(String label, Supplier<FieldPose> pose, BooleanSupplier ready, double xIn, double yIn, double headingDeg, double maxPower, double toleranceIn) driveTo(String, java.util.function.Supplier, double, double, double, double, double); stops ifreadyturns false.followPath(String label, PathJob job, double timeoutSec) Follows a path driven by another library (seePathJob) and waits until it is at the end, at mosttimeoutSec.What happened to each step, e.g.Flips turns, headings and sideways directions whenallianceis RED.booleanmirrorsX()True when routes are mirrored now (RED withmirrorFor(com.crossbotics.ftchelper.match.Alliance)): x and headings flip.Drives a distance: direction 0 forward, 90 right, 180 back, -90 left (robot-relative).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).rememberHeading(String label) Remembers the heading now, forreturnToHeading(java.lang.String, double).Formats the report for telemetry: one line per step.reserveForPark(double seconds) Main steps stop when this many seconds are left, so the park steps have time.returnToHeading(String label, double maxPower) Turns back to the heading saved byrememberHeading(java.lang.String).Runs some code at once and goes on (e.g.voidrunAll()Runs every step in order.intsize()Number of steps added.Any step: a mechanism's step (e.g.subsystems(Subsystem mechanisms) The mechanisms to keep updated during every step (a Subsystems group, or one Subsystem).The telemetry to show steps on (made for you if you do not give one).thenPark()The steps after this are PARK steps: they run even when the main steps ran out of time.timer(MatchTimer matchTimer) A match timer already started at START (made and started byrunAll()if not given).Turns by an amount, in degrees: positive = left (mirrored for RED).Turns to a heading (0 = the direction at the start, positive = left; mirrored for RED).Waits (mechanisms keep working).waitUntil(String label, BooleanSupplier condition, double timeoutSec) Waits until something is true, at mosttimeoutSec.
-
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
The drivetrain for move and turn steps. -
subsystems
The mechanisms to keep updated during every step (a Subsystems group, or one Subsystem). -
telemetry
The telemetry to show steps on (made for you if you do not give one). -
timer
A match timer already started at START (made and started byrunAll()if not given). -
mirrorFor
Flips turns, headings and sideways directions whenallianceis 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 withmirrorFor(com.crossbotics.ftchelper.match.Alliance)): x and headings flip. -
reserveForPark
Main steps stop when this many seconds are left, so the park steps have time. Default 0 (off). -
move
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 reportdistanceIn- inchesdirectionDeg- degrees, clockwise from forward (mirrored for RED)maxPower- 0 to 1
-
turn
Turns by an amount, in degrees: positive = left (mirrored for RED). -
turnTo
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) driveTo(String, java.util.function.Supplier, double, double, double, double, double); stops ifreadyturns false. -
followPath
Follows a path driven by another library (seePathJob) and waits until it is at the end, at mosttimeoutSec. The report saystimed out,STALLED(the distance left stopped going down for 1.5 s, more than 3 in from the end) orNO_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
Remembers the heading now, forreturnToHeading(java.lang.String, double). -
returnToHeading
Turns back to the heading saved byrememberHeading(java.lang.String). -
run
Runs some code at once and goes on (e.g.claw::open,() -> lift.goTo("HIGH")). -
waitFor
Waits (mechanisms keep working). -
waitUntil
Waits until something is true, at mosttimeoutSec. The report says if it timed out. -
step
Any step: a mechanism's step (e.g.lift.goToStep("HIGH")) or your own lambda. -
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 afterwaitForStart(). BLOCKS (on purpose): returns when the routine is done or stopped. Autonomous only. Mechanisms are updated every loop the whole time. -
getReport
What happened to each step, e.g. "Drive to basket: STALLED". Read-only. -
size
public int size()Number of steps added. -
beforeDriving
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
Formats the report for telemetry: one line per step.
-