Updated class Search with finding line in forward mode, included stop when edge found
This commit is contained in:
parent
2d92c52e40
commit
9277c635cd
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user