Many teams just starting out will gloss over the “pre-autonomous” (RobotC) or *initialize” (easyC) section of the competition program. This post is an introduction to the things you can do in that part of your program.

The pre-auton/initialize time period in a competition occurs in between when you turn on the robot & connect the joysticks via VEXnet, and when the match starts. It’s usually many minutes of standing around waiting to go, as anyone who’s been to a tournament can tell you. So, you’ve got plenty of time to do stuff!

Autonomous Selection

VEX LCD ScreenTeams often have more than one autonomous program, such as one for each colored square where the robot could start the match. The most popular use of the pre-autonomous period is to select the specific autonomous routine desired, either through an LCD screen or by using a potentiometer as a knob, with pre-set markers to to choose a specific program.

See my previous posts on the LCD screen and the potentiometer for links to easyC and RobotC code that you can download and use for auton selection (or this more recent post on our favorite LCD menu code, explained in detail).

Sensor Initialization

Gyro sensorPre-auton/Initialize is the best time to get a gyro sensor set up. As mentioned in my post about the gyro (yaw) sensor, the device needs at least a second (preferably several seconds) of sitting dead still in order to get itself oriented. All that time hanging around before the match starts is the best time to do this. Be sure to position the robot in the direction you want to be the “north pole” before you turn it on and connect the joysticks.

Integrated Motor Encoder packageIn easyC, integrated motor encoders must be initialized once before they are used; in RobotC it’s good practice to set encoder values (or the values of other digital sensors) to 0 before the program executes. This is another great use for that pre-match sitting-around time. This step is not something that takes any time to execute, but it is good practice to just keep the sensor setup code in the Initialize tab/pre-auton section; write it, leave it, and forget it. 

Taking Sensor Readings

Ultrasonic Range FinderMy team used the ultrasonic rangefinder earlier this season to help us line up the robot for autonomous. It was important for us to be pointing right at the In The Zone stationary goal to start, so we put an ultrasonic sensor on the front center of the robot, and its reading would show on the LCD screen during pre-autonomous to let the drive team member know if it was aligned correctly.

VEX Line tracker sensorGriffin Tabor was kind enough to share his on-field calibration code for the line tracker sensor. For the line tracker (and light sensor too), it’s important to calibrate for the ambient light in the room you’re in now. It doesn’t help to calibrate these when you’re in your lab, because tournament lighting conditions will invariably be different. So, you can use the pre-auton/Initialize portion of the code to capture readings when you turn the robot on, so that it has the correct “baseline” to work from.

RobotC & easyC: Slightly Different

easyC logoInterestingly, the 2 programming languages handle this part of the code differently. RobotC will run pre-autonomous just once, in between when the robot is turned on and when autonomous is run. easyC will run the initialize portion of the code whenever the robot is disabled. This is an important distinction that should be considered, particularly when you’re using that section to calibrate; in easyC, it’s best to get the robot to calibrate sensors just once, under the controlled environment when you first put the robot down and turn it on (and not every time that the robot is disabled).

RobotC logoFor RobotC users, it’s helpful to understand that pre-auton gets run only once. If you’re using the competition switch, for example, setting the switch to “Disable” will not make pre-auton run again (you must power-cycle to do that). It’s slightly annoying when testing auton over & over, if you want to use the LCD screen to test different patterns, since the auton-selector code is contained in the pre-auton section of the competition template.

Share this post: