FTC Programming

Setting Up The Autonomous File

Setting Up The Autonomous File

How to create a new Autonomous file

Once you have gone onto OnBot on your computer, click on the "OnBotJava" tab at the top. Then you can start adding a new file by clicking the on the left-hand side. Here you can name your file whatever you see fit. Start by naming the file "MyFirstAuton" and make sure "Not an OpMode" is selected and no option is checked at the bottom. Make sure you do not delete the very first line of code. Begin by typing the following code in your Autonomous code file:

@Autonomous(name="MyFirstAuton", group="Linear Opmode")

Next, you are going to set your code and place it into a class that can be accessed later. This is done by typing this:

public class MyFirstAuton extends LinearOpMode {
    // this space is here because this is where you will define your motors
  }  

Setting up motors

Next, we are going to set what motors will be used on our robot and in our code. The motors we will be using are "leftDrive" and "rightDrive". This is done by typing this:

@Autonomous(name="MyFirstAuton", group="Linear Opmode")
    public class MyFirstAuton extends LinearOpMode {
    
      private ElapsedTime runtime = new ElapsedTime();
      private DcMotor leftDrive = null;
      private DcMotor rightDrive = null;
    
      // Make sure power is between -1 and 1
      double power = 1;

The 'power' variable is set above and will serve to hold the motor power we will be running the robot's motors at.

Setting up the code to initialize our robot

Initialization is critical to code, even though the robot does not do anything yet. What initialization does is tell what motors should do what based on the port and the wiring that is on the robot. In order to set up the code to do this, type the following:

@Autonomous(name="MyFirstAuton", group="Linear Opmode")
    //@Disabled
    public class MyFirstAuton extends LinearOpMode {
    
       private ElapsedTime runtime = new ElapsedTime();
       private DcMotor leftDrive = null;
       private DcMotor rightDrive = null;
    
       // Make sure power is between -1 and 1
       double power = 1;
    
       @Override
       public void runOpMode() {
            
            //Initialization code goes here...  
    
           waitForStart(); // the robot initializes once the "INIT" button is pressed on the phone
           runtime.reset(); // this sets that timer variable we made earlier to 0, which is useful for autonomous programming
            
       }
    }

Programming what the robot will do

Finally, we are now able to start giving our robot instructions on what to do during the Autonomous period. To start out the section of this part of code, type this:

@Autonomous(name="MyFirstAuton", group="Linear Opmode")
    //@Disabled
    public class MyFirstAuton extends LinearOpMode {
    
       private ElapsedTime runtime = new ElapsedTime();
       private DcMotor leftDrive = null;
       private DcMotor rightDrive = null;
    
       // Make sure power is between -1 and 1
       double power = 1;
    
       @Override
       public void runOpMode() {
            
            //Initialization code goes here...  
    
           waitForStart();
           runtime.reset();
            //Autonomous robot instructions go here...
       }
    }

And you're done. You have the Autonomous file all setup!

chevron_up