Tag Archives: multi motor

Simple C++ Code for Multi Dynamixel Servo Motor Control

Simple C++ Code for Multi Dynamixel Servo Motor Control

 

// this post is updated to eliminate the dependency on QT, 2015.06.26

 

In this post, I am sharing my C++ class to control multi Dynamixel servo motors.

In my case, I am using MX-24f, but most of dynamixel servo motors are using the same protocol. Thus, you can use this code directly. I am attaching all files (dynamixel library and others) to execute a demo program.

<Download>

If you don’t need common files, just use “multi_dnmx_motor.h” and “multi_dnmx_motor.cpp”. For the usage, see “main.cpp” file. It is super easy.  Demo program was made for Linux environment, but Windows uses still can use “multi_dnmx_motor” class

If you don’t know anything about Dynamixel program. Just follow the below.

 

0. Before following this instruction, check if the connection and settings are correct with “RoboPlus Manager” which can be downloaded in Robotis website, >> Support >> Download.

1. Go to “Dynamixel_src” folder.

2. “Make” : It will generate a library and automatically copy the lib. to the library folder.

3. Go to “Multi_Dynamixel_Motor_Control” folder.

4. Open “multi_dnmx_motor.h” file

5. Change “user setting”. You have to set the baud_rate, number of motors, and their motor IDs. Just change defines. (If you don’t know motors’ these values, use “RoboPlus”, a super easy program, and available in the Robotis website, http://support.robotis.com/en/ )

// User setting
#define BAUD_NUM 34 // 1: 1Mbps 34:57142bps
#define NUM_OF_MOTORS 4 // Number of motors

#define MOTOR_ID_1 1 // Motor 1 ID
#define MOTOR_ID_2 2 // Motor 2 ID
#define MOTOR_ID_3 3 // Motor 3 ID
#define MOTOR_ID_4 4 // Motor 4 ID

6.  compile it with this command

” g++ main.cpp multi_dnmx_motor.cpp -I../include -L../lib -ldxl  ”

7. Execute the program.

 

Good luck ^_^

<Download>