How do I time rotations?

I am trying to write an autonomous program, and I want for my robot to keep the motors on for x amount of rotations, how can I do this?

CURRENT CODE, THE TIMING IS INCORRECT:
//AUTONOMOUS
int rots = 500; //ms for one rot
if (vexRT(Btn8R) == true)
{
motor[leftMotor] = 127;
motor[rightMotor] = 127;
wait1Msec(rots); // 2.54 rotations
stopAllMotors();
motor[leftMotor] = -127;
motor[rightMotor] = -127;
wait1Msec(rots);

}

Thanks!

1 Like

Unofficial Response
I believe you are using the legacy Cortex/V4 system correct?
I believe that timing rotations is incredibly inconsistent. Instead, I believe you should use red shaft encoders or involve a limit switch. Until then I do not believe I can do anything to help you because at the moment right now i’d be playing a guessing game hoping that the code I help you with works when chances are there is a high probability it won’t using just time.

All I know is that its the microcontroller used in the BEST competition, robotics isn’t my main field, I prefer ML. It says cortex 2.0 I think.

In order to run your motors a certain number of rotations you will need some kind of sensor that can measure rotations. As it is, your code starts the motors, waits 500 milliseconds , then runs the motors in the opposite direction for another 500 milliseconds. Because you are only controlling the voltage the motors receive, the number of rotations that a motor completes over a specific time period is highly variable, dependent on battery voltage, robot inertia, and your gear ratio. I’m not well versed on the legal parts for the BEST competition, but if legal I would recommend getting a set of optical encoders with which you can measure the number of rotations that your motors have completed.

3 Likes