stops now only on red/blue knots

This commit is contained in:
haselnussbier 2018-03-20 15:11:19 +01:00 committed by d3rped
parent 1f1c19232a
commit 23ddc2c24a
2 changed files with 37 additions and 14 deletions

View file

@ -44,10 +44,12 @@ class Move:
self._wheel_r.speed_set(24) self._wheel_r.speed_set(24)
self._wheel_l.run() self._wheel_l.run()
self._wheel_r.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_l.speed_set(48 - self._sensor.getbrightness())
self._wheel_r.speed_set(self._sensor.getbrightness()) self._wheel_r.speed_set(self._sensor.getbrightness())
if(isknownstation == False): if(isknownstation == False):
pass #run odometry stuff here pass #run odometry stuff here
self._wheel_l.stop() self._wheel_l.stop()
self._wheel_r.stop() self._wheel_r.stop()

View file

@ -1,6 +1,22 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import ev3dev.ev3 as ev3 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). add enum for color definitions (type should be tupel of int's).
@ -18,22 +34,27 @@ class Sensor:
def __init__(self): def __init__(self):
self._sensor = ev3.ColorSensor() self._sensor = ev3.ColorSensor()
self._sensor.mode = 'COL-REFLECT' self._sensor.mode = 'COL-REFLECT'
self.foundColor = False
def iscolor(self, color): def getbrightness(self):
if(self._sensor.mode == 'RGB-RAW'): self._sensor.mode = 'COL-REFLECT'
curcol = self._sensor.bin_data("hhh") return self._sensor.value()
if curcol == curcol:
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 return True
else: else:
return False return False
else:
print("ERROR: incorrect sensor mode:", self._sensor.mode)
def getbrightness(self): def isBlue(self):
if(self._sensor.mode == 'COL-REFLECT'): self._sensor.mode = 'RGB-RAW'
return self._sensor.value() 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: else:
print("ERROR: incorrect sensor mode:", self._sensor.mode) return False
def setmode(self, newmode): def setmode(self, newmode):
self._sensor.mode = newmode self._sensor.mode = newmode