Bring Values and Sucesses To Our Customers

Home / Support and services / Technical Support

Technical support

Technical Support

How to Develop EtherCAT Motion Controller on ROS (2)

In last article, we have known ROS background, how to install ROS Melodic by Ubuntu18.04, and two ROS programming examples. Please visit “How to Develop EtherCAT Motion Controller on ROS (1)” for details.

Then, today, the second part is coming, that is, how to configure Zmotion dynamic library environment, and how one single-axis of EtherCAT motion controller on ROS is.


ZMOTION
ZMC432

ZMC432 is one 32-axis high-performance EtherCAT motion controller developed by Zmotion. And there are many communication interfaces, such as, EtherCAT, EtherNET, RS232, CAN, U disk, etc. In addition, it supports rich motion control functions, linear interpolation, circular interpolation, helical interpolation, electronic cam, electronic gear, synchronous follow, and so on.

1710747247585940.png

ZMC432 supports 24 inputs and 12 outputs, if you need more resources, 4096 inputs and 4096 outputs can be reached at most through EtherCAT or CAN expansion modules.

1710747272726240.png


ZMOTION
ZMC408CE

Actually, ZMC408CE is similar to ZMC432, including functions, interfaces, but it is one 8-axis high-performance EtherCAT motion controller. And it is with more 4 outputs than ZMC432, among these 16 outputs, OUT0-OUT7 support hardware comparison output, hardware timer, precision output in motion, and PWM.

1710747459506314.png

1710747488705205.png

What’s more, ZMC series motion controllers can be used in offline or online occasions.

For development, ZMC432 and ZMC408CE both use one same set of API function, C, C++, C#, LabVIEW, Python, Delphi all can be used, and mainstream platforms and operation systems all are valid, which means it is easy and convenient to develop.

1710747877746772.png


1. Configure Zmotion Dynamic Link Library Environment

(1)   Add Dynamic Link Library

New build folder "lib" under "content" -- zmotion(catkin_ws/src/zmotion/) of program package, and save dynamic link library "libzmotion.so".  

1710748025303826.png

1710748054877553.png

A. add the third party path (under build) in CMakeLists.txt

link_directories(

lib

${catkin_LIB_DIRS}

)


B. also, link dynamic link library in CMakeLists,txt file(when calling the link libaray, remember to remove lib and .so)

target_link_libraries(talker ${catkin_LIBRARIES} zmotion)



(2)   Add Library Function “zmcaux.cpp”, “zmotion.h”, “zmcaux.h”

A. add zmcaux.cpp file into "catkin_ws/src/zmotion/src"

1710748078664727.png


B. add head file "zmotion.h and zmcaux.h" into "catkin_ws/src/zmotion/include/ zmotion"

1710748098257587.png


C. 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

)


D. modify head file's quote, like below image (need to fill corresponding address of "include" file, zmotion is the name of program package)

#include "zmotion/zmotion.h"

#include "zmotion/zmcaux.h"

1710748116481605.png





2. Zmotion Controller Single-Axis Motion by ROS

“talker” node achieves axis 0 motion, and real time sends the position to “listener” node, then modifies "talker.cpp":

(1) Add Handle & Head File

#include "zmotion/zmotion.h"

#include "zmotion/zmcaux.h"

ZMC_HANDLE g_handle=NULL;


(2) Connect to Motion Controller Through EtherNET

ZMC_LinuxLibInit();

//EtherNET (Ethernet) to link

char ipaddr[16] = {"192.168.0.11"};

int x =ZAux_OpenEth(ipaddr,&g_handle); //***ZMC

ROS_INFO("connect to controller through Ethernet:%d",x);//Return 0 -- success


(3) Single-Axis Motion

ZAux_Direct_SetSpeed(g_handle, 0, 200); //set axis 0 motion speed as 200units/s

ZAux_Direct_SetAccel(g_handle, 0, 2000); //set axis 0 acceleration as 2000units/s/s

ZAux_Direct_SetDecel(g_handle, 0, 2000); //set axis 0 deceleration as 2000units/s/s

ZAux_Direct_SetSramp(g_handle, 0, 100); //set axis 0 S curve time as 100ms

ZAux_Direct_Single_Move(g_handle, 0, 300); //axis 0 moves 100 units that relates to current position


(4) Send Real-Time Position to “listener” Node

float piValue;

while (ros::ok())

{

    std_msgs::Float64 msg;

    ZAux_Direct_GetMpos(g_handle, 0, & piValue);//read time

    msg.data = piValue;

    //output, used to replace prinf/cout

    ROS_INFO("Position is: %f", msg.data);

    chatter_pub.publish(msg);

    ros::spinOnce();

    //sleep, make publishment frequency as 10Hz

    loop_rate.sleep();

}


(5) Compile

cd ~/catkin_ws/

catkin_make


(6) Run the Program

//open one new end station

roscore

//open another new end station

cd ~/catkin_ws/

rosrun zmotion talker

//open another new end station

cd ~/catkin_ws/

rosrun zmotion listener

Following is the running effect, real-time output position:

1710748147536073.png

In addition, it can be seen that axis 0 is running S curve motion from the oscilloscope.

1710748179190308.png




ABOUT ZMOTION

That's all, thank you for your reading -- How to Develop EtherCAT Motion Controller on ROS (2)

For more information, please pay close attention to "Support"  and   "Download" , and there are other platforms about Zmotion - Youtube   &   LinkedIn   &   Twitter    &   Tiktok    &   Facebook including technical information (development environment, routine code), product showing, company development, etc.

Hope to meet you, talk with you and be friends with you.  Welcome!

This article is edited by ZMOTION, here, share with you, let's learn together.

ZMOTION: DO THE BEST TO USE MOTION CONTROL.

Note: Copyright belongs to Zmotion Technology, if there is reproduction, please indicate article source. Thank you.

Zmotion Technology focuses on development of motion control technology and general motion control products, it is a national high and new technology enterprise. Due to its concentration and hard work in motion control technology, ZMOTION already become one of the fastest growing industrial motion control companies in China, and is also the rare company who has managed core technologies of motion control and real time industrial control software completely. Here, Zmotion provides motion controller, motion control card, vision motion controller, expansion module and HMI. In addition, there is one program software developed by Zmotion -- ZDevelop. It is a good choice for you to program and compile. And program through upper computer, there is PC manual.

Zmotion Technology  provides motion control card, motion controller, vision motion controller, expansion module and HMI. ( more keywords  for Zmotion: EtherCAT motion control card, EtherCAT motion controller, motion control system, vision controller, motion control PLC, robot controller, vision positioning...)

Have a good day, best wishes, see you next time.


2013-2023 版权所有 Zmotion Corp. Copyright Reserved 粤ICP备13037187号-1