1
0
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:
Andrey Pokhilko 2020-01-28 20:53:28 +03:00
parent 300268a2ab
commit 17e22bf810
4 changed files with 13 additions and 10 deletions

View File

@ -85,7 +85,7 @@ try:
sa = round(c + b / divider, 1) sa = round(c + b / divider, 1)
sb = round(c - b / divider, 1) sb = round(c - b / divider, 1)
logging.info("SpeedA=%s, SpeedB=%s", sa, sb) 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) # time.sleep(0.5)
finally: finally:
robot.motor_AB.stop() robot.motor_AB.stop()

View File

@ -240,8 +240,8 @@ class LEDRGB(Peripheral):
class Motor(Peripheral): class Motor(Peripheral):
SUBCMD_START_POWER = 0x01 SUBCMD_START_POWER = 0x00
# SUBCMD_START_POWER = 0x02 SUBCMD_START_POWER_GROUPED = 0x03
SUBCMD_SET_ACC_TIME = 0x05 SUBCMD_SET_ACC_TIME = 0x05
SUBCMD_SET_DEC_TIME = 0x06 SUBCMD_SET_DEC_TIME = 0x06
SUBCMD_START_SPEED = 0x07 SUBCMD_START_SPEED = 0x07
@ -271,9 +271,6 @@ class Motor(Peripheral):
return int(absolute) return int(absolute)
def _write_direct_mode(self, subcmd, params): def _write_direct_mode(self, subcmd, params):
if self.virtual_ports:
subcmd += 1 # de-facto rule
params = pack("<B", subcmd) + params params = pack("<B", subcmd) + params
msg = MsgPortOutput(self.port, MsgPortOutput.WRITE_DIRECT_MODE_DATA, params) msg = MsgPortOutput(self.port, MsgPortOutput.WRITE_DIRECT_MODE_DATA, params)
self._send_output(msg) self._send_output(msg)
@ -292,15 +289,20 @@ class Motor(Peripheral):
if power_secondary is None: if power_secondary is None:
power_secondary = power_primary power_secondary = power_primary
if self.virtual_ports:
cmd = self.SUBCMD_START_POWER_GROUPED
else:
cmd = self.SUBCMD_START_POWER
params = b"" params = b""
params += pack("<b", self._speed_abs(power_primary)) params += pack("<b", self._speed_abs(power_primary))
if self.virtual_ports: if self.virtual_ports:
params += pack("<b", self._speed_abs(power_secondary)) 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): def stop(self):
self.start_speed(0) self.timed(0)
def set_acc_profile(self, seconds, profile_no=0x00): def set_acc_profile(self, seconds, profile_no=0x00):
""" """

View File

@ -1,3 +1,4 @@
import sys
import time import time
from binascii import unhexlify from binascii import unhexlify
@ -5,7 +6,7 @@ from pylgbst.comms import Connection
from pylgbst.hub import MoveHub, Hub from pylgbst.hub import MoveHub, Hub
from pylgbst.peripherals import * 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') log = logging.getLogger('test')

View File

@ -151,7 +151,7 @@ class PeripheralsTest(unittest.TestCase):
hub.connection.notification_delayed('050082030a', 0.1) hub.connection.notification_delayed('050082030a', 0.1)
motor.start_power(1.0) 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) hub.connection.notification_delayed('050082030a', 0.1)
motor.stop() motor.stop()