roboglia.dynamixel.DynamixelBus¶
-
class
DynamixelBus
(name='DYNAMIXEL', robot=None, port='', auto=True, baudrate=1000000, protocol=2.0, rs485=False, mock=False)[source]¶ Bases:
roboglia.base.bus.BaseBus
A communication bus that supports Dynamixel protocol.
Uses
dynamixel_sdk
.Note
The parameters listed bellow are only the specific ones introduced by the
DynamixelBus
class. Since this is a subclass ofBaseBus
and the constructor will call thesuper()
constructor, all the paramters supported byBaseBus
are also supported and checked when creating aDynamixelBus
. For instance the name, robot and port are validated.- Parameters
name (str) – The name of the bus
robot (BaseRobot) – A reference to the robot using the bus
port (any) – An identification for the physical bus access. Some busses have string description like
/dev/ttySC0
while others could be just integers (like in the case of I2C or SPI buses)auto (Bool) – If
True
the bus will be opened when the robot is started by callingBaseRobot.start()
. IfFalse
the bus will be left closed during robot initialization and needs to be opened by the programmer.baudrate (int) – Communication speed for the bus
protocol (float) – Communication protocol for the bus; must be 1.0 or 2.0
rs485 (bool) – If
True
,DynamixelBus
will configure the serial port with RS485 support. This might be required for certain interfaces that need this mode in order to control the semi-duplex protocol (one wire) implemented by Dynamixel devices or if you genuinely use RS485 Dynamixel devices.mock (bool) – Indicates to use mock bus for testing purposes; this will make use of the
MockPacketHandler
to simulate the communication on a Dynamixel bus and allow to test the software in CI testing.
- Raises
KeyError – if any of the required keys are missing:
ValueError – if any of the required data is incorrect:
-
__init__
(name='DYNAMIXEL', robot=None, port='', auto=True, baudrate=1000000, protocol=2.0, rs485=False, mock=False)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
property
port_handler
¶ The Dynamixel port handler for this bus.
-
property
packet_handler
¶ The Dynamixel packet handler for this bus.
-
property
protocol
¶ Protocol supported by the bus.
-
property
baudrate
¶ Bus baudrate.
-
property
rs485
¶ If the bus uses rs485.
-
open
()[source]¶ Allocates the port_handler and the packet_handler. If the attribute
mock
wasTrue
when setting up the bus, then uses MockPacketHandler.
-
close
()[source]¶ Closes the actual physical bus. Calls the
super().close()
to check if there is ok to close the bus and no other objects are using it.
-
property
is_open
¶ Returns True or False if the bus is open.
-
ping
(dxl_id)[source]¶ Performs a Dynamixel
ping
of a device.- Parameters
dxl_id (int) – The Dynamixel device number to be pinged.
- Returns
True
if the device responded,False
otherwise.- Return type
bool
-
scan
(range=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253])[source]¶ Scans the devices on the bus.
- Parameters
range (range) – the range of devices to be cheked if they exist on the bus. The method will call
ping()
for each ID in the list. By default the list is [0, 253].Returns –
of int (list) – The list of IDs that have been successfully identified on the bus. If none is found the list will be empty.
-
read
(reg)[source]¶ Depending on the size of the register calls the corresponding TxRx function from the packet handler. If the result is ok (communication error and dynamixel error are both 0) then the obtained value is returned. Communication and data errors are logged and no exceptions are raised.
- Parameters
reg (BaseRegister or subclass) – The register to be read
- Returns
The value read by calling the device.
- Return type
int
-
write
(reg, value)[source]¶ Depending on the size of the register calls the corresponding TxRx function from the packet handler. Communication and data errors are logged and no exceptions are raised.
- Parameters
reg (BaseRegister or subclass) – The register to write to
value (int) – The value to write to the register. Please note that this is in the internal format of the register and it is the responsibility of the register class to provide conversion between the internal and external format if they are different.
-
__repr__
()[source]¶ Returns a representation of a BaseBus that includes the name of the class, the port and the status (open or closed).
-
property
auto_open
¶ Indicates if the bus should be opened by the robot when initializing.
-
property
name
¶ (read-only) the bus name.
-
property
port
¶ (read-only) the bus port.
-
property
robot
¶ The robot that owns the bus.