Quote:
|
Originally Posted by jgannon
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.
|
Thanks, a few questions tho.
You keep on mentioning "the pot"... whats that?
A member on my team said that doing it this way wouldn't be reliable, because as the battery dies it won't be able to spin the wheel as fast as it did before. Will this fix that?
I'd rather ask questions then just copy/paste... =/