Loop timing for RC Servo
Archiver
Posts: 46,084
My knowledge of RC Servos goes something like this
Take a pulsed signal of period 20 ms long. Modulate the pulse-on
time between 1ms and 2ms and you get the Servo to move. 1.5 ms is
the midpoint- pulse widths less rotate the servo one direction, and
pulse widths greater rotate the servo in the other direction. Keep
sending pulses of a specific width (over and over and over again)
and you effectively have "position control" on the Servo. Very cool,
I like it.
So, I've been working through some of the experiments in the
Stampworks manuals, and especially the motor/servo programs. One of
the programs allows a Potentiometer to control the position of the
Servo (via RCTime) and goes like this (Note: I'm using a BS2sx).
'{$STAMP BS2SX} 'STAMP directive
PotCW CON 0
PotCCW CON 1
Servo CON 2
Scale CON $002C ' BS2sx
rcRt VAR Word
rcLf VAR Word
diff VAR Word
sPos VAR Word
Main:
HIGH PotCW
HIGH PotCCW
RCTIME PotCW, 1, rcRt
RCTIME PotCCW, 1, rcLf
rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 250
sPos = rcRt - rcLf
PULSOUT Servo, (1875 + sPos + sPos + sPos)
Off_time: ' For 50 Hz
PAUSE 20
GOTO Main
The last line before returning on the loop (marked by
label "Off_time:" is supposed to specify 20 ms. So in an ideal world
one would expect a total (repeating) pulse period of about 20 ms
(min) or 22ms (max), which is good enough for these Servos (I think).
An upon hooking up a Servo, things seem to work as expected. Again,
this is nice to see things working out.
However, I then hooked the output of the BS2sx (the pin driving the
Servo) up to an Oscilloscope. I wasn't expecting to see a signal of
40+ ms in length! While the modulation of the 1-2 ms pulse width
checked out fine with the scope, the overal signal length was far
longer than I expected, given the "Pause 20" instruction.
I have decided/concluded that the other instructions in the loop,
particularly the RCTIME instructions are taking up a significant
amount of the loop time, and that added to the PAUSE 20 (and the
modulated pulse itself) all contribute to the overal output
waveform.
Is this correct? If not what else is going on?
Thanks
Kevin Gordon
Take a pulsed signal of period 20 ms long. Modulate the pulse-on
time between 1ms and 2ms and you get the Servo to move. 1.5 ms is
the midpoint- pulse widths less rotate the servo one direction, and
pulse widths greater rotate the servo in the other direction. Keep
sending pulses of a specific width (over and over and over again)
and you effectively have "position control" on the Servo. Very cool,
I like it.
So, I've been working through some of the experiments in the
Stampworks manuals, and especially the motor/servo programs. One of
the programs allows a Potentiometer to control the position of the
Servo (via RCTime) and goes like this (Note: I'm using a BS2sx).
'{$STAMP BS2SX} 'STAMP directive
PotCW CON 0
PotCCW CON 1
Servo CON 2
Scale CON $002C ' BS2sx
rcRt VAR Word
rcLf VAR Word
diff VAR Word
sPos VAR Word
Main:
HIGH PotCW
HIGH PotCCW
RCTIME PotCW, 1, rcRt
RCTIME PotCCW, 1, rcLf
rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 250
sPos = rcRt - rcLf
PULSOUT Servo, (1875 + sPos + sPos + sPos)
Off_time: ' For 50 Hz
PAUSE 20
GOTO Main
The last line before returning on the loop (marked by
label "Off_time:" is supposed to specify 20 ms. So in an ideal world
one would expect a total (repeating) pulse period of about 20 ms
(min) or 22ms (max), which is good enough for these Servos (I think).
An upon hooking up a Servo, things seem to work as expected. Again,
this is nice to see things working out.
However, I then hooked the output of the BS2sx (the pin driving the
Servo) up to an Oscilloscope. I wasn't expecting to see a signal of
40+ ms in length! While the modulation of the 1-2 ms pulse width
checked out fine with the scope, the overal signal length was far
longer than I expected, given the "Pause 20" instruction.
I have decided/concluded that the other instructions in the loop,
particularly the RCTIME instructions are taking up a significant
amount of the loop time, and that added to the PAUSE 20 (and the
modulated pulse itself) all contribute to the overal output
waveform.
Is this correct? If not what else is going on?
Thanks
Kevin Gordon
Comments
as to estimate the time it takes for other lines of code to execute
in between servo pulses but at least you have a scope and can
determine the exact length and then subtract that of of the pause 20
command to get the proper spacing in between pulses.
-Dave
--- In basicstamps@yahoogroups.com, "kggsystem" <kevgor@s...> wrote:
> My knowledge of RC Servos goes something like this
>
> Take a pulsed signal of period 20 ms long. Modulate the pulse-on
> time between 1ms and 2ms and you get the Servo to move. 1.5 ms is
> the midpoint- pulse widths less rotate the servo one direction, and
> pulse widths greater rotate the servo in the other direction. Keep
> sending pulses of a specific width (over and over and over again)
> and you effectively have "position control" on the Servo. Very
cool,
> I like it.
>
> So, I've been working through some of the experiments in the
> Stampworks manuals, and especially the motor/servo programs. One of
> the programs allows a Potentiometer to control the position of the
> Servo (via RCTime) and goes like this (Note: I'm using a BS2sx).
>
> '{$STAMP BS2SX} 'STAMP directive
> PotCW CON 0
> PotCCW CON 1
> Servo CON 2
> Scale CON $002C ' BS2sx
> rcRt VAR Word
> rcLf VAR Word
> diff VAR Word
> sPos VAR Word
>
> Main:
> HIGH PotCW
> HIGH PotCCW
>
> RCTIME PotCW, 1, rcRt
> RCTIME PotCCW, 1, rcLf
>
> rcRt = (rcRt */ Scale) MAX 250
> rcLf = (rcLf */ Scale) MAX 250
>
> sPos = rcRt - rcLf
>
> PULSOUT Servo, (1875 + sPos + sPos + sPos)
>
> Off_time: ' For 50 Hz
> PAUSE 20
> GOTO Main
>
> The last line before returning on the loop (marked by
> label "Off_time:" is supposed to specify 20 ms. So in an ideal
world
> one would expect a total (repeating) pulse period of about 20 ms
> (min) or 22ms (max), which is good enough for these Servos (I
think).
>
> An upon hooking up a Servo, things seem to work as expected. Again,
> this is nice to see things working out.
>
> However, I then hooked the output of the BS2sx (the pin driving the
> Servo) up to an Oscilloscope. I wasn't expecting to see a signal of
> 40+ ms in length! While the modulation of the 1-2 ms pulse width
> checked out fine with the scope, the overal signal length was far
> longer than I expected, given the "Pause 20" instruction.
>
> I have decided/concluded that the other instructions in the loop,
> particularly the RCTIME instructions are taking up a significant
> amount of the loop time, and that added to the PAUSE 20 (and the
> modulated pulse itself) all contribute to the overal output
> waveform.
>
> Is this correct? If not what else is going on?
>
> Thanks
> Kevin Gordon
controller) The Basic stamp is not well suited to servo
control if it is doing anything else. The SSC is pic based
and dedicated to handling servo operations. The servo needs
to be continuously sent the command signals and the stamp
can do it, but is not practical do do it and anything else.
Other sgtamps (javelin) do it rather well. If you look at
most of the Stanp based projects that deal with servos,
you'll discover that almost all of them farm the servo
managment to a SSC of some time for this reason alone.
--
Regards
Dave Evartt
American Hovercraft
suppose if you lapse too long you will weaken the servo's "holding power".
Have a look at http://www.al-williams.com/pak8.htm and
http://www.al-williams.com/gp4.htm. In particular, look at
http://www.al-williams.com/servobot.htm.
Good luck!
Al Williams
AWC
* Easy RS232 Power Supplies: http://www.al-williams.com/rs1.htm
>
Original Message
> From: Dave Evartt [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=-qYJivwyQ6-cxzwGlihlfz_OOyLJ24k-yxqaf2Wogex_3bHUNiMnD4a31HOKyH-BzozArpA_kgThLD8oxFjMq8L2lgfgrdM]davee@a...[/url
> Sent: Sunday, November 30, 2003 12:17 AM
> To: basicstamps@yahoogroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Loop timing for RC Servo
>
>
> save yourselves lots of trouble and get an SSC (Serial Servo
> controller) The Basic stamp is not well suited to servo
> control if it is doing anything else. The SSC is pic based
> and dedicated to handling servo operations. The servo needs
> to be continuously sent the command signals and the stamp
> can do it, but is not practical do do it and anything else.
> Other sgtamps (javelin) do it rather well. If you look at
> most of the Stanp based projects that deal with servos,
> you'll discover that almost all of them farm the servo
> managment to a SSC of some time for this reason alone.
> --
> Regards
>
> Dave Evartt
> American Hovercraft
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
You can find ramping servo controllers in the co-processor I sell at
www.bluebelldesign.com. It also includes other Stamp helpful features
like A/D inputs and timers.
There are some technical discussions covering servo control at my
site too.
Harry
Stamp Robotics to the next level
www.bluebelldesign.com
--- In basicstamps@yahoogroups.com, Dave Evartt <davee@a...> wrote:
> save yourselves lots of trouble and get an SSC (Serial Servo
> controller) The Basic stamp is not well suited to servo
> control if it is doing anything else. The SSC is pic based
> and dedicated to handling servo operations. The servo needs
> to be continuously sent the command signals and the stamp
> can do it, but is not practical do do it and anything else.
> Other sgtamps (javelin) do it rather well. If you look at
> most of the Stanp based projects that deal with servos,
> you'll discover that almost all of them farm the servo
> managment to a SSC of some time for this reason alone.
> --
> Regards
>
> Dave Evartt
> American Hovercraft
BOE-Bots that happily drive two servos while processing a wide array of
sensors. Yes, programming is a bit trickier than using a servo
controller, but it can be done with a stock BASIC Stamp.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Dave Evartt [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ynQnEgh0WRjwjZ2keTBiG4K2MHZaHNvKQqtfioC73Y4tJnk6GMoVqwG-Jgbuu4mZfEcMTGTZyQeYgBCwFHMXacKohNmaXg]davee@a...[/url
Sent: Sunday, November 30, 2003 12:17 AM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Loop timing for RC Servo
save yourselves lots of trouble and get an SSC (Serial Servo
controller) The Basic stamp is not well suited to servo
control if it is doing anything else. The SSC is pic based
and dedicated to handling servo operations. The servo needs
to be continuously sent the command signals and the stamp
can do it, but is not practical do do it and anything else.
Other sgtamps (javelin) do it rather well. If you look at
most of the Stanp based projects that deal with servos,
you'll discover that almost all of them farm the servo
managment to a SSC of some time for this reason alone.
--
Regards
Dave Evartt
American Hovercraft
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
That's not really the point. I happen to love the Stamp,
I've used over a hundered of them in the last ten years or
so and I suspect that I'll go on doing so. I also have three
boe bots and have built several robots around stamps. I even
have one of your hexcrawlers, which by the way, uses two
SSCs.
The point is this: The stamp is a great tool, but it i NOT
the total solution and you guys should accept that it is not
the perfect solution. Don't lose any sleep over it.
Because the stamp must continually resend the servo command,
it must always remain in a tight loop that must resend that
command. While this is not a difficuylt thing to do, it does
make the software more complex than it needs to be. The
whole idea is to make it EASY. That's where the stamp
shines.
Thirty years of systems programming has constantly reminded
me to 'keep it simple stupid'. An SSC of any kind takes such
a tremendous load off the programmer that only it's cost and
extra weight should even be a consideration. Considering the
very limited resources that the stamp possesses, it's no
crime to suggest that it can use a little help from time to
time.
This is not an attack on the stamp, though everytime anyone
mentions a lack of perfection in the stamp, it seems to be
taken as an attack. You don't need to defend the stamp and
you don't have to argue everytime someone says something
about the stamp that you don't like.
Now if the stamp incorporated some form of 'virtual' mode
for PWM like the Javelin does, it would not even be an
issue. In fact, I prefer the Javelin on the BOE because it
does a much better job, but that is a different story.
I know this will draw more heated argument and that's not my
intent. I'll just leave it at that.
--
Regards
Dave Evartt
American Hovercraft
Of course, what it takes me 10 lines to do, Jon can usually do in one.
> We will politely disagree with you, David -- having sold nearly 50,000
> BOE-Bots that happily drive two servos while processing a wide array of
> sensors. Yes, programming is a bit trickier than using a servo
> controller, but it can be done with a stock BASIC Stamp.
> save yourselves lots of trouble and get an SSC (Serial Servo
> controller) The Basic stamp is not well suited to servo
> control if it is doing anything else. The SSC is pic based
> and dedicated to handling servo operations. The servo needs
> to be continuously sent the command signals and the stamp
> can do it, but is not practical do do it and anything else.
> Other sgtamps (javelin) do it rather well. If you look at
> most of the Stanp based projects that deal with servos,
> you'll discover that almost all of them farm the servo
> managment to a SSC of some time for this reason alone.
When I tuned the PAUSE Command, so that my "scope" showed the signal
had close to 20ms periodicity, given other loop instructions, the
Servo did indeed have better response (it might be the power of
suggestion, or whatever, but I really think it got snappier
acceleration, etc, and responded quicker), and the torque-load test
I rigged up, which is a 40cm long bamboo rod zap-strapped to the
Servo horn with varying weights suspended at the other end,
responded better than in the prior experiment (when the loop timing
was at 40+ ms).
PS: I don't really have a physical Scope - I have this cute little
Win-Scope software which reads signals sent into my PC's sound
board. I run Windows XP. The Scope software is two channel (dual
trace), with about 20 Hz to 20 KHz bandwidth. It uses the 8 bit A/D
converter built into the sound card. No horizontal sync, and nothing
very special (although it does do off-line FFT's and has storage
capabilities). I find it very useful to test my 555 timers, H-Bridge
and Stamp circuits.
Check it out at;
http://www.mitedu.freeserve.co.uk/Prac/winscope.htm
or
http://www.geocities.com/nlradiofm/winscope.htm
Note: I have no affiliation with this software. I just want to make
some interesting animatronic stuff using Stamps and Servos. The
discussion so far has been very educational.
My next experiment is to try to control two servos, in a kinda
articulated scissor lift mechanism - cobbled together with small
bamboo rods (grown in my own back-yard), zap straps, duct tape, and
Basic Stamps. I'll keep y'all posted.
Kevin Gordon
--- In basicstamps@yahoogroups.com, "nickel152" <nickel152@y...>
wrote:
> You are correct in your observations. I've gone so far in my
programs
> as to estimate the time it takes for other lines of code to
execute
> in between servo pulses but at least you have a scope and can
> determine the exact length and then subtract that of of the pause
20
> command to get the proper spacing in between pulses.
>
> -Dave
>
> --- In basicstamps@yahoogroups.com, "kggsystem" <kevgor@s...>
>> wrote:
>> Blah blah blah
Thanks for the link on Winscope. What are you using as a buffer
between the signals the stamp is generating and your soundcard? The
only problem I can see with Winscope is the low input levels which is
a limitation of the souncards. I'm not sure if my soundcard would
take a +5V to 0V pulsing waveform.
--- In basicstamps@yahoogroups.com, "kggsystem" <kevgor@s...> wrote:
> Thanks for the advice, and also thanks for the advice of everybody.
>
> When I tuned the PAUSE Command, so that my "scope" showed the
signal
> had close to 20ms periodicity, given other loop instructions, the
> Servo did indeed have better response (it might be the power of
> suggestion, or whatever, but I really think it got snappier
> acceleration, etc, and responded quicker), and the torque-load test
> I rigged up, which is a 40cm long bamboo rod zap-strapped to the
> Servo horn with varying weights suspended at the other end,
> responded better than in the prior experiment (when the loop timing
> was at 40+ ms).
>
> PS: I don't really have a physical Scope - I have this cute little
> Win-Scope software which reads signals sent into my PC's sound
> board. I run Windows XP. The Scope software is two channel (dual
> trace), with about 20 Hz to 20 KHz bandwidth. It uses the 8 bit A/D
> converter built into the sound card. No horizontal sync, and
nothing
> very special (although it does do off-line FFT's and has storage
> capabilities). I find it very useful to test my 555 timers, H-
Bridge
> and Stamp circuits.
>
> Check it out at;
>
> http://www.mitedu.freeserve.co.uk/Prac/winscope.htm
> or
> http://www.geocities.com/nlradiofm/winscope.htm
>
>
> Note: I have no affiliation with this software. I just want to make
> some interesting animatronic stuff using Stamps and Servos. The
> discussion so far has been very educational.
>
> My next experiment is to try to control two servos, in a kinda
> articulated scissor lift mechanism - cobbled together with small
> bamboo rods (grown in my own back-yard), zap straps, duct tape, and
> Basic Stamps. I'll keep y'all posted.
>
> Kevin Gordon
>
> --- In basicstamps@yahoogroups.com, "nickel152" <nickel152@y...>
> wrote:
> > You are correct in your observations. I've gone so far in my
> programs
> > as to estimate the time it takes for other lines of code to
> execute
> > in between servo pulses but at least you have a scope and can
> > determine the exact length and then subtract that of of the pause
> 20
> > command to get the proper spacing in between pulses.
> >
> > -Dave
> >
> > --- In basicstamps@yahoogroups.com, "kggsystem" <kevgor@s...>
> >> wrote:
> >> Blah blah blah
> We will politely disagree with you, David -- having sold nearly 50,000
> BOE-Bots that happily drive two servos while processing a wide array of
> sensors. Yes, programming is a bit trickier than using a servo
> controller, but it can be done with a stock BASIC Stamp.
>
Here too. I have seven servos on my toddler-derivative. The processor can
handle all seven servos concurrently at ten cycles per second. That's good
enough for motion that is lightly resisted, but not for a servo under load
like a driving leg or other limb.
A 100 ms re-visit time is not fast enough for a servo under significant
load, so I idle the three upper-body servos to get a faster real time loop
for walking. Then I revisit the two lower-body servos under load twice for
each time I visit the lightly loaded lower body servos. That gives me a
smooth control of motion. I could increase the ratio of visits to the loaded
vs unloaded servos and smooth things even more.
It's a stock BS2 driving those four servos concurrently, not one of the
faster models.
Gary