From 9277c635cd975874a03f394f4ca8f319194832ea Mon Sep 17 00:00:00 2001 From: Tanja Sukal Date: Tue, 19 Sep 2023 13:18:28 +0000 Subject: [PATCH] Updated class Search with finding line in forward mode, included stop when edge found --- Color_Sorting/Program/Python_Obstical_sorter.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Color_Sorting/Program/Python_Obstical_sorter.py b/Color_Sorting/Program/Python_Obstical_sorter.py index 274e980..1d7a8f6 100644 --- a/Color_Sorting/Program/Python_Obstical_sorter.py +++ b/Color_Sorting/Program/Python_Obstical_sorter.py @@ -54,12 +54,14 @@ def search (): nr_orange, o_block = pixy2.get_blocks(orange, 2) nr_green, g_block = pixy2.get_blocks(green, 2) if cs.reflected_light_intensity < 15: # if outline is reached change state to edge + tank.stop() last_state = state state = 5 elif us.distance_centimeters < 10: # if a block is currently in the arms change to sort last_state = state state = 3 elif nr_orange > 0: # when orange block is found then change to get + tank.stop() last_state = state state = 2 elif nr_green > 0: # when green block is found then change to avoid @@ -70,6 +72,10 @@ def search (): tank.on(fast,fast) sleep(0.2) j+=1 + if cs.reflected_light_intensity <= 8 : + tank.stop() + last_state = state + state = 5 gyro.reset() j=0 # Reset control variable @@ -116,6 +122,7 @@ def get (): m_right.on(SpeedPercent(-slow)) m_left.on(SpeedPercent(slow)) if cs.reflected_light_intensity < 15: # robot detected line change to edge + tank.stop() last_state = state state = 5 # When colorsensor detects line then switch state @@ -132,6 +139,7 @@ def sort (): # search for green blocks nr_green, g_block = pixy2.get_blocks(green, 2) if cs.reflected_light_intensity < 15: # when reached line change to edge + tank.stop() last_state = state state = 5 elif nr_green > 0: