Lesson: Linear OpModes

Explore the details of the linear OpMode model.

Understand how linear OpModes work and how to use them.

The Linear OpMode is much simpler than the regular OpMode. There is only one method you can override: runOpMode(). This method is called after the Init button is pressed on the DS. So how do you separate initialization from actually starting the program running? You use the waitForStart() method of the base LinearOpMode class.
So from the start of your code in runOpMode() to the waitForStart() method call, you would place all of your initialization activity. When the Init button is pressed, all of your code up to the waitForStart() is executed and then your program waits for the Start button to be pressed. After that your program is in control until the end of the game period. You will most likely need a loop of some sort where you monitor the controllers and take action, but in the autonomous mode you may just execute a set of sequential instructions. In any case, your program must end at the appropriate time. When looping, you can monitor the OpModeIsActive() function (part of the base LinearOpMode class) to determine when you should stop your program.
Lets modify the NullOp OpMode sample to be of the linear form:

We use a while loop to continue executing as long as the OpMode is active (opModeActive() returns true).

Note that we call telemetry.update() after the addData() calls. The update() method actually sends the data added with any preceeding addData() calls to the Driver Station. This is different than the regular OpMode.

We also need to call the idle() method at the end of any looping we do to share the phone's processor with other processes on the phone.


Lesson navigation: