EasyStack Docs

Routine

Esta página aún no está traducida. Se muestra la versión en inglés.

A Routine is the easiest way to tell the robot what to do. You write the steps in the same order they happen, one after the other, in the same chained style you already use to set up motors and servos. When the routine reaches a wait, your OpMode keeps running, so nothing freezes.

#Your First Routine

Java
Routine.start()
        .run(() -> shooter.spinUp())
        .waitUntil(shooter::atSpeed)
        .run(() -> intake.on())
        .waitMs(500)
        .run(() -> intake.off())
        .schedule();

Read it like a list: spin the shooter up, wait until it is at speed, turn the intake on, wait half a second, turn the intake off. Routine.start() begins an empty list. Every method adds a step and returns the routine, so you can keep chaining. The last call, schedule(), starts it.

Routines need the scheduler to be running. Add addComponents(new EasyCommandComponent()) in initialize(). See the Commands tab.

#The Steps

  • run(action): does something once, right away. Use it to set a power, move a servo or call a method.
  • runFor(ms, action): repeats the action on every loop for a fixed time.
  • runUntil(condition, action): repeats the action on every loop until the condition becomes true.
  • runIf(condition, action): does the action once, but only if the condition is true at that moment.
  • waitMs(ms): waits for a time, in milliseconds.
  • waitUntil(condition): waits until the condition is true.
  • waitUntil(condition, timeoutMs): waits until the condition is true, but gives up after the timeout. Use it so the robot never gets stuck.
  • then(commands...): adds any command, for example one you wrote yourself or one from a subsystem.
  • parallel(commands...): runs several commands at the same time and continues when all of them are done.
  • race(commands...): runs several commands at the same time and continues when the first one is done.

#Starting a Routine

  • schedule(): starts it right now.
  • build(): gives you the finished command without starting it. Use it when something else starts the command, such as a button.
Java
Routine shoot = Routine.start()
        .run(() -> shooter.spinUp())
        .waitUntil(shooter::atSpeed, 2000)
        .run(() -> intake.on());

driver.aButton().onPress(shoot.build());

Build a routine once and press the button as many times as you like. If you press while it is still running, nothing happens. When it finishes, the next press starts it again from the first step.

#Subsystems

When a step uses a subsystem, pass it as the last argument. This tells the scheduler that the step needs it, so two routines never fight over the same mechanism:

Java
Routine.start()
        .run(() -> lift.up(), lift)
        .waitUntil(lift::atTop, 1500)
        .run(() -> claw.open(), claw)
        .schedule();

If you do not use subsystems, you can ignore this.

#More Examples

A simple autonomous:

Java
Routine.start()
        .run(() -> drive.driveRobotCentric(0, 0.5, 0))
        .waitMs(1200)
        .run(() -> drive.stop())
        .parallel(
                Commands.once(() -> shooter.spinUp()),
                Commands.waitUntil(shooter::atSpeed))
        .run(() -> intake.on())
        .waitMs(800)
        .run(() -> shooter.stop())
        .schedule();

A move that must never get stuck:

Java
Routine.start()
        .run(() -> arm.moveToDegrees(90))
        .waitUntil(arm::isAtPosition, 1500)
        .run(() -> claw.open())
        .schedule();

#Errors

  • A step with a null action or condition throws an IllegalArgumentException that says which one.
  • A negative time throws an IllegalArgumentException with the value you passed.
  • A routine with no steps does nothing and finishes at once.

#Routine or Command Classes?

  • Routine: the order of the steps is the whole point. A sequence of actions, an autonomous, a shooting cycle. This covers most robots.
  • Command classes: you need something very specific, such as a custom command that is reused in many places. See Custom Commands, Group Commands, Utilities and Decorators.

Both work together: then(...) accepts any command, and build() gives you a command that can go inside any group.

Última actualización 2026-11-16

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.