Skip to content

Simple Auto

Now that the kitbot can move in teleop mode, it is time to make it move during the auto mode. To do this, another OpMode needs to be written that contains all the code needed to make the robot do what’s wanted in auto. Additionally the @Autonomous annotation is added above the class definition so it shows up in the driverstation under autonomous OpModes. This auto will be a timed based auto, meaning everything the robot does will be based on how long it has been since the start of autonomous. To keep track of how long it has been since the start of auto an instance of Timer is created in the OpMode and reset when the robot is enabled.

The code for the auto should be added to the MyAuto.java file inside the opmode folder. The goal of the auto is to drive forward at half speed for four seconds then stop. This can be accomplished by periodically checking if it has been four seconds since the start of auto using the Timer instance. If it has been at least four seconds then command the drivetrain with zero speed. Otherwise command the drivetrain to drive forward at half speed. Writing that out in code will look like this

/*
* This method runs periodically, using the same period as the Robot instance.
*
* Additional periodic methods may be configured with addPeriodic(),
* which can have periods that differ from the main Robot instance.
*/
@Override
public void periodic() {
if (autoTimer.hasElapsed(4.0)) { // Drive for 4 seconds after the start of auto
robot.drivetrain.arcadeDrive(0.0, 0.0); // Stop the drivetrain after 4 seconds
} else {
robot.drivetrain.arcadeDrive(0.5, 0.0); // Drive forward at half speed with no rotation
}
}

Video of running sim gui + AScope and selecting auto correctly

Try adding on to this auto yourself. For example, the robot could drive forward at half speed for four seconds, turn counter clockwise for two seconds, then drive forward at full speed for three seconds. You could also try creating additional autonomous OpModes so you can select between the different autos you have created.