Logo

Westside Robotics FTC Java Programming Guide

Code Your Autonomous OpMode

Create a new, blank, Iterative, autonomous OpMode. Verify that the autonomous library is added, along with the motor and servo libraries.

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;

Give a name to your auto code.

@Autonomous(name="Brad’s Auto OpMode")

Copy and paste your motor and servo declarations at the beginning of your class, as well as the contents of your init method from the teleop OpMode you’ve been working on. You’ll also want to copy and paste the set power methods for your drive motors at the end of your loop method, and you’ll need to create drive, strafe, and rotate variables at the beginning of the loop.

For each of your states, you’ll have an if statement to check which state you’re in. Inside each of those statements, you’ll set your drive, strafe, and rotate values to control how the robot moves. For each transition out of that state, you’ll have another if statement within the if statement for the state to check the transition condition and change the state appropriately - so your loop method ends up looking something like this:

double drive, strafe, rotate;
if(state == 1) {
  drive = 1;
  strafe = 1;
  rotate = 1;
  if(readyToTransition()) {
    state = 2;
  }
}
// more states go here
// set motor powers here

Following our plan from the last section, write the code to make your robot drive forward 3000 encoder ticks and then stop.