希望PiCar-S绕过对象

时间:2019-04-23 01:34:50

标签: python raspberry-pi

我正在使用带有线传感器和超声波回避传感器的PiCar-S。我们的PiCar处于黑色胶带迷宫中,我们希望pi-car只使用Line Sensors中的2个右传感器。我们将在迷宫上放置物体,当它通过Ultrasonic躲避传感器检测到物体时,它将停止并拍照(不可移动的物体标记为O,可移动的物体标记为X)将可移动的物体移离迷宫。对于无法移动的物体,PiCar需要绕过它们并继续回到生产线上。我如何开始在代码中修复此部分( BOLDED ):

def avoidObject(within_a_distance):
    within_a_distance = within_a_distance*2.54
    average = (objSensor.distance()+objSensor.distance()+objSensor.distance()) / 3
    if average <= within_a_distance:
        motors.stop()
        camera.start_preview()
        objResponse = input("What is this?: ")
        if objResponse == "X":
            print("MoOb...waiting for MoOb extraction...")
        **elif objResponse == "O":
            print("non-MoOb...going around...")
            while objSensor.distance() <= within_a_distance:
                motors.backward()
                time.sleep(1)
                motors.stop()
                steering.turn_left()
                motors.forward()
                time.sleep(1.5)
                steering.turn_right()
                time.sleep(1.5)
                steering.turn(1)
                steering.turn_straight()**

        elif objResponse == "Q":
            print("Found the Ore...collecting sample...Mission Complete")

    elif isMoObDetected(DISTANCE_THRESHOLD) == True:
        print("The cow says MooooooooOb!")
        while objSensor.distance() > 6:
            walk()

        #the car will wait until we move the moOb
        # and then continue to follow the line

    If object is X
    
motors.backward() #Go back to give it enough room to turn
    time.sleep(1) 
    steering.turn(135) #I want it to make a right
    Time.sleep(1)
    Steering.turn_straight() #Straighten  out
    Time.sleep(1)
    Steering.turn_left() #Make some sort of left turn to get back on the line
    Continue following the line

0 个答案:

没有答案