PROS waiting for motor to complete rotation

So I am programming functions to move our team’s robot in autonomous, and basically I want to move the robot a certain amount of rotations forward but wait for the motors to finish spinning before starting the next task. I think VCS and VexCode there’s something like startRotateTo vs rotateTo but I can’t find that in PROS.

Screen Shot 2020-05-10 at 8.51.11 PM

Currently I do not have a robot to download to and test this, and my main point of concern is the while loop. So .get_position says that it gets absolute encoder units, but what if I want to rotate past 360 degrees? Would the while loop just never be satisfied because if the motor passes 360 degrees, it would start over from 1?

Any tips would be greatly appreciated! I am planning to use the new IMU when our team gets it, so that might help get around this issue.

I think motor.move_relative() is the correct function to use. However, you will need to call it only once before staring of the loop.

https://pros.cs.purdue.edu/v5/api/cpp/motors.html#move-relative

This function simply sets the target for the motor, it does not block program execution until the movement finishes. The example code shows how to block until a movement is finished.

int targetPosition = motor1.get_position() + inches;

motor1.move_relative(inches,speed);

while( fabs(motor1.get_position()-targetPosition)>3 )
    pros::delay(10);

Since motors may stop not exactly at target position, you will need to figure out what distance around the target is ok to stop at. I set it to +/-3.

Also, it is best to use an average of positions of the motors on the left and right side of the robot, instead of relying on a single motor encoder.

3 Likes

Oh… Ok I will try that. Also, when the .get_position says it’s the absolute encoder value, does that mean like absolute as in it will just keep on counting upwards, or does it mean from 0-360 and it’ll start over from 0 after 1 rotation?

Notice that “position” is of type “double” so it can be very large. The count in encoder units is not limited to 1 rotation. So if 360 encoder counts is 1 rotation then 720 is 2 rotations, etc.

3 Likes

I see. Ok I had a misconception about the abilities of the encoders. Thank you very much!

1 Like