我有一些来自 ADAFRUIT 的 python 示例脚本,它控制着一个伺服系统,它可以工作!
我想通过从命令行调用两个值来执行它以更改 ServoMin 和 ServoMax 值。我遇到的问题是,当我import sys
设置它时它似乎不喜欢它ServoMin = (sys.argv)
。我不确定为什么它不接受 int 或 str。有任何想法吗?
这是代码主体:
#!/usr/bin/python
from Adafruit_PWM_Servo_Driver import PWM
import time
import sys
# ===========================================================================
# Example Code
# ===========================================================================
# Initialise the PWM device using the default address
# bmp = PWM(0x40, debug=True)
pwm = PWM(0x50, debug=True)
servoMin = 150 # Min pulse length out of 4096
servoMax = 600 # Max pulse length out of 4096
def setServoPulse(channel, pulse):
pulseLength = 1000000 # 1,000,000 us per second
pulseLength /= 60 # 60 Hz
print "%d us per period" % pulseLength
pulseLength /= 4096 # 12 bits of resolution
print "%d us per bit" % pulseLength
pulse *= 1000
pulse /= pulseLength
pwm.setPWM(channel, 0, pulse)
pwm.setPWMFreq(60) # Set frequency to 60 Hz
while (True):
# Change speed of continuous servo on channel O
pwm.setPWM(0, 0, servoMin)
time.sleep(1)
pwm.setPWM(0, 0, servoMax)
time.sleep(1)