Controlling continuous servo using python in Raspberry Pi,but the continuous servo can't stop

Viewed 5378

I'm trying to control a continuous servo(DF15RSMG) using python in Raspberry Pi, but the continuous servo can't stop. Code as follows:

import RPi.GPIO as GPIO  
import time  
import signal  
import atexit  

atexit.register(GPIO.cleanup)    

GPIO.setmode(GPIO.BCM)  
GPIO.setup(17, GPIO.OUT, initial=False)  
p = GPIO.PWM(17,50) #50HZ  
p.start(0)  
time.sleep(2)  

while(True):  
  for i in range(0,181,10):  
    p.ChangeDutyCycle(2.5 + 10 * i / 180)  
    time.sleep(0.02)                       
    p.ChangeDutyCycle(0)                    
    time.sleep(0.2)  

  for i in range(181,0,-10):  
    p.ChangeDutyCycle(2.5 + 10 * i / 180)  
    time.sleep(0.02)  
    p.ChangeDutyCycle(0)  
    time.sleep(0.2)  

Code above is work for SG90 Servo.Having seen this question Raspberry pi servo doesn't stop ,but I still haven't know how to solve this problem,What should I do?

1 Answers
Related