Ejemplo n.º 1
0
def touch_collision_protocol(touch_sensor_tuple):
    stop_both()
    move_back(15, TIME)
    if touch_sensor_tuple[0]:
        turn_left(30, TIME)
        turn_right(-30, TIME)
    elif touch_sensor_tuple[1]:
        turn_left(-30, TIME)
        turn_right(30, TIME)
Ejemplo n.º 2
0
def ultrasonic_collision_protocol():
    stop_both()
    leds.set_color("LEFT", "RED")
    leds.set_color("RIGHT", "RED")

    move_back(15, TIME)
    if random.randint(1, 2) == 1:
        turn_left(-30, TIME)
        turn_right(30, TIME)
    else:
        turn_left(30, TIME)
        turn_right(-30, TIME)

    leds.set_color("LEFT", "GREEN")
    leds.set_color("RIGHT", "GREEN")
Ejemplo n.º 3
0
def color_collision_protocol(color_sensor_tuple):
    leds.set_color("LEFT", "RED")
    leds.set_color("RIGHT", "RED")

    if color_sensor_tuple[0]:
        stop_both()
        move_back(15, TIME)
        turn_left(-30, TIME)
        turn_right(30, TIME)
    elif color_sensor_tuple[2]:
        stop_both()
        move_back(15, TIME)
        turn_right(-30, TIME)
        turn_left(30, TIME)
    elif color_sensor_tuple[1]:
        move_back(15, 1)
        if random.randint(1, 2) == 1:
            turn_left(-10, TIME)
            turn_right(10, TIME)
        else:
            turn_right(-10, TIME)
            turn_left(10, TIME)

    leds.set_color("LEFT", "GREEN")
    leds.set_color("RIGHT", "GREEN")
Ejemplo n.º 4
0
def position_on_border_line(border_color):
    last_sensor_fired = "left"
    turn_speed = 5
    while not found_parking_spot(detect_line(border_color)):
        if cs_left.color == border_color:
            turn_right(-turn_speed, 0.1)
            turn_left(turn_speed, 0.2)
            last_sensor_fired = "left"
        elif cs_right.color == border_color:
            turn_left(-turn_speed, 0.1)
            turn_right(turn_speed, 0.2)
            last_sensor_fired = "right"
        elif cs_middle.color == border_color:
            move_back(10, 1)
            if last_sensor_fired == "right":
                turn_left(-10, 0.3)
                turn_right(10, 0.3)
            else:
                turn_right(-10, 0.3)
                turn_left(10, 0.3)
        else:
            move_both(10)