New drive system
parent
86b243a9b0
commit
7c827e385e
|
|
@ -56,53 +56,64 @@ async def move_on_color():
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
print(ms.tilt_angles())
|
print(ms.tilt_angles())
|
||||||
|
|
||||||
left = cs.reflection(port.C)
|
|
||||||
right = cs.reflection(port.E)
|
|
||||||
green = 25
|
|
||||||
black = 18
|
|
||||||
white = 90
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if left < green and left > black and right < green and right > black:
|
# Farbcodes lesen
|
||||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
left_color = cs.color(port.C)
|
||||||
|
right_color = cs.color(port.E)
|
||||||
|
gradient = ms.tilt_angles()[2]
|
||||||
|
# Farbcodes
|
||||||
|
BLACK = 0
|
||||||
|
GREEN = 6
|
||||||
|
WHITE = 10
|
||||||
|
|
||||||
elif left < green and left > black:
|
# --- LOGIK NUR MIT FARBEN ---
|
||||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
|
||||||
|
|
||||||
elif right < green and right > black:
|
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||||
|
if left_color == GREEN and right_color == GREEN:
|
||||||
|
mp.move_tank(mp.PAIR_1, -100, 100)
|
||||||
|
time.sleep_ms(2300)
|
||||||
|
|
||||||
|
# Linker Sensor sieht Grün → Linksabbiegen
|
||||||
|
elif left_color == GREEN and right_color != GREEN:
|
||||||
|
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||||
|
time.sleep_ms(700)
|
||||||
|
mp.move_tank(mp.PAIR_1, -100, 100)
|
||||||
|
time.sleep_ms(1200)
|
||||||
|
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||||
|
time.sleep_ms(300)
|
||||||
|
|
||||||
|
# Rechter Sensor sieht Grün → Rechtsabbiegen
|
||||||
|
elif right_color == GREEN and left_color != GREEN:
|
||||||
|
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||||
|
time.sleep_ms(700)
|
||||||
mp.move_tank(mp.PAIR_1, 100, -100)
|
mp.move_tank(mp.PAIR_1, 100, -100)
|
||||||
|
time.sleep_ms(1200)
|
||||||
elif left < black and right > white:
|
mp.move_tank(mp.PAIR_1, 100, 100)
|
||||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
time.sleep_ms(300)
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Rechter Schwarz, linker Weiß → sanft nach rechts
|
||||||
|
elif right_color == BLACK and left_color == WHITE:
|
||||||
|
mp.move_tank(mp.PAIR_1, 50, -50)
|
||||||
|
|
||||||
# while True:
|
# Beide Weiß → geradeaus (vermutlich neben der Linie)
|
||||||
# roll_value = ms.tilt_angles()[2]
|
elif left_color == WHITE and right_color == WHITE:
|
||||||
# # Change to switch case
|
mp.move(mp.PAIR_1, 0, velocity=150)
|
||||||
# if cs.reflection(port.C) < 60:
|
|
||||||
# mp.move_tank(mp.PAIR_1, -100, 100)
|
|
||||||
# elif cs.reflection(port.E) < 60:
|
|
||||||
# mp.move_tank(mp.PAIR_1, 100, -100)
|
|
||||||
# elif roll_value < -150: # uphill function
|
|
||||||
# mp.move(mp.PAIR_1, 0, velocity=450)
|
|
||||||
# else:
|
|
||||||
# mp.move(mp.PAIR_1, 0, velocity=200)
|
|
||||||
|
|
||||||
# Geradeaus
|
# TODO: ---- Weiß auf beiden Seiten = Linie verloren ----
|
||||||
|
# wenn links == weiß UND rechts == weiß:
|
||||||
|
# langsam drehen bis schwarz gefunden
|
||||||
|
|
||||||
# linkskurve
|
elif gradient < -150:
|
||||||
# rechtskurve
|
mp.move(mp.PAIR_1, 0, velocity=350)
|
||||||
|
|
||||||
# Kreuzung (grüner Punkt)
|
elif gradient > 50:
|
||||||
# wenn grün, dann biege um 90 Grad in die richtung ab (wenn vor schwarzer linie)
|
mp.move(mp.PAIR_1, 0, velocity=100)
|
||||||
|
|
||||||
# Sackgasse (= zwei grüne Punkte)
|
|
||||||
# -> Drehung 180 Grad
|
|
||||||
|
|
||||||
# Bergauf
|
|
||||||
# Bergab
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
mp.pair(mp.PAIR_1, port.A, port.D)
|
mp.pair(mp.PAIR_1, port.A, port.D)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue