我找到了一个解决方案,使舵机逐步达到所需的角度,但这取决于舵机的当前角度。这是代码:
if servo_current angle > servo_desired_angle :
while(x=true) :
servo_current_angle -=1
duty_cycle = (((12.5-2.5)/(180-0) * servo_current_angle) +2.5
p.ChangeDutyCycle (duty_cycle)
time.sleep(0.01)
if servo_current angle = servo_desired_angle :
x = false
elif servo_current_angle < servo_desired_angle :
while(x=true) :
servo_current_angle +=1
duty_cycle = (((12.5-2.5)/(180-0) * servo_current_angle) +2.5
p.ChangeDutyCycle (duty_cycle)
time.sleep(0.01)
if servo_current angle = servo_desired_angle :
x = false
问题是如何知道伺服电流角度?