JWindy92
Posts: 3
Joined: Thu May 24, 2018 2:40 am

Controlling a 360 degree servo

Thu May 24, 2018 2:48 am

I picked up a 360 degree servo and I've got it to turn and change directions, but once it starts, I can't get it to stop. Can anyone explain to me how I can tell the motor to stop moving?

Here's the code:

Code: Select all

import RPi.GPIO as GPIO
import time

servoPIN = 4

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

p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz

p.start(2.5) # Initialization

try:
    while True:

        p.ChangeDutyCycle(7.5)
        time.sleep(0.5)
        p.ChangeDutyCycle(2.5)
        time.sleep(0.5)

except KeyboardInterrupt:
    p.stop()
    GPIO.cleanup()
The motor is an LS-8101F. Thanks

mattmiller
Posts: 2245
Joined: Thu Feb 05, 2015 11:25 pm

Re: Controlling a 360 degree servo

Thu May 24, 2018 6:31 am

I think with these continuous rotation servos that they have a little screw that you adjust so that the motor doesn't turn when duty-cycle set to 7.5 (equivalent of 1.5mS duration)

(Not got one but have some on order from China so I've read up on them a little bit)

Also, if duty-cycle = 7.5 is supposed to be no rotation - then maybe try setting it before your p.stop in your ctrl-c section

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

Re: Controlling a 360 degree servo

Thu May 24, 2018 8:06 am

You control speed, not position, with the PWM signal. If you need position control you will have to your own positional feedback and control loop.
As mattmiller says you stop movement by setting PWM to middle of the range.

JWindy92
Posts: 3
Joined: Thu May 24, 2018 2:40 am

Re: Controlling a 360 degree servo

Thu May 24, 2018 11:59 pm

So if I understand correctly, the turning the screw would adjust the setting to that 7.5 is equal to the middle of the range? so I just have to dial it in? In theory that is...

Also, does this look like it could be the screw? (from what you've read that is)
Attachments
Photo on 5-24-18 at 7.56 PM.jpg
Photo on 5-24-18 at 7.56 PM.jpg (135.24 KiB) Viewed 1986 times

mattmiller
Posts: 2245
Joined: Thu Feb 05, 2015 11:25 pm

Re: Controlling a 360 degree servo

Fri May 25, 2018 6:35 am

I can't find anything online about adjusting that servo model

So maybe you'll just have to fine-tune the duty cycle value to find the mid-range value?

Also, RPi.GPIO PWM signals are quite jittery (as they are software generated) , so if you can't find a reliable mid-range value that stops the motor from turning you might have to switch to using servod or @joan pigpiod instead which use accurate hardware timing signals

Return to “Automation, sensing and robotics”