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 (1)

It can be referred from the title, this article will talk about “How to Develop EtherCAT Motion Controller on ROS”. And here takes two controllers as examples, ZMC432 and ZMC408CE.

Before that, let’s see how ZMC432 and ZMC408CE are.

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.

ZMC432

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.

ZMC432-1


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.

ZMC408CE

ZMC408CE-1

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.

Uniform API Function



1. What Is ROS ?

ROS (robot operating system) is one operating system (secondary operating system) after opening source for robots. The main aim is to promote code reuse ration in the field of robotic R&D.

ROS is a processing frame of distributed type (also can be called as Nodes), then execution files can be designed independently and they can loosen couple while running. In addition, these processes can be encapsulated into data packages (Packages) and stack (Stacks) for sharing and distributing.

What's more, ROS supports joint system of code library, then cooperation also can be distributed. In this way, this kind of design (from file system level to community level) makes it possible to independently determine development and implement work. All above functions are achieved through ROS basic tools.

Simply, ROS as a kind of flexible operating system, it is really random on system nodes, they can be located in different PC, even in different Ethernet. Then, we can use one Arduino as one node to post message, and use one laptop as one node to subscribe above information and use one phone as one node to drive motor. Therefore, it can be seen ROS can be applied in all kinds of occasions.

ROS Robots

(1)    ROS Main Features

A. Distributed & Point to Point

The point to point design of ROS and mechanisms such as service and node managers can disperse the real-time computing pressure brought by functions of PC vision and audio recognition, which can adapt to the challenges encountered by multi-robots.

7.png

B. Multiple Program Languages

ROS supports several kinds of programming languages, such as, C++, Python, Octave, and LISP. Also, it includes multiple kinds of interfaces of other languages.

8.png

C. Simplification & Integration

Systems built by ROS are modular, and codes in each module can be compiled independently. And "simplification" theory can be easily achieved through "CMake" tool (for compiling).

And complex codes are encapsulated into the library by ROS. It only builds some application programs to show library, which means it allows simple codes that exceed prototype to be transplanted and reused.

D. Rich Tool Package

To manage complicated ROS software framework, we use a lot of small tools to compile and run all kinds of ROS components. Then, the kernel is designed, namely, it is not to build a huge development and running environment.

9.png

E. Free & Open Source

All source codes of ROS are released in public.


(2)    ROS Applications

In recent years, domestic and foreign robot enterprises, driverless enterprises, and drone enterprises (DJI drones) all have joined the ROS. Now actually many enterprises need engineers who knows or masters ROS knowledge. Then it can be known ROS is popular increasingly. Please see below ROS typical applications.

A. “Boss" in robot controllers -- KEBA , their controllers support ROS.

KEBA

B. Robonaut 2 developed based on ROS by USA NASA has been already working on the International Space Station.

1710294566936886.png

C. The bottom layer of Baidu's Apollo unmanned vehicle is developed based on ROS. It can be found on github (apollo-platform).

1710295986346436.png

D. ROS-I prepares to cooperate with Microsoft and BMW to develop a set of automation solutions (Reference: A ROS-Industrial Collaboration with Microsoft and BMW)

1710296008723572.png

E.  Many industrial robotic arms use ROS system. Among them, the 5th anniversary video officially released by ROS-I at the end of 2017 is full of robots in the four major families. The KUKA youbot robot in the picture below is developed by using the ROS system.

1710296063786394.png



2. How to Install the Software ?

This part mainly talks about the detailed process of installing ROS Melodic on Ubuntu 18.04 (this article takes Ubuntu 18.04 as an example, the same is true for others, and it does not affect the use of motion controller).

(1)    Set “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 “key” (key is updated)

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

421C365BD9FF1F717815A3895523BAEEB01FA116

1710296114754981.png


(3)    Update “package” (maybe a long time, please wait a moment)

$ sudo apt-get update

At this time, it may meet following questions.

1710296121645585.png

Solution is following, enter in end:

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

$ sudo apt-get update

1710296135597172.png

When “Reading package lists … Done” appears, which means updating succeeds.


(4)    Install “ROS melodic” (full version)

$ 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

Effects:

1710296189685968.png

1710296194178916.png

If you meet following problems when input the instruction "sudo rosdep init":

A. sudo: rosdep: command not found

Enter in the terminal: sudo apt install rospack-tools

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

--enter "sudo gedit /etc/hosts" in the terminal, then open hosts file--

1710296202774085.png

--add "199.232.28.133 raw.githubusercontent.com" in the file, and new file added as follow--

1710296209164066.png

--save file and exit--

1710296217886979.png

--execute “sudo rosdep init” in the terminal, then problem is solved--

--test whether ROS is installed successfully or not--

$ roscore

If it is successful, like this:

1710296951327430.png



3. ROS Programming Examples 

There are mainly two ROS routines, “message publish” and “subscription”.

(1)    Build One ROS Work Space

$mkdir -p ~/catkin_ws/src

$cd ~/catkin_ws/

$ catkin_make


(2)    Create One ROS Program Package (zmotion is the package name, it can be defined as others)

$cd ~/catkin_ws/src

$catkin_create_pkg zmotion std_msgs roscpp

$cd ~/catkin_ws

$ catkin_make


(3)    After Creating the Program Package, “source ~ / catkin_ws / devel / setup.bash is required in each running, otherwise the file cannot be found.

Enter in the terminal:

$ gedit ~/.bashrc

add at the end of the file and save

$ source ~/catkin_ws/devel/setup.bash


(4)    New Build One Node File

Create a src directory in the zmotion package directory:

$ cd ~/catkin_ws/src/zmotion   //enter the ZMotion package path

$ mkdir -p src   //new build the src folder for saving c++ program

$ cd src/   // enter the src folder path

$ touch talker.cpp   //create a new publishment message node cpp file

$ touch listener.cpp   //create a new subscription message node cpp file


(5)    Edite “Publish Node” (talker.cpp)

Functions to be achieved:

--initialize ROS system

--publish message of std_msgs/Float64 on chatter topic

--publish the message in 10 times/s

1710296973859969.png


(6)    Edit “Subscript Node” (listener.cpp)

Functions to be achieved:

--initialize ROS system

--subscript message of chatter topic

--enter self-cycle, waiting for message

--message arrived, call chatterCallback() function.

1710296979208835.png


(7)    Modify “CMakeLists.txt”

A. Open the path of program package "zmotion(catkin_ws/src/zmotion)", find the file "CMakeLists.txt".

1710296992503976.png

B. The lowest version is modified as 2.8.3

cmake_minimum_required(VERSION 2.8.3)

C. Find the file "find_package", and add the dependent package "message_generation".

find_package(catkin REQUIRED COMPONENTS

roscpp

std_msgs

message_generation

)

D. Make sure "generate_message" that is called.

generate_messages(

DEPENDENCIES

std_msgs

)

E. Make sure dependent of this message is added in dependent when running.

catkin_package(

# INCLUDE_DIRS include

# LIBRARIES beginner_tutorials

# CATKIN_DEPENDS roscpp std_msgs

# DEPENDS system_lib

CATKIN_DEPENDS message_runtime

)

F. Modify the configuration under "build".

--(to be continued, in next article)

Copyright © 2013-2024 Shenzhen Zmotion Technology Co.,Ltd Design by Zmotion    粤ICP备13037187号 Motion Controller-Motion Control Card

Contact Us-Youtube