Using encoder to turn V5 motor

Total noob here. I want to be able to set a V5 smart motor to turn a certain amount of rotations. There seems to be no actual command that tells it to go a certain amount of revolutions, so I thought to use the built in motor encoder in the smart motor; however, I can’t find a command to use the encoder. If anyone can please answer my (probably) simple question, that would be great!


The rotateTo is saying what the command type is, the 360 is the number of encoder units, the rotationUnits is the way to read the encoders (using degrees so that the encoders think in terms of how many degrees it has rotated), the 100 is the velocity, and the velocity Units is the way to interpret the velocity (using percent for ease, now the 100 means to run at full power). The false and true is whether or not to wait for the completion of the rotation. The first one does not, but since the second one does, it ends up waiting for both pretty much. There are much more complicated ways to do this but this is a simple one.

For future reference, you can look at commands in the VCS api and it usually will tell you what the commands do.
edit: although it will not usually directly say “using encoder counts”

rotateFor() is your friend

Leftfront.rotateFor(count, rotationUnits::rev,false);

as one example of making the motor rotate for count number of turns.

Yes what @lacsap did is just a plain example of rotating for an amount of units. I did an example of going to a position of the encoders. Both work well. I like to use rotateTo just so that you can say go to this position multiple times and it could even out. But if you use rotateTo, make sure to account for the accumulating encoder positions or just reset the internal encoders with


rotateTo would be good for like an arm or claw and is sometimes good for drive. rotateFor is for drive code like auton.
edit: the way you worded your question seems that you would like @lacsap 's response. Good luck!

So if I use that code and I set the count to 6, it will turn for 6 revolutions?

Sorry misread code. If I read the code correctly you are right.

Ok. Thanks so much. That was very helpful.

Leftfront.rotateFor(6, rotationUnits::rev,false);

would do the trick to turn six rotations.