Page 1 of 1

2 Servo Motor Control

Posted: Mon Mar 27, 2017 10:36 pm
by luiskrlos84
We want to control two servo motors to do the same function to rotate 180 degrees and then comeback to the original position, but we are having trouble syncin the second motor with the first motor. We were able to make the first one rotate 180 degrees, we only need to add the second motor. We are using GPIO pin 11 for servo motor signal 1, and we want to use pin 13 for motor 2. We are powering the servos with an external supply.
Here it our code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
servoPin=11
GPIO.setup(servoPin, GPIO.OUT)
pwm=GPIO.PWM(servoPin,50)
pwm.start(1)
while(1):
for i in range (0,110):
DC=1./20.*(i)+2
pwm.ChangeDutyCycle(DC)
time.sleep(.02)
for i in range(110,0,-1):
DC=1./20.*i+2
pwm.ChangeDutyCycle(DC)
time.sleep(.02)
pwm.stop()
GPIO.cleanup()

Re: 2 Servo Motor Control

Posted: Tue Mar 28, 2017 12:37 am
by MarkyV
In my experience you won't be able to get a good PWM signal as you will get too much jitter using just outputs through the GPIO - my advice would be to use ServoBlaster : https://github.com/richardghirst/PiBits ... rvoBlaster.

Hope that helps

Mark

Re: 2 Servo Motor Control

Posted: Tue Mar 28, 2017 12:44 am
by Gavinmc42
Servo motors are also analog, they will rarely rotate at the same speed unless you make them by slicing up the steps.
To move to +90 degrees from 0 degrees that means changing the pulse width from 1.5ms to 2ms.
Do it in steps, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0ms, allow time for each servo to move to that position.
The number of steps and pause time will need to be experimented with.

Re: 2 Servo Motor Control

Posted: Thu Mar 30, 2017 10:51 pm
by luiskrlos84
Gavinmc42 wrote:Servo motors are also analog, they will rarely rotate at the same speed unless you make them by slicing up the steps.
To move to +90 degrees from 0 degrees that means changing the pulse width from 1.5ms to 2ms.
Do it in steps, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0ms, allow time for each servo to move to that position.
The number of steps and pause time will need to be experimented with.
So how will the code will be? Because I don't really understand what you said, thanks

Re: 2 Servo Motor Control

Posted: Fri Mar 31, 2017 3:11 am
by Gavinmc42
Add a pause between each step.
This gives time for the motors/gears to move.
You have loops but no delay to allow the servos to catch up

You could write a program to do 10 complete 180 moves and time them.
Servos are not instantaneous, they might take 0.5 -0.8sec to move.
It depends on the servos what this time is, high power ones are slower or bigger.
Sounds like you have one slower than the other, this could be due to binding gears etc.
Check specs for servos find the times ie Operating Speed: 0.14sec.60º/ 0.13sec.60º
These are the fastest times, load will slow them done.
The servo will not move faster than that. 180 degrees = 0.42sec.
To be safe double that to 840ms, 10 steps means delay 84ms, 100 steps 8.4ms.

http://robotshop.com/letsmakerobots/ser ... ng-arduino

Real industrial servos have acceleration, velocity curves controlled by software.