Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print('Using "normal" pypot package...')
def rw_pypot():
dxl.get_present_position(ids)
dxl.set_goal_position(dict(zip(ids, itertools.repeat(0))))
dt = timeit(rw_pypot, args.N, os.path.join(bp, 'rw_pypot.list'))
print('in {}ms'.format(dt * 1000))
print('Using pref-forged packet...')
c_get = [c for c in DxlIO._AbstractDxlIO__controls
if c.name == 'present position'][0]
c_set = [c for c in DxlIO._AbstractDxlIO__controls
if c.name == 'goal position'][0]
pos = dxl_code(0, c_set.length)
rp = DxlReadDataPacket(ids[0], c_get.address, c_get.length)
sp = DxlSyncWritePacket(c_set.address, c_set.length, ids[:1] + list(pos))
def rw_forged_packet():
dxl._send_packet(rp)
dxl._send_packet(sp, wait_for_status_packet=False)
dt = timeit(rw_forged_packet, args.N, os.path.join(bp, 'rw_forged.list'))
print('in {}ms'.format(dt * 1000))
print('Using raw serial communication...')
s_read = rp.to_string()
s_write = sp.to_string()
def rw_serial():
dxl._serial.write(s_read)
def _checksum(cls, packet):
return bytearray(dxl_code(crc16(packet[:-2], len(packet) - 2), 2))
def __new__(cls, address, length, id_value_couples):
return DxlInstructionPacket.__new__(cls, DxlBroadcast,
DxlInstruction.SYNC_WRITE,
list(itertools.chain(dxl_code(address, 2),
dxl_code(length, 2),
id_value_couples)))
def _buff(self):
return bytearray(itertools.chain(DxlPacketHeader.marker,
(self.id, ),
dxl_code(self.length, 2),
(self.instruction, ),
self.parameters))
def __new__(cls, address, length, id_value_couples):
return DxlInstructionPacket.__new__(cls, DxlBroadcast,
DxlInstruction.SYNC_WRITE,
list(itertools.chain(dxl_code(address, 2),
dxl_code(length, 2),
id_value_couples)))
def to_array(self):
return self._buff() + bytearray(dxl_code(self.checksum, 2))
def __new__(cls, id, address, length):
return DxlInstructionPacket.__new__(cls, id,
DxlInstruction.READ_DATA,
list(dxl_code(address, 2)) +
list(dxl_code(length, 2)))