Instructional Material: OpMode Basics

The term OpMode or Operational Mode (also Op Mode and opmode) refers to a class located within the FTC SDK (robot controller app source code). You create this class to add your code to the controller app. Your code is really just a part of the controller app, with the rest of the app supplied by the FTC source code. We don't modify that other part of the code, we just create the custom robot behavior we want by adding our own OpModes. Here is a quick video overview of OpModes.

So how do we do this? We create a new class and extend the FTC provided OpMode class. In essence, we add functionality to the base application by adding new OpModes to it. Each "program" we write for our robot is a class that “extends” the OpMode class. A class that is an extension of another class is a descendant or sub-class: it has (inherits) the properties and methods of the original, but those can be changed or added to. We discuss extending classes in this lesson. When a robot is being operated, the driver station is used to select an OpMode and the controller phone runs only that OpMode.

A quick refresher on robot coding. All robot programs are essentially a looping activity. Your code repeatedly runs in a loop obtaining input, acting on that input and doing it again. 

OpModes are of two types, regular and linear. In a regular OpMode, the predefined method loop() is called repeatedly during robot operation. You write code to respond to these calls to loop(). The key idea is that you do not write a "loop" in your code, the base OpMode provides that for you by calling the loop method repeatedly on a timed basis. This is similar to an event based programming model. Your code responds to the "loop" event. This model is somewhat more difficult for beginners to use.

The linear OpMode is a traditional sequential execution model. Your code is started by the base OpMode and runs on its own until execution is over. In this model you must provide the loop in your code. This model is simpler to use and understand. Note that either model is valid and the choice of OpMode is up to the programmer, however the lessons in this Unit will focus on the linear OpMode.

In either case, when you add a new OpMode (a class file) you need to tell the base controller app that you have done so. You do this by using a Java special statement called an Annotation. An Annotation is an instruction to the Java compiler and is used by the FTC SDK to register your OpMode. The Annotation is placed in your code just above the OpMode class name and contains a title for your OpMode and classifies the OpMode as autonomous or teleop. You can further place your OpModes into groups of your choosing. You can temporarily remove an OpMode by adding another Annotation which disables the OpMode. We will show exactly how this is done in the program examples we will be looking at shortly. This registration process is what makes your OpMode visible to the robot controller phone and available to run.

Either type of OpMode can be used to program the two modes of robot control program execution, autonomous and teleop. In autonomous, the robot is not under the control of humans and as such will receive no input from the driver station phone. This mode is timed and is typically 30 seconds long. A timer on your driver station phone can be used to control the autonomous period, stopping your robot for you or you can manually stop the robot by pressing Stop (square black button) on the driver station. Your code will have to make all decisions and handle everything the robot is designed to do in the autonomous period.

In teleop mode, the robot is operated with input from humans via the Xbox controllers attached to the driver station. This mode is typically 2 minutes long and is stopped manually (Stop button) under direction of the match referee. In this mode your code will monitor Xbox controller input and translate that input into robot actions.

Both modes are started by pressing the Init button and then the Start (arrow) button on the driver station when directed by the referee. The Init button is used to tell your (teleop only) code it should perform whatever initialization functions you have programmed and the Start button begins program execution. We will explore these modes of execution and the driver station controls in more detail shortly.

 

Material Type: 
Lecture/Presentation
Education Level: 
Middle School
High School
Focus Subject: 
Computing / Computer Science
Robotics Software
HW Platform: 
Tetrix
SW Platform: 
Java
Interactivity Style: 
Mixed
Audience: 
Learner