我正在尝试将SG90伺服系统用作RC汽车的转向装置,我已经成功使它响应A(左)和D(右),但是几秒钟不输入任何指令后,它停止了响应并以一定角度锁定。
(问题的视频) https://youtu.be/K5UR1pHKGgA
import RPi.GPIO as GPIO
import pigpio
GPIO.setmode(GPIO.BOARD)
from time import sleep
import sys, tty, termios, time
import time
from pynput import keyboard
GPIO.setwarnings(False)
GPIO.setup(07, GPIO.OUT)
pwm=GPIO.PWM(07, 50)
pwm.start(7.5)
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def steering():
i = 1
while i == 1:
char = getch()
if(char == "a"):
pwm.ChangeDutyCycle(12.5)
print (" Left ")
if(char == "d"):
pwm.ChangeDutyCycle(2.5)
print (" Right ")
if(char == "x"):
print(" Program Ended ")
break
steering()
GPIO.cleanup()