mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Use command codes in write direct
This commit is contained in:
parent
300268a2ab
commit
17e22bf810
@ -85,7 +85,7 @@ try:
|
||||
sa = round(c + b / divider, 1)
|
||||
sb = round(c - b / divider, 1)
|
||||
logging.info("SpeedA=%s, SpeedB=%s", sa, sb)
|
||||
robot.motor_AB.start_power(sa, sb)
|
||||
robot.motor_AB.start_speed(sa, sb)
|
||||
# time.sleep(0.5)
|
||||
finally:
|
||||
robot.motor_AB.stop()
|
||||
|
@ -240,8 +240,8 @@ class LEDRGB(Peripheral):
|
||||
|
||||
|
||||
class Motor(Peripheral):
|
||||
SUBCMD_START_POWER = 0x01
|
||||
# SUBCMD_START_POWER = 0x02
|
||||
SUBCMD_START_POWER = 0x00
|
||||
SUBCMD_START_POWER_GROUPED = 0x03
|
||||
SUBCMD_SET_ACC_TIME = 0x05
|
||||
SUBCMD_SET_DEC_TIME = 0x06
|
||||
SUBCMD_START_SPEED = 0x07
|
||||
@ -271,9 +271,6 @@ class Motor(Peripheral):
|
||||
return int(absolute)
|
||||
|
||||
def _write_direct_mode(self, subcmd, params):
|
||||
if self.virtual_ports:
|
||||
subcmd += 1 # de-facto rule
|
||||
|
||||
params = pack("<B", subcmd) + params
|
||||
msg = MsgPortOutput(self.port, MsgPortOutput.WRITE_DIRECT_MODE_DATA, params)
|
||||
self._send_output(msg)
|
||||
@ -292,15 +289,20 @@ class Motor(Peripheral):
|
||||
if power_secondary is None:
|
||||
power_secondary = power_primary
|
||||
|
||||
if self.virtual_ports:
|
||||
cmd = self.SUBCMD_START_POWER_GROUPED
|
||||
else:
|
||||
cmd = self.SUBCMD_START_POWER
|
||||
|
||||
params = b""
|
||||
params += pack("<b", self._speed_abs(power_primary))
|
||||
if self.virtual_ports:
|
||||
params += pack("<b", self._speed_abs(power_secondary))
|
||||
|
||||
self._write_direct_mode(self.SUBCMD_START_POWER, params)
|
||||
self._write_direct_mode(cmd, params)
|
||||
|
||||
def stop(self):
|
||||
self.start_speed(0)
|
||||
self.timed(0)
|
||||
|
||||
def set_acc_profile(self, seconds, profile_no=0x00):
|
||||
"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import time
|
||||
from binascii import unhexlify
|
||||
|
||||
@ -5,7 +6,7 @@ from pylgbst.comms import Connection
|
||||
from pylgbst.hub import MoveHub, Hub
|
||||
from pylgbst.peripherals import *
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.basicConfig(level=logging.DEBUG if 'pydevd' in sys.modules else logging.INFO)
|
||||
|
||||
log = logging.getLogger('test')
|
||||
|
||||
|
@ -151,7 +151,7 @@ class PeripheralsTest(unittest.TestCase):
|
||||
|
||||
hub.connection.notification_delayed('050082030a', 0.1)
|
||||
motor.start_power(1.0)
|
||||
self.assertEqual(b"0800810311510164", hub.writes.pop(1)[1])
|
||||
self.assertEqual(b"0800810311510064", hub.writes.pop(1)[1])
|
||||
|
||||
hub.connection.notification_delayed('050082030a', 0.1)
|
||||
motor.stop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user