Today, ZhengMotion Technology will share with you "Motion Control Card Application Development Tutorial: ROS (Part 2)". This chapter is based on the program in "Motion Control Card Application Development Tutorial: ROS (Part 1)" with slight modifications to realize 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 ECI2418 and ECI2618 from Zheng Motion Technology. These two products are 4-axis and 6-axis motion control cards, respectively.
The ECI2418 supports 4-axis pulse input and encoder feedback, with 24 onboard inputs, 16 onboard outputs, 2 AD, 2 DA, and a handwheel interface. Some output ports support high-speed PWM control.
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.
Both ECI2418 and ECI2618 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 "Motion Control Card Application Development Tutorial: ROS (Part 1)," we discussed the background of ROS applications, the detailed process of installing ROS Melodic on Ubuntu 18.04, and used a ROS programming case study—message publishing and subscription—to illustrate the application development of ROS for the Zheng Motion Technology 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.
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.cpp
src/zmcaux.cpp
include /zmotion/zmotion.h
include /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"
Single-axis motion under two 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); //***ZMC
ROS_INFO( "Ethernet link controller:%d" , x); // Returns 0 if 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/s
ZAux_Direct_SetDecel(g_handle, 0, 2000); // Sets the deceleration of axis 0 to 2000 units/s/s
ZAux_Direct_SetSramp(g_handle, 0, 100); // Sets the S-curve time on axis 0 to 100ms
ZAux_Direct_Single_Move(g_handle, 0, 300); // Move axis 0 100 units relative to the 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); // Get the value when...
msg.data = piValue;
// Output, used to replace prinf/cout
ROS_INFO("Position is: %f", msg.data);
chatter_pub.publish(msg);
ros::spinOnce();
//Sleep mode to allow the output frequency to be 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 tutorial on "Motion Control Card Application Development Tutorial: ROS (Part 2)" from 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.