我的树莓派上有一个用 Python 编写的程序,用于控制 2 个电机。这是一些代码:
def fullLeft() :
speed1 = motor1Speed
speed2 = motor2Speed
setMotor1Speed(100)
setMotor2Speed(-100)
while io.input(forward1Control) and io.input(backward2Control) :
print( "%d : %d" %(motor1Speed,motor2Speed))
stop()
setMotor1Speed(speed1)
setMotor2Speed(speed2)
print("Left Done")
def fullRight() :
speed1 = motor1Speed
speed2 = motor2Speed
setMotor1Speed(-100)
setMotor2Speed(100)
while io.input(forward2Control) and io.input(backward1Control) :
print( "%d : %d" %(motor1Speed,motor2Speed))
stop()
setMotor1Speed(speed1)
setMotor2Speed(speed2)
print("Right Done")
def stop () :
io.output(forward1Out,False)
motor1Forward.stop()
io.output(backward1Out, False)
motor1Backward.stop()
io.output(forward2Out, False)
motor2Forward.stop()
io.output(backward2Out, False)
motor2Backward.stop()
global motor1Speed
motor1Speed = 0
global motor2Speed
motor2Speed = 0
stop()
在我介绍该方法的功能之前,一切都运行良好fullRight()
。问题是它fullLeft()
工作得很好,但是在fullRight()
函数的第二个 while 循环之后,我有错误Segmentation Fault
并且程序崩溃了。我不知道该怎么做,为什么会这样。谁能帮我弄清楚问题是什么...