서보를 제어하는 ADAFRUIT의 일부 Python 예제 스크립트가 있는데 작동합니다.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)
'sys.argv'이 목록입니다. 'sys.argv [1]'을 의미 했습니까? –
'sys.argv'는 목록을 반환합니다. 이것을 시도해보십시오 :'servoMin, servoMin = map (int, sys.argv [1 : 3])' –