31 lines
794 B
Python
31 lines
794 B
Python
#!/usr/bin/env python3
|
|
|
|
import ev3dev.ev3 as ev3
|
|
|
|
|
|
class Wheel:
|
|
def __init__(self, port):
|
|
self._motor = ev3.LargeMotor(port)
|
|
self._motor.stop_action = 'brake'
|
|
self._motor.duty_cycle_sp = 20
|
|
|
|
def run(self):
|
|
self._motor.run_direct()
|
|
|
|
def stop(self):
|
|
self._motor.stop()
|
|
|
|
def speed_set(self, newspeed):
|
|
self._motor.duty_cycle_sp = newspeed
|
|
|
|
def speed_mod(self, modifier):
|
|
self._motor.duty_cycle_sp = self._motor.duty_cycle_sp + modifier
|
|
|
|
def turnbyamount(self, posdif, speed):
|
|
self._motor.run_to_rel_pos(position_sp=posdif, speed_sp=speed)
|
|
|
|
def getmovement(self):
|
|
self.position = self._motor.position
|
|
self._motor.position = self._motor.position - self.position
|
|
return self.position
|