Coding auton in VexCode V5 pro

My team’s having our first opportunity to be with a field setup in a few hours, and it’s also our first(and only before our first comp) opportunity to code auton. However, as our coder, I’m quite new to V5 Pro, and I don’t know how to code auton. Any help is really appreciated.

1 Like

If this is your first time programming an autonomous, I would recommend first learning programming logic by using Vexcode V5 Blocks. If you have a dying urge to do VEXcode V5 Pro, I would recommend looking at the


I can’t use v5 blocks, as first of all, my robot’s already coded in v5 pro, and our program quite literally doesn’t allow it.

Then I would recommend looking at the API for all of functions and look at the example programs to learn how to structure your program.

And I guess I do have one more question. Like I said, I’m quite new to V5 pro, and I’m not quite sure where to put auton code.

1 Like

Welcome to VEXcode v5 pro!

As @74656A said,

will be very helpful. The fundamental “building blocks” of code you will be using can be accessed here, as well as concise explanations of what the code snippets do and usage examples.

An autonomous is basically a list of steps telling the robot what to do.

void autonomous(void) {

To make things as simple as the above example, we can enlist the aid of functions, which are like “blocks” of code that you can reuse multiple times.

1. Movement
I would point at the startRotateFor and rotateFor commands to program your base movement function. These commands, when used together, start all the motors and then wait for the last of the motors to finish to continue with the program. You can use these commands in a function like the following:

void moveBase(float revs) {

  // start motors 1, 2, and 3 but don't wait for them to finish before moving on
  motor1.startRotateFor(revs, rotationUnits::rev);
  motor2.startRotateFor(revs, rotationUnits::rev);
  motor3.startRotateFor(revs, rotationUnits::rev);

  // start motor 4 but wait for it to finish before moving on
  motor4.rotateFor(revs, rotationUnits::rev);

All this will be put ABOVE the autonomous section, because the autonomous section is where everything will be run. You would call the function in the autonomous section. To call a function, just type the function name with a pair of parentheses and a semicolon after. Inside the parentheses, type the value(s) you want to pass into the function.

To call the above example function and move 5 revs, you would place this piece of code in the autonomous section:


2. Multithreading (Task Usage)
Multithreading is neither intuitive nor easy, but this is a short overview of what you can do with it. If you’re running into problems with time and/or that you can’t move one component at the same time as another component, you can use tasks to eliminate this problem.

Tasks are functions that can run at the same time as other functions, which means you can run multiple robot components at once if you have 1 component per function.

To create a task, just create a function that does whatever you want to overlay, but instead of starting it with void, start it with int or float or any other returning data type. Then, at the end of the function, put a return statement, which will look like this:

return 0;

What this statement does is enables the function to be a different data type than void. Void types don’t return anything, which is why they don’t need the return statement.

Once you’ve got your function, make another function that IS a void function, and name it the same as your task function but put “CALL” at the end of the name so you can differentiate them.

Inside the call function, put a task calling statement. This is what it looks like:

vex::task t(taskFunctionName);

Then, use your call function in your autonomous as necessary. Here is an example of what the whole thing would look like:

// the task function can't have parameters unless you use a global variable
int taskFunction() {
  // do task stuff
  return 0;

// this is the calling function
void taskFunctionCALL() {
  // call the task
  vex::task t(taskFunction);

// this is what you'd put in the autonomous section

Hope that helped, and good luck with your autonomous! :grin:


I would recommend making a motor group and calling it Drive. Then you can make things like

Drive.setVelocity(50, percent);
Drive.spinFor(360, degrees);
Index.spin(forward, 100, percent);

Not the most advanced or accurate but if you don’t have a lot of time I would do this.

1 Like

If you are new to Vexcode Pro. I recommend using a competition template. To get this template go to the File tab on the top left corner. You will see a menu called examples. Click that and that will open a menu with a bunch of different examples using sensors and other stuff. If you scroll down you will see a label called competition template. It will ask you to open a new file and name it. Once it has opened scroll down and there will be a function called autonomous. That is where you put your autonomous code