V5 Cap Manipulator Programming

We are currently using the V5 system with Robot Mesh Studio and are having troubles with programming. We can’t figure out how make a motor rotate a certain degree while in driver control not autonomous. For example, we want to make it so that the cap manipulator rotates only 180 degrees when a button is pressed. Does anyone have some sort of example program to get us on the right track?

Robot Mesh Studio Blockly, Python, or C++?

C++

I don’t plan on using a potentiometer, but how would I do it with C++ programming on the V5 brain?

So the method for “rotate X degrees” is


motor.rotateFor

. There are several versions of rotateFor, but all of them have a final argument called


bool waitForCompletion

. If the final argument is


true

, it won’t let anything else run until the move is complete (called “blocking”), but if you make the last argument


false

it will start the motor rotating and continue with the rest of your code.

Now, to make sure that you don’t keep calling


rotateFor

before it’s actually finished rotating, you will want to check the condition


motor.isSpinning()

for


false

or


motor.isDone()

for


true

.

If you wanted it to go to specific positions that are 180 degrees apart instead of just 180 degrees from its current location, I would instead use


motor.rotateTo

. It has the same


bool waitForCompletion

argument that


motor.rotateFor

has, but instead takes positions relative to where the motor started (or was last zeroed) instead of from where the motor currently is.


motor.rotateTo

also has the advantage of not actually caring if you call it repeatedly without checking for done-ness.

You can check out a bit more on the motor class here.

you could alternatively make a physical stopper so that the intake can only rotates 180 degrees before it hits the stop. That would make the autonomous really simple and make the drivers job much easier.

I like this solution because if the physical stopper is well built it will probably be less likely to break then a sensor.

@JuiceBox The sensors are built-in to the V5 motors. Stalling electric motors is also not good for them. I would strongly advise using the sensors that are already present and not trying to burn the expensive electric motors by ramming them into things.