VEX C++ Encoder Issues

We’ve been having a problem with our Autonomous when driving for revolutions when the velocity is set to a limit. It seems that when we have it moving, say for example at 75 percent for 1.5 revolutions the motors seem to continuously speed up then slow down back to that limit causing our robot to do what as I can describe as almost “fish-tailing”.

Our Code :

LeftMotor.setVelocity(75, vex::velocityUnits::pct);
FLeftMotor.setVelocity(75, vex::velocityUnits::pct);
FRightMotor.setVelocity(75, vex::velocityUnits::pct);
RightMotor.setVelocity(75, vex::velocityUnits::pct);

RightMotor.rotateFor(1.5, vex::rotationUnits::rev);


If anyone could help explain how I would fix this it would be much appreciated!

Are FRightMotor and RightMotor really supposed to spin in opposite directions?

I don’t see a brakeType for one motor.

Not that it matters for anything but cleanliness here, but you have three absolutely useless lines of code at the top because you have assigned velocities when you use them.

There are two things I could see being issues based on the provided sample. The first being that




are likely using different PID algorithms, as one is trying to maintain a velocity and the other is trying to reach a position. The second is that


will always stop with


whereas you are stopping the other three motors with


. If you change from the


calls to


calls with a


wait for completion flag at the end (e.g.


) you should get more predictable behavior. It would also let you get rid of the stop commands altogether and shorten your code by a couple lines.

@John TYler I originally tried to have them all on the rotateFor command but when I did that our robot would sit there and jitter back in forth like it was over-correcting.

@callen They’re all spinning in the same direction. I’m assuming you thought rev was reverse, but in this case it was revolutions. The rotateFor command has an auto brake already in it. As for the assigned velocities that’s for the rest of the program.

Oops. I see that now. I was reading all the directionType::fwd and misread the next line. Yes, rotateFor has an auto brake, but what type of brake is it? I would be explicit about it unless you know for sure.

@callen I still can’t see how that would affect why our robot is sort of “fish-tailing”. The rotateFor command as said by @John TYler has a hold after it reaches the specified distance.

@6008A At this point I’m prepared to say that your problem is not in the section of code that you’ve shown us so far. That leaves other parts of the code or the hardware as possible culprits.

@callen All the position-targeted motor movement commands in RMS and VCS end in a hold braking mode. That’s something that happens down at the level of the motor’s firmware if I’m remembering correctly.