fixed an error in wheel.py and createt template for sensor.py

This commit is contained in:
d3rped 2018-03-18 16:04:38 +01:00
parent 2fdb165f6d
commit bfd00d33ed
2 changed files with 34 additions and 7 deletions

View file

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import ev3dev.ev3 as ev3
# add enum for color definitions
class Sensor:
def __init__(self):
self._sensor = ev3.ColorSensor()
self._sensor.mode = 'REF-RAW'
def iscolor(self, color):
curcol = self._sensor.bin_data("hhh")
if curcol == curcol:
return True
else:
return False
# see https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity
def getbrightness(self):
if(self._sensor.mode == 'REF-RAW'):
return self._sensor.value
else:
print("ERROR: incorrect sensor mode.")
def setmode(self, newmode):
self._sensor.mode = newmode

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import ev3dev.ev3 as ev3
@ -5,8 +7,7 @@ class Wheel:
def __init__(self, port):
self._motor = ev3.LargeMotor(port)
self._motor.stop_action = 'brake'
self._speed = 20
self._motor.duty_cycle_sp = self._speed
self._motor.duty_cycle_sp = 20
def run(self):
self._motor.run_direct()
@ -15,14 +16,12 @@ class Wheel:
self._motor.stop()
def speed_set(self, newspeed):
self._speed = newspeed
self._motor.duty_cycle_sp = self._speed
self._motor.duty_cycle_sp = newspeed
def speed_mod(self, modifier):
self._speed = self._speed + modifier
self._motor.duty_cycle_sp = self._speed
self._motor.duty_cycle_sp = self._motor.duty_cycle_sp + modifier
def getmovement(self):
self.position = self._motor.position
self._motor.position.reset()
self._motor.position = 0
return self.position