Your first OpMode
Read the FTC lifecycle and run a complete telemetry-only Java program
An is a program selected on the . It runs on the , which talks to the , , and gamepads. The Driver Station selects, , starts, and stops that program.
Begin with telemetry rather than a moving . Telemetry is information your program sends to the Driver Station. It lets you check that the right program is installed and see what an input is doing.
File structure
In Android Studio, create HelloRobot.java inside TeamCode/src/main/java/org/firstinspires/ftc/teamcode/. For OnBot , create the corresponding Java OpMode using its editor. The public class and file names must match.
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp(name = "Hello Robot", group = "Practice")
public class HelloRobot extends LinearOpMode {
@Override
public void runOpMode() {
telemetry.addLine("Initialized. Press START to read the stick.");
telemetry.update();
waitForStart();
if (!opModeIsActive()) return;
while (opModeIsActive()) {
double forward = -gamepad1.left_stick_y;
telemetry.addData("Forward request", "%.2f", forward);
telemetry.addData("A pressed", gamepad1.a);
telemetry.update();
idle();
}
}
}The package identifies where the class belongs. Imports bring SDK types into scope. @TeleOp registers a driver-controlled program and gives it a Driver Station name. extends LinearOpMode selects the lifecycle used by this example. The SDK calls runOpMode(); you do not call it yourself.
Gamepad playground
This example uses the same active loop to drive a simulated robot. Play compiles, initializes, and starts the OpMode; the real Driver Station has separate INIT and START steps.
Press Play, click the , then hold W to drive forward or S to reverse. Release the key to remove power. Press Stop, change speed from 0.25 to 0.5 near the top of the code, and run it again. The same stick input now requests more power.
Edit the example, then press Play. Reloading this page or changing theme restores the example.
On a narrow screen, Code and Simulator switch between the panes. On a touchscreen, use the left on-screen stick. This version adds motors so you can see the input take effect; the Hello Robot program above only sends telemetry to the Driver Station.
INIT, START, and STOP
Code before waitForStart() runs during INIT. Use it to map hardware, configure directions, and report readiness. A motor command here can run before START; initialization is not an automatic motion barrier.
waitForStart() waits for START or a stop request. The following active check handles STOP during that wait. while (opModeIsActive()) repeats the robot's work while it is allowed to run. idle() gives other work a chance to run; it is not a fixed timestep. Every inner movement loop also needs a stop check and a measured deadline.
For output devices, put shutdown in finally around the active work so an exception also removes motor power. See the motor example. Do not put a long calculation or an unguarded while (true) between stop checks.
Iterative OpModes
An iterative OpMode exposes init(), optional init_loop(), start(), repeated loop(), and stop(). Each loop() call should finish promptly so the SDK can call it again. A LinearOpMode gives you one method and lets you write your own active loop. Both can run responsive code; neither makes a blocking mechanism routine concurrent by itself.
First test
Build and deploy the TeamCode application in Android Studio, or build in OnBot Java. Select Hello Robot on the Driver Station. INIT should display the readiness message; START should display changing stick and button values. Move the left stick forward: the negated Y value should become positive. Press STOP and confirm the program ends.
Change the telemetry label, redeploy, and verify that the new label appears. This checks the edit–build–install loop before hardware adds another possible failure.