Basic Autonomous concepts

Hi all! I’m new to VEX this year and am trying to figure out how all the coding works. I have a lot of experience with other coding languages, but I’m not sure how all of the motor functions work in vex.

I’m trying to make a basic autonomous for my team’s first competition, but i really don’t know what i’m doing and i can’t find any good online tutorials

Currently, to drive the robot forward (for, say, 2 seconds) i’m using something like this:

leftDrive.rotateFor(vex::directionType::fwd, 2, vex::timeUnits::sec, 50, vex::velocityUnits::pct);

rightDrive.rotateFor(vex::directionType::rev, 2, vex::timeUnits::sec, 50, vex::velocityUnits::pct);

all placed inside the autonomous function

my big concern is that this will end up running one motor for 2 seconds, then the other. Is this the case? i would apperciate any tips you can give me. thanks!

1 Like

Your code will only allow you to move one motor at a time. Instead of using what you have use this instead:

leftDrive.spin(forward, 50, percent);
rightDrive.spin(forward, 50, precent);


it says “wait()” is undefined

It seems like you are using an older version of VexCode. Use vex::task::sleep(2000); instead.

thanks, that worked!
one last question:
does Competition.autonomous( autonomous ); actually run the autonomous program? or do i have to add something else?

That is the default code that comes with the competition template. I would suggest leaving it alone. What you would do to run auton is turn on your controller, select programs, select your program with the auton, and instead of pressing play, select the timed match. When you are ready, press A and a 3 second countdown will start.

Another way to run auton is to use a competition switch (I like this way a lot more because I can start it immediately with no countdown) but you’d need to buy one for $20

1 Like

thanks a ton for all your help!

Actually there is a way of running the motor using rotations without waiting for time, called waitForCompletion. Simply adding a “, false” to the end of a rotateFor command tells the Brain to not wait for the completion of the action and to start running the next action.

For example:

left.spinFor(directionType::fwd, 1, rotationUnits::rev, 100, velocityUnits::pct);
right.spinFor(directionType::fwd, 1, rotationUnits::rev, 100, velocityUnits::pct);

waits for the left motor to complete the action before starting the right motor action.

But adding a false to the end of left tells the Brain to start running the next command:

left.spinFor(directionType::fwd, 1, rotationUnits::rev, 100, velocityUnits::pct, false);
right.spinFor(directionType::fwd, 1, rotationUnits::rev, 100, velocityUnits::pct);

And in this case, the right motor starts spinning. This means that both will motors will run simultaneously for the same amount of time since they are moving the same amount of rotations.

Alternatively you could use a motor group or drive train and complete these actions easier. You can set up a drive train and motor group like this:

//motor definitions:
vex::motor RightRearMotor (vex::PORT9, vex::gearSetting::ratio18_1,true);
vex::motor RightFrontMotor (vex::PORT10, vex::gearSetting::ratio18_1,true);
vex::motor LeftFrontMotor (vex::PORT1, vex::gearSetting::ratio18_1,false);
vex::motor LeftRearMotor (vex::PORT2, vex::gearSetting::ratio18_1,false);

//4 motor base motor group:
vex::motor_group d(LeftFrontMotor, LeftRearMotor, RightFrontMotor, RightRearMotor);

//4 motor base drivetrain:
vex::motor_group l(LeftFrontMotor, LeftRearMotor);
vex::motor_group r(RightFrontMotor, RightRearMotor);
vex::drivetrain dt(l, r);