fixed an error in wheel.py and createt template for sensor.py
This commit is contained in:
parent
2fdb165f6d
commit
bfd00d33ed
2 changed files with 34 additions and 7 deletions
|
@ -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
|
13
src/wheel.py
13
src/wheel.py
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import ev3dev.ev3 as ev3
|
import ev3dev.ev3 as ev3
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,8 +7,7 @@ class Wheel:
|
||||||
def __init__(self, port):
|
def __init__(self, port):
|
||||||
self._motor = ev3.LargeMotor(port)
|
self._motor = ev3.LargeMotor(port)
|
||||||
self._motor.stop_action = 'brake'
|
self._motor.stop_action = 'brake'
|
||||||
self._speed = 20
|
self._motor.duty_cycle_sp = 20
|
||||||
self._motor.duty_cycle_sp = self._speed
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._motor.run_direct()
|
self._motor.run_direct()
|
||||||
|
@ -15,14 +16,12 @@ class Wheel:
|
||||||
self._motor.stop()
|
self._motor.stop()
|
||||||
|
|
||||||
def speed_set(self, newspeed):
|
def speed_set(self, newspeed):
|
||||||
self._speed = newspeed
|
self._motor.duty_cycle_sp = newspeed
|
||||||
self._motor.duty_cycle_sp = self._speed
|
|
||||||
|
|
||||||
def speed_mod(self, modifier):
|
def speed_mod(self, modifier):
|
||||||
self._speed = self._speed + modifier
|
self._motor.duty_cycle_sp = self._motor.duty_cycle_sp + modifier
|
||||||
self._motor.duty_cycle_sp = self._speed
|
|
||||||
|
|
||||||
def getmovement(self):
|
def getmovement(self):
|
||||||
self.position = self._motor.position
|
self.position = self._motor.position
|
||||||
self._motor.position.reset()
|
self._motor.position = 0
|
||||||
return self.position
|
return self.position
|
||||||
|
|
Loading…
Reference in a new issue