Servo Duty cycles.

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Servo Duty cycles.

#11 Post by Keith Baxter »

jph wrote: Sat May 15, 2021 11:48 am Ok Brother, no worries. Don't ask how I know.... :lol: :oops:
Yeh,

I am going to wake up at 3am tomorrow with it all worked out.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Servo Duty cycles.

#12 Post by jph »

I tell my bride that every day...................................................................... :o ;)
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Servo Duty cycles.

#13 Post by Keith Baxter »

Hi,

O well. The more I think about this the more I see why peeps steer away. It is far to complicated for most.

I will set up some simplified code so that working out all the math and variables is simply entering a few parameters. Something that definitely needs to be addressed IMHO.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Servo Duty cycles.

#14 Post by Keith Baxter »

Hi,

Another Q...

From an accuracy point of view and thinking about 3D printer steppers. The stepper needs to rotate more than it moves the axis. Servo moves a ( pointer, trim-wheel, aileron and rudder (in a RC plane) etc) ----Yes I understand the difference between servo's and steppers.

In other words the smaller gear should be on the servo and the bigger gear on the pointer. NOT?

Why would the designer of the instruments opt to stress the servo buy having a 1 to 2.5 ratio? Is it for accuracy or speed?

The other Q @Corjan is If I have many servo's. Should I apply the dataref throttle that works so well with canvas()

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Servo Duty cycles.

#15 Post by jph »

Keith Baxter wrote: Sat May 15, 2021 12:51 pm Hi,

O well. The more I think about this the more I see why peeps steer away. It is far to complicated for most.

I will set up some simplified code so that working out all the math and variables is simply entering a few parameters. Something that definitely needs to be addressed IMHO.


Keith
Hi Keith, for the maths, if it helps - take this example.
A 'standard' servo (RC model type) is supposed to operate at around 50Hz. (this is stated by the servo maker)
meaning that 50 times a second the servo looks for it's signal.
That therefore means that the time between the servo looking at one signal to the next is 1/50 seconds. = 20mS.

The POSITION of the servo is dictated by a PULSE DURATION
The duration of that pulse that is applied in most servos is normally between 1mS and 2mS where 1.5mS is the centre point of the servo range and 1mS is one end of the travel limit, and 2mS is the opposite end of the travel limit.
So, our PWM 'frequency' is 50Hz.
At 50Hz, the servo takes a measurement every 1/50 seconds = every 20mS. Our POSITION of the servo is still dictated by the duration of the pulse that we apply every 20 mS
To get a pulse duration of 1.5mS (the nominal servo centre position) then, using PWM (pulse width modulation) - which is a measure of the percentage of the frequency of the signal - in this case - 50hz = 20mS.. we need to know what percentage of 20mS is 1.5mS.
We can do this by dividing the 'desired pulse width' in mS by the frequency of the PWM signal in mS
In this case - if we wanted a pulse width of 1.5mS for the servo centre position, and the PWM 'FREQUENCY' is 50hz which is 1/50 in mS (20mS). then the pulse width (%) is 1.5 / 20 = 0.075 this is the PWM DUTY CLYCLE in percentage terms.
For the minimum servo signal - ie: full - one way - being 1mS
Then the PWM percentage in this case is 1 / 20 = 0.05 % so a DUTY CYCLE of 0.05%
and for the opposite limit of travel - being 2mS - then the PWM percentage is 2 / 20 = 0.1 which is a DUTY CYCLE of 0.1%

in the real world, a lot of the cheaper servos can operate over a greater range - still with an approximate 1.5mS centre position. So you servo may be able to offer a greater than 180 degree travel hence accepting - for example - 0.8mS to 2.2mS .. which would give a duty cycle (percentage) requirement (at 50hz frequency) of 0.8 / 20 to 2.2 / 20 , which is 0.04 DUTY CYCLE to 0.11 DUTY CYCLE which is the value entered into AM.
Some servos can operate over a greater range - you need to experiment with your own servo.
The data to enter into AM for frequency is 50 (as the requirement for AM is in Hz)
The DUTY CYCLE is as calculated above.
Hope that helps ? I can try to granulate that more if it helps // it is one of those things that gets you really frustrated then becomes a light bulb moment and you think - Yeah !
Joe.
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Servo Duty cycles.

#16 Post by jph »

Keith Baxter wrote: Sat May 15, 2021 1:50 pm Hi,

Another Q...

From an accuracy point of view and thinking about 3D printer steppers. The stepper needs to rotate more than it moves the axis. Servo moves a ( pointer, trim-wheel, aileron and rudder (in a RC plane) etc) ----Yes I understand the difference between servo's and steppers.

In other words the smaller gear should be on the servo and the bigger gear on the pointer. NOT?

Why would the designer of the instruments opt to stress the servo buy having a 1 to 2.5 ratio? Is it for accuracy or speed?
Keith
Hi again and good morning Keith.
This is apples and oranges.
A stepper motor by its nature has (in the case of any standard stepper) an unlimited number of steps that can be applied hence an unlimited amount of rotation / circular movement.
In a cnc type environment then the stepper is usually geared - or micro stepped - to take many steps in relation to the actual movement of the actuator / axis. For various reasons. One being accuracy as most are 1.8 degrees per step where we need a much higher resolution at the axis device.

Regarding an RC servo. an RC servo is a limited device, in that it can only move (normally) over a limited range. Usually 180 degrees, sometimes 220 degrees etc..... but whatever that range is, in degrees, - then that is all she wrote.
For an instrument in our context, then the larger gear would be on the servo and the smaller gear on the pointer so that the limited range of the servo can be converted to a larger range of pointer movement. Otherwise the pointer movement would be entirely limited by the servo range in degrees.
If you put the smaller gear on the servo and the bigger gear on the pointer - and for example - the gearing is 2.5:1 overall, then for the maximum movement of the servo (around 180 degrees) then the pointer would only move 180/2.5 degrees = 72 degrees !!! :(
Yet, putting the larger gear on the servo and the smaller on the pointer giver the opposite presuming a 2.5:1 ratio = a nominal 180 degrees on the servo MULTIPLIED by 2.5 = 450 degrees of movement of the pointer.
So it is neither for accuracy OR speed, it is for the degrees of movement only.
Does that make sense ?
Joe.
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Servo Duty cycles.

#17 Post by Keith Baxter »

Hi Joe,

Far to complicated for the average Joe (Pun intended) and way over engineered. :mrgreen: :lol: :lol: :lol:

Peeps want a simple solution that is easy to work with. I will put up some code later today that will make it easy for all to understand.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Servo Duty cycles.

#18 Post by jph »

No worries Keith. I personally don't see it as overcomplicated as I have used PWM in many cases, however, I see where you are coming from. (I feel the same about Messageport at this moment, but that is because I haven't sat down and got my head around it and experimented with it in detail. I am sure it It will all /click/ into place for me when I get around to scratching my head more and wading into it :lol: ) -
IF AM had a dedicated 'servo' output then it would be easier to write a more user friendly code, however, it is a generic PWM output, which is understandable as it uses to Hardware PWM section of the Arduino etc. and, is useful for many applications as well as for a servo.
But, yes, a dedicated servo would be more 'user friendly' and the math I posted above could easily be converted into code. It is worth considering though, that if you try to write a servo specific code based on 50Hz PWM frequency, then that would only apply to analog servos and ignore the far more appropriate capabilities of DIGITAL RC servos which can and do operate at at much higher frequency. - although they are backwards compatible. Also, the range of servo movement, and indeed, the centre position can be slightly different from servo to servo. Although, the better quality SG90 units are very stable once the operating parameters have been determined by trial and error.

Just for interest here is a datasheet for the ubiquitous and most copied servo ever - the sg90
The pointers I have added should help others in some of the respects that I mentioned.
servo.jpg
ANY code that helps others is superb.
Joe
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Servo Duty cycles.

#19 Post by Keith Baxter »

Joe,

I am just going to confuse all even more. :lol:

What is a horn angle ?
What is µs ?
What is this guy talking about???


Code: Select all

Servos are controlled by pulse width, the pulse width determines the horn angle.

A typical servo responds to pulse widths in the range 1000 to 2000 µs.

A pulse width of 1500 µs moves the servo to angle 0. Each 10 µs increase in pulse width typically moves the servo 1 degree more clockwise. Each 10 µs decrease in pulse width typically moves the servo 1 degree more anticlockwise.

Small 9g servos typically have an extended range and may respond to pulse widths in the range 500 to 2500 µs.

Why do people think servos are controlled by duty cycle? Because servos are typically given 50 pulses per second (50 Hz). So each pulse is potentially a maximum of 20000 µs (1 million divided by 50). A duty cycle is the percentage on time. 100% will be a 20000 µs pulse, way outside the range accepted by a servo.

Do some calculations at 50 Hz for sample pulse widths.

 500 / 20000 = 0.025 or  2.5 % dutycycle
1000 / 20000 = 0.05  or  5.0 % dutycycle
1500 / 20000 = 0.075 or  7.5 % dutycycle
2000 / 20000 = 0.1   or 10.0 % dutycycle
2500 / 20000 = 0.125 or 12.5 % dutycycle
Don't use dutycycles, if possible use pulse widths, and think in pulse widths. If you send pulses at 60 Hz by duty cycle the servo will go to the wrong position.
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Servo Duty cycles.

#20 Post by jph »

Keith Baxter wrote: Sun May 16, 2021 9:50 am Joe,

I am just going to confuse all even more. :lol:

What is a horn angle ?
What is µs ?
What is this guy talking about???


Code: Select all

Servos are controlled by pulse width, the pulse width determines the horn angle.

A typical servo responds to pulse widths in the range 1000 to 2000 µs.

A pulse width of 1500 µs moves the servo to angle 0. Each 10 µs increase in pulse width typically moves the servo 1 degree more clockwise. Each 10 µs decrease in pulse width typically moves the servo 1 degree more anticlockwise.

Small 9g servos typically have an extended range and may respond to pulse widths in the range 500 to 2500 µs.

Why do people think servos are controlled by duty cycle? Because servos are typically given 50 pulses per second (50 Hz). So each pulse is potentially a maximum of 20000 µs (1 million divided by 50). A duty cycle is the percentage on time. 100% will be a 20000 µs pulse, way outside the range accepted by a servo.

Do some calculations at 50 Hz for sample pulse widths.

 500 / 20000 = 0.025 or  2.5 % dutycycle
1000 / 20000 = 0.05  or  5.0 % dutycycle
1500 / 20000 = 0.075 or  7.5 % dutycycle
2000 / 20000 = 0.1   or 10.0 % dutycycle
2500 / 20000 = 0.125 or 12.5 % dutycycle
Don't use dutycycles, if possible use pulse widths, and think in pulse widths. If you send pulses at 60 Hz by duty cycle the servo will go to the wrong position.
Keith
Hi Keith,
'horn angle' . The usual part that fits on to the servo - that is included in the RC servo kit - for example the 'arm' ... is often called a 'horn' .. so the horn angle is the amount of possible movement from one extreme to the other of that arm or attachment.

uS = Micro Seconds - where -
mS MILLI SECOND is a THOUSANDTH of a second which = 1/1000 . So 1 mS is one thousandth of a second.
uS MICROSECOND, is 1 MILLIONTH of a second which = 1 / 1000000. So 1 uS is 1 millionth of a second.

as for what he is talking about ... he is saying more of less what I am, but he is - imho, overcomplicating things.
He is using uS instead of mS.

Hence the line
"A typical servo responds to pulse widths in the range 1000 to 2000 µs."

Also is equal to 'A typical servo responds to pulse widths in the range 1mS to 2 mS'
It is just another unit of measurement as 1000 uS is equal to 1 mS.... and as another example 1000 mS = 1 second, or 1 million uS = 1 second. Just different units of measurement like Kg and Grams where 1000 grams = 1 Kg... and a thousand Kg = 1 metric ton.

The above can be used as an analogy where the metric ton (1000Kg) is 1 second in time.
1 Kg = 1000th of a metric ton.... as in 1mS = 1000th of a second
and 1 gram = 1000000th of a metric ton. as in 1 uS = 1 millionth of a second.

The rest of the above stuff he mentions is meaningless without the grasp of the measurements.
If you are into 'exponents' in math then 1mS = 1 x 10^-3 seconds and 1uS = 1 x 10 ^ -6 seconds..


He also says -

'Don't use dutycycles, if possible use pulse widths, and think in pulse widths'.
Hmm.. well this is not the case in AM and I also disagree with his thought process. One needs to understand both really as both are closely and intrinsically related as the pulse width - as quoted by the servo manufacturer - determines the figure entered into AM, and this is related to the PWM frequency. He also eludes to this but I believe it is misleading as the overall picture has to be considered.
If you get your head around a 50hz frequency with a 1.5ms pulse width requirement, then the data entered into AM is simply the percentage of the pulse width (as a time measurement) in relation to the frequency (as a time measurement) . Convert all values to the same domain - or more simply to units of time in seconds or parts thereof. Break down each part into the same units of measurement of time to calculate the required figures. ALL parts - frequency - pulse width etc can be and should be converted to the same unit of measurement and then the percentage calculation - DUTY CYLCE - is a matter of simple math. By not converting frequency and pulse width requirements to a standard value then the maths becomes a nightmare.
It also changes completely if you change the PWM frequency as , as shown above, the percentage of the pulse width in relation to the frequency is no longer the same.
Sorry, it seems confusing.
But I would really suggest looking at the relationship between time period measurements first - such as seconds, mS and uS as all the calculations rely on these.
I am probably not helping brother am I ? :(
Joe
Joe. CISSP, MSc.

Post Reply