Renewed Calibrate Function for RGB sensor. calibrateBrightness not yet Tested, calibrateRGB not completely implemented yet
This commit is contained in:
parent
f59ae44d4e
commit
6f00e3c717
2 changed files with 40 additions and 4 deletions
36
src/move.py
36
src/move.py
|
@ -12,6 +12,9 @@ class Move:
|
|||
self._wheel_r = Wheel('outC')
|
||||
self._camera = Sensor()
|
||||
self._bumper = ev3.TouchSensor()
|
||||
self.maxbrightness
|
||||
self.minbrightness
|
||||
self.edgebrightness
|
||||
except OSError:
|
||||
print("ERROR: Cannot find Motor/Sensor")
|
||||
|
||||
|
@ -20,8 +23,36 @@ class Move:
|
|||
depending on environment lighting
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
@ -51,8 +82,7 @@ class Move:
|
|||
self._wheel_l.speed_set((60 - (self._camera.getbrightness()/5))-4)
|
||||
self._wheel_r.speed_set((self._camera.getbrightness()/5))
|
||||
self._camera.getcolor()
|
||||
if(isknownstation == False):
|
||||
if(not isknownstation):
|
||||
pass # run odometry stuff here
|
||||
|
||||
self._wheel_l.stop()
|
||||
self._wheel_r.stop()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
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).
|
||||
|
@ -34,6 +34,8 @@ class Sensor:
|
|||
self._sensor.mode = 'RGB-RAW'
|
||||
self.RGB = self._sensor.bin_data("hhh")
|
||||
self.lastcolor = None
|
||||
self.maxbrightness
|
||||
self.minbrightness
|
||||
|
||||
def refresh(self):
|
||||
self.RGB = self._sensor.bin_data("hhh")
|
||||
|
@ -55,3 +57,7 @@ class Sensor:
|
|||
|
||||
def setmode(self, newmode):
|
||||
self._sensor.mode = newmode
|
||||
|
||||
def calibrateRGB(self):
|
||||
# Enums are uncangeable right? Dunno how to calibrate like that
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue