Dynamixel is a kind of networked actuator for robots developed by Korean manufacture ROBOTIS. It is widely used by companies, universities, and hobbyists due to its versatile expansion capability, power feedback function, position, speed, internal temperature, input voltage, and so on.
The Dynamixel servos can be connected in a daisy chain; it is a method of connecting device in a serial fashion, that is, connecting one device to another through the connected devices, and can control all the connected servos from one controller. Dynamixel servos communicate via RS485 or TTL. The list of available Dynamixel servos is given at http://www.robotis.com/xe/dynamixel_en.
The interfacing of Dynamixel is very easy. Dynamixel comes with a controller called USB2Dyanmixel, which will convert USB to Dynamixel compatible TTL/RS485 levels. The following figure shows the interfacing diagram of Dynamixel:
ROBOTIS provides Dynamixel SDK for accessing motor registers; we can read and write values to Dynamixel registers and retrieve data such as position, temperature, voltage, and so on.
The instructions to set USB2Dynamixel and Dynamixel SDK are given at support.robotis.com/en/.
Dynamixel can be programed using Python libraries. One of the Python libraries for handling Dynamixel servos is pydynamixel. This package is available for Windows and Linux. Pydynamixel will support RX, MX, and EX series servos.
We can download the pydynamixel Python package from https://pypi.python.org/pypi/dynamixel/.
Download the package and extract it to the home
folder. Open a terminal/DOS prompt and execute the following command:
sudo python setup.py install
After installing the package, we can try the following Python example, which will detect the servo attached to the USB2Dynamixel and write some random position to the servo. This example will work with RX and MX servos.
#!/usr/bin/env python
The following code will import the necessary Python modules required for this example. This includes Dynamixel Python modules too:
import os import dynamixel import time import random
The following code defines the main parameters needed for Dynamixel communication parameters.The nServos
variable denoted number of Dynamixel servos connected to the bus. The portName
variable indicates the serial port of USB2Dynamixel to which Dynamixel servos are connected. The baudRate
variable is the communication speed of USB2Dynamixel and Dynamixel.
# The number of Dynamixels on our bus. nServos = 1 # Set your serial port accordingly. if os.name == "posix": portName = "/dev/ttyUSB0" else: portName = "COM6" # Default baud rate of the USB2Dynamixel device. baudRate = 1000000
The following code is the Dynamixel Python function to connect to Dynamixel servos. If it is connected, the program will print it and scan the communication bus to find the number of servos starting from ID 1
to 255
. The Servo ID is the identification of each servo. We are given nServos
as 1
, so it will stop scanning after getting one servo on the bus:
# Connect to the serial port print "Connecting to serial port", portName, '...', serial = dynamixel.serial_stream.SerialStream( port=portName, baudrate=baudRate, timeout=1) print "Connected!" net = dynamixel.dynamixel_network.DynamixelNetwork( serial ) net.scan( 1, nServos )
The following code will append the Dynamixel ID and the servo object to the myActuators
list. We can write servo values to each servo using servo id and servo object. We can use the myActuators
list for further processing:
# A list to hold the dynamixels myActuators = list() print myActuators This will create a list for storing dynamixel actuators details. print "Scanning for Dynamixels...", for dyn in net.get_dynamixels(): print dyn.id, myActuators.append(net[dyn.id]) print "...Done"
The following code will write random positions from 450 to 600 to each Dynamixel actuator that is available on the bus. The range of positions in Dynamixel is 0 to 1023. This will set the servo parameters such as speed
, torque,torque_limt
, max_torque
, and so on:
# Set the default speed and torque for actuator in myActuators: actuator.moving_speed = 50 actuator.synchronized = True actuator.torque_enable = True actuator.torque_limit = 800 actuator.max_torque = 800
The following code will print the current position of the current actuator:
# Move the servos randomly and print out their current positions while True: for actuator in myActuators: actuator.goal_position = random.randrange(450, 600) net.synchronize()
The following code will read all data from actuators:
for actuator in myActuators: actuator.read_all() time.sleep(0.01)
for actuator in myActuators: print actuator.cache[dynamixel.defs.REGISTER['Id']], actuator.cache[dynamixel.defs.REGISTER['CurrentPosition']] time.sleep(2)
18.217.194.39