Raspberry Pi分段错误 - Python

时间:2013-07-31 18:36:51

标签: python segmentation-fault raspberry-pi raspbian

我在我的Raspberry Pi上有一个用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并且程序崩溃了。我不知道该怎么办,为什么会这样。有人可以帮我弄清问题是什么......

0 个答案:

没有答案