Renewed Calibrate Function for RGB sensor. calibrateBrightness not yet Tested, calibrateRGB not completely implemented yet

This commit is contained in:
haselnussbier 2018-03-22 17:40:19 +01:00 committed by d3rped
parent f59ae44d4e
commit 6f00e3c717
2 changed files with 40 additions and 4 deletions

View file

@ -12,6 +12,9 @@ class Move:
self._wheel_r = Wheel('outC') self._wheel_r = Wheel('outC')
self._camera = Sensor() self._camera = Sensor()
self._bumper = ev3.TouchSensor() self._bumper = ev3.TouchSensor()
self.maxbrightness
self.minbrightness
self.edgebrightness
except OSError: except OSError:
print("ERROR: Cannot find Motor/Sensor") print("ERROR: Cannot find Motor/Sensor")
@ -20,8 +23,36 @@ class Move:
depending on environment lighting depending on environment lighting
''' '''
def _calibrate(self): def _calibrate(self):
pass self._sensor.calibrateRGB()
self.calibrateBrightness()
# pass
def calibrateBrightness(self):
i = 0
self._camera.refresh()
maxbrightness, minbrightness = self._camera.getbrightness()
self._wheel_l.speed_set(5)
self._wheel_r.speed_set(-5)
self._wheel_r.run()
self._wheel_l.run()
tempvalue
while(i < 500):
self._camera.refresh()
tempvalue = self._camera.getbrightness()
if(tempvalue > self.maxbrightness):
self.maxbrightness = tempvalue
if(tempvalue < self.minbrightness):
self.minbrightness = tempvalue
i = i + 1
self._wheel_l.stop()
self._wheel_r.stop()
self.edgebrightness = (self.maxbrightness + self.minbrightness)/2
while(not (self.edgebrightness - 10 < self._camera.getbrightness() < self.edgebrightness + 10))
self._wheel_l.speed_set(5)
self._wheel_r.speed_set(-5)
self._wheel_l.stop()
self._wheel_r.stop()
# pass
''' '''
Function to correct errors should the robot wander astray Function to correct errors should the robot wander astray
''' '''
@ -51,8 +82,7 @@ class Move:
self._wheel_l.speed_set((60 - (self._camera.getbrightness()/5))-4) self._wheel_l.speed_set((60 - (self._camera.getbrightness()/5))-4)
self._wheel_r.speed_set((self._camera.getbrightness()/5)) self._wheel_r.speed_set((self._camera.getbrightness()/5))
self._camera.getcolor() self._camera.getcolor()
if(isknownstation == False): if(not isknownstation):
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,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import ev3dev.ev3 as ev3 import ev3dev.ev3 as ev3
from enum import Enum, unique 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).
@ -34,6 +34,8 @@ class Sensor:
self._sensor.mode = 'RGB-RAW' self._sensor.mode = 'RGB-RAW'
self.RGB = self._sensor.bin_data("hhh") self.RGB = self._sensor.bin_data("hhh")
self.lastcolor = None self.lastcolor = None
self.maxbrightness
self.minbrightness
def refresh(self): def refresh(self):
self.RGB = self._sensor.bin_data("hhh") self.RGB = self._sensor.bin_data("hhh")
@ -55,3 +57,7 @@ class Sensor:
def setmode(self, newmode): def setmode(self, newmode):
self._sensor.mode = newmode self._sensor.mode = newmode
def calibrateRGB(self):
# Enums are uncangeable right? Dunno how to calibrate like that
pass