1.00 on god frfr
parent
b7d96846f0
commit
18dcbeb506
|
|
@ -6,20 +6,6 @@ import sys
|
||||||
import runloop
|
import runloop
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Implementation of Basic operations and misc. ##############################################
|
|
||||||
|
|
||||||
# await mp.move_for_degrees(mp.PAIR_1, 360, 45, velocity=280)
|
|
||||||
|
|
||||||
# motor.run_for_degrees(portNum, 200, 300)
|
|
||||||
# await runloop.sleep_ms(2000)
|
|
||||||
|
|
||||||
# mp.move_tank(mp.PAIR_1, 280, -280)
|
|
||||||
# await runloop.sleep_ms(2000)
|
|
||||||
|
|
||||||
# WANTED_COLOR = color.BLACK
|
|
||||||
|
|
||||||
# Productive Code ###########################################################################
|
|
||||||
|
|
||||||
BLACK = 0
|
BLACK = 0
|
||||||
GREEN = 6
|
GREEN = 6
|
||||||
WHITE = 10
|
WHITE = 10
|
||||||
|
|
@ -56,7 +42,7 @@ async def avoid_obstacle(speed=100):
|
||||||
mp.move_tank(mp.PAIR_1, -speed, -speed)
|
mp.move_tank(mp.PAIR_1, -speed, -speed)
|
||||||
while cs.color(port.B) != BLACK:
|
while cs.color(port.B) != BLACK:
|
||||||
mp.move_tank(mp.PAIR_1, 10, -110)
|
mp.move_tank(mp.PAIR_1, 10, -110)
|
||||||
#await turn_right(85)
|
|
||||||
async def move_on_color():
|
async def move_on_color():
|
||||||
won = False
|
won = False
|
||||||
speed = 100
|
speed = 100
|
||||||
|
|
@ -65,7 +51,6 @@ async def move_on_color():
|
||||||
last_seen_black = ""
|
last_seen_black = ""
|
||||||
|
|
||||||
old = time.ticks_ms()
|
old = time.ticks_ms()
|
||||||
# print("initial old: " + str(old))
|
|
||||||
while not won:
|
while not won:
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,7 +65,6 @@ async def move_on_color():
|
||||||
GREEN = 6
|
GREEN = 6
|
||||||
WHITE = 10
|
WHITE = 10
|
||||||
RED = 9
|
RED = 9
|
||||||
straight = False
|
|
||||||
|
|
||||||
# Distanzsensor
|
# Distanzsensor
|
||||||
ds_front = ds.distance(port.D)
|
ds_front = ds.distance(port.D)
|
||||||
|
|
@ -93,7 +77,6 @@ async def move_on_color():
|
||||||
speed = -100
|
speed = -100
|
||||||
|
|
||||||
# --- LOGIK NUR MIT FARBEN ---
|
# --- LOGIK NUR MIT FARBEN ---
|
||||||
# Finish line logik
|
|
||||||
if left_color == RED or right_color == RED:
|
if left_color == RED or right_color == RED:
|
||||||
won = True
|
won = True
|
||||||
|
|
||||||
|
|
@ -104,9 +87,12 @@ async def move_on_color():
|
||||||
# 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:
|
||||||
saw_green_left = True
|
saw_green_left = True
|
||||||
|
old = time.ticks_ms()
|
||||||
|
|
||||||
|
|
||||||
elif right_color == GREEN and left_color != GREEN:
|
elif right_color == GREEN and left_color != GREEN:
|
||||||
saw_green_right = True
|
saw_green_right = True
|
||||||
|
old = time.ticks_ms()
|
||||||
|
|
||||||
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
# Beide Sensoren sehen Grün (z.B. Kreuzung / Markierung)
|
||||||
elif left_color == GREEN and right_color == GREEN:
|
elif left_color == GREEN and right_color == GREEN:
|
||||||
|
|
@ -136,31 +122,30 @@ async def move_on_color():
|
||||||
|
|
||||||
# Schwarz-Logik
|
# Schwarz-Logik
|
||||||
elif front_sens > 25 and last_seen_black == "left":
|
elif front_sens > 25 and last_seen_black == "left":
|
||||||
#time.sleep_ms(100)
|
|
||||||
while cs.reflection(port.C) > 25: # front_sensor
|
while cs.reflection(port.C) > 25: # front_sensor
|
||||||
if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE: # left_color
|
if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE: # left_color
|
||||||
last_seen_black = "left"
|
last_seen_black = "left"
|
||||||
|
|
||||||
if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE: # right_color
|
if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE: # right_color
|
||||||
last_seen_black = "right"
|
last_seen_black = "right"
|
||||||
#mp.move_tank(mp.PAIR_1, speed, speed)
|
|
||||||
#time.sleep_ms(1000)
|
|
||||||
break
|
break
|
||||||
|
old = time.ticks_ms()
|
||||||
mp.move_tank(mp.PAIR_1, -125, -20)
|
mp.move_tank(mp.PAIR_1, -125, -20)
|
||||||
|
|
||||||
|
|
||||||
elif front_sens > 25 and last_seen_black == "right":
|
elif front_sens > 25 and last_seen_black == "right":
|
||||||
#time.sleep_ms(100)
|
|
||||||
while cs.reflection(port.C) > 25:
|
while cs.reflection(port.C) > 25:
|
||||||
if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE:
|
if cs.color(port.F) == BLACK and cs.color(port.B) == WHITE:
|
||||||
last_seen_black = "right"
|
last_seen_black = "right"
|
||||||
|
|
||||||
if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE:
|
if cs.color(port.B) == BLACK and cs.color(port.F) == WHITE:
|
||||||
last_seen_black = "left"
|
last_seen_black = "left"
|
||||||
#mp.move_tank(mp.PAIR_1, speed, speed)
|
|
||||||
#time.sleep_ms(1000)
|
|
||||||
break
|
break
|
||||||
|
old = time.ticks_ms()
|
||||||
mp.move_tank(mp.PAIR_1, -20, -125)
|
mp.move_tank(mp.PAIR_1, -20, -125)
|
||||||
|
|
||||||
elif right_color == BLACK or left_color == BLACK:
|
elif right_color == BLACK or left_color == BLACK:
|
||||||
|
old = time.ticks_ms()
|
||||||
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)
|
time.sleep_ms(20)
|
||||||
|
|
@ -170,25 +155,18 @@ async def move_on_color():
|
||||||
elif left_color == BLACK and right_color == WHITE:
|
elif left_color == BLACK and right_color == WHITE:
|
||||||
last_seen_black = "left"
|
last_seen_black = "left"
|
||||||
|
|
||||||
|
|
||||||
# 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:
|
||||||
last_seen_black = "right"
|
last_seen_black = "right"
|
||||||
|
|
||||||
# Beide Weiß, Front Schwarz → geradeaus
|
# Beide Weiß, Front Schwarz → geradeaus
|
||||||
elif cs.color(port.B) == WHITE and cs.color(port.F) == WHITE and front_sens < 25:
|
elif cs.color(port.B) == WHITE and cs.color(port.F) == WHITE and front_sens < 25:
|
||||||
straight = True
|
if time.ticks_diff(time.ticks_ms(), old) > 1000:
|
||||||
|
last_seen_black = ""
|
||||||
|
old = time.ticks_ms()
|
||||||
mp.move_tank(mp.PAIR_1, speed, speed)
|
mp.move_tank(mp.PAIR_1, speed, speed)
|
||||||
runloop.sleep_ms(50)
|
runloop.sleep_ms(50)
|
||||||
|
|
||||||
|
|
||||||
# if time.ticks_diff(time.ticks_ms(), old) > 5000:
|
|
||||||
# print(time.ticks_diff(time.ticks_ms(), old))
|
|
||||||
# straight = True
|
|
||||||
|
|
||||||
# Alles Weiß
|
|
||||||
# elif cs.color(port.B) == WHITE and cs.color(port.F) == WHITE and front_sens > 25:
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
mp.pair(mp.PAIR_1, port.A, port.E)
|
mp.pair(mp.PAIR_1, port.A, port.E)
|
||||||
await move_on_color()
|
await move_on_color()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue