diff --git a/src/main.llsp3 b/src/main.llsp3 index fa3b404..4e44427 100644 --- a/src/main.llsp3 +++ b/src/main.llsp3 @@ -60,7 +60,7 @@ async def move_on_color(): while not won: - + # Farbcodes lesen left_color = cs.color(port.B) right_color = cs.color(port.F) @@ -74,7 +74,6 @@ async def move_on_color(): WHITE = 10 RED = 9 straight = False - turn_way_if_lost_right = True # Distanzsensor ds_front = ds.distance(port.D) @@ -109,7 +108,7 @@ async def move_on_color(): saw_green_left = False mp.move_tank(mp.PAIR_1, -speed, speed) time.sleep_ms(2300) - + elif saw_green_left and left_color == BLACK: saw_green_left = False mp.move_tank(mp.PAIR_1, speed, speed) @@ -129,24 +128,42 @@ async def move_on_color(): mp.move_tank(mp.PAIR_1, speed, speed) time.sleep_ms(300) + # Schwar-Logik elif front_sens > 25 and last_seen_black == "left": - while cs.reflection(port.C) > 25: - mp.move_tank(mp.PAIR_1, -100, 50) + #time.sleep_ms(100) + while cs.reflection(port.C) > 25: + if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE: + last_seen_black = "left" + if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE: + last_seen_black = "right" + #mp.move_tank(mp.PAIR_1, speed, speed) + #time.sleep_ms(1000) + break + mp.move_tank(mp.PAIR_1, -75, 50) + elif front_sens > 25 and last_seen_black == "right": + #time.sleep_ms(100) while cs.reflection(port.C) > 25: - mp.move_tank(mp.PAIR_1, 50, -100) + if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE: + last_seen_black = "right" + if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE: + last_seen_black = "left" + #mp.move_tank(mp.PAIR_1, speed, speed) + #time.sleep_ms(1000) + break + mp.move_tank(mp.PAIR_1, 50, -75) elif right_color == BLACK or left_color == BLACK: if right_color == BLACK and left_color == BLACK: mp.move_tank(mp.PAIR_1, speed, speed) time.sleep_ms(20) - + # Linker Sensor ist Schwarz, rechter Weiß → sanft nach links elif left_color == BLACK and right_color == WHITE: last_seen_black = "left" - + # Rechter Schwarz, linker Weiß → sanft nach rechts elif right_color == BLACK and left_color == WHITE: @@ -159,17 +176,18 @@ async def move_on_color(): runloop.sleep_ms(50) if straight: - if time.ticks_diff(time.ticks_ms(), old) > 2750: + if time.ticks_diff(time.ticks_ms(), old) > 200: old = time.ticks_ms() - if turn_way_if_lost_right: - mp.move_tank(mp.PAIR_1, speed, 0) - await runloop.sleep_ms(200) - turn_way_if_lost_right = not turn_way_if_lost_right - else: - mp.move_tank(mp.PAIR_1, 0, speed) - await runloop.sleep_ms(200) - turn_way_if_lost_right = not turn_way_if_lost_right - + # if turn_way_if_lost_right: + # mp.move_tank(mp.PAIR_1, speed, 0) + # await runloop.sleep_ms(200) + # turn_way_if_lost_right = not turn_way_if_lost_right + # else: + # mp.move_tank(mp.PAIR_1, 0, speed) + # await runloop.sleep_ms(200) + # turn_way_if_lost_right = not turn_way_if_lost_right + if front_sens > 25: + last_seen_black = "" else: old = time.ticks_ms()