2101
OpMode vs LinearOpMode

Go back to 0000 Index

There are two ways to create OpModes using the FTC SDK: OpMode and LinearOpMode. The one that you pick determines the structure of your code. Any OpMode should be able to be created using either method. The method you use is up to your preference. An equivalent example will be shown for each method.

Using LinearOpMode

The LinearOpMode allows you to use a method instead of an event-driven system like OpMode. Here is a summary of the structure of a LinearOpMode:

Example

public Example extends LinearOpMode {
	@Override
	public void runOpMode() {
		// runs on init
		DcMotor motor = hardwareMap.get(DcMotor.class, "motor");
		waitForStart();
		
		// runs once start button is pressed
		motor.setPower(1.0);
	}
}

Using OpMode

The OpMode allows you to use a class with event listeners instead of a function that runs linearly. These are the methods you can override to run code on an event:

Example

public Example extends OpMode {
	DcMotor motor;

	@Override
	public void init() {
		motor = hardwareMap.get(DcMotor.class, "motor");
	}

	@Override
	public void runOpMode() {
		motor.setPower(1.0);
	}
}

References