Robot won't run function repeatedly in auton in Vexcode

We are having issues with our code in vexcode. When we call the rotation function image into our autonomous function image and run it, the robot will skip over all the rotations until the last one, which will work. We even tried getting rid of the rotation function and just inserting the same code each time we rotate, but it still won’t work. How can we fix this?

The problem is that startRotateFor function does not wait for the motor to reach it’s target.

The function you want to use is rotateFor, it is the same as startRotateFor, but has the option to wait for the motor to finish spinning. Also both function can already take velocity by default. You code would look something like this…

void rotate_r(float deg)
	LeftRear.rotateFor(deg/85, vex::rotations, 75, vex::pct, false);
	//LeftRear.startRotateFor(deg/85, vex::rotations, 75, vex::pct);
	RightRear.rotateFor(-deg/85, vex::rotations, 75, vex::pct);

The false means that the first statement will not wait for the motor to finish spinning, but the second will. The second (commented out) line will work too since it doesn’t wait for the motor to stop spinning.

An alternative, which might work a bit better would to use isDone function…

void rotate_r(float deg)
	LeftRear.startRotateFor(deg/85, vex::rotations, 75, vex::pct);
	RightRear.startRotateFor(-deg/85, vex::rotations, 75, vex::pct);
	while(!LeftRear.isDone() || !RightRear.isDone()) vex::task::sleep(15);

This will wait for both motor to be done spinning and not just one.

Some people implement their own PID. V5 does have built in PID, but creating your own can give you more fine and better control, which would result in a better autonomous. This does not mean you have to do this since the built in PID can work decently in many case.

Also Vexcode has a ridiculous amount of functions for classes like motor. Many functions have multiple name for identical functions. (This isn’t necessarily a bad thing, but I am just point this out.) The build in command help is not great and what I usually do is look though the header files, which include all available commands in Vexcode. If you are interested here is a link to a post about this.


The doxygen documentation is quite useful for this as well.