Arduino Forum

Using Arduino => Motors, Mechanics, and Power => Topic started by: brainybrown86 on Apr 25, 2014, 04:38 pm

Title: Pulse frequency and Servos
Post by: brainybrown86 on Apr 25, 2014, 04:38 pm
Hello,
If I use the already implemented Servo functions form Arduino, how do they behave regarding the pulse frequency of servos?:
Do the servo functions have already implemented a fixed time delay that assures that subsequent impulses are not sended too fast to the servo (e.g. in a while loop), or do I have to control for that on my own (e.g. if I had a while loop to include a delay comment after each motor command)?

If there is a delay already implemented in the servo functions, how can I change this value (e.g. if the servo allows a very high pulse frequency)?

I would be very glad for an answer.
Cheers.
Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 25, 2014, 05:36 pm
When you give a command such as myservo.write(90) the Arduino continuously produces the appropriate pulses until you give another command for the same servo. This all happens invisibly in the background.

In general you only need to give another servo.write() command when you want to move the servo arm to a different position.But it won't do any harm to repeatedly call servo.write() with the same position.

...R
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 25, 2014, 05:55 pm
The servo library commands are written to the flashram and read from there by servo library commands. Thus , once written, the command will repeat until overwritten. In other words "what he [Robin2] said..."
Title: Re: Pulse frequency and Servos
Post by: brainybrown86 on Apr 25, 2014, 06:41 pm
Okay, when it "continuously produces the appropriate pulses" at which pulse frequency does this happen and can this be modulated?  For, some servos allow higher pulse frequencies and some only allow lower pulse frequencies - or do I confuse something?
I would like to have the fastest control of servo moving as possible...

Thank you. 
Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 25, 2014, 10:37 pm
Sorry, but analogWrite() has nothing to do with servos.

The servo library produces a servo pulse every 20 millisecs in accordance with the normal servo standard.

I doubt if faster pulses would give a noticeable effect on the response of the servo as it takes an appreciable time (in computer terms) for the servo arm to move.

...R
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 25, 2014, 11:55 pm
Quote
If there is a delay already implemented in the servo functions, how can I change this value (e.g. if the servo allows a very high pulse frequency)?  


I don't have the answer for this question
*EDIT* The post with the link to "analogWrite" reference page was deleted because it does not apply to servo library.

Does anyone know what the OP is asking ? Is his question about duty cycle of the servo pwm ? (he doesn't mention that. His question is about delays and I don't know what delays he is talking about. When I look at the servo pwm waveform on the scope the only thing that might be construed as a delay (by a newbee) is the off time of the pwm waveform.
Title: Re: Pulse frequency and Servos
Post by: zoomkat on Apr 26, 2014, 05:32 am
Seems some need to get up to speed on hobby servo operation.

http://en.wikipedia.org/wiki/Servo_control
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 26, 2014, 06:07 am
@Zoomcat,
Who me ? I know about PWM , but I couldn't tell what the OP was trying to ask with his questions about delays.
Was he trying to ask about duty cycle ? . I have a scope so I can look at any signals I want and I have already compared the servo pwm to the regular pwm and I know what the difference is.
The OP didn't mention duty cycle. Is that what he meant when he said delay ?

Quote
Do the servo functions have already implemented a fixed time delay that assures that subsequent impulses are not sended too fast to the servo (e.g. in a while loop), or do I have to control for that on my own (e.g. if I had a while loop to include a delay comment after each motor command)?
If there is a delay already implemented in the servo functions, how can I change this value (e.g. if the servo allows a very high pulse frequency)?  


Have you figured out what he is trying to ask ?








Title: Re: Pulse frequency and Servos
Post by: brainybrown86 on Apr 26, 2014, 02:32 pm
Thank you for your replies.

Okay let me perhaps again explain what I mean. I am not a native english speaker and probably I do not use the right technical terminology. I'm sorry for that.

Our goal is to constantly transform a biosignal (e.g. the eeg mu-rhythm of the motor cortex) into corresponding servo movements, with time delays as little as possible (this is really really important).

As far as I understood it, in normal servo control a PWM of 1-2ms is normally sent to a servo every 20ms, because the typical servo only has this pulse frequency of 50hz - and thus is not able to process a faster updating of new servo commands. Am I right with this?

However, we would like to use a very fast servo (the Align DS610: http://www.servodatabase.com/?sort=speed), which - in addition to his high speed (0.08 sec/60°) - is said to also have a higher pulse frequency than normal, namely 200hz. Thus, if I understand this right, this servo should be able to receive a new command each 5ms, instead of each 20ms (Aim I right with this interpretation?).

My question is now what happens if I sent two servo commands (using the implemented servo library) directly after each other: Will the second servo command immediately overwrite the first command, or will the second command only be arriving the servo after at least 20ms?
And if this is the case, how can I avoid this?

Thank you very much so far.

Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 26, 2014, 03:57 pm
I don't see anything about 200Hz on that site, and I looked at a few different servos.

I suspect (from other Threads here) it refers to the internal frequency at which the servo updates its position in response to the regular 50Hz pulses from the controller.

You couldn't rely on the new servo command overwriting the current command. Even if it did it would mean that your code would have to update it very frequently which is the opposite of how the system is intended to work.

If you really do need a 200Hz pulse rate you will either have to modify a copy of the Servo library or (which is probably easier) write your own code.

...R
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 26, 2014, 04:38 pm
The fastest RC servo currently available is the Airtronics 94758Z.
http://www.servodatabase.com/servo/airtronics/94758z  (http://www.servodatabase.com/servo/airtronics/94758z)
Servo speed specs are rated by TIME/Degrees traveled, so this one , being rated for 0.06(sec)/60 deg means that the fastest possible move for 60 degrees will take 0.06 seconds which if repeated continuously would be a frequency of 16.6 hz. Obviously , if the fastest servo sold is 16.6 hertz for a 60 degree movement, you can kiss your plan of getting it to operate at 200hz goodbye. That's a pipe dream. Not possible. A medical EEG does not use RC servos, so your plan to build a working EEG chart recorder  using hobby servos and Bic pens is, well, maybe not flawed, but perhaps a little under researched. I don't know if you have ever actually seen an EEG chart recorder up close and personal, (I have, I was a medic in the AF and worked in a hospital ) but they have very delicate needles (the old mechanical ones , designed and build many years  before you were born) and one of the reasons is the energy needed to move some mass is proportional to the velocity and mass . An RC servo arm has a much greater mass than an EEG chart recorder needle so the torque needed is much greater. The needle , moving 3 cm (0.03 meters) in 5mS (200 hz) is  dist/time=velocity===>  0.03m/0.005mS=6 m/S . The fastest servo available is 3 cm (approx 60 deg)  ===>0.03m /0.06S=0.5m/S , which is 1/12th the velocity of an EEG chart recorder.
Title: Re: Pulse frequency and Servos
Post by: brainybrown86 on Apr 26, 2014, 06:09 pm
Okay, I see that my plans are somewhow unrealistic or time-wasting, so I just will leave like it is.
I just wanted to assure to get the maximum out of what is possible with our servos.

Regarding the pulse frequency, I referred to this table here, http://www.ronlund.com/rcheli/HELP_SERVO_PULSE.html, but perhaps they refer to some other frequency?

Regarding EEG: Yes, I am acquainted with EEG, I am actually a cognitive neuroscientist.
I do not want to build an eeg recording system, I want to real-time control a robotic hand based on neuronal oscillations observed in the eeg.
And of course, I do not want to update the servos 200 times a second (10 times a second would be already awesome).
In fact, we will have to conduct some frequency analysis of the eeg raw signal (mu-component), in order to receive the final amplitude values that then can be transformed into motor commands (so there will be other latencies as well).
I just wanted to assure that there won`t be any unnecessary delays between each new calculated amplitude value and the following servo movement. But I see, that it is probably much more worth to spent more time on reducing the other possible latencies (eeg-amplifier to Matlab, online eeg artefact correction, frequency analysis, (classifier), servo command)

Thank you.
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 26, 2014, 06:58 pm
What do you need now?
Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 26, 2014, 07:44 pm


Regarding the pulse frequency, I referred to this table here, http://www.ronlund.com/rcheli/HELP_SERVO_PULSE.html, but perhaps they refer to some other frequency?

....

(10 times a second would be already awesome).



I think those frequency figures are all internal to the servo. Most of them refer to the standard 1500usec centre position.

If 10 times per second is OK I completely fail to see what all your questions are about as the normal servo pulses occur 50 times per second.

Or else we have been misunderstanding each other ...

...R
Title: Re: Pulse frequency and Servos
Post by: zoomkat on Apr 26, 2014, 08:02 pm
Quote
I do not want to build an eeg recording system, I want to real-time control a robotic hand based on neuronal oscillations observed in the eeg.


From this statement is your robotic hand expected to have much faster movements than a human hand? The needle on a cheap undampened analog multimeter can move much faster than a human finger. The laws of inertia and momentum have to be respected when things are expected to move or change directions quickly. Have you actually setup a servo and done some testing of movement speed?  You probably modify the gearing in a standard servo similar to the below servo mod to increase the movement speed some. Lot of confusion as to PWM in servos. In a typical analog servo the internal H-bridge supplies the motor pulses at ~50hz. Digital servo H-bridges pulse the motor at much higher frequencies for better holding power (but also produced an auditory "whine" sound that some don't like). Both of these types are controlled with the standard servo pulse duration method.  

http://www.youtube.com/watch?v=wCx52hT4pu8
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 27, 2014, 01:05 am
Quote
However, we would like to use a very fast servo (the Align DS610: http://www.servodatabase.com/?sort=speed), which - in addition to his high speed (0.08 sec/60°) - is said to also have a higher pulse frequency than normal, namely 200hz. Thus, if I understand this right, this servo should be able to receive a new command each 5ms, instead of each 20ms (Aim I right with this interpretation?). 

NO.
Regarding the table you referred to :
since you are Cognitive Neurologist and not an Electronics tech or engineer, we can hardly expect you to know the PWM protocol for RC servos as opposed to the standard PWM of an arduino analogWrite command. What you saw on that table was a cross reference of the frequency of the repeating pulse to the center position pulse width. RC servo PWM differs from analogWrite PWM
in that the pulse width is much narrower and the total deviation of this pulse width is much smaller than the pwm of analogWrite which is a % duty cycle. Servo pulse width is not % duty cycle . The table indicates that for the center position , a pulse width of 1500uS repeats is transmitted at 200 hz. . The period for a 200 hertz waveform is 5mS. This means that during the 5mS period of the 200 hz pwm signal , the HIGH pulse is 1500uS , which is a duty cycle equivilent to 30% , but the total deviation never achieves 100% because the servo signal has a very narrow pulse width with a small deviation, unlike an analogWrite pulse which can deviated from 0% to 100%. We don't expect a Cognitive Neurologist to understand this, but that's what it means and has nothing at all to do with how fast the servo arm moves.
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 27, 2014, 02:01 am
@Zoomcat,
Loved the servo hack !
Title: Re: Pulse frequency and Servos
Post by: brainybrown86 on Apr 27, 2014, 01:41 pm
Alright thank you very much for your comments and explanations, I will just use the Arduino implemented functions without any modifications attempts.
Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 27, 2014, 02:47 pm

The table indicates that for the center position , a pulse width of 1500uS repeats is transmitted at 200 hz.


I see no evidence for this. In my opinion the columns in that table are separate. Normal servos use 1500uS pulse widths as the centre position and require pulses of that width 50 times per second, not 200. There is nothing in the table to suggest that the servos are incompatible with regular RC recevers that produce pulses at 50Hz.

...R
Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 27, 2014, 04:53 pm
I didn't suggest there was any incompatibility. I didn't see anything about 50hz there and I don't see that it matters either way. The frequency at which the pulse is repeated is probably not critical anyway. I'm no expert in servo design but my understanding is that the pulsewidth is the critical spec because that's what changes when the servo receives commands. When you watch the servo pulsewidth on a scope , you're seeing the same 1500uS pulse with either servo. The difference is that your seeing it 4 times more often with the faster digital servos, but if you receive only one bill every month do you have to pay any more if you receive 4 copies of the same bill (one a week) during that month ? (crude analogy , I admit) but my point is that the servo must obeay a command to set it's pulse width some value whether it receives the same command 50 times a second or 200 doesn't change the command. If I have this all wrong please tell me because I do want to know. I'm just saying that is my understanding of it as it stands at the moment.
Title: Re: Pulse frequency and Servos
Post by: retrolefty on Apr 27, 2014, 06:05 pm

I didn't suggest there was any incompatibility. I didn't see anything about 50hz there and I don't see that it matters either way.
The frequency at which the pulse is repeated is probably not critical anyway. I'm no expert in servo design but my understanding
is that the pulsewidth is the critical spec because that's what changes when the servo receives commands. When you watch the servo pulsewidth on a scope , you're seeing the same 1500uS pulse with either servo. The difference is that your seeing it 4 times more often with the faster digital servos, but if you receive only one bill every month do you have to pay any more if you receive 4 copies of the same bill (one a week) during that month ? (crude analogy , I admit) but my point is that the servo must obeay a command to set it's pulse width some value whether it receives the same command 50 times a second or 200 doesn't change the command. If I have this all wrong please tell me because I do want to know. I'm just saying that is my understanding of it as it stands at the moment.


No, your are correct. The "high update frequency" servos will work fine at either 50hz or at whatever higher updating rate they are rated for. They still obey the same universal 1000-2000 usec pulse width commands, with of course some amount of under and over range from that 'standard'. If there is any actual advantage of using a 'high frequency' servos depends on what the servo is doing for a living, as in what mass load it is moving. I would suspect that ESC modules might benefit in some cases if they had higher update frequency capabilities, but for a servo moving something mechanically I would think that the servo's internal motor and gear train would have to be upgraded to higher performance to actually benefit from the faster updating capabilities. But who knows if it's mostly marketing hype or useful in real work applications.

Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 27, 2014, 06:48 pm

No, your are correct. The "high update frequency" servos will work fine at either 50hz or at whatever higher updating rate they are rated for.


I am learning also. Thanks.

...R
Title: Re: Pulse frequency and Servos
Post by: zoomkat on Apr 28, 2014, 07:15 am
The "high update frequency" servos (which I'm just hearing about) is still vague to me. The below might be what is being talked about. The update frequency a standard servo seems to be limited by requiring at least 6ms between updates. Digital servos may have this minimum dead time reduced, but there still has to be some dead time between commands. 

Quote
but 120Hz is about the limit for most standard servos. This is a result of the NE544 specs (the original servo amp) that requires 6ms of "off" time between pulses.


Title: Re: Pulse frequency and Servos
Post by: Robin2 on Apr 28, 2014, 10:54 am
The other thing that confuses me about the high servo update frequency is the business of multiplexing the signals for several channels for transmission between the transmitter and the receiver. If there is a 50Hz update frequency there is about 20 msecs between pulses, Since the longest pulse is a little over 2msecs there is "space" for about 8 channels within the 20 msecs.

If you increase the update frequency it seems to me the "space" for multiple channels is correspondingly reduced. And I can't see any value in the receiver getting pulses at 50Hz and repeating some of them at a higher frequency on individual channels - there would be no additional data.

But I may be completely dazed and confused.

...R
Title: Re: Pulse frequency and Servos
Post by: retrolefty on Apr 28, 2014, 03:47 pm

The other thing that confuses me about the high servo update frequency is the business of multiplexing the signals for several channels for transmission between the transmitter and the receiver. If there is a 50Hz update frequency there is about 20 msecs between pulses, Since the longest pulse is a little over 2msecs there is "space" for about 8 channels within the 20 msecs.

If you increase the update frequency it seems to me the "space" for multiple channels is correspondingly reduced. And I can't see any value in the receiver getting pulses at 50Hz and repeating some of them at a higher frequency on individual channels - there would be no additional data.

But I may be completely dazed and confused.

...R


Your not confused, that old standard R/C PPM data stream only allowed for updating individual channels at around a 50 Hz rate. I suspect the newer R/C spread spectrum radios use a different PPM frame rate and therefore might support a newer higher frequency servos?

Title: Re: Pulse frequency and Servos
Post by: raschemmel on Apr 28, 2014, 04:04 pm
Total PWM Period =(20mS +20mS)=22mS
Duty Cycle = 2mS/22mS= 9%