Merged
parent
a80071a0df
commit
b75bcda25a
|
|
@ -52,7 +52,10 @@ async def avoid_obstacle():
|
|||
await turn_right(90)
|
||||
|
||||
async def move_on_color():
|
||||
while True:
|
||||
won = False
|
||||
old = time.ticks_ms
|
||||
|
||||
while not won:
|
||||
|
||||
# Farbcodes lesen
|
||||
left_color = cs.color(port.C)
|
||||
|
|
@ -62,15 +65,21 @@ async def move_on_color():
|
|||
BLACK = 0
|
||||
GREEN = 6
|
||||
WHITE = 10
|
||||
|
||||
RED = 9
|
||||
strait = False
|
||||
# Distanzsensor
|
||||
ds_front = ds.distance(port.F)
|
||||
|
||||
# --- LOGIK NUR MIT FARBEN ---
|
||||
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||
if ds_front < 75:
|
||||
# Finish line logik
|
||||
if left_color == RED or right_color == RED:
|
||||
won = True
|
||||
break
|
||||
|
||||
elif ds_front < 75:
|
||||
await avoid_obstacle()
|
||||
|
||||
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||
elif left_color == GREEN and right_color == GREEN:
|
||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
||||
time.sleep_ms(2300)
|
||||
|
|
@ -80,7 +89,7 @@ async def move_on_color():
|
|||
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||
time.sleep_ms(700)
|
||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
||||
time.sleep_ms(1200)
|
||||
time.sleep_ms(1050)
|
||||
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||
time.sleep_ms(300)
|
||||
|
||||
|
|
@ -89,10 +98,12 @@ async def move_on_color():
|
|||
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||
time.sleep_ms(700)
|
||||
mp.move_tank(mp.PAIR_1, 100, -100)
|
||||
time.sleep_ms(1200)
|
||||
time.sleep_ms(1050)
|
||||
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||
time.sleep_ms(300)
|
||||
|
||||
elif right_color == BLACK and left_color == BLACK:
|
||||
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||
# Linker Sensor ist Schwarz, rechter Weiß → sanft nach links
|
||||
elif left_color == BLACK and right_color == WHITE:
|
||||
mp.move_tank(mp.PAIR_1, -50, 50)
|
||||
|
|
@ -103,6 +114,7 @@ async def move_on_color():
|
|||
|
||||
# Beide Weiß → geradeaus (vermutlich neben der Linie)
|
||||
elif left_color == WHITE and right_color == WHITE:
|
||||
strait = True
|
||||
mp.move(mp.PAIR_1, 0, velocity=150)
|
||||
|
||||
# TODO: ---- Weiß auf beiden Seiten = Linie verloren ----
|
||||
|
|
@ -115,6 +127,13 @@ async def move_on_color():
|
|||
elif gradient > 50:
|
||||
mp.move(mp.PAIR_1, 0, velocity=100)
|
||||
|
||||
if strait:
|
||||
if time.ticks_diff(time.ticks_ms(), old) > 2000:
|
||||
old = time.ticks_ms
|
||||
mp.move_tank(mp.PAIR_1, 100, 50)
|
||||
else:
|
||||
old = time.ticks_ms
|
||||
|
||||
async def main():
|
||||
mp.pair(mp.PAIR_1, port.A, port.D)
|
||||
await move_on_color()
|
||||
|
|
|
|||
Loading…
Reference in New Issue