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

Servo Duty cycles.

#1 Post by Keith Baxter »

Hi,

Any pointer as to how servo duty cycles are worked out?
I have the standard TowerPro sg90 and the results are not as expected.

Code: Select all

-- Add the TowerPro sg90 servo motor to the script
pwm_brake_press = hw_output_pwm_add("Brake Press servo", 50, 0.0)

-- The dial scale go's from 90º to 315º which is 62.5% of 360º (total movement of 225º)
-- In this case the duty cycle ranges from {0.0 to 0.625}????
-- We have an brake pressure that goes from 0 to 4000 PSI
function new_brake_press(bp)

    hw_output_pwm_duty_cycle(pwm_brake_press, (0.625/4000) * bp)

end

xpl_dataref_subscribe("laminar/B738/brake/brake_press", "INT", new_brake_press)

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 

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Servo Duty cycles.

#2 Post by JackZ »

@Keith Baxter
IIIRC I made quite a while ago a long tutorial about servos and particularly the SG90

A quick search should yield this

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Servo Duty cycles.

#3 Post by JackZ »

My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

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

Re: Servo Duty cycles.

#4 Post by Keith Baxter »

JackZ wrote: Sat May 15, 2021 10:29 am Got it.
https://siminnovations.com/forums/viewt ... cle#p14377
Jacques,

Yes I found it and i remember it. Thank you for reminding me. However it leaves me more confused because because I think I am applying the logic but obviously not because the servo continues to spin or rock back and forth.

I do not know if it is code related or Arduino PWM related.

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 

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Servo Duty cycles.

#5 Post by JackZ »

Are you working on the triple brake press for the 320?
I’m working on it as well
1585F8C6-6E41-412F-8580-060891D4EEF6.jpeg
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

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

Re: Servo Duty cycles.

#6 Post by Keith Baxter »

Jacques,

These. I purchased about 18 months ago befor I bought the 3D printer and cnc

https://www.cockpitsimparts.co.uk/22-gauges

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
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Servo Duty cycles.

#7 Post by Ralph »

0.625 is too much. It goes from something like 0.03 to 0.13.

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

Re: Servo Duty cycles.

#8 Post by jph »

Hi Chaps,
Here is a good tutorial on standard servos. Basically the duration between pulses is 20mS - at the end of the 20mS period a PWM level is applied between - nominally - 1mS to 2mS where around 1.5mS is the centre - or there abouts. Sometimes, with certain servos, you can exceed the limits as in - less than 1mS and more than 2mS to increase throw, (rotation degrees) - which is mostly limited by the servo end stops and design. that is about is as far as the signalling goes and nothing much more to note.
https://learn.sparkfun.com/tutorials/ho ... torial/all
Keith, you 'seem' to be trying to drive the servo beyond it's normal design limit (180 degrees) ? which may work for some models of the SG90 but not for others.
I am not quite sure as to the capabilities of your specific servos, but the gauges you link to seem to be geared so as not to use > than the servo nominal throw angle.

you can easily test using the following arduino sketch -

Code: Select all

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}
You can ignore the pot input for testing and bypass the analogRead and simply alter the 'val' in the myservo.write(val); code to suit ///

Joe.
Joe. CISSP, MSc.

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

Re: Servo Duty cycles.

#9 Post by Keith Baxter »

Joe,

My bad I did not take into account the gearing. :oops: :oops:

The big gear on the servo is 40t and the small one on the pointer shaft 16t
So 1 rotation of the servo is 2.5 rotations of the pointer.

Will test and revert.

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.

#10 Post by jph »

Ok Brother, no worries. Don't ask how I know.... :lol: :oops:
Joe. CISSP, MSc.

Post Reply