Skip to main content
  • This tutorial shows you how to read data from a Dynamixel using the Dynamixel Easy SDK.

NOTE: It assumes that you have already installed the SDK.

Make py file

  • Create a new Python source file Open it with your editor.
$ touch tutorial_step2.py

Check the Port Names

  • Before running the code, check the port name of the connected Dynamixel.
  • For General
    • OpenRB-150: ttyACM0: USB ACM device
    • U2D2: FTDI USB Serial Device converter now attached to ttyUSB0
$ sudo dmesg | grep tty

Source Code Description

from dynamixel_easy_sdk import *

def main():
connector = Connector("/dev/ttyACM0", 57600)
motor1 = connector.createMotor(1)

present_position = motor1.getPresentPosition()
print("Present Position:", present_position)

if __name__ == "__main__":
main()

Import Library​

  • Import dynamixel_easy_sdk.
from dynamixel_easy_sdk import *

Create Connector and Motor Object​

  • Create a Connector object with port name and baud rate to manage the communication.
def main():
connector = Connector("/dev/ttyACM0", 57600)
  • Create a Motor object for each Dynamixel servo you want to control with its ID, using the createMotor method of the Connector class.
motor1 = connector.createMotor(1)

Get Present Position​

  • You can read the present position of the motor using the getPresentPosition method.
present_position = motor1.getPresentPosition()
print("Present Position:", present_position)

Error Handling

  • When an error occurs, DxlRuntimeError is raised.
  • You can catch this error using a try-except block.
try:
motor1.getPresentPosition()
except DxlRuntimeError as e:
print(e)
  • DxlRuntimeError contains DxlError Enum that provides detailed information about the error.
try:
motor1.getPresentPosition()
except DxlRuntimeError as e:
if e.dxl_error == DxlError.SDK_COMM_TX_FAIL:
print("Transmission failed.")
elif e.dxl_error == DxlError.SDK_COMM_RX_FAIL:
print("Receive failed.")