View Single Post
  #7   Spotlight this post!  
Unread 26-03-2008, 10:26
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,854
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Controlling Motors More Accurately

What you want to do is certainly possible and there are, as usual, several ways of accomplishing velocity control.

Your biggest issue is limiting how often/fast to update your speed.
Motor updates on Vex/EasyC occur in the background at 54 times per second, but the EasyC code runs much, much faster than this. So if you just dropped in the code you proposed (with the addition of a 125-255 limit check) then your speed would immediately count up to the max 255, then when you pass your target rps it would run immediately right back down to 127. Effectively, the motor would only see stop or full speed.

You'll need to learn to use a timer set to run at 54 Hz to limit how often you update "speed."

Oscillation past the target rps point might be an issue and you'll need to add a limit check to avoid both overflow/wrap-around and reverse speed, e.g.,
Code:
unsigned char speed=127;   // You can pick a better/faster start value that matches the speed you're trying to hit
if (speed < 127) speed = 127;
if(speed > 254) speed = 254;
If your servo will just be running free, then your code should work, if slowly.
However, if the servo will have varying loads put on it then you might need a little more sophistication in how you adjust speed.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 26-03-2008 at 10:29.