stops now only on red/blue knots
This commit is contained in:
parent
1f1c19232a
commit
23ddc2c24a
2 changed files with 37 additions and 14 deletions
|
@ -44,10 +44,12 @@ class Move:
|
|||
self._wheel_r.speed_set(24)
|
||||
self._wheel_l.run()
|
||||
self._wheel_r.run()
|
||||
while(self._bumper.value() == False):
|
||||
|
||||
while(not (self._bumper.value() or self._sensor.isRed() or self._sensor.isBlue())):
|
||||
self._wheel_l.speed_set(48 - self._sensor.getbrightness())
|
||||
self._wheel_r.speed_set(self._sensor.getbrightness())
|
||||
if(isknownstation == False):
|
||||
pass #run odometry stuff here
|
||||
|
||||
self._wheel_l.stop()
|
||||
self._wheel_r.stop()
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import ev3dev.ev3 as ev3
|
||||
from enum import Enum, unique
|
||||
|
||||
|
||||
@unique
|
||||
class Color(Enum):
|
||||
RED = (80, 95, 20, 40, 15, 30)
|
||||
BLUE = (10, 25, 60, 80, 70, 90)
|
||||
|
||||
def __init__(self, rmin, rmax, gmin, gmax, bmin, bmax):
|
||||
self.rmin = rmin
|
||||
self.rmax = rmax
|
||||
self.gmin = gmin
|
||||
self.gmax = gmax
|
||||
self.bmin = bmin
|
||||
self.bmax = bmax
|
||||
|
||||
|
||||
'''
|
||||
add enum for color definitions (type should be tupel of int's).
|
||||
|
@ -18,22 +34,27 @@ class Sensor:
|
|||
def __init__(self):
|
||||
self._sensor = ev3.ColorSensor()
|
||||
self._sensor.mode = 'COL-REFLECT'
|
||||
|
||||
def iscolor(self, color):
|
||||
if(self._sensor.mode == 'RGB-RAW'):
|
||||
curcol = self._sensor.bin_data("hhh")
|
||||
if curcol == curcol:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
print("ERROR: incorrect sensor mode:", self._sensor.mode)
|
||||
self.foundColor = False
|
||||
|
||||
def getbrightness(self):
|
||||
if(self._sensor.mode == 'COL-REFLECT'):
|
||||
return self._sensor.value()
|
||||
self._sensor.mode = 'COL-REFLECT'
|
||||
return self._sensor.value()
|
||||
|
||||
def isRed(self):
|
||||
self._sensor.mode = 'RGB-RAW'
|
||||
r, g, b = self._sensor.bin_data("hhh")
|
||||
if(Color.RED.rmin <= r <= Color.RED.rmax and Color.RED.gmin <= g <= Color.RED.gmax and Color.RED.bmin <= b <= Color.RED.bmax):
|
||||
return True
|
||||
else:
|
||||
print("ERROR: incorrect sensor mode:", self._sensor.mode)
|
||||
return False
|
||||
|
||||
def isBlue(self):
|
||||
self._sensor.mode = 'RGB-RAW'
|
||||
r, g, b = self._sensor.bin_data("hhh")
|
||||
if(Color.BLUE.rmin <= r <= Color.BLUE.rmax and Color.BLUE.gmin <= g <= Color.BLUE.gmax and Color.BLUE.bmin <= b <= Color.BLUE.bmax):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def setmode(self, newmode):
|
||||
self._sensor.mode = newmode
|
||||
|
|
Loading…
Reference in a new issue