roboglia.dynamixel.MockPacketHandler

class MockPacketHandler(protocol, robot, err=0.1)[source]

Bases: object

A class used to simulate the Dynamixel communication without actually using a real bus or devices. Used for testing in the CI environment. The class includes deterministic behavior, for instance it will use the existing values of the device to mock a response, as well as well as stochastic behavior where with a certain probability we generate communication errors in order to be able to test how the code deals with these situations. Also, for read of registers that are read only the class will introduce small random numbers to the numbers already in the registers so to simulate values that change over time (ex. current position).

Parameters
  • protocol (float) – Dynamixel protocol to use. Should be 1.0 or 2.0

  • robot (BaseRobot) – The robot for in order to bootstrap information.

  • err (float) – A value that is used to generate random communication errors so that we can test the parts of the code that deal with this.

__init__(protocol, robot, err=0.1)[source]

Initialize self. See help(type(self)) for accurate signature.

getProtocolVersion()[source]

Returns the Dynamixel protocol used.

getTxRxResult(err)[source]

Used to get a string representation of a communication error. Invokes the official function from PacketHandler in dynamixel_sdk.

Parameters

err (int) – An error code as reported by the communication medium

Returns

A string representation of this error.

Return type

str

getRxPacketError(err)[source]

Used to get a string representation of a device response error. Invokes the official function from PacketHandler in dynamixel_sdk.

Parameters

err (int) – An error code as reported by the Dynamixel device

Returns

A string representation of this error.

Return type

str

write1ByteTxRx(ph, dev_id, address, value)[source]

Mocks a write of 1 byte to a device. In err percentage time it will raise a communication error. From the remaning cases again an err percentage will be raised with device error (overheat).

The paramters are copied from the PacketHadler in dynamixel_sdk.

You would rarely need to use this.

write2ByteTxRx(ph, dev_id, address, value)[source]

Same as write1ByteTxRx() but for 2 Bytes registers.

write4ByteTxRx(ph, dev_id, address, value)[source]

Same as write1ByteTxRx() but for 4 Bytes registers.

read1ByteTxRx(ph, dev_id, address)[source]

Same as write1ByteTxRx() but for reading 1 Bytes registers.

read2ByteTxRx(ph, dev_id, address)[source]

Same as write1ByteTxRx() but for reading 2 Bytes registers.

read4ByteTxRx(ph, dev_id, address)[source]

Same as write1ByteTxRx() but for reading 4 Bytes registers.

syncWriteTxOnly(port, start_address, data_length, param, param_length)[source]

Mocks a SyncWrite transmit package. We return randomly an error or success.

syncReadTx(port, start_address, data_length, param, param_length)[source]

Mocks a SyncWrite transmit package. We return randomly an error or success.

readRx(port, dxl_id, length)[source]

Mocks a read package received. Used by SyncRead and BulkRead. It will attempt to produce a response based on the data already exiting in the registers. If the register is a read-only one, we will add a random value between (-10, 10) to the exiting value and then trim it to the min and max limits of the register. When passing back the data, for registers that are more than 1 byte a low endian conversion is executed (see DynamixelRegister.register_low_endian()).

readTxRx(port, dxl_id, address, length)[source]

Mocks a read package received. Used by RangeRead. It will attempt to produce a response based on the data already exiting in the registers. If the register is a read-only one, we will add a random value between (-10, 10) to the exiting value and then trim it to the min and max limits of the register. When passing back the data, for registers that are more than 1 byte a low endian conversion is executed (see DynamixelRegister.register_low_endian()).

bulkWriteTxOnly(port, param, param_length)[source]

Simulate a BulkWrite transmit package. We return randomly an error or success.

bulkReadTx(port, param, param_length)[source]

“Simulate a BulkWrite transmit of response request package. We return randomly an error or success.

ping(ph, dxl_id)[source]

Simulates a ping on the Dynamixel bus.