Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • Simple Autonomous
  • Encoder Autonomous
  • Autonomous State Machines
  • Actions and Sequencing
  • Plan and Test a Vision-Selected Autonomous

Actions and Sequencing

Prepare autonomous code for Road Runner action composition.

Autonomous FoundationsAdvanced

In this lesson, you will:

  • Write instant and running actions.
  • Return completion correctly.
  • Compose actions safely.

Concept narrative

Actions are reusable autonomous behaviors that continue until they report completion. This model aligns with Road Runner 1.0 and command-based robot thinking.

Robot mental model

An action is a cooperative task. It must do a small amount of work each time run is called, report telemetry, and finish when its condition is satisfied.

Implementation walkthrough

Create one instant servo action and one encoder-wait action. Then compose them sequentially. Keep run calls short; do not hide sleeps inside custom actions.

MechanismAction.javaJava

public Action liftTo(int target) {
    return new Action() {
        private boolean initialized;
        private final ElapsedTime timer = new ElapsedTime();

        @Override
        public boolean run(@NonNull TelemetryPacket packet) {
            boolean stopRequested = !opModeIsActive();
            if (stopRequested) {
                lift.setPower(0.0);
                packet.put("liftStopRequested", true);
                packet.put("liftExit", "stop");
                return false;
            }

            if (!initialized) {
                lift.setTargetPosition(target);
                lift.setMode(DcMotor.RunMode.RUN_TO_POSITION);
                lift.setPower(0.4);
                timer.reset();
                initialized = true;
            }

            int error = target - lift.getCurrentPosition();
            boolean timedOut = timer.seconds() >= 2.0;
            boolean running = Math.abs(error) > 25 && !timedOut;

            packet.put("liftError", error);
            packet.put("liftTimedOut", timedOut);
            packet.put("liftStopRequested", stopRequested);
            if (!running) {
                lift.setPower(0.0);
                packet.put("liftExit", timedOut ? "timeout" : "target");
            }
            return running;
        }
    };
}

try {
    Actions.runBlocking(liftTo(targetTicks));
} finally {
    lift.setPower(0.0); // Cover OpMode interruption as well as normal completion.
}

Common mistakes and debugging

Returning false too soon starts the next action early; returning true forever stalls auto. Long blocking calls starve parallel actions.

Practice

Write an action that moves a lift until error is small, then use it in a sequence with a claw action.

Checkpoint

  • Each run call returns promptly so other actions can continue.
  • The lift action initializes mode and power exactly once.
  • The action ends on tolerance or a documented timeout and reports the reason.
  • Lift power returns to zero after completion and after OpMode interruption.
  • A teammate can reproduce the sequence from the saved target, timeout, and telemetry.

Reflection check

Check your understanding before moving on.

For a Road Runner 1.0 Action, what does returning true from run(packet) mean?
Before a lift action waits for encoder error to shrink, what setup must it perform?

0 of 2 answered

References

Road Runner 1.0 ActionsAction composition, custom actions, and autonomous structure.FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.
Loading lesson progress
Previous lessonAutonomous State MachinesNext lessonPlan and Test a Vision-Selected Autonomous