树莓派伺服不停 [英] Raspberry pi servo doesn't stop

查看:101
本文介绍了树莓派伺服不停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我尝试在 pi 相机上使用伺服 (Doman s0306d),尝试运行我发现的这个脚本来测试电机,它开始运行但不会停止,除非我手动从面包板上拔下它.

So I'm trying to use a servo (Doman s0306d) with the pi camera, tried running this script I found to test the motor, it starts running but doesn't stop unless I manually unplug it from the breadboard.

import RPi.GPIO as IO        # calling for header file for GPIO’s of PI
import time                           # calling for time to provide delays in program
IO.setwarnings(False)          # do not show any warnings
IO.setmode (IO.BCM)            # programming the GPIO by BCM pin numbers. (like PIN29 as‘GPIO5’)
IO.setup(19,IO.OUT)             # initialize GPIO19 as an output
p = IO.PWM(19,50)              # GPIO19 as PWM output, with 50Hz frequency
p.start(7.5)                             # generate PWM signal with 7.5% duty cycle
time.sleep(4)
for x in range(0,5):                                                       # execute loop forever                                    
        p.ChangeDutyCycle(7.5)                   # change duty cycle for getting the servo position to 90º
        time.sleep(1)                                      # sleep for 1 second
        p.ChangeDutyCycle(12.5)                  # change duty cycle for getting the servo position to 180º
        time.sleep(1)                                     # sleep for 1 second
        p.ChangeDutyCycle(2.5)                  # change duty cycle for getting the servo position to 0º
        time.sleep(1)                                    # sleep for 1 second
p.ChangeDutyCycle(0)
p.stop()
IO.cleanup()

有什么想法吗?谢谢.

推荐答案

您使用的伺服是连续"伺服 - 所以您需要给它零速或"STOP"设置脉宽为1500us(根据网站http://www.domanrcobby.com/content/?150.html).我没有在 pi 上使用 PWM,但如果百分比是 50Hz 脉冲率(20ms 间隔),那么这应该是您的 7.5% 中心值.您需要确保伺服器在代码退出之前获得该脉冲.

The servo you are using is a "continuous" servo - so you need to give it the zero speed or "STOP" setting pulse width of 1500us (according to the website http://www.domanrchobby.com/content/?150.html). I haven't used PWM on the pi but if the percentages are of the 50Hz pulse rate (20ms interval) then that should be your 7.5% centre value. You need to make sure the servo gets that pulse before your code exits.

[Original] 您在退出时将占空比设置为 0,这可能意味着伺服没有任何脉冲.有些舵机在没有得到脉冲后会停止一段时间,但有些舵机(特别是数字舵机,但不是全部)会继续尝试从它们收到的最后一个脉冲开始达到设置.建议您将设置保留在您知道伺服可以达到的中档7.5,并在清理之前延迟一段时间.

[Original] You are setting the duty cycle to 0 when you exit, which will probably mean the servo doesn't get any pulses. Some servos will stop sometime after they don't get pulses, but some servos (particularly digital servos, but not all) will continue to try achieve the setting from the last pulse they received. Suggest you leave the setting at the mid range 7.5 which you know the servo can achieve and delay for a little while before cleaning up.

这篇关于树莓派伺服不停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆