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

Class DynamixelClient

dynamixel_client.py:60–346  ·  view source on GitHub ↗

Client for communicating with Dynamixel motors. NOTE: This only supports Protocol 2.

Source from the content-addressed store, hash-verified

58
59
60class DynamixelClient:
61 """Client for communicating with Dynamixel motors.
62
63 NOTE: This only supports Protocol 2.
64 """
65
66 # The currently open clients.
67 OPEN_CLIENTS = set()
68
69 def __init__(self,
70 motor_ids: Sequence[int],
71 port: str = '/dev/ttyUSB0',
72 baudrate: int = 1000000,
73 lazy_connect: bool = False,
74 pos_scale: Optional[float] = None,
75 vel_scale: Optional[float] = None,
76 cur_scale: Optional[float] = None):
77 """Initializes a new client.
78
79 Args:
80 motor_ids: All motor IDs being used by the client.
81 port: The Dynamixel device to talk to. e.g.
82 - Linux: /dev/ttyUSB0
83 - Mac: /dev/tty.usbserial-*
84 - Windows: COM1
85 baudrate: The Dynamixel baudrate to communicate with.
86 lazy_connect: If True, automatically connects when calling a method
87 that requires a connection, if not already connected.
88 pos_scale: The scaling factor for the positions. This is
89 motor-dependent. If not provided, uses the default scale.
90 vel_scale: The scaling factor for the velocities. This is
91 motor-dependent. If not provided uses the default scale.
92 cur_scale: The scaling factor for the currents. This is
93 motor-dependent. If not provided uses the default scale.
94 """
95 import dynamixel_sdk
96 self.dxl = dynamixel_sdk
97
98 self.motor_ids = list(motor_ids)
99 self.port_name = port
100 self.baudrate = baudrate
101 self.lazy_connect = lazy_connect
102
103 self.port_handler = self.dxl.PortHandler(port)
104 self.packet_handler = self.dxl.PacketHandler(PROTOCOL_VERSION)
105
106 self._pos_vel_cur_reader = DynamixelPosVelCurReader(
107 self,
108 self.motor_ids,
109 pos_scale=pos_scale if pos_scale is not None else DEFAULT_POS_SCALE,
110 vel_scale=vel_scale if vel_scale is not None else DEFAULT_VEL_SCALE,
111 cur_scale=cur_scale if cur_scale is not None else DEFAULT_CUR_SCALE,
112 )
113 self._pos_reader = DynamixelPosReader(
114 self,
115 self.motor_ids,
116 pos_scale=pos_scale if pos_scale is not None else DEFAULT_POS_SCALE,
117 vel_scale=vel_scale if vel_scale is not None else DEFAULT_VEL_SCALE,

Callers 2

dxl_test.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected