树莓Pi分割错误Python

2024-04-19 06:48:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用Python编写的Raspberry Pi程序,用来控制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

在我介绍fullRight()方法上的stop()函数之前,一切都很好。问题是fullLeft()工作得很好,但是在fullRight()函数的第二个while循环之后,我出现了错误Segmentation Fault,程序崩溃了。我不知道该怎么办,为什么会这样。有人能帮我弄清楚是什么问题吗。。。在


Tags: iofalseinputoutputdefstopprintwhile