src/main.llsp3 aktualisiert
parent
6560ce3cac
commit
244cdfdd7a
|
|
@ -54,6 +54,8 @@ async def move_on_color():
|
||||||
won = False
|
won = False
|
||||||
old = time.ticks_ms()
|
old = time.ticks_ms()
|
||||||
speed = 100
|
speed = 100
|
||||||
|
saw_green_left = False
|
||||||
|
saw_green_right = False
|
||||||
|
|
||||||
while not won:
|
while not won:
|
||||||
|
|
||||||
|
|
@ -69,16 +71,16 @@ async def move_on_color():
|
||||||
RED = 9
|
RED = 9
|
||||||
straight = False
|
straight = False
|
||||||
turn_way_if_lost_right = True
|
turn_way_if_lost_right = True
|
||||||
|
|
||||||
# Distanzsensor
|
# Distanzsensor
|
||||||
ds_front = ds.distance(port.D)
|
ds_front = ds.distance(port.D)
|
||||||
|
|
||||||
if gradient < -150:
|
if gradient < -120:
|
||||||
speed = 400
|
speed = -80
|
||||||
|
|
||||||
elif gradient > 50:
|
elif gradient > 50:
|
||||||
speed = 50
|
speed = -50
|
||||||
else:
|
else:
|
||||||
speed = 100
|
speed = -100
|
||||||
|
|
||||||
# --- LOGIK NUR MIT FARBEN ---
|
# --- LOGIK NUR MIT FARBEN ---
|
||||||
# Finish line logik
|
# Finish line logik
|
||||||
|
|
@ -87,27 +89,38 @@ async def move_on_color():
|
||||||
break
|
break
|
||||||
|
|
||||||
elif ds_front < 75 and ds_front > -1:
|
elif ds_front < 75 and ds_front > -1:
|
||||||
await avoid_obstacle()
|
#await avoid_obstacle()
|
||||||
|
pass
|
||||||
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
|
||||||
elif left_color == GREEN and right_color == GREEN:
|
|
||||||
mp.move_tank(mp.PAIR_1, -speed, speed)
|
|
||||||
time.sleep_ms(2300)
|
|
||||||
|
|
||||||
# Linker Sensor sieht Grün → Linksabbiegen
|
# Linker Sensor sieht Grün → Linksabbiegen
|
||||||
elif left_color == GREEN and right_color != GREEN:
|
elif left_color == GREEN and right_color != GREEN:
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
saw_green_left = True
|
||||||
time.sleep_ms(700)
|
|
||||||
|
elif right_color == GREEN and left_color != GREEN:
|
||||||
|
saw_green_right = True
|
||||||
|
|
||||||
|
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||||
|
elif left_color == GREEN and right_color == GREEN:
|
||||||
|
saw_green_right = False
|
||||||
|
saw_green_left = False
|
||||||
mp.move_tank(mp.PAIR_1, -speed, speed)
|
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)
|
||||||
|
time.sleep_ms(1200)
|
||||||
|
mp.move_tank(mp.PAIR_1, speed, -speed)
|
||||||
time.sleep_ms(1050)
|
time.sleep_ms(1050)
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
mp.move_tank(mp.PAIR_1, speed, speed)
|
||||||
time.sleep_ms(300)
|
time.sleep_ms(300)
|
||||||
|
|
||||||
# Rechter Sensor sieht Grün → Rechtsabbiegen
|
# Rechter Sensor sieht Grün → Rechtsabbiegen
|
||||||
elif right_color == GREEN and left_color != GREEN:
|
elif saw_green_right and right_color == BLACK:
|
||||||
|
saw_green_right = False
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
mp.move_tank(mp.PAIR_1, speed, speed)
|
||||||
time.sleep_ms(700)
|
time.sleep_ms(1200)
|
||||||
mp.move_tank(mp.PAIR_1, speed, -speed)
|
mp.move_tank(mp.PAIR_1, -speed, speed)
|
||||||
time.sleep_ms(1050)
|
time.sleep_ms(1050)
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
mp.move_tank(mp.PAIR_1, speed, speed)
|
||||||
time.sleep_ms(300)
|
time.sleep_ms(300)
|
||||||
|
|
@ -115,13 +128,17 @@ async def move_on_color():
|
||||||
elif right_color == BLACK or left_color == BLACK:
|
elif right_color == BLACK or left_color == BLACK:
|
||||||
if right_color == BLACK and left_color == BLACK:
|
if right_color == BLACK and left_color == BLACK:
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
mp.move_tank(mp.PAIR_1, speed, speed)
|
||||||
|
time.sleep_ms(20)
|
||||||
|
|
||||||
|
|
||||||
# Linker Sensor ist Schwarz, rechter Weiß → sanft nach links
|
# Linker Sensor ist Schwarz, rechter Weiß → sanft nach links
|
||||||
elif left_color == BLACK and right_color == WHITE:
|
elif left_color == BLACK and right_color == WHITE:
|
||||||
mp.move_tank(mp.PAIR_1, speed-100, speed)
|
mp.move_tank(mp.PAIR_1, speed, -(int (speed / 4)))
|
||||||
|
|
||||||
|
|
||||||
# Rechter Schwarz, linker Weiß → sanft nach rechts
|
# Rechter Schwarz, linker Weiß → sanft nach rechts
|
||||||
elif right_color == BLACK and left_color == WHITE:
|
elif right_color == BLACK and left_color == WHITE:
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed-100)
|
mp.move_tank(mp.PAIR_1, -(int (speed / 4)), speed)
|
||||||
|
|
||||||
# Beide Weiß → geradeaus (vermutlich neben der Linie)
|
# Beide Weiß → geradeaus (vermutlich neben der Linie)
|
||||||
elif left_color == WHITE and right_color == WHITE:
|
elif left_color == WHITE and right_color == WHITE:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue