Introducing the OpMode
Pick a program, any program...
Last updated
Was this helpful?
Pick a program, any program...
Last updated
Was this helpful?
OpModes are essential to programming in FTC. It is the entry point of your programs—think public static void main
. It is where your programs access all external resources, like robot hardware and telemetry. Short for “Operation Mode”, the OpMode is the true foundation upon which you program a FTC robot.
A TV can have multiple channels. A smartphone can have multiple apps. A computer can have multiple programs. A codebase for FTC can have multiple OpModes. An OpMode is a particular procedure that is executed by a FTC Robot Controller phone. You might create OpModes to test electronics, run autonomously for the Autonomous Period, run using remote control for the TeleOp Period, or to experiment with unfamiliar software.
Each OpMode you create can be found as a menu option on the Driver Station app. Above the circular button, two dropdown options are available on both sides of the OpMode selection menu, denoting TeleOp and Autonomous respectively. Each dropdown menu contains the names of all the declared OpModes in its category. Once you select the desired OpMode and press INIT, an object belonging to its class is instantiated, and either runOpMode
or init
is executed.
When setting up the robot on the field, one member of the drive team selects the desired Autonomous OpMode and presses INIT. We recommend that your Autonomous OpModes use to inform the drive team when it is fully initialized and whether any errors have occurred; the drive team may not touch the Driver Station screen nor enter the field after signalling to the referee that it is ready. Before autonomous begins, the OpMode will stay initialized. Once autonomous begins, the drive coach presses Play (â–¶), and the OpMode continues to execute. If the current OpMode belongs to the Autonomous category, an automatic 30-second timer can stop the OpMode once the Autonomous period ends; this timer is shown to the right of the circular button.
Between Autonomous and TeleOp, the drive coach switches from the Autonomous OpMode to the TeleOp OpMode and initializes it while the drivers pick up their controllers. When the TeleOp countdown ends, the drive coach presses Play (â–¶), and the OpMode continues to execute.
Once the TeleOp period ends, the drive coach presses Stop (â—Ľ), and the OpMode is asked to stop. The low-level mechanism for this differs by whether the OpMode is linear; refer to for more details.
If your OpMode happens to throw an uncaught exception, one of the following may occur:
Emergency Stop: The OpMode will abort, and a brief summary of the uncaught exception will be shown in telemetry. To resume operation, you are required to restart the robot through the Driver Station. Doing so is illegal during Autonomous but legal during TeleOp.
Crashing app: The Robot Controller app will crash, and Android will show the message "Unfortunately, FTC Robot Controller has stopped." There is no known way to recover from this during competition.
By the nature of the FTC Control System, the Robot Controller and the Driver Station may occasionally and spontaneously disconnect. When this happens, the OpMode will attempt to stop, and the Robot Controller app will attempt to regain communication with the Driver Station. When (and if) this connection is restored, the drive team may restart the OpMode from the Driver Station.
Annotate the class with either @Autonomous
or @TeleOp
. This will determine where your new OpMode will be found on the Driver Station interface. Select the option that is appropriate for your OpMode’s intended model of operation.
Give the annotation parameters name
and group
. The name
should uniquely identify the OpMode in a list of OpMode names. The value of the group
parameter allows you to further organize OpModes; in the Driver Station interface, OpModes are first divided into two lists, one for OpModes marked with @Autonomous
and one for those marked with @TeleOp
. Then, each of these lists are also sorted alphabetically by group
, and the OpModes within each group
are sorted alphabetically by name
. Thus, there are many options when it comes to organizing your OpModes. Always use a distinctive and descriptive name
such that all of your team's drivers can easily distinguish the proper OpMode to run at any time without the assistance of programmers. By ARC convention, the value of group
should be one of the following:
“Competition”: to denote that the current OpMode should be used during an actual competition
“Experimental”: to denote that the current OpMode is used to experiment with untested or otherwise unfamiliar code
“Troubleshoot”: to denote that the current OpMode is used to verify the operation of particular features, such as hardware devices.
"Other": for OpModes whose purpose is not covered by any of the options above.
Fill the method bodies with desired logic.
For a LinearOpMode
, the empty definition should look like this:
For an OpMode
, the empty definition should look like this:
We encourage you not to copy & paste from this guide. Typing the code out helps you memorize this structure and eliminate any dependence on this guide when creating new OpModes. Many competition venues do not allow access to the Internet in the pits, which means that you cannot always rely on this guide.
What is an OpMode?
Where can you select which OpMode to run?
True or False: You do not need to create a new class in order to make a new OpMode.
FTC has become notorious for its disconnection problems. During , for example, 9971 LANBros disconnected during the match and caused its alliance to lose Worlds. More recently, during , 14270 Quantum Robotics disconnected during the match and caused its alliance to be eliminated. So don't be so frustrated when you experience a disconnect from time to time—it happens to the best teams out there as well.
Refer to the for a demonstration. To define an OpMode in Java, simply follow the following steps:
Make a new class for the OpMode, and let the class extend either OpMode
or LinearOpMode
. (See for an explanation of these options)
Declare the required abstract methods. For a LinearOpMode
, the required method is public void runOpMode()
; for an iterative OpMode
, the required methods are public void init()
and public void loop()
. See for an explanation of these methods.
In the , you will discover the differences between these two paradigms of programming OpModes.