Quote:
|
Originally Posted by MikeWasHere05
Somehow measure the amount of time it takes for the wheel to spin one revolution at speed x.
Set it to run at speed x for the needed amount of length/time.
|
Here's what I would suggest. This is kinda pseudo-code, but you'll get the idea.
Code:
#define COUNT 20 //determine this number experimentally
void turn90(void)
{
int i=0;
int last=0;
while(i<COUNT)
{
pwm01=255;
pwm02=0;
if(rc_ana_in01<last)
i++;
last=rc_ana_in01;
}
pwm01=127;
pwm02=127;
}
COUNT is the number of revolutions it takes for your robot to turn 90 degrees. You have two servos connected to pwm01 and pwm02. You have a multi-turn pot on analog input 01. The value from the pot goes from 0 to 1023, and then starts over at 0 again. (That's just how the processor does it, for some reason. I dunno why they went with 10 bits instead of 8.) If the number is suddenly less than it was last time it checked, then the pot has made a complete revolution. This is more precise than measuring time, because the values needed for other angles are not 1:1, due to inertia and stall friction. If you wanted an angle of 45º, change it to while(i<COUNT/2). If you want 180º, change it to while(i<COUNT*2). I'm not sure if I'm making any sense, so ask me if you don't understand it.