barrettj103
Posts: 1
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: 13304
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: 1506
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: 3688
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.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

PiGraham
Posts: 3162
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: 1640
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: 2648
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 !

Return to “Beginners”

Who is online

Users browsing this forum: jbudd, pcmanbob and 7 guests