94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import ev3dev.ev3 as ev3
|
|
from wheel import Wheel
|
|
from sensor import Sensor
|
|
from odometry import Odometry
|
|
|
|
|
|
class Move:
|
|
def __init__(self, planet):
|
|
try:
|
|
self._wheel_l = Wheel('outB')
|
|
self._wheel_r = Wheel('outC')
|
|
self._camera = Sensor()
|
|
self._bumper = ev3.TouchSensor()
|
|
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
|
|
'''
|
|
def _calibrate(self):
|
|
self._sensor.calibrateRGB()
|
|
self.calibrateBrightness()
|
|
# pass
|
|
|
|
def calibrateBrightness(self):
|
|
i = 0
|
|
self.maxbrightness = self._camera.getbrightness()
|
|
self.minbrightness = self._camera.getbrightness()
|
|
self._wheel_l.speed_set(15)
|
|
self._wheel_r.speed_set(-15)
|
|
self._wheel_r.run()
|
|
self._wheel_l.run()
|
|
tempvalue = 0
|
|
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._camera.getbrightness() == self.edgebrightness)):
|
|
self._wheel_l.speed_set(15)
|
|
self._wheel_r.speed_set(-15)
|
|
self._wheel_l.stop()
|
|
self._wheel_r.stop()
|
|
# pass
|
|
'''
|
|
Function to correct errors should the robot wander astray
|
|
'''
|
|
# Probably redundant because aligning can be done while scanning other paths
|
|
|
|
def _aligntoedge(self):
|
|
pass
|
|
|
|
'''
|
|
uses odometry and the planet object to map edges that are connected to
|
|
current node.
|
|
|
|
Use either relative motor pos or timed driving to center on node.
|
|
Next turn around and detect edges through drops in _sensor.getbrightness()
|
|
'''
|
|
def getstationedges(self):
|
|
self._wheel_l.turnbyamount(500, 250)
|
|
self._wheel_r.turnbyamount(-500, 250)
|
|
|
|
def traversetonextstation(self, isknownstation):
|
|
self._wheel_l.speed_set(self.edgebrightness//2)
|
|
self._wheel_r.speed_set(self.edgebrightness//2)
|
|
self._wheel_l.run()
|
|
self._wheel_r.run()
|
|
|
|
while (not self._bumper.value() and self._camera.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()
|
|
if(not isknownstation):
|
|
print(self._odometry.degree(self._wheel_l.getmovement(), self._wheel_r.getmovement(), 0))
|
|
# pass # run odometry stuff here
|
|
self._wheel_l.stop()
|
|
self._wheel_r.stop()
|