Basic Autonomous Programming (OnBot Java)

What is Autonomous Mode in FTC?

In FTC, autonomous mode is a period at the start of each match where the robot operates entirely based on pre-programmed instructions, without any driver input. This is your opportunity to score points by having your robot perform tasks automatically. Understanding how to structure and write autonomous code is essential for competition success.

Structure of an FTC OpMode

FTC programs are organized into OpModes. An OpMode is a Java class that defines the robot's behavior for a specific mode (autonomous or teleop). In OnBot Java, you create a new OpMode by extending the LinearOpMode class and overriding the runOpMode() method. The OpMode must be annotated with @Autonomous to be selectable as an autonomous program. For more details, see FTC Docs: Creating and Running an Op Mode (OnBot Java).

Minimal Autonomous OpMode Example

@Autonomous(name="MyFirstAutonomous")
public class MyFirstAutonomous extends LinearOpMode {
    @Override
    public void runOpMode() {
        // Initialization code here
        telemetry.addData("Status", "Initialized");
        telemetry.update();

        // Wait for the game to start (driver presses PLAY)
        waitForStart();

        // Autonomous actions go here
        while (opModeIsActive()) {
            // Example: do nothing
            telemetry.addData("Status", "Running");
            telemetry.update();
        }
    }
}

Practice Exercise: Your First Autonomous OpMode

Write an autonomous OpMode that drives a motor for 2 seconds, then stops. Use telemetry to display status before, during, and after movement.

  • Map a DC motor using hardwareMap.
  • Use waitForStart() to wait for the match to begin.
  • Set the motor power to drive forward for 2 seconds.
  • Stop the motor and update telemetry.

Further Reading & Resources

Open full interactive app