applied commit: 08e0f98. Moved the brightness updater into the refresh method.
This commit is contained in:
parent
172e368380
commit
40c5adfa0b
4 changed files with 30 additions and 18 deletions
20
src/move.py
20
src/move.py
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import ev3dev.ev3 as ev3
|
||||
from wheel import Wheel
|
||||
from sensor import Sensor
|
||||
from odometry import Odometry
|
||||
|
@ -11,16 +10,14 @@ class Move:
|
|||
try:
|
||||
self._wheel_l = Wheel('outB')
|
||||
self._wheel_r = Wheel('outC')
|
||||
self._camera = Sensor()
|
||||
self._bumper = ev3.TouchSensor()
|
||||
self._sensor = Sensor()
|
||||
except OSError:
|
||||
print("ERROR: Cannot find Motor/Sensor")
|
||||
self.maxbrightness = 0
|
||||
self.minbrightness = 0
|
||||
self.edgebrightness = 0
|
||||
self._odometry = Odometry()
|
||||
|
||||
except OSError:
|
||||
print("ERROR: Cannot find Motor/Sensor")
|
||||
|
||||
'''
|
||||
determine maximum and minimum brightness of lines/white space
|
||||
depending on environment lighting
|
||||
|
@ -55,7 +52,7 @@ class Move:
|
|||
self._wheel_r.speed_set(-15)
|
||||
self._wheel_l.stop()
|
||||
self._wheel_r.stop()
|
||||
# pass
|
||||
|
||||
'''
|
||||
Function to correct errors should the robot wander astray
|
||||
'''
|
||||
|
@ -80,12 +77,13 @@ class Move:
|
|||
self._wheel_l.run()
|
||||
self._wheel_r.run()
|
||||
|
||||
while (not self._bumper.value() and self._camera.lastcolor == None):
|
||||
while (not self._sensor.bumperispressed() and self._sensor.lastcolor == None):
|
||||
self._camera.refresh()
|
||||
self._wheel_l.speed_set(self.maxbrightness//2 - self._camera.getbrightness()//2)
|
||||
self._wheel_r.speed_set(self._camera.getbrightness()//2)
|
||||
self._camera.getcolor()
|
||||
self._wheel_l.speed_set(self.maxbrightness//2 - self._sensor.getbrightness()//2)
|
||||
self._wheel_r.speed_set(self._sensor.getbrightness()//2)
|
||||
self._sensor.getcolor()
|
||||
if(not isknownstation):
|
||||
print(self._odometry.degree(self._wheel_l.getmovement(), self._wheel_r.getmovement(), 0))
|
||||
|
||||
self._wheel_l.stop()
|
||||
self._wheel_r.stop()
|
||||
|
|
|
@ -50,6 +50,7 @@ class Planet:
|
|||
def __init__(self):
|
||||
""" Initializes the data structure """
|
||||
self._planetmap = {}
|
||||
self._unexedge = []
|
||||
self._curnode = None
|
||||
self.target = None
|
||||
|
||||
|
@ -73,6 +74,12 @@ class Planet:
|
|||
def getcurnode(self):
|
||||
return self._curnode
|
||||
|
||||
def addtounexedge(self, node_edge_list):
|
||||
self._unexedge = self._unexedge + node_edge_list
|
||||
|
||||
def exploreedge(self, node_edge):
|
||||
self._unexedge.remove(node_edge)
|
||||
|
||||
'''
|
||||
Returns a shortest path between two nodes.
|
||||
Used Algorithm: Dijkstra's Algorithm
|
||||
|
|
|
@ -30,18 +30,25 @@ class Color(tuple, Enum):
|
|||
|
||||
class Sensor:
|
||||
def __init__(self):
|
||||
self._sensor = ev3.ColorSensor()
|
||||
self._sensor.mode = 'RGB-RAW'
|
||||
self.RGB = self._sensor.bin_data("hhh")
|
||||
self._bumper = ev3.TouchSensor()
|
||||
self._camera = ev3.ColorSensor()
|
||||
self._camera.mode = 'RGB-RAW'
|
||||
self.RGB = self._camera.bin_data("hhh")
|
||||
self._brightness = self._camera.value()
|
||||
self.lastcolor = None
|
||||
|
||||
def refresh(self):
|
||||
self.RGB = self._sensor.bin_data("hhh")
|
||||
def bumperispressed(self):
|
||||
self._bumper.value()
|
||||
|
||||
def refresh(self): # do we still want to check if the propper camera/sensor mode is set?
|
||||
self.RGB = self._camera.bin_data("hhh")
|
||||
self._brightness = self._camera.value()
|
||||
|
||||
def getbrightness(self):
|
||||
return self._sensor.value()
|
||||
return self._brightness
|
||||
|
||||
def getcolor(self):
|
||||
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])):
|
||||
self.lastcolor = Color.RED
|
||||
if(self.RGB[0] < Color.BLUE[0] and (self.RGB[1], self.RGB[2]) > (Color.BLUE[1], Color.BLUE[2])):
|
||||
|
|
Loading…
Reference in a new issue