vwok
Posts: 3
Joined: Tue May 10, 2016 12:16 pm

PIGPIO multiple servos

Tue May 10, 2016 12:32 pm

Hi there

I'm using the PIGPIO library to control my servos. It's working great for controlling one servo, but when I'm using multiple, they're acting crazy. They move by themselves to random positions continuously and they react verrrryy slowly and badly to my pulse signals.

Code: Select all

...

GPIO.setmode(GPIO.BCM)
pinLeft= 6
pinMiddle=5
pinRight = 4

pinServos = [pinRight, pinMiddle, pinLeft]

pi = pigpio.pi()

for x in pinServos:
        pi.set_mode(x, pigpio.OUTPUT)
        pi.set_PWM_frequency(x, 33)
        pi.set_servo_pulsewidth(x, 0)

pi.set_servo_pulsewidth(pinPoortL, 1000)
pi.set_servo_pulsewidth(pinPoortR, 1000)
pi.set_servo_pulsewidth(pinPoortM, 1000)



PiGraham
Posts: 3935
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: PIGPIO multiple servos

Tue May 10, 2016 1:31 pm

It should work OK. I've use pigpio to control several servos at once, although not recently.
Check your power supply to the servos. Try the same program running with just one servo connected. Does it behave correctly? If it does you probably have a hardware problem. If it doesn't it may be a software issue.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIGPIO multiple servos

Tue May 10, 2016 1:41 pm

Could you post the full code?

By the way

pi.set_servo_pulsewidth(x, 0)

does the same as

pi.set_mode(x, pigpio.OUTPUT)
pi.set_PWM_frequency(x, 33)
pi.set_servo_pulsewidth(x, 0)

Servo mode forces output mode and servo mode forces a PWM frequency of 50 Hz.

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: PIGPIO multiple servos

Tue May 10, 2016 1:50 pm

I would check your power line to your servo's, in r/c applications (cars/planes/helicopters) servos are usually allowed 3A on the power line with a max draw of 5a if stalled.
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

timrowledge
Posts: 1346
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: PIGPIO multiple servos

Tue May 10, 2016 3:52 pm

To reiterate darkbibble's point - I hope you have separate power for the servos. Connect the gnd from the Pi to the gnd of the servo power and only connect the servo 5v to the other psu. Trying to actually power servos from the Pi can cause release of the magic smoke.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

vwok
Posts: 3
Joined: Tue May 10, 2016 12:16 pm

Re: PIGPIO multiple servos

Wed May 11, 2016 6:14 am

Ok here are some pictures of my project. I'm trying to control the doors of a fisher-price house with my cellphone.
IMG_20160511_075854.jpg
IMG_20160511_075854.jpg (47.26 KiB) Viewed 3138 times
IMG_20160511_080004.jpg
IMG_20160511_080004.jpg (39.08 KiB) Viewed 3138 times
Full code:

Code: Select all

def main():
    #SETUP GPIO PARAMETERS
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    #12 and 16 are used for LED's
    pinGroen = 12
    pinRood = 16
    pinPoortR = 6
    pinPoortM = 5
    pinPoortL = 4
    pinServos = [pinPoortR, pinPoortM, pinPoortL]
    GPIO.setup([pinGroen,pinRood], GPIO.OUT, initial = GPIO.LOW)
  
    #SETUP PIGPIO
    pi = pigpio.pi() #Special PWM module
    for x in pinServos:
        pi.set_mode(x, pigpio.OUTPUT)
        pi.set_PWM_frequency(x, 33)
        pi.set_servo_pulsewidth(x, 0)
        
    poortLinksToe = 2000
    poortLinksOpen = 1000
    poortRechtsToe = 500
    poortRechtsOpen = 1500

 def servoControle():
       #get checkbox values from HTML form
        servoLinks = request.forms.get('poortLinks')
        servoRechts = request.forms.get('poortenRechts')

        #Gate left open or close  
        valueLinks = poortLinksOpen if servoLinks else poortLinksToe
        pi.set_servo_pulsewidth(pinPoortL, valueLinks)

        #Gates right open or close
        valueRechts = poortRechtsOpen if servoRechts else poortRechtsToe
        pi.set_servo_pulsewidth(pinPoortR, valueRechts)
        pi.set_servo_pulsewidth(pinPoortM, valueRechts)
        print(pi.get_servo_pulsewidth(pinPoortR))

   #Return HTML template and call Servo function
    @route("/")
    def toon():
        stylesheets('button.css')
        lampControle()
        servoControle()
        #function to return template:
        return showTemp()

Major Tom
Posts: 65
Joined: Wed Feb 03, 2016 8:13 am
Location: Strung up in heavens high.

Re: PIGPIO multiple servos

Wed May 11, 2016 6:51 am

Your power supply is only rated at 300mA. It seems a little small for 3 servos. Are you powering the Pi from the same supply?

What you could do is change your code so that there is a delay between moving each servo to a new position. Servos will draw more power when moving, than when they are staying in one position, especially when lightly loaded. So, you could move servo 1 to a new position, wait one second, then move servo 2, and so on. It may help you get round the power limitation of your PSU.
My circuit's dead, there's something wrong.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIGPIO multiple servos

Wed May 11, 2016 8:21 am

They look like standard size servos. Each one by itself might draw an amp or so if acting against a force. At the moment it does seem very likely that the glitches are caused by lack of power.

vwok
Posts: 3
Joined: Tue May 10, 2016 12:16 pm

Re: PIGPIO multiple servos

Wed May 11, 2016 7:50 pm

Thanks for the thoughts.
I tried to add a delay of 1 second after each servo movement, but it doens't really help. When I move the left servo, the others are moving as well and vice versa.

I will try to connect a higher Amp supply one of the days.

Return to “Troubleshooting”