In last article, we have known ROS background, how to install ROS Melodic by Ubuntu18.04, and two ROS programming examples. Please visit “How to Develop EtherCAT Motion Controller on ROS (1)” for details.
Then, today, the second part is coming, that is, how to configure Zmotion dynamic library environment, and how one single-axis of EtherCAT motion controller on ROS is.
ZMC432 is one 32-axis high-performance EtherCAT motion controller developed by Zmotion. And there are many communication interfaces, such as, EtherCAT, EtherNET, RS232, CAN, U disk, etc. In addition, it supports rich motion control functions, linear interpolation, circular interpolation, helical interpolation, electronic cam, electronic gear, synchronous follow, and so on.
ZMC432 supports 24 inputs and 12 outputs, if you need more resources, 4096 inputs and 4096 outputs can be reached at most through EtherCAT or CAN expansion modules.
Actually, ZMC408CE is similar to ZMC432, including functions, interfaces, but it is one 8-axis high-performance EtherCAT motion controller. And it is with more 4 outputs than ZMC432, among these 16 outputs, OUT0-OUT7 support hardware comparison output, hardware timer, precision output in motion, and PWM.
What’s more, ZMC series motion controllers can be used in offline or online occasions.
For development, ZMC432 and ZMC408CE both use one same set of API function, C, C++, C#, LabVIEW, Python, Delphi all can be used, and mainstream platforms and operation systems all are valid, which means it is easy and convenient to develop.
(1) Add Dynamic Link Library
New build folder "lib" under "content" -- zmotion(catkin_ws/src/zmotion/) of program package, and save dynamic link library "libzmotion.so".
A. add the third party path (under build) in CMakeLists.txt
link_directories(
lib
${catkin_LIB_DIRS}
)
B. also, link dynamic link library in CMakeLists,txt file(when calling the link libaray, remember to remove lib and .so)
target_link_libraries(talker ${catkin_LIBRARIES} zmotion)
(2) Add Library Function “zmcaux.cpp”, “zmotion.h”, “zmcaux.h”
A. add zmcaux.cpp file into "catkin_ws/src/zmotion/src"
B. add head file "zmotion.h and zmcaux.h" into "catkin_ws/src/zmotion/include/ zmotion"
C. and add these three library files in CMakeLists.txt:
add_executable(talker
src/talker.cpp
src/zmcaux.cpp
include/zmotion/zmotion.h
include/zmotion/zmcaux.h
)
D. modify head file's quote, like below image (need to fill corresponding address of "include" file, zmotion is the name of program package)
#include "zmotion/zmotion.h"
#include "zmotion/zmcaux.h"
“talker” node achieves axis 0 motion, and real time sends the position to “listener” node, then modifies "talker.cpp":
(1) Add Handle & Head File
#include "zmotion/zmotion.h"
#include "zmotion/zmcaux.h"
ZMC_HANDLE g_handle=NULL;
(2) Connect to Motion Controller Through EtherNET
ZMC_LinuxLibInit();
//EtherNET (Ethernet) to link
char ipaddr[16] = {"192.168.0.11"};
int x =ZAux_OpenEth(ipaddr,&g_handle); //***ZMC
ROS_INFO("connect to controller through Ethernet:%d",x);//Return 0 -- success
(3) Single-Axis Motion
ZAux_Direct_SetSpeed(g_handle, 0, 200); //set axis 0 motion speed as 200units/s
ZAux_Direct_SetAccel(g_handle, 0, 2000); //set axis 0 acceleration as 2000units/s/s
ZAux_Direct_SetDecel(g_handle, 0, 2000); //set axis 0 deceleration as 2000units/s/s
ZAux_Direct_SetSramp(g_handle, 0, 100); //set axis 0 S curve time as 100ms
ZAux_Direct_Single_Move(g_handle, 0, 300); //axis 0 moves 100 units that relates to current position
(4) Send Real-Time Position to “listener” Node
float piValue;
while (ros::ok())
{
std_msgs::Float64 msg;
ZAux_Direct_GetMpos(g_handle, 0, & piValue);//read time
msg.data = piValue;
//output, used to replace prinf/cout
ROS_INFO("Position is: %f", msg.data);
chatter_pub.publish(msg);
ros::spinOnce();
//sleep, make publishment frequency as 10Hz
loop_rate.sleep();
}
(5) Compile
cd ~/catkin_ws/
catkin_make
(6) Run the Program
//open one new end station
roscore
//open another new end station
cd ~/catkin_ws/
rosrun zmotion talker
//open another new end station
cd ~/catkin_ws/
rosrun zmotion listener
Following is the running effect, real-time output position:
In addition, it can be seen that axis 0 is running S curve motion from the oscilloscope.
ABOUT ZMOTION
That's all, thank you for your reading -- How to Develop EtherCAT Motion Controller on ROS (2)
For more information, please pay close attention to "Support" and "Download" , and there are other platforms about Zmotion - Youtube & LinkedIn & Twitter & Tiktok & Facebook, including technical information (development environment, routine code), product showing, company development, etc.
Hope to meet you, talk with you and be friends with you. Welcome!
This article is edited by ZMOTION, here, share with you, let's learn together.
ZMOTION: DO THE BEST TO USE MOTION CONTROL.
Note: Copyright belongs to Zmotion Technology, if there is reproduction, please indicate article source. Thank you.
Zmotion Technology focuses on development of motion control technology and general motion control products, it is a national high and new technology enterprise. Due to its concentration and hard work in motion control technology, ZMOTION already become one of the fastest growing industrial motion control companies in China, and is also the rare company who has managed core technologies of motion control and real time industrial control software completely. Here, Zmotion provides motion controller, motion control card, vision motion controller, expansion module and HMI. In addition, there is one program software developed by Zmotion -- ZDevelop. It is a good choice for you to program and compile. And program through upper computer, there is PC manual.
Zmotion Technology provides motion control card, motion controller, vision motion controller, expansion module and HMI. ( more keywords for Zmotion: EtherCAT motion control card, EtherCAT motion controller, motion control system, vision controller, motion control PLC, robot controller, vision positioning...)
Have a good day, best wishes, see you next time.