This article mainly introduces the configuration of the dynamic link library environment for positive motion technology and the single-axis motion of the EtherCAT motion controller under 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.
In the previous lesson, we introduced the background of ROS applications and the detailed process of installing ROS Melodic on Ubuntu 18.04. We also explained in detail the application development of the EtherCAT motion controller in ROS through the ROS programming case study "Message Publishing and Subscription". For details, click → Application of EtherCAT Motion Controller in ROS (Part 1).
01. Configure the dynamic link library environment for positive motion technology
1. Add dynamic link library
Create a new folder named lib under the package directory zmotion (catkin_ws/src/zmotion/) and store the dynamic link library libzmotion.so.
Add the path to the third-party library (under the build directory) to CMakeLists.txt:
·
link_directories( lib ${catkin_LIB_DIRS})
And link the dynamic link library in the CMakeLists.txt file (remove the lib and .so from the filename when calling the library):
·
target_link_libraries(talker ${catkin_LIBRARIES} zmotion)
2. Add library functions zmcaux.cpp, zmotion.h, and zmcaux.h. Add the zmcaux.cpp file to the catkin_ws/src/zmotion/src directory:
Add the header files zmotion.h and zmcaux.h to the catkin_ws/src/zmotion/include/zmotion directory:
Add these three library files to CMakeLists.txt:
·
add_executable(talker src/talker.cppsrc/zmcaux.cppinclude/zmotion/zmotion.hinclude/zmotion/zmcaux.h)
Modify the header file references as shown in the image below (you need to fill in the relative path of the include file, and zmotion is the package name):
·
#include "zmotion/zmotion.h" #include "zmotion/zmcaux.h"
02. Single-axis motion of the positive motion controller under ROS
The talker node implements movement on axis 0 and sends its position to the listener node in real time. Modify talker.cpp as follows:
1. Add handle and header file
·
#include "zmotion/zmotion.h" #include "zmotion/zmcaux.h" ZMC_HANDLE g_handle=NULL;
2. Connect the motion controller via Ethernet
·
ZMC_LinuxLibInit(); // Ethernet connection char ipaddr[16] = {"192.168.0.11"}; int x = ZAux_OpenEth(ipaddr,&g_handle); //*** ZMCROS_INFO("Ethernet link controller:%d",x); // If 0 is returned, the connection is successful
3. Achieve single-axis motion
·
`ZAux_Direct_SetSpeed(g_handle, 0, 200);` // Sets the speed of axis 0 to 200 units/s. `ZAux_Direct_SetAccel(g_handle, 0, 2000);` // Sets the acceleration of axis 0 to 2000 units/s. `ZAux_Direct_SetDecel(g_handle, 0, 2000);` // Sets the deceleration of axis 0 to 2000 units/s. `ZAux_Direct_SetSramp(g_handle, 0, 100);` // Sets the S-curve time of axis 0 to 100ms. `ZAux_Direct_Single_Move(g_handle, 0, 300);` // Moves axis 0 100 units relative to its current position.
4. Send the real-time location to the listener node.
·
float piValue; while (ros::ok()){ std_msgs::Float64 msg; ZAux_Direct_GetMpos(g_handle, 0, &piValue);//When getting msg.data = piValue; //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();}
5. Compilation
·
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
The running result is shown below, with the location output in real time:
Furthermore, we can see on the oscilloscope on the host computer that axis 0 is moving in an S-curve motion:
This concludes the second 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.