OpModes
Learn how FTC programs are structured.
An OpMode is a program that runs on your robot. Every TeleOp, Autonomous, and testing program you create is an OpMode.
OpModes allow your code to communicate with the FTC Robot Controller and control your hardware.
Creating an OpMode
OpModes are created as Java classes that extend either:
LinearOpModeOpMode
Example:
@TeleOp
public class ExampleTeleOp extends LinearOpMode {
@Override
public void runOpMode() {
}
}The annotation tells the FTC SDK what type of program this is.
TeleOp vs Autonomous
TeleOp
TeleOp programs are controlled by drivers using gamepads.
@TeleOp(name = "Drive TeleOp")
public class DriveTeleOp extends LinearOpMode {
}Examples:
- Driving the robot
- Controlling mechanisms
- Operating the intake or shooter
Autonomous
Autonomous programs run without driver input.
@Autonomous(name = "Auto")
public class Auto extends LinearOpMode {
}Examples:
- Following paths
- Scoring game elements
- Moving to specific locations
LinearOpMode
LinearOpMode uses a sequential programming style.
The robot executes code from top to bottom.
@Override
public void runOpMode() {
waitForStart();
while (opModeIsActive()) {
}
}runOpMode()
This is where your robot code goes.
public void runOpMode() {
}waitForStart()
Pauses your program until the driver presses start.
waitForStart();opModeIsActive()
Checks whether the OpMode is currently running.
while (opModeIsActive()) {
}OpMode
OpMode uses an event-loop style.
Instead of one long program, the SDK repeatedly calls your methods.
@TeleOp
public class Example extends OpMode {
@Override
public void init() {
}
@Override
public void loop() {
}
}init()
Runs once when the OpMode starts.
Used for:
- Hardware initialization
- Setting variables
- Preparing the robot
loop()
Runs repeatedly while the OpMode is active.
Used for:
- Reading gamepads
- Controlling motors
- Updating mechanisms
LinearOpMode vs OpMode
| LinearOpMode | OpMode |
|---|---|
| Sequential code | Event-based code |
Uses runOpMode() | Uses init() and loop() |
| Easier for beginners | More advanced |
| Common for autonomous | Common for TeleOp frameworks |
Most beginners should start with LinearOpMode.
Utility OpModes (Coming Soon!)
Introduced in SDK version 11.2, Utility OpModes are programs used for testing and debugging.
Running an OpMode
To run your program:
- Build the project in Android Studio.
- Upload the code to the Control Hub.
- Open the Driver Station app.
- Select your OpMode.
- Press Start.
Key Takeaways
- An OpMode is a robot program.
- TeleOp uses driver input.
- Autonomous runs without drivers.
LinearOpModeuses sequential programming.OpModeuses an event loop.- Utility OpModes help test and debug robots.
Was this resource helpful?
