LinearOpMode - ftc8380/coding-guide GitHub Wiki
GM0 has a fantastic little section on this topic, but let me introduce it a little bit more.
OpMode
You're used to seeing OpModes like
public class Example extends OPMode {
@Override
public void init() {
// Gets run when INIT pressed
}
@Override
public void init_loop() {
// Gets run over and over after INIT pressed, but before PLAY pressed
}
@Override
public void start() {
// Gets run when START pressed
}
@Override
public void loop() {
// Gets run over and over after START pressed, but before STOP pressed
}
@Override
public void stop() {
// Gets run when STOP pressed
}
Oh, yeah. Forgot to mention, init_loop(), start(), and stop() are a thing. Just in case you ever need them (I haven't).
LinearOpMode
Now allow me to introduce the linear equivalent,
public class Example extends LinearOpMode {
@Override
public void runOpMode() {
// Gets run when INIT pressed
while(opModeInInit()) {
// Gets run over and over after INIT pressed, but before PLAY pressed
// You should remove the loop entirely if it's empty
}
waitForStart();
// Gets run when START pressed (must come after waitForStart())
while(opModeIsActive()) {
// Gets run over and over after START pressed, but before STOP pressed
// You should remove the loop entirely if it's empty
}
}
}
There are a few key differences: you'll notice that there's only one method to override: runOpMode. The other methods like waitForStart() are only being called and not overridden.
This makes it so that you don't need private instance variables like with the OpMode class. Because there's only one method, you can declare and initialize variables in that method and use them as you wish.
As a general rule of thumb, you'll use OpMode to write teleop code and autonomous will be done in LinearOpMode.