MCPcopy Create free account
hub / github.com/MarkFzp/act-plus-plus / sync_write

Method sync_write

dynamixel_client.py:265–297  ·  view source on GitHub ↗

Writes values to a group of motors. Args: motor_ids: The motor IDs to write to. values: The values to write. address: The control table address to write to. size: The size of the control table value being written to.

(self, motor_ids: Sequence[int],
                   values: Sequence[Union[int, float]], address: int,
                   size: int)

Source from the content-addressed store, hash-verified

263 return errored_ids
264
265 def sync_write(self, motor_ids: Sequence[int],
266 values: Sequence[Union[int, float]], address: int,
267 size: int):
268 """Writes values to a group of motors.
269
270 Args:
271 motor_ids: The motor IDs to write to.
272 values: The values to write.
273 address: The control table address to write to.
274 size: The size of the control table value being written to.
275 """
276 self.check_connected()
277 key = (address, size)
278 if key not in self._sync_writers:
279 self._sync_writers[key] = self.dxl.GroupSyncWrite(
280 self.port_handler, self.packet_handler, address, size)
281 sync_writer = self._sync_writers[key]
282
283 errored_ids = []
284 for motor_id, desired_pos in zip(motor_ids, values):
285 value = signed_to_unsigned(int(desired_pos), size=size)
286 value = value.to_bytes(size, byteorder='little')
287 success = sync_writer.addParam(motor_id, value)
288 if not success:
289 errored_ids.append(motor_id)
290
291 if errored_ids:
292 logging.error('Sync write failed for: %s', str(errored_ids))
293
294 comm_result = sync_writer.txPacket()
295 self.handle_packet_result(comm_result, context='sync_write')
296
297 sync_writer.clearParam()
298
299 def check_connected(self):
300 """Ensures the robot is connected."""

Callers 1

write_desired_posMethod · 0.95

Calls 3

check_connectedMethod · 0.95
handle_packet_resultMethod · 0.95
signed_to_unsignedFunction · 0.85

Tested by

no test coverage detected