This article mainly introduces the configuration of the dynamic link library environment for motion control technology and the single-axis motion of the EtherCAT motion controller under ROS.

Introduction to ZMC432 Functions

ZMC432 is a multi-axis high-performance EtherCAT bus motion controller launched by Motion Technology, equipped with communication interfaces including EtherCAT, Ethernet, RS232, CAN, and USB. The ZMC series motion controllers can be applied in various scenarios requiring offline or online operations.
ZMC432 supports up to 32-axis motion control, including functions such as linear interpolation, arbitrary circular interpolation, spatial arcs, spiral interpolation, electronic cam, electronic gear, and synchronous following.
ZMC432 supports 32-axis pulse input and encoder feedback, with general I/O including 24 input channels and 12 output channels; 2 AD, 2 DA; with specific output channels supporting high-speed PWM control.
ZMC432 can expand hardware resources through EtherCAT and CAN bus, supporting up to 4096 input and 4096 output channels.

Introduction to ZMC408CE Functions

ZMC408CE is a multi-axis high-performance EtherCAT bus motion controller launched by Motion Technology, equipped with communication interfaces including EtherCAT, Ethernet, RS232, CAN, and USB. The ZMC series motion controllers can be applied in various scenarios requiring offline or online operations.
ZMC408CE supports 8-axis motion control, expandable to a maximum of 32 axes, and supports functions such as linear interpolation, arbitrary circular interpolation, spatial arcs, spiral interpolation, electronic cam, electronic gear, and synchronous following.
ZMC408CE supports 8-axis motion control, which can use pulse axes (with encoder feedback) or EtherCAT bus axes, with general I/O including 24 input channels and 16 output channels, part of which are high-speed I/O, and two channels each for analog AD/DA, with the fastest EtherCAT refresh cycle of 125us.
ZMC408CE supports hardware comparison output for 8 channels, hardware timers, precise output during motion, and supports 8-channel PWM output, with corresponding output channels being OUT0-7, supporting simultaneous triggering of hardware comparison outputs for 8 channels.
ZMC408CE can flexibly expand hardware resources, supporting up to 4096 inputs and 4096 outputs through CAN or EtherCAT bus.
In the previous lesson, we introduced the application background of ROS and the detailed process of installing ROS Melodic on Ubuntu 18.04, and explained the application development of the EtherCAT motion controller in ROS through the ROS programming example “Message Publishing and Subscription”. For details, click →Application of EtherCAT Motion Controller in ROS (Part 1).
1. Add Dynamic Link Library
Create a folder named lib under the package directory zmotion (catkin_ws/src/zmotion/) to store the dynamic link library libzmotion.so.
Add the third-party library path in CMakeLists.txt (under build):
link_directories( lib ${catkin_LIB_DIRS})
target_link_libraries(talker ${catkin_LIBRARIES} zmotion)
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)
Modify the header file references as shown in the figure below (the relative path of the include files should be filled in, zmotion is the package name):
#include "zmotion/zmotion.h"
#include "zmotion/zmcaux.h"

The talker node implements the motion of axis 0 and sends its position to the listener node in real-time. Modify talker.cpp as follows:
#include "zmotion/zmotion.h"
#include "zmotion/zmcaux.h"
ZMC_HANDLE g_handle=NULL;
2. Link to Motion Controller via Ethernet
ZMC_LinuxLibInit(); // Ethernet link
char ipaddr[16] = {"192.168.0.11"};
int x = ZAux_OpenEth(ipaddr, &g_handle); //***ZMCROS_INFO("Ethernet link controller:%d",x); // Return 0 indicates successful connection
3. Implement Single-Axis Motion
ZAux_Direct_SetSpeed(g_handle, 0, 200); // Set axis 0 speed to 200 units/s
ZAux_Direct_SetAccel(g_handle, 0, 2000); // Set axis 0 acceleration to 2000 units/s/s
ZAux_Direct_SetDecel(g_handle, 0, 2000); // Set axis 0 deceleration to 2000 units/s/s
ZAux_Direct_SetSramp(g_handle, 0, 100); // Set axis 0 S-curve time to 100ms
ZAux_Direct_Single_Move(g_handle, 0, 300); // Move axis 0 relative to the current position by 100 units
4. Send Real-Time Position to Listener Node
float piValue;
while (ros::ok()) {
std_msgs::Float64 msg;
ZAux_Direct_GetMpos(g_handle, 0, &piValue); // Get position
msg.data = piValue; // Output, replace printf/cout
ROS_INFO("Position is: %f", msg.data);
chatter_pub.publish(msg);
ros::spinOnce(); // Sleep to make publish frequency 10Hz
loop_rate.sleep();
}
cd ~/catkin_ws/catkin_make
6. Run the Program
// Open a new terminal
roscore
// Open another new terminal
cd ~/catkin_ws/
rosrun zmotion talker
// Open another new terminal
cd ~/catkin_ws/
rosrun zmotion listener

This concludes the sharing of the application of Motion Technology’s EtherCAT motion controller in ROS (Part 2). Thank you for reading!
For more exciting content, please follow the “Motion Assistant” public account. If you need relevant development environment and example code, please consult Motion Technology sales engineers: 400-089-8936.

About Motion Technology
Shenzhen Motion Technology Co., Ltd. was established in 2013, focusing on the research of pure domestic motion control technology and the development of general motion control software and hardware platforms and products. It is a national high-tech enterprise and a specialized and innovative “little giant” enterprise.
Motion Technology gathers outstanding talents from companies like Huawei and ZTE. Striving for innovation, the company currently holds more than fifty intellectual property rights, including patents and copyrights. While adhering to independent innovation, it actively collaborates with major universities and research institutes to jointly research the basic technology of motion control, making it one of the fastest-growing companies in the field of industrial control in China, and one of the few companies that fully masters core motion control technology and real-time industrial control software platform technology.
In addition to the main R&D center, Motion Technology has three R&D branches in Zhongshan, Wuhan, and Shanghai. To better serve customers, there are two regional service centers in Suzhou and Dongguan, and sales and technical service institutions in Foshan, Xiamen, Qingdao, Xi’an, Wuhan, Chengdu, Tianjin, and Zhengzhou.
After years of development and application by numerous partners, Motion Technology’s products are widely used in fields such as 3C electronics, semiconductors, new energy, robotics, packaging and printing, textile and apparel, laser processing, medical pharmaceuticals, CNC machine tools, and traditional processing.
