我有一个激活两个伺服系统的程序。现在,代码激活伺服“A”,然后激活伺服“B”,然后在循环中重复此操作。我想添加第三个伺服,伺服“C”,我想设置它,以便它们在“A”和“B”循环两次后运行。所以顺序是:'A' 'B' 'A' 'B' 'C' 然后它会循环。现在伺服系统只能在循环上以“A”“B”“A”“B”的模式运行。我被卡住了,似乎无法弄清楚如何做到这一点。有任何想法吗?
import RPi.GPIO as GPIO
import time
aServoPin = 11
bServoPin = 13
GPIO.setmode(GPIO.BOARD)
GPIO.setup(aServoPin, GPIO.OUT)
GPIO.setup(bServoPin, GPIO.OUT)
aPwm = GPIO.PWM(aServoPin, 50)
bPwm = GPIO.PWM(bServoPin, 50)
aPwm.start(5)
bPwm.start(5)
while True:
a = 0
b = 0
while(a < 5):
for i in range(45, 135):
position = 1./18.*(i)+2
aPwm.ChangeDutyCycle(position)
time.sleep(0.005)
for i in range(135, 45, -1):
position = 1./18.*(i)+2
aPwm.ChangeDutyCycle(position)
time.sleep(0.005)
a = a + 1
while(b < 5):
for i in range(135, 45, -1):
position = 1./18.*(i)+2
bPwm.ChangeDutyCycle(position)
time.sleep(0.005)
for i in range(45, 135):
position = 1./18.*(i)+2
bPwm.ChangeDutyCycle(position)
time.sleep(0.005)
b = b + 1
time.sleep(1)
aPwm.stop()
bPwm.stop()
GPIO.cleanup()