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 ^_^
how install to C++ in the Windows 7?
Sorry but I cannot help you learning C programming. I would like to recommend you to learn first C++ programming. There are many good tutorials in Youtube. Good luck.
When I run the makefile on my Linux box I get the error ”
/home/querist/Qt/5.1.1/gcc/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile Multi_Dynamixel_Motor_Control.pro
make: /home/querist/Qt/5.1.1/gcc/bin/qmake: Command not found
make: *** [Makefile] Error 127 ”
If you could tell me if I am missing any libraries or other things, I would really appreciate it. I am semi new to make files are their errors.
Hi, Robert, I just updated the post to eliminate the dependency of QT. So you might be able to compile the code. Good luck ^^
Thank you for that. when I run the a.out that is created from the make file, what are the parameters it is looking for in order to move the servo? I have tried numerous combinations with no success. Thank you.
Oh do not use make file. Please just compile with the command line that I wrote at (5).
Sorry, That is what I used, it gives me an executable, but when I run that Executable, it seems to be waiting for input after it says “succeed to open USB2Dynamixel” , what form of input should I use? I have tried different combinations and none have worked.
In this case, I like to suggest you to run “RoboPlus manager” which can be downloaded in the website of Robotis. You can see and modify all of settings with this program.
Hi, The code was developed for my project, so that it includes some strange names in variables. I am now updating the code to remove all unnecessary parts. Probably I might be able to update all codes to work correctly.
hi. thank you for your code.
i am trying your code in QT but i have problem about #include .. have an error “no such file or directory”.. but i have copy all of DynamixelSDK-3.4.1 folder in Directory of my project.. can you help me?
Thank you
sorry.. aboout include map