Re: Multiple R/C servo control
- From: "Wayne C. Gramlich" <Gramlich@xxxxxxxxxxx>
- Date: Tue, 20 Sep 2005 22:29:19 GMT
Padu wrote:
Hi folks,
I've been doing lots of tests with controlling R/C servos lately, some good experiences and some bad experiences. I even wrote an introduction paper on how to interface the PC with R/C servos using the serial port and a PIC microcontroller.
The strategy I present in that paper is very basic, and although it works fine, it is kind of jittery and does not support too many servos. Now I'm working on a improved version of my servo controller that will theoretically get rid of the flicker and support unlimited servos (in theory).
I am a firm believer that the best way to learn something is to teach it. Therefore I will try to make another paper exposing this new method (of course, if it works). Before doing that, I need to know if someone else already did such tutorial paper, and if yes, if it is similar to my strategy.
Here's an outline of my strategy, please express yourself if you find a flaw in it as I'm going to test it tonight.
1-Assume there is an array of servos controlled by the uP and this array has the following fields: servo_idx, pulse_width_uS, servo_no Whenever the array is updated (through serial commands), it is sorted in by pulse_width_uS
2-Drive all servo lines high, set TMR0 with the time interval of the first servo of the array
3-When TMR0 triggers, set the respective servo low. Also set low all the subsequent servos from that list that have the same pulse_width_uS. Set new TMR0 interval as the difference between next servo pulse width and current one.
4-Repeat this operation for all servos until there are no more servos to drive low. At that point, set TMR0 with 20ms - current pulse_width_uS
And that goes forever. There are a couple more quirks to it, but that's the overall outline. If you are controlling 4 servos, TMR0 should trigger 5 times in the worst case, 1 time for driving all servo lines up and 4 times (less if some of them share the same time interval) to drive them low.
That gives me lots of time in between pulses to do whatever I want (receive USART bytes for example) without interfering too much with the PWM timing mechanism.
Do you think it is a good approach to try? If yes, do you think it would be worthy to write a short paper on that?
Padu:
Controlling servos from a PIC has been done before. My PIC based servo controller can be found at the URL below:
<http://gramlich.net/projects/robobricks/servo4/rev_j/index.html>
There is a subtle issue with servos -- they are very sensitive to the pulse width. Changing the pulse width by a uSec or two will cause the servo to move a small but noticable amount.
The scheme you propose will have a difficult time producing pulse widths that are close to one another. Changing the pulse width of one servo might cause the pulse widths of the other servos to change a little.
The simpler strategy is to forget all the sorting and just pulse one servo at a time in sequence. Turn on servo 1, set TMR1, turn off servo 1, and repeat for each servo in sequence. Given a maximum pulse width of 2.5uSec, you can visit 8 servos every 20uSec.
Lastly, remember that PIC's are really really cheap. If you find yourself doing all sorts of tricks to get them to do what you want, consider using more PIC's. For example, suppose that you are using a digital servo and need a really fast update rate. Dedicating a PIC to each digital servo is not unthinkable.
Once you get your PIC code working, by all means write it up.
My $.02,
-Wayne .
- Follow-Ups:
- Re: Multiple R/C servo control
- From: Padu
- Re: Multiple R/C servo control
- References:
- Multiple R/C servo control
- From: Padu
- Multiple R/C servo control
- Prev by Date: Re: Multiple R/C servo control
- Next by Date: Re: Multiple R/C servo control
- Previous by thread: Re: Multiple R/C servo control
- Next by thread: Re: Multiple R/C servo control
- Index(es):
Relevant Pages
|