WestlakeLEARN
FTC · Java

FIRST Tech Challenge

FTC · Java

  • Action Builder and Trajectories
  • Custom Mechanism Actions
  • MeepMeep Preview
  • Three-Branch Autonomous Structure
  • Build a Full Road Runner Autonomous

Custom Mechanism Actions

Write actions that cooperate with drive paths.

Module 13: Road Runner 1.0 Actions and AutonomousRoad Runner

In this lesson, you will:

  1. 01Write an action that returns quickly while work continues.
  2. 02End on target or timeout and publish the stop reason.
  3. 03Guarantee zero mechanism power when the action or OpMode exits.

Concept narrative

Custom actions let mechanisms participate in autonomous without threads or sleeps. They run in small repeated steps and finish by returning false.

Robot mental model

A good mechanism action is polite: it does a little work, reports useful packet telemetry, and gives other actions time to run.

Implementation walkthrough

Write an action that initializes once, commands a target, checks sensor or encoder error, and returns false when finished.

CustomAction.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) {
            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);

            if (!running) lift.setPower(0.0);
            return running;
        }
    };
}

try {
    Actions.runBlocking(liftTo(targetTicks));
} finally {
    lift.setPower(0.0); // Also stop the mechanism when the OpMode is interrupted.
}

Common mistakes and debugging

Actions that sleep or loop internally starve parallel actions. Actions with bad finish conditions stall or skip steps.

Practice

Create a lift action and run it in parallel with a short drive action.

Checkpoint

  • Each run call returns promptly so parallel actions can continue.
  • The action ends on target or a documented timeout.
  • Telemetry identifies target, error, timeout, and completion reason.
  • Mechanism power returns to zero after completion and OpMode interruption.
  • The test record includes the setup, prediction, and observed result.
  • A teammate can repeat the check from the saved evidence without guessing.

Reflection check

Check your understanding before moving on.

Which result best demonstrates completion of “Custom Mechanism Actions”?

Why record the test setup, prediction, and observed result?

0 of 2 answered

References

Road Runner 1.0 ActionsAction composition, custom actions, and autonomous structure.FTC DashboardLive telemetry, graphs, config variables, and camera streaming.

Finished reading?

Mark this lesson complete — “MeepMeep Preview” is up next.

Action Builder and TrajectoriesMeepMeep Preview