barrettj103
Posts: 4
Joined: Tue Dec 05, 2017 8:15 am

Continuous rotation servo control.

Wed Dec 06, 2017 10:11 am

I have looked at several posts on this issue and have not really found an answer. My first question is how the 1000, 1500, and 2000 micro second bursts translate to the ChangeDutyCycle variables? I have tried many different numbers but can't really figure out what the pi is doing. I am using what seems like the standard code for learning servo behavior.

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 100)
p.start(5)
time.sleep(5)
p.stop()
GPIO.cleanup()
This code runs it clockwise at a good speed, but it never stops. I am running this over ssh, but I don't see why that would make it not stop

All I need it to do is run clockwise for a set (Short) period of time and then stop until the method is called again. Any help will be appreciated.

I'm also looking to learn this for any future projects I might do so the more info the better.

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

Re: Continuous rotation servo control.

Wed Dec 06, 2017 11:19 am

I suggest you use (my) pigpio or servoblaster or RPIO.GPIO for servo pulses. They each use hardware timed pulses. Software timed pulses will be much more subject to jitter (which will shorten the servo's life).

E.g. http://abyz.me.uk/rpi/pigpio/pigs.html#S/SERVO

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Continuous rotation servo control.

Wed Dec 06, 2017 12:52 pm

This method requires hardware, but it takes the processing load off the RPi. I use this, and I'm very pleased with the performance.
https://www.adafruit.com/product/815

pcmanbob
Posts: 4460
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Continuous rotation servo control.

Wed Dec 06, 2017 12:52 pm

So the reason your servo does not stop is because you have not told it to, most servos will hold the last position you set them to but as yours is a Continuous rotation servo it will just keep spinning.

To make your servo stop you need to set the duty cycle to the mid position, try this you may need to adjust the middle value to find the exact value to make your servo stop

Code: Select all


import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 100)
p.start(5)

p.ChangeDutyCycle(2.5)
time.sleep(5)
p.ChangeDutyCycle(11.5) # may need to be adjusted
time.sleep(5)
p.ChangeDutyCycle(20.5)
time.sleep(5)
p.ChangeDutyCycle(11.5) # may need to be adjusted

GPIO.cleanup()
[code]

you servo should turn in one direction then stop then turn in the other direction then stop.
Last edited by pcmanbob on Wed Dec 06, 2017 2:11 pm, edited 2 times in total.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

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

Re: Continuous rotation servo control.

Wed Dec 06, 2017 1:35 pm

pcmanbob wrote:
Wed Dec 06, 2017 12:52 pm
So the reason your servo does not stop is because you have not told it to.
Agreed.

It may be the case that no PWM signal will stop the servo.
If not it may be necessary to maintain the mid-position signal and not quit with GPIO.Cleanup().

User avatar
scruss
Posts: 1821
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Continuous rotation servo control.

Wed Dec 06, 2017 4:01 pm

For much higher level control, there's also gpiozero.Servo. Punch in the particular servo's timing parameters from the data sheet (or failing that, ServoDatabase.com) and then just feed it values from -1 .. +1, with 0 for stopped.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

mikerr
Posts: 2728
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Continuous rotation servo control.

Wed Dec 06, 2017 6:53 pm

A normal servo goes to a selected position, then stops.

A continuous rotation servo is controlled in a similar way, but :

- sent a position of "centre" it will stop (at e.g. 90)
- sent a position away from center (e.g. 75 or 150) it will rotate continuously,
- rotate direction will depend on which side of the "centre" the position pulse was.
- on some serves rotate speed also depends on how far from centre the pulse is.

Note the "centre", or no-movement position can vary between individual servos
I have identical ones here where centre is 90 on one, 93 on the other !

Also very new is the parallax 360 feedback servo:
https://www.parallax.com/product/900-00360
which has an extra wire to provide exact positional angle feedback.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

evaoxo
Posts: 1
Joined: Wed Oct 03, 2018 12:00 am

Re: Continuous rotation servo control.

Wed Oct 03, 2018 12:08 am

Hi, do you have a simple example python code for the motor you suggested?
I’m currently using this motor, but I don’t know how to control it with different speed and how to do with the feedback since there is no 360 servo library in python.

danjperron
Posts: 3072
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Continuous rotation servo control.

Wed Oct 03, 2018 1:32 am

My first question is how the 1000, 1500, and 2000 micro second

The PWM for Rpi.GPIO works in percent.

Normal servo use a cycle of 20ms (50Hz)

Then
1000 us = 1000us / 20000us * 1000 = 5
1500 us = 7.5
2000 us = 10

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)

p = GPIO.PWM(12, 50)

print("center")
p.start(7.5)
time.sleep(2)
print("45 degree")
p.ChangeDutyCycle(5)
time.sleep(2)
print("The other 45 degree")
p.ChangeDutyCycle(10)
time.sleep(2)
print("Center again")
p.ChangeDutyCycle(7.5)
time.sleep(2)
print("stop")
p.stop()
GPIO.cleanup()
[code]

RPi.GPIO use software PWM. it is not steady!

Return to “Beginners”