src/main.llsp3 aktualisiert
parent
7c827e385e
commit
7a46ef0dc4
|
|
@ -1,8 +1,6 @@
|
|||
from hub import button, port, motion_sensor as ms
|
||||
import motor
|
||||
from hub import port, motion_sensor as ms
|
||||
import motor_pair as mp
|
||||
import color_sensor as cs
|
||||
import color
|
||||
import sys
|
||||
import runloop
|
||||
import time
|
||||
|
|
@ -53,10 +51,11 @@ def flipflop(state, r, s):
|
|||
# Productive Code ###########################################################################
|
||||
|
||||
async def move_on_color():
|
||||
start_time = time.time()
|
||||
print(ms.tilt_angles())
|
||||
|
||||
while True:
|
||||
won = False
|
||||
old = time.ticks_ms
|
||||
|
||||
while not won:
|
||||
|
||||
# Farbcodes lesen
|
||||
left_color = cs.color(port.C)
|
||||
|
|
@ -66,11 +65,17 @@ async def move_on_color():
|
|||
BLACK = 0
|
||||
GREEN = 6
|
||||
WHITE = 10
|
||||
RED = 9
|
||||
strait = False
|
||||
|
||||
# --- LOGIK NUR MIT FARBEN ---
|
||||
# Finish line logik
|
||||
if left_color == RED or right_color == RED:
|
||||
won = True
|
||||
break;
|
||||
|
||||
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||
if left_color == GREEN and right_color == GREEN:
|
||||
elif left_color == GREEN and right_color == GREEN:
|
||||
mp.move_tank(mp.PAIR_1, -100, 100)
|
||||
time.sleep_ms(2300)
|
||||
|
||||
|
|
@ -79,7 +84,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)
|
||||
|
||||
|
|
@ -88,11 +93,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 +109,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 ----
|
||||
|
|
@ -113,7 +120,14 @@ async def move_on_color():
|
|||
mp.move(mp.PAIR_1, 0, velocity=350)
|
||||
|
||||
elif gradient > 50:
|
||||
mp.move(mp.PAIR_1, 0, velocity=100)
|
||||
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)
|
||||
|
|
@ -121,4 +135,4 @@ async def main():
|
|||
|
||||
sys.exit()
|
||||
|
||||
runloop.run(main())
|
||||
runloop.run(main())
|
||||
Loading…
Reference in New Issue