Share this

Application of EtherCAT motion controller in ROS (Part 1)

2026-04-06 03:21:18 · · #1

This article takes the EtherCAT motion controllers ZMC432 and ZMC408CE with positive motion technology as examples to introduce the application and development of positive motion technology motion controllers on ROS.

Before we begin our formal learning, let's first understand the EtherCAT motion controllers ZMC432 and ZMC408CE from the positive motion technology. These two products are 32-axis and 8-axis EtherCAT motion controllers, respectively.

ZMC432 Function Introduction

The ZMC432 is a multi-axis, high-performance EtherCAT bus motion controller launched by Zheng Motion. It has communication interfaces such as EtherCAT, EtherNET, RS232, CAN and USB flash drive. The ZMC series motion controllers can be used in various occasions that require offline or online operation.

The ZMC432 can support up to 32 axes of motion control, and supports functions such as linear interpolation, arbitrary circular interpolation, spatial circular interpolation, helical interpolation, electronic cam, electronic gear, and synchronous following.

The ZMC432 supports 32-axis pulse input and encoder feedback. Its general-purpose I/O includes 24 input ports and 12 output ports; 2 AD and 2 DA ports; some output ports support high-speed PWM control.

The ZMC432 can be expanded to 4096 inputs and 4096 outputs via EtherCAT and CAN buses.

ZMC408CE Function Introduction

The ZMC408CE is a multi-axis, high-performance EtherCAT bus motion controller launched by Zheng Motion. It has communication interfaces such as EtherCAT, EtherNET, RS232, CAN and USB flash drive. The ZMC series motion controllers can be used in various occasions that require offline or online operation.

The ZMC408CE supports 8-axis motion control, expandable to a maximum of 32 axes, and supports linear interpolation, arbitrary circular interpolation, spatial circular interpolation, helical interpolation, electronic cam, electronic gear, synchronous following and other functions.

The ZMC408CE supports 8-axis motion control and can use pulse axes (with encoder feedback) or EtherCAT bus axes. The general-purpose I/O includes 24 input ports and 16 output ports. Some I/O are high-speed I/O, with two analog AD/DA channels and an EtherCAT refresh cycle of up to 125us.

The ZMC408CE supports 8 channels of hardware compare output, hardware timer, precise output during motion, and also supports 8 channels of PWM output, with corresponding output ports OUT0-7, supporting simultaneous triggering of hardware compare output on all 8 channels.

The ZMC408CE allows for flexible hardware resource expansion, and can be expanded to 4096 inputs and 4096 outputs via CAN or EtherCAT bus.

→ Both ZMC432 and ZMC408CE use the same set of API functions and support development languages ​​such as C, C++, C#, LabVIEW, Python, and Delphi. They also support platforms such as VC6.0, VB6.0, Qt, and .Net, and operating systems such as Windows, Linux, WinCE, and iMac.

01. ROS Application Background

ROS (Robot Operating System) is an open-source secondary operating system for robots. Its primary design goal is to improve code reusability in the field of robot development.

ROS is a distributed processing framework (also known as Nodes). This allows executables to be designed independently and loosely coupled at runtime. These processes can be encapsulated in packages and stacks for easy sharing and distribution.

ROS also supports a federated system of code repositories, enabling collaborative distribution. This design, from the file system level to the community level, makes it possible to independently decide on development and implementation. All of these functionalities can be achieved through ROS's foundational tools.

In short, ROS, as a flexible operating system, allows for a high degree of flexibility in the nodes on the system. They can reside on different computers or even on different networks. We can use an Arduino as a node to publish information, a laptop as a node to subscribe to such information, and a mobile phone as a node to drive a motor, etc.

The aforementioned flexibility allows ROS to be adapted to many different applications.

The main characteristics of ROS can be summarized as follows:

1. Distributed point-to-point design: ROS's point-to-point design, along with mechanisms such as service and node managers, can distribute the real-time computing pressure brought by functions such as computer vision and speech recognition, and can adapt to the challenges encountered by multiple robots.

2. Multilingual support

ROS supports many different languages, such as C++, Python, Octave, and LISP, and also includes various interface implementations for other languages.

3. Streamlining and Integration

The system built with ROS is modular, and the code in each module can be compiled separately. Moreover, the CMake tool used for compilation makes it easy to achieve the concept of simplification.

ROS essentially encapsulates complex code within libraries, creating only small applications to demonstrate the functionality of the ROS libraries, thus allowing simpler code to be ported and reused beyond the prototype.

4. Abundant toolkit

To manage the complex ROS software framework, we utilized a large number of small tools to compile and run a wide variety of ROS components, thus designing it as a kernel rather than building a massive development and runtime environment.

5. Free and open source

All of ROS's source code is publicly available.

Some applications of ROS in the industry

In recent years, domestic and international robotics companies, autonomous driving companies, and drone companies (DJI) have all joined the ROS camp. Furthermore, in recruitment advertisements from major companies such as Tencent, Pony.ai, Alibaba's Cainiao Network, and Baidu Apollo, positions such as autonomous driving planning algorithm engineers, autonomous navigation engineers, robot perception algorithm engineers, and system platform R&D architects all require "familiarity with ROS" or "preference will be given to candidates with ROS development experience." From this, we can see the development trend of the ROS system, which is gradually dominating the Chinese market in the robotics industry. Below are some typical ROS application scenarios:

1. KEBA, a leading player in robot controllers, has controllers that support ROS.

2. NASA's Robonaut 2, developed based on ROS, is already working on the International Space Station.

3. Baidu's Apollo autonomous vehicle is based on ROS, and it was almost changed to ROS 2. It can be found on GitHub (apollo-platform).

4. ROS-I is currently preparing to collaborate with Microsoft and BMW to develop an automation solution (see: A ROS-Industrial Collaboration with Microsoft and BMW).

5. Many industrial robotic arms have begun using the ROS system, and the official ROS-I fifth-anniversary video released at the end of 2017 featured robots from the four major robotic arm manufacturers. The KUKA Youbot robot shown below is developed using the ROS system.

02 Software Installation Process This section mainly describes the detailed process of installing ROS Melodic on Ubuntu 18.04 (this article uses Ubuntu 18.04 as an example, but the same applies to other versions and does not affect the use of the motion controller).

1. Configure sources.list

$ sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

2. Set the key (public key has been updated)

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

3. Update package (this will take a while, please be patient).

$ sudo apt-get update

At this point, the following problems may occur:

The solution is as follows: Enter the following in the terminal:

$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F42ED6FBAB17C654$ sudo apt-get update

When you see "Reading package lists... Done", it means the update is complete.

4. Install the full version of ROS melodic

$ sudo apt-get install ros-melodic-desktop-full

5. Initialize rosdep

$sudo rosdep init$rosdep update$echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc$ source ~/.bashrc

Renderings:

If you encounter the following problem when entering the command `sudo rosdep init`:

(1) The problem of sudo : rosdep : command not found

In the terminal, type: sudo apt install rospack-tools

(2)ERROR: cannot download default sources list from: https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list Website may be down.

① In the terminal, type: sudo gedit /etc/hosts to open the hosts file. The content should look like this;

② Add 199.232.28.133 raw.githubusercontent.com to the file. The file will look like this after adding it.

③Then save the file and exit;

④ Execute the following command in the terminal: sudo rosdep init, and the problem is solved.

6. Test if ROS is installed successfully.

$ roscore

The page opened successfully as shown in the image below:

03. ROS Programming Cases This section mainly covers two ROS programming cases: "Message Publishing" and "Subscription". 1. Create a ROS workspace.

$mkdir -p ~/catkin_ws/src$cd ~/catkin_ws/$ catkin_make

2. Create a ROS package (zmotion is the package name, but it can also be defined as something else).

·

$cd ~/catkin_ws/src$catkin_create_pkg zmotion std_msgs roscpp$cd ~/catkin_ws$ catkin_make

3. After creating the package, you need to `source ~/catkin_ws/devel/setup.bash` every time you run it; otherwise, the file cannot be found. To solve this, you need to `source` it every time:

·

In the terminal, type: `$ gedit ~/.bashrc` Add the following line to the end of the file and save it: `$ source ~/catkin_ws/devel/setup.bash`

4. Create a new node file. Create a src directory within the zmotion package directory:

·

`$cd ~/catkin_ws/src/zmotion` // Enter the zmotion package directory. `$mkdir -p src` // Create a new folder named `src` to store C++ programs. `$cd src/` // Enter the `src` folder. `$touch talker.cpp` // Create a new `.cpp` file for publishing messages. `$touch listener.cpp` // Create a new `.cpp` file for subscribing to messages.

5. Write and publish the node (talker.cpp).

Functionality:

(1) Initialize the ROS system;

(2) Publish std_msgs/Float64 messages on the chatter topic;

(3) Messages are sent at a frequency of 10 times per second.

·

#include "ros/ros.h" #include "std_msgs/Float64.h" #include int main(int argc, char **argv){ // Initialize ROS, name remapping (unique), must be the base name, without / ros::init(argc, argv, "talker"); // Create a handle for the process's node, the first created NodeHandle initializes the node ros::NodeHandle n; // Tell the host to publish a std_msgs message on the chatter topic // The host will subscribe to all chatter topic nodes, the parameter represents the size of the publish queue (first in first out) ros::Publisher chatter_pub = n.advertise("chatter", 1000); ros::Rate loop_rate(10); // Self-loop frequency int count = 0; while (ros::ok()) { std_msgs::Float64 msg; msg.data = count*1.0; // Output, used to replace printf/cout ROS_INFO("Position is: %f", msg.data); chatter_pub.publish(msg); ros::spinOnce(); // Sleep to make the publishing frequency 10Hz loop_rate.sleep(); ++count; } return 0;}

6. Write the subscription node (listener.cpp). Implement the following functions: (1) Initialize the ROS system; (2) Subscribe to chatter topic messages; (3) Enter a self-loop and wait for messages to arrive; (4) When a message arrives, call the chatterCallback() function.

·

#include "ros/ros.h" #include "std_msgs/Float64.h" // Callback function void chatterCallback(const std_msgs::Float64::ConstPtr& msg){ ROS_INFO("I heard: %f", msg->data);} int main(int argc, char **argv){ ros::init(argc, argv, "listener"); ros::NodeHandle n; // Tell the master to subscribe to chatter topic messages ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); ros::spin(); // Self-loop return 0;}

7. Modify CMakeLists.txt.

(1) Open the path to the package zmotion (catkin_ws / src / zmotion) and find the CMakeLists.txt file.

(2) The minimum version has been changed to 2.8.3.

·

cmake_minimum_required(VERSION 2.8.3)

(3) Locate find_package and add the dependency package message_generation.

·

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs message_generation)

(4) Ensure that generate_message is called.

·

generate_messages(DEPENDENCIES std_msgs)

(5) Ensure that the dependency for this message is also added to the runtime dependencies.

·

catkin_package(# INCLUDE_DIRS include# LIBRARIES beginner_tutorials# CATKIN_DEPENDS roscpp std_msgs# DEPENDS system_lib CATKIN_DEPENDS message_runtime)

(6) Modify the settings under build

① Comment out the include directive in include_directories.

include_directories( include ${catkin_INCLUDE_DIRS})

② Add the following code to the specified location. The code below can be added arbitrarily to the build. I added it to the appropriate location for aesthetic purposes. As long as it is added to the build, it will take effect.

·

add_executable(talker src/talker.cpp)add_executable(listener src/listener.cpp)add_dependencies(talker $zmotion_generate_messages_cpp)//zmotion is the package name target_link_libraries(talker ${catkin_LIBRARIES})target_link_libraries(listener ${catkin_LIBRARIES})

(7) Finally, list the complete CMakeLists.txt.

·

cmake_minimum_required(VERSION 2.8.3)project(zmotion)find_package(catkin REQUIRED COMPONENTS roscpp std_msgs message_generation)## Generate added messages and services with any dependencies listed heregenerate_messages( DEPENDENCIES std_msgs)################################### catkin specific configuration #################################catkin_package(# INCLUDE_DIRS include# LIBRARIES zmotion# CATKIN_DEPENDS roscpp std_msgs# DEPENDS system_libCATKIN_DEPENDS message_runtime)############# Build ############## Specify additional locations of header files## Your package locations should be listed before other locationsinclude_directories( include ${catkin_INCLUDE_DIRS})## Declare a C++ executable## With catkin_make all packages are built within a single CMake context## The recommended prefix ensures that target names across packages don't collideadd_executable(talker src/talker.cpp)add_executable(listener src/listener.cpp)## Rename C++ executable without prefixadd_dependencies(talker $zmotion_generate_messages_cpp)## Specify libraries to link a library or executable target againsttarget_link_libraries(talker ${catkin_LIBRARIES})target_link_libraries(listener ${catkin_LIBRARIES})

8. Modify the package.xml file.

·

message_generationmessage_generationmessage_runtime

9. Compile.

·

$ cd ~/catkin_ws$ catkin_make

10. Run the program. (1) Open a new terminal and start the ROS system;

·

$ roscore

(2) Open a new terminal and run the publish node;

·

$ cd ~/catkin_ws // Enter the working control directory $ rosrun zmotion talker // Run the publish node program

(3) Open a new terminal and run the subscription node;

·

$ cd ~/catkin_ws$ rosrun zmotion listener

(4) Results. Results of running the release node program:

·

[INFO] [WallTime: 1314931831.774057] Position is: 1.000000 3.000000[INFO] [WallTime: 1314931834.782059] Position is: 4.000000[INFO] [WallTime: 1314931835.784853] Position is: 5.000000

Results of running the subscription node program:

·

[INFO] [WallTime: 1314931970.262246] I heard: 1.000000[INFO] [WallTime: 1314931971.266348] I heard: 2.000000[INFO] [WallTime: 1314931972.270429] I heard: 3.000000[INFO] [WallTime: 1314931973.274382] I heard: 4.000000[INFO] [WallTime: 1314931974.277694] I heard: 5.000000

This concludes the first part of our discussion on the application of EtherCAT motion controllers in ROS.

For more exciting content, please follow the "Zheng Motion Assistant" WeChat official account. For related development environment and example code, please contact Zheng Motion's technical sales engineer: 400-089-8936.

This article is original content from Zheng Motion Technology. We welcome everyone to reprint it for mutual learning and to jointly improve China's intelligent manufacturing level. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.


Read next

CATDOLL 128CM Kelsie Silicone Doll (Soft Silicone Head)

Height: 128 Silicone Weight: 21kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: N/A Vaginal Depth: 3-15cm...

Articles 2026-02-22