Hello together,
I extended my 3Pi with a Ultrasonic device, with which I want to measure distances. Then I want to move to the nearest found obstacle.
In order to measure distances, the 3Pi should completely rotate once. At a specified angle, the robot is supposed to stop, perform the measurement and move to the next specified angle. However, I am having trouble with an exact rotation.
Here is the rotation code:
void rotate_degree(uint16_t degree){
//Rotate left or right
if(degree < 0) {
set_motors(40, -40);
} else {
set_motors(-40, 40);
}
float multiplicator = degree / 360.0;
//sleepTime360Degrees is the time the motors have to be turned on in order to make a full turn (based on the calibration)
uint16_t sleepTime = sleepTime360Degrees * multiplicator;
delay_ms(sleepTime);
//Stop motors, when time is over
set_motors(0,0);
}
Here, I set the motors to my desired speed and wait until the rotation of the specified degree is done. However, all my rotations are to short (~340° for 360°, ~75° for 90°…).
I perform a calibration when starting the robot. Here, I put the robot’s middle reflectance sensor over a small marker. Then, the robot rotates until its middle reflectance sensor is over the marker again and the time for a rotation is stopped. This is repeated 5 times. Lastly, I calculate the arithmetic mean of all elapsed times and store this result in sleepTime360Degrees.
I want to use the 3Pi on different surfaces, therefore, I think a calibration has to be done. However, I don’t know how to fix the problem with my non-exact rotations.
If needed, I can post my code for the calibration, but I think the calibration should be ok. Maybe there is a better way to perform the rotation itself?
I hope I was able to make my problem clear and that you can help me here! Thank you!
Sincerely,
centershock