Controlling servos with Adafruit 16-Channel PWM Servo HAT

Our weekly LIVE video chat. Every Wednesday at 8pm ET!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
dpersh
 
Posts: 5
Joined: Sun Mar 29, 2015 3:48 pm

Controlling servos with Adafruit 16-Channel PWM Servo HAT

Post by dpersh »

Hi,

I'm building a robot that needs to control 4 servos. I'm using Tower Pro MG90S (Micro Servo High Torque Metal Gear[ID:1143]) with Adafruit 16-Channel PWM Servo HAT.

Sometimes those servos would have trouble settling in for the required angle and would start buzzing and stuttering. I wonder if there a way to disengage a servo without cutting the power to it? All of my experimentation with configuring PWM driver to shut servos of were fruitless so far. I tried setting individual channels to [on = 0, off = 4096] (should kill PWM completely), tried setting all the channel to off in the same manner, tried putting PWM controller chip to sleep and even issuing SWRESET command - nothing makes any difference.

Generally, servos keep staying engaged once I've sent any meaningful PWM signal to the them. And they would stay engaged until the power if cut off completely.

Is this an expected behavior?

Thanks,
Denis

User avatar
adafruit_support_bill
 
Posts: 88138
Joined: Sat Feb 07, 2009 10:11 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit_support_bill »

I tried setting individual channels to [on = 0, off = 4096]
Try on = 0, off = 0.

User avatar
dpersh
 
Posts: 5
Joined: Sun Mar 29, 2015 3:48 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by dpersh »

Nope, doesn't help

User avatar
adafruit2
 
Posts: 22187
Joined: Fri Mar 11, 2005 7:36 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit2 »

one more, try off = 0, on = 4096 ? can you see the signal on an oscilloscope?

User avatar
dpersh
 
Posts: 5
Joined: Sun Mar 29, 2015 3:48 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by dpersh »

Unfortunately I do not have access to the oscilloscope. However, trying one of those servos with Arduino I get the same result as with the Pi's Servo HAT. I loaded up Servo/Sweep example into my Uno and servo did what was expected, yet it would stay engaged even when I physically disconnect signal wire from it. It's only when the power or the ground leads are disconnected servo goes limp.

So, I'm guessing this is the property of Tower Pro MG90S servos. Since I bought those from Adafruit I wonder if you can reach out to the manufacturer to clarify on this topic.

Thanks!

User avatar
adafruit_support_bill
 
Posts: 88138
Joined: Sat Feb 07, 2009 10:11 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit_support_bill »

Interesting. I have not seen that behavior with the MG90S before. But Tower has made other changes to this model over the years. I'll have to look into that.

User avatar
adafruit2
 
Posts: 22187
Joined: Fri Mar 11, 2005 7:36 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit2 »

it might be a digital servo. perhaps digital servos 'hold'? :/

User avatar
dpersh
 
Posts: 5
Joined: Sun Mar 29, 2015 3:48 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by dpersh »

How can I tell? Is there a workaround?

User avatar
adafruit_support_bill
 
Posts: 88138
Joined: Sat Feb 07, 2009 10:11 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit_support_bill »

The MG90S is not a digital servo - at least not the ones I have here. I will order up a couple from from current stock and do a tear-down on it to see what is inside.

User avatar
bkaemmereit
 
Posts: 4
Joined: Mon Oct 27, 2014 11:31 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by bkaemmereit »

Hi there!

I have similar issues with the Torcster Servo NR-645 MG BB.

The code runs pretty fine with the Graupner C 507.

My wiring

Any ideas?
Last edited by bkaemmereit on Mon Apr 27, 2015 4:15 pm, edited 1 time in total.

User avatar
adafruit_support_bill
 
Posts: 88138
Joined: Sat Feb 07, 2009 10:11 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by adafruit_support_bill »

I'm not familiar with that brand of servo. I'd check with your servo supplier.

User avatar
bkaemmereit
 
Posts: 4
Joined: Mon Oct 27, 2014 11:31 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by bkaemmereit »

At the moment i try to figure out in which value ranges the servo might run

Is it basicly correct?

Code: Select all

servoMin = 0
servoMax = 4096

freq = 50
pwm.setPWMFreq(freq)

while True:

    freq = freq + 1
    pwm.setPWMFreq(freq)
    print "setPWMFreq: %d" % freq

    pwm.setPWM(0, 0, servoMin)
    print "servoMin: %d" % servoMin

    time.sleep(1)

    pwm.setPWM(0, 0, servoMax)
    print "servoMax: %d" % servoMax
    
    print  "-------------------------------"

    time.sleep(1)

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by Franklin97355 »

What is the output when you run that code?

User avatar
bkaemmereit
 
Posts: 4
Joined: Mon Oct 27, 2014 11:31 am

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by bkaemmereit »

You mean in the console?

pi@raspberrypi ~/projects/lasi.us/test $ sudo python servotry06.py
setPWMFreq: 51
servoMin: 0
servoMax: 4096
-------------------------------
setPWMFreq: 52
servoMin: 0
servoMax: 4096
-------------------------------
setPWMFreq: 53
servoMin: 0
servoMax: 4096
-------------------------------
setPWMFreq: 54
servoMin: 0
servoMax: 4096
-------------------------------
setPWMFreq: 55
servoMin: 0
servoMax: 4096
-------------------------------

The servo itself is just twitching - sometimes a not reproducable movement...

User avatar
dpersh
 
Posts: 5
Joined: Sun Mar 29, 2015 3:48 pm

Re: Controlling servos with Adafruit 16-Channel PWM Servo HA

Post by dpersh »

You probably do not want to change PWM frequency much as that's global for all of the PWM channels on Servo HAT. Essentially, setPWMFreq sets your duty cycle where 50~60Hz is generally a recommended freq range for servo control (AFAIK)

So, basically you set your PWM freq once and then find the range of your servos relative to it. You manipulate On and Off values passed to pwm.setPWM(Channel, On, Off) where:

On is the tick number at which signal goes High
Off is the tick number at which signal goes Low

You have total of 4096 ticks (0..4095) to work with.

Setting On = 4096 (special value) would instruct PCA9685 to go all *high* on the given channel throughout the duty cycle
Setting Off = 4096 (special value) would instruct PCA9685 to go all *low* on the given channel throughout the duty cycle

Read up on PCA9685 - datasheet explains it all.

Also, I would appreciate if you do not hijack this thread as I'm still hoping for the resolution of my original problem :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Ask an Engineer! VIDEO CHAT (closed)”