mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Tested motor on port D
This commit is contained in:
parent
3c82405040
commit
afe5c3a55a
16
demo.py
16
demo.py
@ -2,7 +2,7 @@ import logging
|
|||||||
import traceback
|
import traceback
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from pylegoboost import MoveHub, COLORS
|
from pylegoboost import MoveHub, COLORS, EncodedMotor, PORT_D
|
||||||
from pylegoboost.comms import DebugServerConnection, BLEConnection
|
from pylegoboost.comms import DebugServerConnection, BLEConnection
|
||||||
|
|
||||||
log = logging.getLogger("demo")
|
log = logging.getLogger("demo")
|
||||||
@ -12,7 +12,8 @@ def demo_all(conn):
|
|||||||
movehub = MoveHub(conn)
|
movehub = MoveHub(conn)
|
||||||
# demo_led_colors(movehub)
|
# demo_led_colors(movehub)
|
||||||
# demo_motors_timed(movehub)
|
# demo_motors_timed(movehub)
|
||||||
demo_motors_angled(movehub)
|
# demo_motors_angled(movehub)
|
||||||
|
demo_port_c_motor(movehub)
|
||||||
|
|
||||||
|
|
||||||
def demo_led_colors(movehub):
|
def demo_led_colors(movehub):
|
||||||
@ -45,6 +46,17 @@ def demo_motors_angled(movehub):
|
|||||||
movehub.motor_B.angled(angle, -1)
|
movehub.motor_B.angled(angle, -1)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
movehub.motor_AB.angled(360, 1, -1)
|
||||||
|
sleep(1)
|
||||||
|
movehub.motor_AB.angled(360, -1, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def demo_port_c_motor(movehub):
|
||||||
|
portd = EncodedMotor(movehub, PORT_D)
|
||||||
|
portd.angled(90, 1)
|
||||||
|
sleep(1)
|
||||||
|
portd.angled(90, -1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
@ -21,8 +21,8 @@ class MoveHub(object):
|
|||||||
self.motor_B = EncodedMotor(self, PORT_B)
|
self.motor_B = EncodedMotor(self, PORT_B)
|
||||||
self.motor_AB = EncodedMotor(self, PORT_AB)
|
self.motor_AB = EncodedMotor(self, PORT_AB)
|
||||||
|
|
||||||
# self.port_c
|
self.port_c = None
|
||||||
# self.port_d
|
self.port_d = None
|
||||||
|
|
||||||
# self.button
|
# self.button
|
||||||
# self.tilt_sensor
|
# self.tilt_sensor
|
||||||
@ -94,7 +94,10 @@ class EncodedMotor(Peripheral):
|
|||||||
# movement type
|
# movement type
|
||||||
command = self.TIMED_GROUP if self.port == PORT_AB else self.TIMED_SINGLE
|
command = self.TIMED_GROUP if self.port == PORT_AB else self.TIMED_SINGLE
|
||||||
# time
|
# time
|
||||||
command += struct.pack('<H', int(seconds * 1000))
|
msec = int(seconds * 1000)
|
||||||
|
if msec > 255 * 255:
|
||||||
|
raise ValueError("Too large value for seconds: %s", seconds)
|
||||||
|
command += struct.pack('<H', msec)
|
||||||
|
|
||||||
self._wrap_and_write(command, speed_primary, speed_secondary)
|
self._wrap_and_write(command, speed_primary, speed_secondary)
|
||||||
|
|
||||||
@ -111,6 +114,7 @@ class EncodedMotor(Peripheral):
|
|||||||
command += struct.pack('<I', angle)
|
command += struct.pack('<I', angle)
|
||||||
|
|
||||||
self._wrap_and_write(command, speed_primary, speed_secondary)
|
self._wrap_and_write(command, speed_primary, speed_secondary)
|
||||||
|
# TODO: how to tell when motor has stopped?
|
||||||
|
|
||||||
|
|
||||||
class ColorDistanceSensor(Peripheral):
|
class ColorDistanceSensor(Peripheral):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user