Implemented rudimentary edge following. Also fixed a minor error in sensor.py

This commit is contained in:
d3rped 2018-03-19 00:03:35 +01:00
parent 48dfc2a03b
commit 23fb6e80e7
2 changed files with 25 additions and 2 deletions

View file

@ -1,15 +1,38 @@
#!/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
class Move: class Move:
def __init__(self, planet): def __init__(self, planet):
pass self._wheel_l = Wheel('outB')
self._wheel_r = Wheel('outC')
self._sensor = Sensor()
self._bumper = ev3.TouchSensor()
def _calibrate(self): def _calibrate(self):
pass pass
def _aligntoedge(self): def _aligntoedge(self):
pass pass
def getstationedges(self):
pass
def traversetonextstation(self, isknownstation):
self._wheel_l.speed_set = 20
self._wheel_r.speed_set = 20
self._wheel_l.run()
self._wheel_r.run()
while(self._bumper.value() == False):
# this does not work... why?
# self._wheel_l.speed_set(newspeed)
# self._wheel_r.speed_set(newspeed)
self._wheel_l._motor.duty_cycle_sp = 48 - self._sensor.getbrightness()
self._wheel_r._motor.duty_cycle_sp = self._sensor.getbrightness()
if(isknownstation == False):
pass #run odometry stuff here
self._wheel_l.stop()
self._wheel_r.stop()

View file

@ -20,7 +20,7 @@ class Sensor:
# see https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity # see https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity
def getbrightness(self): def getbrightness(self):
if(self._sensor.mode == 'COL-REFLECT'): if(self._sensor.mode == 'COL-REFLECT'):
return self._sensor.value return self._sensor.value()
else: else:
print("ERROR: incorrect sensor mode.") print("ERROR: incorrect sensor mode.")