舵機控制訊號腳頻寬及時序維基百科上的資料
大多數伺服馬達以時鐘的12點為中心點是脈衝寬度1.5m,
1 ms 的脈衝寬度當作 -90 度,
2 ms 則為 +90 度
但要看實際舵機的擺動角度
樹莓派GPIO接腳
Black – comes to GND (pin 6) from the Pi
Red – comes to 3V3 (pin 1) from the Pi
Yellow/Orange – to a free GPIO pin (e.g., GPIO17, pin 11)
為了安全性可在Data PIN串接1k電阻,防止樹莓派燒毀
(因舵機的電壓為4~6V高於Raspberry pi3.3V)
python 控制程式如下:
import RPi.GPIO as GPIO import time servoPIN = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(servoPIN, GPIO.OUT) p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz #給ChangeDutyCycle及start的函數的參數為工作週期(dc)範圍0.0 <= dc <= 100.0 p.start(0) # Initialization try: while True: p.ChangeDutyCycle(2.5) time.sleep(0.5) p.ChangeDutyCycle(5) time.sleep(0.5) p.ChangeDutyCycle(7.5) time.sleep(0.5) p.ChangeDutyCycle(10) time.sleep(0.5) p.ChangeDutyCycle(12.5) time.sleep(0.5) p.ChangeDutyCycle(10) time.sleep(0.5) p.ChangeDutyCycle(7.5) time.sleep(0.5) p.ChangeDutyCycle(5) time.sleep(0.5) p.ChangeDutyCycle(2.5) time.sleep(0.5) except KeyboardInterrupt: p.stop() finally: GPIO.cleanup()
#如舵機有輕微抖動你可稍微觸發ChangeDutyCycle(0)
#
MG996R servos to have minimum pulse width around 771 and maximum around 2193
#when running off 5v .
#目前台灣查到MG996R舵機(180度)的操控頻率,脈寬信號 500-1500-2500,對應的角度是0度~+-90度
#另外公式思考? ( (MaxPW – MinPW) * (180 / MaxAngle) ) + MinPW
沒有留言:
張貼留言