0

Basically I want to control the angle of the rotation of the servo motor but I don't seem to know how... From the tech sheet I know this motor shouldn't be a continuous one, any hint would be appreciated

I have tried:

import RPi.GPIO as GPIO
import time

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

p = GPIO.PWM(25, 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()

And

from gpiozero import Servo
from time import sleep

myGPIO=25

myCorrection=0.45
maxPW=(2.0+myCorrection)/1000
minPW=(1.0-myCorrection)/1000

servo = Servo(myGPIO,min_pulse_width=minPW,max_pulse_width=maxPW)

while True:
    servo.value=0
    print("0")
    sleep(10)
    servo.value=0.6
    print("0")
    sleep(10)
ka_lin
  • 103
  • 3
  • My answer based on PowerPro MG996R to the following question might help: https://raspberrypi.stackexchange.com/questions/99315/run-the-program-in-the-laptop-and-use-the-raspberry-gpios – tlfong01 Jul 20 '19 at 01:01
  • I took a look on your implementation. If you checked the video you can see the issue I am facing. Thanks for your time. I know I should not add videos or such but it shows best the problem – ka_lin Jul 20 '19 at 13:07
  • Ah, I see what you mean by "continuous" rotation. You mean rotating more than the usual 180 degrees. There is a well known trick to do this. Let me see if I can find it for you. BTW, video is good. I used to think a picture is worth 1,000 words, and a video is worth 10,000 words. – tlfong01 Jul 20 '19 at 13:18
  • You might like to read my answer to the following question (https://raspberrypi.stackexchange.com/questions/97999/sg-5010-servo-360-degree-modification-not-working ), which contains a reference to modify the servo to rotate more than 360 degrees, actually any number of rotations. The question is "closed", so I am not sure if you can read it. Let me know if you cannot, then I will copy and paste the reference here. – tlfong01 Jul 20 '19 at 13:26
  • I guess this video is what you want: ( https://www.youtube.com/watch?v=AahhjgqJdMA ) I am going to bed. So see you tomorrow. Good luck to your servo hacking! :) – tlfong01 Jul 20 '19 at 13:36

1 Answers1

1

Servos move to a commanded angle and then stop.

Servos are controlled by a series of short pulses, typically sent 50 times per second (50 Hz). The length of each pulse determines the commanded angle. Typically the pulse length is between 1000 and 2000 microseconds (µs).

There is no standard for which pulse length is used for which angle. However most servos treat a pulse length of about 1500 µs as the centre. Longer pulse lengths turn more clockwise. Shorter pulse lengths turn more counterclockwise. Most servos are happy for pulses in the range 1000 to 2000 µs. I would not use pulse lengths outside the range 1000 to 2000 µs without care as some servos can be damaged.

You will have to experiment to determine the range of pulse lengths acceptable to your servos. There will be variations between models and between servos of the same model.

I suggest you use (my) pigs servo command to check the pulse lengths.

E.g. if your servo is connected to (Broadcom) GPIO 4.

sudo pigpiod # start the daemon

pigs s 4 1000 # send 1000 µs pulses on GPIO 4
pigs s 4 1500 # send 1500 µs pulses
pigs s 4 2000 # send 2000 µs pulses

Once you determine the end angles you can assume that movement will be linear between the two, i.e. a change in pulse length of 100 µs will result in the same change in angle throughout the range.

joan
  • 71,024
  • 5
  • 73
  • 106