Applied commit: a540201, the previous one was actually 5855373

This commit is contained in:
haselnussbier 2018-03-24 19:56:29 +01:00 committed by d3rped
parent 78ce8da918
commit c1f68b84e3
2 changed files with 29 additions and 12 deletions

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import ev3dev.ev3 as ev3
from wheel import Wheel from wheel import Wheel
from sensor import Sensor from sensor import Sensor
from odometry import Odometry from odometry import Odometry
@ -33,9 +34,23 @@ class Move:
depending on environment lighting depending on environment lighting
''' '''
def _calibrate(self): def _calibrate(self):
self._sensor.calibrateRGB() ev3.Sound.beep()
while(not self._sensor.bumperwaspressed):
self._sensor.checkbumper()
self._sensor.reset()
self._sensor.calibrateBrightness() self._sensor.calibrateBrightness()
# pass sleep(2)
ev3.Sound.beep()
while(not self._sensor.bumperwaspressed):
self._sensor.checkbumper()
self._sensor.reset()
self._sensor.calibrateRGB(self._sensor.red)
sleep(2)
ev3.Sound.beep()
while(not self._sensor.bumperwaspressed):
self._sensor.checkbumper()
self._sensor.calibrateRGB(self._sensor.blue)
self._sensor.reset()
''' '''
Function to correct errors should the robot wander astray Function to correct errors should the robot wander astray

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import ev3dev.ev3 as ev3 import ev3dev.ev3 as ev3
from enum import Enum
''' '''
add enum for color definitions (type should be tupel of int's). add enum for color definitions (type should be tupel of int's).
@ -22,10 +21,11 @@ Formula:
Y=(0.299 x R) + (0.587 x G) + (0.114 x B); Y=(0.299 x R) + (0.587 x G) + (0.114 x B);
''' '''
'''
class Color(tuple, Enum): class Color(tuple, Enum):
RED = (65, 30, 20) RED = (65, 30, 20)
BLUE = (20, 45, 60) BLUE = (20, 45, 60)
'''
class Sensor: class Sensor:
@ -42,6 +42,8 @@ class Sensor:
print("Error while setting up sensors. Please make sure that everything is plugged in properly.") print("Error while setting up sensors. Please make sure that everything is plugged in properly.")
self.lastcolor = None self.lastcolor = None
self.edgebrightness = None self.edgebrightness = None
self.red = None
self.blue = None
def refresh(self): def refresh(self):
self.RGB = self._camera.bin_data("hhh") self.RGB = self._camera.bin_data("hhh")
@ -64,16 +66,16 @@ class Sensor:
def getcolor(self): def getcolor(self):
if(self._camera.mode == 'RGB-RAW'): if(self._camera.mode == 'RGB-RAW'):
if(self.RGB[0] > Color.RED[0] and (self.RGB[1], self.RGB[2]) < (Color.RED[1], Color.RED[2])): if(self.RGB[0] > self.red[0] and (self.RGB[1], self.RGB[2]) < (self.red[1], self.red[2])):
self.lastcolor = Color.RED self.lastcolor = self.red
if(self.RGB[0] < Color.BLUE[0] and (self.RGB[1], self.RGB[2]) > (Color.BLUE[1], Color.BLUE[2])): if(self.RGB[0] < self.blue[0] and (self.RGB[1], self.RGB[2]) > (self.blue[1], self.blue[2])):
self.lastcolor = Color.BLUE self.lastcolor = self.blue
def calibrateRGB(self, color): def calibrateRGB(self, color):
self.refresh() self.refresh()
if (color is Color.RED): if (color is self.red):
newRED = (self.RGB[0]-5, self.RGB[1]+5, self.RGB[2]+5) newRED = (self.RGB[0]-5, self.RGB[1]+5, self.RGB[2]+5)
Color.RED = newRED self.red = newRED
elif (color is Color.BLUE): elif (color is self.blueE):
newBLUE = (self.RGB[0]+5, self.RGB[1]-5, self.RGB[2]-5) newBLUE = (self.RGB[0]+5, self.RGB[1]-5, self.RGB[2]-5)
Color.BLUE = newBLUE self.blue = newBLUE