Today, ZhengMotion Technology will share with you "Application of Motion Control Card in ROS (Part 2)". This chapter is based on the program of "Application of Motion Control Card in ROS (Part 1)" with slight modifications, realizing the development of ZhengMotion Technology's motion control card under ROS.
Before we begin our formal learning, let's first understand the motion control cards ECI2618 and ECI2828 from Zheng Motion Technology. These two products are 6-axis and 8-axis motion control cards, respectively.
The ECI2618 supports 6-axis pulse input and encoder feedback, with 24 onboard inputs, 16 onboard outputs, 2 AD converters, 2 DA converters, and a handwheel interface. Some output ports support high-speed PWM control.
The ECI2828 supports 8-axis bus input and encoder feedback, with 24 onboard inputs, 16 onboard outputs, 2 AD channels, 2 DA channels, and a handwheel interface. Some output ports support high-speed PWM control.
Both ECI2618 and ECI2828 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 "Application of Motion Control Card in ROS (Part 1)," we discussed the background of ROS applications, the detailed process of installing ROS Melodic on Ubuntu 18.04, and used ROS programming examples—message publishing and subscription—to illustrate the application development of the ROS motion control card.
As we learned in the previous article, ROS, as a flexible operating system, allows for a high degree of flexibility in the nodes running on it. These nodes 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, among other things. This flexibility allows ROS to adapt to a wide range of applications.
ROS features a distributed peer-to-peer design, multi-language support, streamlined and integrated architecture, a rich toolkit, and is free and open-source. The ROS system is gradually dominating the Chinese market in the robotics industry.
This article mainly discusses configuring the dynamic link library environment for positive motion technology and the single-axis motion of the motion control card under ROS.
I. 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"
II. Single-axis motion under ROS
This section mainly discusses the single-axis motion of motion control cards 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 control card 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:
References
1.ROS Wiki: http://wiki.ros.org/
2. Positive Motion Technology: ZMotion PC Function Library Programming Manual
3.https://blog.csdn.net/weixin_42544625/article/details/86802753
This concludes our sharing of "Application of Motion Control Card in ROS (Part 2)" by Zheng Motion Technology. For more exciting content, please follow the "Zheng Motion Assistant" WeChat official account.
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.