LinearOpMode Lifecycle
Understand init, start, active loop, and stop behavior.
Understand init, start, active loop, and stop behavior.
In this lesson, you will:
LinearOpMode lets students write robot code as a readable sequence, but the SDK still controls the lifecycle. Code before waitForStart runs during init, code after waitForStart runs only after start, and every repeated behavior must respect opModeIsActive so the Stop button remains reliable.
Imagine the robot waiting at the field wall. During init, it should map hardware, set safe positions, and report readiness. During active control, it should loop quickly. During stop, it should stop commanding motion. A match robot that ignores lifecycle boundaries is stressful and unsafe.
Write an OpMode with explicit init telemetry, a while loop for opModeInInit if needed, waitForStart, then the active loop. Put hardware setup before start and repeated gamepad/sensor decisions inside the active loop.
LifecycleDemo.javaJava
telemetry.addLine("Init complete");
telemetry.update();
waitForStart();
int loops = 0;
while (opModeIsActive()) {
loops++;
telemetry.addData("loops", loops);
telemetry.addData("runtime", getRuntime());
telemetry.update();
}If the robot moves during init, hardware writes are in the wrong place. If Stop is delayed, look for sleep calls or while loops that do not check opModeIsActive. If telemetry appears only once, telemetry.update is probably outside the loop.
Create a lifecycle demo that reports init time, start time, active loop count, and stop behavior. Explain which lines run before Start and which lines repeat during the match.
Check your understanding before moving on.
0 of 2 answered