POWERLINK Sur Raspberry Pi 3
POWERLINK Sur Raspberry Pi 3
Lloyd Tran
David Barbulovic
This thesis investigated how one can build a PowerLink network and Control Nodes
that act as, e.g., sensor, actuators, etc., together with B&R:s products. Establish-
ing different PowerLink networks was also investigated such as PLC connected to
Raspberry Pi2. Configuration and step-by-step introduction of what PowerLink is
and how it works is also mentioned in this thesis. In addition to creating PowerLink
networks and nodes, this thesis also looked into implementing OpenCV for image
processing with a camera on a Raspberry Pi2 connected to a B&R PLC.
This thesis showed that it is possible to create sensors, control and directly test them
from a PC or implement them on a industrial PLC. For the users it is greatly bene-
ficial due to the fact that a control node can execute code, e.g., filter measurements,
before sending data to the PLC.
3
Acknowledgements
We want to thank B&R and Department of Automation Control for helping us with
supplies of hardware and knowledge. A special thanks to our supervisor Anders
Robertsson for help and advice during the thesis period.
5
Acronyms
MN - Managing Node
CN - Controlled Node
I/O - Input/Output
7
Contents
1. Introduction 11
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2 Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2. Theory 14
2.1 PowerLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.4 Ethernet Communication and Socketing . . . . . . . . . . . . . 26
2.5 Threading and Mutex . . . . . . . . . . . . . . . . . . . . . . . 27
3. Method 28
3.1 The steps of building a PowerLink Network . . . . . . . . . . . 28
3.2 Contents of the PowerLink stack . . . . . . . . . . . . . . . . . 28
3.3 Installing libpcap . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4 Building the Libraries . . . . . . . . . . . . . . . . . . . . . . . 31
3.5 Building the PowerLink Stack . . . . . . . . . . . . . . . . . . . 32
3.6 Running the Network . . . . . . . . . . . . . . . . . . . . . . . 33
3.7 Installing OpenCV on Raspberry Pi2 . . . . . . . . . . . . . . . 34
3.8 Creating Raspberry Pi2/Beaglebone Black CN . . . . . . . . . . 35
3.9 PowerLink with one PC as MN and another PC as CN . . . . . . 36
3.10 Starting node, order of start . . . . . . . . . . . . . . . . . . . . 36
3.11 PowerLink with PC MN and B&R:s X20BC1483 CN and open-
Configurator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.12 PowerLink with PC as MN and ACCOPOS 1045 . . . . . . . . . 39
3.13 PowerLink with PC MN and Raspberry Pi2 CN . . . . . . . . . 39
3.14 PowerLink with B&R PLC MN and Raspberry Pi2 CN . . . . . 40
3.15 PowerLink with B&R PLC MN and BeagleBone Black CN . . . 41
3.16 The OpenCV program . . . . . . . . . . . . . . . . . . . . . . . 41
3.17 PowerLink with B&R PLC MN and OpenCV on Raspberry Pi2 CN 41
3.18 PowerLink with B&R PLC MN and OpenCV on Raspberry Pi3 . 44
9
Contents
10
1
Introduction
1.1 Background
To control automation equipment, including work cell coordination and configura-
tion of e.g., industrial robots, conveyor belts, external axes and IO-units, one often
uses a Programmable Logic Controller (PLC). This in turn often requires that the
user has dedicated configuration programs from the manufacturer.
If the setup of sensors, IO-units or actuators are to be changed, one must program
and learn about the PLC through the supplied program from the manufacturer,
which may be time consuming, as it requires the user to have the program and
the right operating system in order to use it. It would be more resourceful if the
user could change parameters through scripting without requiring to use a specific
operating system. To implement this, openPowerLink with openConfigurator will
be used [PowerLink, 2017].
1.2 Goal
The goal for this master’s thesis project is to implement a PowerLink real-time
communication between a PC and a PowerLink node. The PowerLink node should
also be able to work with Automation Studio and be a working device together
11
Chapter 1. Introduction
with, e.g., an industrial robot. The PowerLink node can be, e.g., a Raspberry Pi2
or BeagleBone hardware with IO-units, sensors or actuators. Another PowerLink
node will be an motor/sensor-drive, ACOPOS 1045, from B&R, as the task for
the thesis work also concerns the motor-drive and to investigate if and how it can
be directly controlled from a PC or other computer units through PowerLink. The
final approach will be to setup a PowerLink communication between the Managing
Node and motor-drive, e.g., where a camera connected to another that CN acts as a
sensor to aid in the task of picking up an object with help of a FlexPicker controlled
by ACOPOS 1045.
The goal of controlling the FlexPicker is done according to Figure 1.1. The camera
node sends the coordinates of the object to be picked up to a PC. This in turn sends
the coordinates of the Acopos and then controls the FlexPicker. The control of
FlexPicker is done through Acopos, as it controls the motors of the robot.
1.3 Limitations
The reason for the limitation of the scope of only creating two different kinds of
PowerLink nodes, is because the thesis needs to be possible to do during the thesis
12
1.3 Limitations
project. This thesis will also not look further into network safety, as it is outside the
scope of this master thesis.
13
2
Theory
Understanding the problem is done by understanding the theory. In this section the
theory for various subjects is described.
2.1 PowerLink
Managing- and Control Nodes
PowerLink is an Ethernet-based communication, deterministic and real-time Ether-
net protocol. It is an improvement to old field-bus systems as the older technology
requires different buses for different tasks [OpenPowerLink, 2017b].
PowerLink works by having a Management Node (MN) and one or several Con-
trolled Nodes (CN). The MN is the one that sets up the communication and main-
tains it, whereas the CN (or CN:s) receives or sends data to the MN or even to other
CN:s, depending on how the PowerLink is configured. The PowerLink network
14
2.1 PowerLink
The Cycle
In order to achieve a deterministic network with PowerLink, timing of different
procedures is required. This is done in the PowerLink cycle, which consists of
two parts; the isochronous- and asynchronous phase. In the isochronous phase
the real-time data exchange between the nodes appears within the cycle, whereas
the asynchronous phase starts after the isochronous phase. It is through the asyn-
chronous phase "hot plugging" is made possible, which allows adding of nodes
without affecting the real-time behavior.
These phases are visualized in Figure 2.2. As the figure shows, a lot of things
happen. In order to simplify the understanding of what is happening during a Pow-
erLink cycle, a step-by-step procedure is described.
The MN initiates the communication by sending a SoC, Start of Cycle. Here the
MN synchronizes with the CN:s. Thereafter the synchronization is completed and
the isochronous phase starts. A PReq, Poll Request, is sent from the MN to the
address of the CN, which includes data. The CN that has received the Poll Request
from the MN, responds with PRes, Poll Response, and real-time data. This is then
repeated for all registered and connected CN.
The MN starts next with sending SoA, Start of Asynchronous, which ends the
isochronous phase and starts the asynchronous phase. This makes it possible to
15
Chapter 2. Theory
send non time-critical data. The CN or the MN sends an Async Data, Asynchronous
Send, where the asynchronous data is transported [Ethernet.PowerLink.org, 2017b].
Node Addressing
In order for the PowerLink communication to be established, nodes for the network
need to be addressed. This is done by setting a unique 8-bit node ID. The range of
ID 1-239 are reserved for the PowerLink CNs, while the ID 240 is reserved for the
PowerLink MN. Address 0 is an invalid address, the rest of the ID:s are reserved for
other purposes, e.g., diagnostic node, dummy node etc.,[OpenPowerLink, 2017d].
As stated before, the PowerLink network has two parts, the iscohronous and the
asynchronous. The PDO communication appears in the ischocronous part in the
PowerLink network. The frames that are used are PollRequest (Preq) and PollRe-
sponse (Pres), which transmits the PDO information.
1 SoC = 64 Bytes
1 SoA = 64 Bytes
The calculation of the time for the transmission is determined by the total amount
of bits on the network, which are given by:
With the number of total bits, calculating the minimum cycle time can thus be cal-
culated as described below.
16
2.2 Hardware
tcycle = Bits on the network · 10ns + Reaction time between all frames
The reaction time is 960ns, which is the inter-frame gap between all frames, al-
though there is also a more generalized formula that can be used [B&R, 2015]:
tcycle =tSoC +tIPG +tSoA +tIPG +tASnd +tIPG + ∑ tPDO. f rame.including.IPG + ∑ thub.level
MN,CNs CNs
Here the Inter-packet gap (IPG) is the same as the reaction time, which is 960ns.
The hub level indicates the number of hubs between the MN and the CN, and the
time added per hub level equals 3µs.
2.2 Hardware
B&R PLC
The Programmable Logic Controller is mainly a computer, where different tasks
can be implemented, such as computation, control etc. Thanks to this, the PLC
device is used extensively throughout the automation industry. The PLC device that
is used is an X20 model from B&R, which allows it to expand the module with
digital or analog I/O:s. One should note that the different models of the X20 PLC:s
may vary significantly in capacity but have no differences visually.
X20CP1483 PLC This kind of PLC B&R was used in this thesis project. It has
two Ethernet ports, one for the standard Ethernet and one Ethernet PowerLink port,
EPL, which is needed in order to connect to the PLC through PowerLink.
17
Chapter 2. Theory
B&R Bus
The B&R X20BC1483 Bus is much smaller than the PLC, but still supports external
I/O:s to extend the Bus, such as digital and analog I/O:s. The X20BC1483 also
supports PowerLink.
Raspberry Pi2
Raspberry Pi2 can be looked at as a very small computer. The board itself contains
four USB ports, HDMI ports, micro SD card holder, a 900MHz quad-core ARM
Cortex-A7 CPU, 1 GB RAM, 3.5mm audio jack, Camera and Display Interface
[Raspberrypi, 2017a].
18
2.2 Hardware
BeagleBone Black
The BeagleBone Black board has similar functionality as the Raspberry Pi2 board,
though the hardware is different. It consists of 512MB DDR3 RAM 800MHz,
AM335x 1GHz processor, HDMI output, and 92 pin headers.
19
Chapter 2. Theory
2.3 Software
Operating system
In this master thesis the following operating systems have been used:
• Microsoft Windows 7
• Microsoft Windows 10
• Raspbian jessie/Ubuntu
• Fedora
C++ is the newer language, based on C, but have many more features such as e.g.,
object-oriented and generic programming. When a projects is starting to grow big-
ger then the cmake is coming in handy.
When running Cmake with the configuration files it locates files, libraries and exe-
cutables. For a project with multiple toolkits where each toolkit may contain several
directories, Cmake will also be able to support the order of the run, e.g., executa-
bles must be built before the code is compiled and linked to final application. In
other words Cmake is designed to support complex projects build with directory
hierarchies and applications dependent on several libraries. Also, an advanced user
can even build a makefile for a particular compiler and OS combination [Cmake,
2017].
20
2.3 Software
Notepad++
Notepad++ is both a text editor and a source code editor for Microsoft Windows.
Unlike the standard Notepad in Microsoft Windows, Notepad++ has more features,
it supports syntax highlighting, code folding and tabbed editing. Code folding al-
lows user to "hide" or "fold" the code user has edited and show only the subsection
name and tabbed editing grants the user the possibility to open multiple files in a
single window. Notepad++ is written in C++ and is a free software for any user to
download [Notepad++, 2017].
Visual Studio
Visual Studio is an advanced integrated development environment (IDE) from Mi-
crosoft. It is used to develop programs for Microsoft Windows and can also be used
to develop web sites, web services and web applications. Visual Studio supports
many different programming languages, where the built-in languages are Visual
Basic, C, C#, C++, J# and F#. Other languages are also supported in Visual Studio
but has to be installed separately. Visual studio contains features like code editor,
debugger and designer [Microsoft_Visual_studio, 2017].
Debugger allows the user to set breakpoints and when the condition is met the code
will be stall at the breakpoint. The user can either "step over" to run one code line at
a time or the user can also "step into" a function to debug inside. While debugging
the user can also inspect the value of variables by hovering the mouse pointer on
top of the variable [Microsoft_Visual_studio, 2017].
Visual Studio supports design for graphical user interface (GUI) for end-users. It
is built on Windows Form where the designer can drag and drop on the form to
create the layout. There are many different designer tools depending on the applica-
tion, e.g., Windows Form Designer for C# or visual basic, another designer are web
designer for web application [Microsoft_Visual_studio, 2017].
Automation Studio
Automation Studio, developed by B&R, is a software used to program controllers,
drives but also for visualization of such as HMIs. Automation Studio reminds a
little bit about Visual Studio in terms of allowing the user to debug and generate
data files. It also has support for different programming languages like Ladder
21
Chapter 2. Theory
diagram (LD), Function Block Diagram (FBD), Sequential Functions Chart (SFC)
and Structured Text (ST). Automation Studio also supports object-oriented pro-
gramming in C++, ANSI C and Matlab/Simulink for simulation. The version of
Automations Studio that was used during the thesis was 4.2.5 [B&R, 2008].
< / Object>
Listing 2.1 Example of input descriptions in an XDD-file
22
2.3 Software
< / Object>
Listing 2.2 Example of output descriptions in an XDD-file
The object index is an identifier of the object, which is given in hex (16-bit) and
name is just the string name of the object. Depending of what the objectType has
for value, it can have different meanings. If the objectType value is 7, this indi-
cates that it is a variable, number 8 indicates an array of the same data type and
number 9 says that the object type is a record, which means the values can have
different data types. The line that says dataType describes what kind of data type
the object/sub-object has. In the Listings 2.1 and 2.2, the data types are set to 0005,
which is unsigned8 [OpenPowerlink, 2017a].
The accessType line decides what kind of privileges the object should have. There
are four types of privileges; const means that the object can only be read from the
network node side, the values can not be changed during runtime and that the value
is predefined. The ro means read-only, wo is write-only and lastly rw defines that
the object has the read-write privileges.
23
Chapter 2. Theory
Eclipse
Eclipse is an development environment for programming and uses mainly Java
IDK. Eclipse also supports other programming language like C++, C etc. but only
via plugins. It offers a range of plugins for the program, including openConfigurator
which is used to build a PowerLink network [Eclipse, 2017] . Eclipse is compatible
with and can be installed and run on many operating system.
openConfigurator
openConfigurator is an Eclipse plugin, and is one of the stepping stones of success-
fully building a PowerLink network. The plugin itself has the functionality to create
a PowerLink Network by using XDD/XDC files. Creating a PowerLink network
can be cumbersome if done from scratch, but nevertheless, it is pretty much straight
forward by using the following recipe.
In order to create the PowerLink Network, first one must create the MN for the
system, which is done aside with choosing the XDD-file. Note that the XDD-file
must be written for an MN, as the corresponding file contains information if the
node is a MN or CN. Next step is to add a CN, which is also done by choosing
the XDD-file which holds the information about the CN. The cycle time for the
network can also be chosen, but note that a too short cycle time for the PowerLink
network will result in a network that would not be able to setup the communication
as specifications will be violated [OpenPowerlink, 2017b].
When the MN and CN/CN:s have been added to the openConfiguration, Eclipse
will generate four files and these are:
mnobd.cdc: The file contains the configuration data of the PowerLink network. This
includes configuration data for the MN and CN/CN:s. The configuration of a CN is
done by the configuration manager (CFM), which is part of the MN.
mnobd.txt: This file is a text-file description of mnobd.cdc, which contains all the
MN and CN configuration data. This file in not crucial for the creation of a Power-
Link network, as the file primarily is used for diagnostic reasons.
24
2.3 Software
xap.xml: This type of file is an XML-file, and it contains information of the process
image.
xap.h: The xap.h header file is one of the more interesting files. It includes the
structure definition of the process image in the form of two ANSI C structures.
The header file can be directly included in the openPowerLink stack and runs the
desired network.
The final thing that should be mentioned, is that a PowerLink network can not have
more than one active MN in the network, as it violates the idea of PowerLink, but it
is possible to have one or several redundant MNs in the network. A redundant MN
makes it possible to have one or more MNs in the network, put only one of them
will act as a MN in the network. If, e.g., the connection to the original MN is lost,
then the redudant MN will step in and control the network and thus the network can
continue to operate.
OpenCV
Open Source Computer Vision Library, OpenCV, is open source software for com-
puter vision. It supports a number of programing languages, such as Python, C++,
C, Java and Matlab. It also has support for Linux, Windows, Mac OS and the An-
droid operating system [OpenCV, 2017a].
25
Chapter 2. Theory
In the OpenCV program HSV (Hue, Saturation and Value) is the pixel representa-
tion which is most commonly used to detect objects. Hue determines the colour,
eg. 0 corresponds to colour red, etc. Saturation is the amount of grey and Value
describes the intensity (brightness) of the colour [ThoughtCo, 2017].
Wireshark
The Wireshark software is open-software and is used for analyzing network data
packages from the device that is transmitted to or sent from inside the network, as
long that the devices supports Ethernet communication or PowerLink. It is also able
to either in online or offline mode analyze a network. Other features are filters for
the package and able to analyze USB, Bluetooth and many others protocols. Identi-
fication of what kind of packages (TCP, UDP etc.) and what kind of information is
sent can be visualized in the software.
26
2.5 Threading and Mutex
changes in the code of the programs. The idea is to create a local Ethernet server
and client network where the information can be sent, where one program will act
as a server while the other one will act as a client. In this thesis, the server will
recieve the information while the client sends it. When creating an Ethernet local
network, it is possible to use either TCP or UDP communication protocol. The
main difference between TCP and UDP is that with TCP there is handshaking and
a guarantee that the data will arrive at the desired destination, whereas UDP has no
form of handshaking and no guarantee of delivery.
27
3
Method
This chapter is divided into two parts. The first part explains how a PowerLink net-
work is built while the second part explains the implementation of different Power-
Link networks.
Step 1: Download the desired PowerLink stack and choose version of the stack.
Note that older versions can have some limitations, so it is recommended to down-
load the latest version. The stack can be downloaded at openPowerLink’s webpage
[OpenPowerLink, 2017b].
These steps can be a bit hard for a newcomer in the PowerLink area, therefore a
detailed explanation of how to do will be explained in this chapter.
There are many files in the PowerLink stack, but for building and maintain-
ing a PowerLink network, the most interesting files reside in the folder called
apps. In the contents of apps, there are additional folders, which are commons,
28
3.2 Contents of the PowerLink stack
To program a CN to send, e.g., a float number or adding digital inputs, some com-
mand lines need to be altered/added in the the file objdict.h. These files reminds
very much of the XDD-file for the CN. This file is what the CN uses when initial-
izing the console for the CN. With the file, turning a CN device to a senor can be
done. How the programming is done is described in Section 3.14, PowerLink with
B&R PLC MN and Raspberry Pi2 CN.
If the PC has Linux operating system, then the execution files that should be used
are inside the folder linux and if the PC has Windows operating system the build
files that are to be used is inside the folder windows. A more detailed explanation
on how to build a PowerLink network and run it, is mentioned in Sections 3.3 and
3.4.
src The demo_mn_console folder contains the following textfiles, apps.c, apps.h,
apps.c, event.c, event.h, main.c and xap.c. However for programming and identi-
fying inputs and outputs, the files that are interesting are apps.c and xap.c but the
demo_cn_console folder does not have the xap.c.
For programming the PowerLink network, this is done in apps.c and how to do
so will be further explained in the next subsection Programming the Network. The
29
Chapter 3. Method
other textfile, which is one of the most important files is the xap.c, as this contains
what inputs and outputs the network has and is used in apps.c. The XDD-file de-
scribed inputs and outputs can be looked in xap.c, if the generation of the xap.c has
correctly been done that is. How to generate the xap.c is described in section 3.6,
PowerLink with PC and B&R:s X20BC1483.
The file event.c is doing as the name implies; it handles the event for the system.
It also processes the history of the events. The event handler provides the interface
for posting events to other modules in the system.
In app.c is where the variable can be sent and received between MN and CN. In
the function initProcessImage() a user can link an input or an output to be sent
between an MN and a CN. The linking is only possible if the XDD-file has the
correct configuration. The linking procedure is done as in the following:
o b d S i z e = s i z e o f ( p P r o c e s s I m a g e I n _ l −> d i g i t a l I n ) ;
varEntries = 1;
r e t = o p l k _ l i n k P r o c e s s I m a g e O b j e c t ( 0 x6000 ,
0 x01 ,
o f f s e t o f ( PI_IN , d i g i t a l I n ) ,
FALSE ,
obdSize ,
&v a r E n t r i e s ) ;
30
3.3 Installing libpcap
When the link procedure is complete, the system is ready to send and receive data,
which is done in method processSync(). The following code will show an example:
/ * r e a d i n p u t image − d i g i t a l o u t p u t s * /
d i g i t a l O u t _ l = p P r o c e s s I m a g e O u t _ l −> d i g i t a l O u t ;
/ * s e t u p o u t p u t image − d i g i t a l i n p u t s * /
p P r o c e s s I m a g e I n _ l −> d i g i t a l I n = d i g i t a l I n _ l ;
Listing 3.2 Send and recieve data on CN app.c
The following command is used to install libpcap in the Linux environment. To use
this command, connection to the Internet has to be provided.
s u d o a p t −g e t i n s t a l l l i b p c a p −dev
Listing 3.3 The command for installing libpcap in Linux environment
Note that when running on Windows operating system, Visual Studio has to be
installed. Before building the libraries the following command needs to be run.
vcvars32
Listing 3.4 Presteps before building libraries on a Windows system.
31
Chapter 3. Method
> cd <openPOWERLINK_dir> / s t a c k / b u i l d / l i n u x
> cmake −DCMAKE_BUILD_TYPE=Debug . . / . .
> make
> make i n s t a l l
Listing 3.5 Installing Debug libraries on Linux operating system
> cd <openPOWERLINK_dir> / s t a c k / b u i l d / l i n u x
> cmake −DCMAKE_BUILD_TYPE= R e l e a s e . . / . .
> make
> make i n s t a l l
Listing 3.6 Installing Release libraries on Linux operating system
Please note that if one of the libraries, Release or Debug, is missing, this could lead
to the error OPLKLIB-NOTFOUND or OPLKLIB_DEBUG-NOTFOUND when
trying to build a PowerLink network.
32
3.6 Running the Network
( Name_Of_Execution_File ) . exe
Listing 3.11 Running the PowerLink execution files on Windows operating system
To run the PowerLink network on a Linux operating system, the following com-
mand can be used.
. / ( Name Of E x e c u t i o n f i l e )
Listing 3.12 Running the PowerLink execution files on Linux operating system
When running the program in Windows or Linux, a list of network cards will appear
that are on the PC. The user has to identify which network that runs the PowerLink
communication and this can be done by disabling the network one at a time and
identify where the PowerLink communication will be. When running the console
on a Linux machine, the Ethernet card to choose is eth0. It will run the PowerLink
network on this Ethernet card by default.
Something that is very important to keep in mind, is that when making changes
to the PowerLink network, e.g., adding features through programming, and then
running it, the old code could still run. To run the newer code, follow these steps.
33
Chapter 3. Method
1. Start by deleting all the build files from build folder, but don’t remove the
files that came with the stack.
2. Then rebuild the new code, as described in Section 3.4.
3. Run it.
These steps can be looked at as compiling the code. An example of how it looks
when initializing a PowerLink network on a Windows Operating system is given
below by Figure 3.1.
sudo a p t −g e t u p d a t e
sudo a p t −g e t u p g r a d e
sudo r p i −u p d a t e
sudo reboot
Listing 3.13 Updating and upgrading the Raspberry Pi2 board
34
3.8 Creating Raspberry Pi2/Beaglebone Black CN
When the board is up to date, some packages may need to be installed; these are,
e.g., GCC 4.4.x, CMake 2.6 or newer version, Git, etc. These can all be downloaded
with the following commands [OpenCV, 2017c].
s u d o a p t −g e t i n s t a l l b u i l d − e s s e n t i a l
s u d o a p t −g e t i n s t a l l cmake g i t l i b g t k 2 .0 − dev pkg−c o n f i g
l i b a v c o d e c −dev l i b a v f o r m a t −dev l i b s w s c a l e −dev
Listing 3.14 Installing the required packages for OpenCV
OpenCV can be built from source using cmake, although this requires some steps.
An example of how the setup looks like is given below.
cd " p a t h t o t h e d i r e c t o r y " / o p e n c v
mkdir r e l e a s e
cd r e l e a s e
cmake −D CMAKE_BUILD_TYPE=RELEASE
−D CMAKE_INSTALL_PREFIX = / u s r / l o c a l ..
Listing 3.15 Installing the required files
The last step is to install the run file which is done with the following command.
make
s u d o make i n s t a l l
Listing 3.16 Install the run file
35
Chapter 3. Method
If the board successfully boots up, then cmake has to be installed. This can either be
done my letting the board install cmake from the net or download it from cmake’s
webpage.
The last part is to make the board a CN, which requires that the PowerLink stack is
downloaded on a usb memory card and then mount it into the usb port of the board.
Then the files have to be copied from the usb to the file system on the microSD-card.
The easiest way is to make a directory and copy the files from the usb onto it. After
this everything is setup. The board can now be built, programmed and run with the
commands previously described in the different sections above.
The setup works like this: one PC acts as MN and the other as CN. To establish
this kind of PowerLink network between two PC:s requires an Ethernet cable to
be connected to the network interface card, on each PC. An illustration is given in
Figure 3.2.
36
3.11 PowerLink with PC MN and B&R:s X20BC1483 CN and openConfigurator
Using openConfigurator
For controlling the in- and outputs, openConfigurator has to be used, in order to
make it possible to program the MN so it can control the CN. The openConfigura-
tor plug-in creates the network by generating mnobd.cdc, mnobd.txt, xap.xml and
xap.h, as mentioned in the theory chapter 2.3.
The method for using openConfigurator is done by using the following steps [Ka-
lycito, 2017b].
1. Install Eclipse
3. Choose new PowerLink project in Eclipse. The the program will ask for the
XDD-file for the MN. Note that the XDD-file has to be written for the MN, other-
wise, it will not work.
4. The next step is to add the CN. This is done by adding the XDD-file for the CN
and choosing the id for it. As mentioned above, the XDD-file has to be written for
the CN.
5. For the CN, map all available objects, i.e., outputs. This is can be done by select-
ing Map all available objects in TPDO and RPDO. Here it is possible to see what
kind of I/O:s that the CN has.
6. Select the desired cycle time for the network. After this, the generation of the
files should be successful.
The XDD-file that was used for the MN was imported from the PowerLink stack.
37
Chapter 3. Method
Figure 3.4 The network view of the PowerLink network after adding a CN [Ka-
lycito, 2017b].
38
3.12 PowerLink with PC as MN and ACCOPOS 1045
Figure 3.5 View of where the cycle time can be changed [Kalycito, 2017b].
pProcessImageIn_l->CN1_AnalogueOutput_00h_AI16_AnalogueOutput_1 = 1;
pProcessImageIn_l->CN1_AnalogueOutput_00h_AI16_AnalogueOutput_2 = 1;
While the code mentioned above sets the analog output to 1 which gives a 1 on the
Bus and the lamp for the analog outputs glows.
39
Chapter 3. Method
connected to the Raspberry Pi2 using an Ethernet cable and the PowerLink com-
munication is up and running but neither the MN nor CN is sending or receiving
in the PowerLink stack. Applying the knowledge from previous using Listing 3.2
and changing the digitalIn_l(UINT8) to any value from 0 to 255 on the sending
node and receiving node will pick it up. Confirming this can be done by printing the
variable digitalOut_l on the receiving node.
Figure 3.7 The general idea of implementing XDD-file on a B&R PLC [B&R,
2015].
The adding of a CN is done by selecting Tools and Import Device inside Automa-
tion Studio.
For reading values from the CN it requires that the user enables the read or write
part of values from the CN in the I/O configuration in Automation Studio.
Importing the Raspberry Pi2 as a CN is done by adding the XDD-file for the node.
The setup of the Raspberry Pi2 has to be done first so it can run as a CN in the
40
3.15 PowerLink with B&R PLC MN and BeagleBone Black CN
network.
In Section 3.17, it is shown how one can decide what values the CN should send to
the MN, which in this case is the PLC.
Figure 3.8 Example of setting values on the input which will be sent to the MN
The values can be viewed from the PLC, although it requires some changes in Au-
tomation Studio. This is made in I/O configuration, where the inputs have to be set
from None to Read. This will allow the PLC to print these values for observation.
41
Chapter 3. Method
The creation of more I/O:s is done inside the file objdicts.h and the XDD-file that
is used by the MN, PLC in this case. The objdicts.h needs to be exactly as the
XDD-file and if the XDD-file does not match the other file, then the PLC will not
be able to communicate with the new I/O:s, as the XDD-file that the PLC MN uses
does not describe the new I/O:s.
The following text and Figure 3.9 and 3.10 describe how the objdicts.h and XDD-
file are altered for creating new I/O:s are done.
As mentioned in the theory part of XDD, different values in the XDD-file have dif-
ferent meaning. The data types can be set according to the Figures 3.9 and 3.10. This
will create a digital input with the data type. Notice the similarities and differences
from objdicts.h to the XDD-file. In objdicts.h the OBD_BEGIN_INDEX_RAM
macro can be found. The macro defines the index entry of the object dictionary
[OpenPowerLink, 2017e]. The macro has three sets of parameters. The first one
describes the object index of the entry, in this case 6000 - 9FFF indicates that its a
standardized device profile area. Next parameter shows how many sub-objects there
are in this object, 0x05 indicates that there are five sub-objects. The last parameter
is of boolean type and can only be set true or false. This last parameter is a flag
which indicates that if the object is accessed, then it will trigger a user event. As
there is no need for this, it is set to false [OpenPowerLink, 2017h].
42
3.17 PowerLink with B&R PLC MN and OpenCV on Raspberry Pi2 CN
The shell for the digital inputs has now been created. Now the definition of what the
object for the variables has for data length, in other words the size of the data. This
is done in the macro OBD_SUBINDEX_RAM_VAR, which has seven parameters.
The first one is the address, which is the same as before, 0x6000. The second pa-
rameter defines the number of sub-indexes, in this case 0x00 is written, which gives
the information that it is not used. The third parameter defines the object type, here
it is written kObdTypeUInt8, which indicates that the data type is UNSIGNED8.
[OpenPowerLink, 2017f]. The fourth parameter defines the access right for the ob-
ject type, here its written as kObdAccConst, with this it tells that the object contains
a constant value [OpenPowerLink, 2017g]. The fifth parameter indicates which C
data type is used, with tObdUnsigned8 it assigns the data type INTEGER8 accord-
ing to PowerLink specifications [OpenPowerLink, 2017f]. The sixth parameter is
the name of the object, which in this case is just Number Of Entries. Lastly, the
seventh parameter is the default value for the subindex, with 0x04 it indicates that
it is a constant value [OpenPowerLink, 2017e].
When modifications have been done to the objdicts.h and the XDD-file, for the
MN and CN, the corresponding file needs to be exactly the same. The result of not
doing this will be that the PLC will not find the input or the CN will get an error
when building the PowerLink running files. The meaning of "exactly" is that the
inputs need to be described in both files. When examining Figures 3.9 and 3.10, the
difference is that objectType is written in numbers, 0008 indicates thats its an array
while 0007 is a single value variable [OpenPowerLink, 2017a]. The data type is
defined in dataType, where 0005 is UNSIGNED8 and 0008 is data type REAL32.
accessType is here set to const, which says that the object can only be read from the
network and node side. ro gives the read only from the network [OpenPowerLink,
2017a].
To ensure that the XDD-file is correctly written, either the XDD-file can be com-
piled and checked for errors at OpenPowerLink’s website or in Automation Studio.
When all the files are ready, the XDD-file can now be implemented in B&R:s PLC
43
Chapter 3. Method
and a PowerLink network with Raspberry Pi2 can now be established, where the
OpenCV can send its values through desired inputs. Note that in this case the writ-
ten OpenCV code was written in C++ and PowerLink stack in C. To communicate
between the programs a server/client base network was established through sock-
eting. Here the OpenCV program will act as a client and send the information to
PowerLink, which acts as a server.
44
3.20 PowerLink with B&R PLC MN and OpenCV on Stationary Computer CN
and Threading with Mutex
Figure 3.11 illustrates the current setup.
As explained before, the camera will feed the OpenCV program with pictures of
the robot workspace. When this information reaches the OpenCV software it will
begin to calculate the position of the object. When this is completed, the data will
then be sent to the client which in turn sends the data to the server, which is located
in the PowerLink software. The server writes the information to variables that are
shared with the send data method, which locks the resource, then reads the variables
and unlocks. The second thread, PowerLink, will lock the shared resource, read the
variables and send the information to the MN, PLC, and then unlock when finished.
45
Chapter 3. Method
46
4
Results
From Section 3.10 the PC could control the I/O on the X20BC1484. The digital
module of the bus had a number of outputs that could be lit e.g, if 0x1010 was sent
to the module meaning that output 2 and 4 were set. Data on other modules, like
digital input, analog input/output can also be read and sent to. Something that was
noticeable was that the MN restarted itself continuously, but this was later resolved
by expanding the cycle time, as the cause was that the cycle time was too short.
When comparing BeagleBone Black, Raspberry Pi2 and Pi3, the Raspberry Pi3
proved to be the most stable node to handle. For instance the BeagleBone Black
took approximately eight hours to just install the software cmake. The BeagleBone
Black Board can still be used as a CN, but it is not recommended, as compiling can
take long time compared with Raspberry Pi2. It is possible to use crosscompiling,
in the sense that one is compiling the program on a PC and then importing to the
BeagleBone. However, the problem of hardware limitations is still an issue.
47
Chapter 4. Results
48
4.2 The OpenCV Software
49
Chapter 4. Results
The identification of the problem was made when running Raspberry Pi3 with only
the PowerLink side. The PowerLink network sent only some integers to the MN,
PLC, and the system did not restart itself. But as soon the OpenCV software was
executed the problem reappeared. Even threading and mutex was used to allocate
the data power mainly to PowerLink so it can send the information as fast as pos-
sible and reassure that the shared resources do not interfere with the programs. If
the information takes too long to be send, then the PowerLink communication will
restart itself. But the problem still persisted and this led to the conclusion that the
Raspberry Pi2 and Pi3 can not be used as sensor nodes due to hardware limitations
and not suitable for industrial applications as the stability is a must. Instead, a sta-
tionary Ubuntu computer was used, which led to a satisfactory sensor node with
good real-time performance.
Performance
When OpenCV was executed on the Raspberry Pi2, measurements showed that the
computation time was approximately ten times slower than when running on a PC
with i7 processor which make the Raspberry Pi2 not suitable for a high performance
system. The Pi3 had a better performance, however the Pi2 and Pi3 had still the
same problem of running PowerLink and OpenCV together.
50
4.4 Unstable connections and Unfamiliar Errors
For the stationary Ubuntu computer, the results were good and worked satisfactorily
with good real-time performance. Time was measured between the calculation time
of the OpenCV and the send data time in PowerLink.
This shows that it has a good real-time performance, which can be easily imple-
mented in terms of automatic control. The sensor node will send the data to the
PLC which lets the user use the information for their needs, e.g., a robot movement
to pick up a object. This kind of device is both suitable for testing and industrial
systems, since it is much easier to install desired programs and software in a Ubuntu
computer than a PLC.
The calculation time data was gathered with 65 samples. The median calculation
time was 0.8972/65 = 0.0138 seconds, for calculating the coordinates to sending it
through to the PowerLink section of the code. While as the time for sending data
through PowerLink had the median time of 0.00016 seconds. This shows that the
PowerLink node has good real-time performance and is suitable to be integrated in
an automatic control device, e.g., determining position for robots or for objects in
their workspace.
Operating system
Running PowerLink on Microsoft Windows and Linux is not any problem since
both the operating system supports pcap. Linux is using libpcap and Microsoft Win-
dows is using Winpcap. No investigation has been done to macOS since there was
no computer available.
51
5
Discussion and
Conclusions
5.1 Conclusions
The PowerLink Network
Creating new I/O:s and datatypes proved to be cumbersome as no direct documenta-
tion showed how to create these. The PowerLink stack provides a lot of files, which
makes it easy to get lost in the jungle of information. OpenPowerLink’s webpage
provides a demo of how to build a PC to PC PowerLink connection, though there
is no mentioning on how, for example, to send some data from one PC to another.
This knowledge is self gained, as it requires the user to go into the stack files and
identify where the programming should take place.
Choosing another set of drives was not possible, as the motor drives, ACOPOS
1045, are only those available and connected to the FlexPicker in the Robotlab. The
idea was to compare, later on, the implementation of controlling the ABB Flex-
Picker with the master thesis as mentioned before, Alvaro Gomez-Trenor Sobrino’s
Real-time control of the FlexPicker ABB robot [Control, 2018], and show that it is
easier to just use PowerLink. Nevertheless, due to the missing piece, which is the
52
5.1 Conclusions
XDD-file for ACOPOS 1045, made this not possible. One could ask the question,
why was it not investigated beforehand if the XDD-file was available. The reasons
are two. The first reason is the lack of experience of building these kinds of systems.
The second reason was that reading manuals gave the idea that XDD-file could be
provided by just asking the manufacturer. As the XDD-file for X20BC0083 was
directly provided from B&R:s webpage, it gave the idea the other XDD-file for
ACOPOS 1045 also was available, which later on proved that this was not the case.
Learning how to use and create a PowerLink network was a handful of work, as
the demo for implementing a Raspberry Pi2 CN did not work as planned. This was
because the files for some reasons could not be installed properly, which required a
lot of time before this problem could be solved. Even using OpenConfigurator was
a problem. There is a lot of information about it, even tutorials and videos, but no
documentation showed which files should be replaced in the PowerLink stack. To
know which files to replace was learned through testing.
To mention, the support for PowerLink exists from OpenPowerLink in form of fo-
rums. Here questions were asked regarding the files for RaspBerry Pi2 files and the
error that makes the PowerLink restarting. It took approximately two days before
a response on the first question, the last one has not been responded yet, but will
hopefully be soon so others can handle this kind of problem when meeting it. This
shows that a project can be significantly delayed if need of support and no work
around the problem were available. The problem was later resolved but took a lot
of time which significantly delayed the project.
Initially when trying to install OpenCV on the Raspberry Pi2 board, it did not go as
planned. The board froze during the installation and when rebooting was attempted,
the board could not boot up. This led to reinstallation of a newer operating system
on the board which, eventually, led to that OpenCV could be successfully installed.
As mentioned before, the OpenCV code that was implemented on the Raspberry Pi2
board, was borrowed from Alvaro Gomez-Trenor Sobrino’s Real-time control of
the FlexPicker ABB robot [Control, 2018]. The code was successfully implemented
and executed but due to limitation in computer power on the Raspberry Pi2 board,
53
Chapter 5. Discussion and Conclusions
made it ten times slower than running with an ordinary PC. Conclusion was made
when discussing with the thesis writer, Alvaro Gomez-Trenor Sobrino, about the
efficiency of the program.
Having OpenCV on a Raspberry Pi2 and Pi3 board proved that camera vision pro-
gram can be implemented and act as a sensor. The main problem with this was
compatibility, where the OpenCV code was written in C++ and PowerLink in C.
Rewriting the OpenCV code would have required a lot of time. Knowledge about
how OpenCV works would have to be gained and then rewriting the code. All of
this would have taken a lot of time. Thus a server/client network was created to
solve this problem.
During the implementation part, efficiency was also looked at. If one, e.g., has a
system where the dependency for running smoothly lies on a sensor. That is slow
and for some unknown reason restarts itself, while the good part is that it is easy to
implement. Even if the PowerLink sensor is easy to connect, stability and perfor-
mance is still the crucial part of making the desired system a working system. For
research purposes it can still be used, as the PowerLink network will still send the
desired information, but for industrial systems it is not recommended as, e.g., a con-
trolled machine will stop now and then due to that the PowerLink network with the
sensor is restarting. Thus its not recommended to use small boards like Raspberry
Pi for sensor implementation. It is recommended to use a ordinary Linux computer
for building sensors for research and industrial systems.
54
5.2 Future Work
For future development integrating this kind of sensor into automatic control solu-
tions will be possible. Other implementations of the OpenCV, such as Aruco which
ressembles a QR code but has vast information on it, is also very interesting to look
into and implement it as a PowerLink sensor node [OpenCV, 2017b]. It will also
be much easier to implement as the user does not have to program into Automation
Studio, only receiving the information and using it in an automation control solu-
tion. This thesis shows that its possible to create a sensor node and send the data
through PowerLink with ease. At the same time, it shows that its not necessary to
open sockets on, e.g., a PLC in order to send desired information to it.
The development for the future can be summarized into two parts. Ensure that the
PowerLink connection is stable and integrate Alvaro Gomez Trenor Sobrino’s thesis,
Real-time control of the FlexPicker ABB robot [Control, 2018], and this thesis work
together and show that determinism can be achieved in a automatic control network.
55
Bibliography
56
Bibliography
57
Bibliography
58
Bibliography
59
/XQG8QLYHUVLW\ Document name
0$67(5¶67+(6,6
'HSDUWPHQWRI$XWRPDWLF&RQWURO Date of issue
%R[ )HEUXDU\
6(/XQG6ZHGHQ Document Number
7)57
Author(s) Supervisor
/OR\G7UDQ $QGHUV5REHUWVVRQ'HSWRI$XWRPDWLF&RQWURO/XQG
8QLYHUVLW\6ZHGHQ
'DYLG%DUEXORYLF 5ROI-RKDQVVRQ'HSWRI$XWRPDWLF&RQWURO/XQG
8QLYHUVLW\6ZHGHQH[DPLQHU
Abstract
7KLVWKHVLVLQYHVWLJDWHGKRZRQHFDQEXLOGD3RZHU/LQNQHWZRUNDQG&RQWURO1RGHVWKDWDFWDVHJ
VHQVRUDFWXDWRUVHWFWRJHWKHUZLWK% 5VSURGXFWV(VWDEOLVKLQJGLIIHUHQW3RZHU/LQNQHWZRUNVZDV
DOVRLQYHVWLJDWHGVXFKDV3/&FRQQHFWHGWR5DVSEHUU\3L&RQILJXUDWLRQDQGVWHSE\VWHS
LQWURGXFWLRQRIZKDW3RZHU/LQNLVDQGKRZLWZRUNVLVDOVRPHQWLRQHGLQWKLVWKHVLV,QDGGLWLRQWR
FUHDWLQJ3RZHU/LQNQHWZRUNVDQGQRGHVWKLVWKHVLVDOVRORRNHGLQWRLPSOHPHQWLQJ2SHQ&9IRU
LPDJHSURFHVVLQJZLWKDFDPHUDRQD5DVSEHUU\3LFRQQHFWHGWRD% 53/&
3RZHU/LQNLVDGHWHUPLQLVWLF(WKHUQHWEDVHGSURWRFRO,WZRUNVE\KDYLQJD0DQDJLQJ1RGHWKDWDFWV
DVWKHPRGHUDWRUIRUWKHQHWZRUN7KHQWKHUHDUHWKH&RQWURO1RGHVZKLFKDUHVODYHVQRGHVLQWKH
QHWZRUN7KHUHVXOWVKRZHGWKDWLWLVSRVVLEOHWRFUHDWHFRQWUROQRGHVWKDWFDQEHFRQWUROOHGDQGUHDG
WKURXJK3RZHU/LQNRQD3&RU3/&7KH3RZHU/LQNFDPHUDQRGHWKDWZDVFUHDWHGZDVLPSOHPHQWHG
RQ5DVSEHUU\3LZLWK2SHQ&97KHLGHDEHKLQGWKLVZDVWRVKRZWKDWLWLVSRVVLEOHWRHDVLO\VHWXSD
3RZHU/LQNQRGH2QHRIWKHSUREOHPVWKDWZDVH[SHULHQFHGZDVWKDWWKH3RZHU/LQNVWDFNDQG
2SHQ&9FRGHWKDWZDVWREHLPSOHPHQWHGZDVZULWWHQLQ&&EXWWKLVZDVVROYHGE\HVWDEOLVKLQJ
D6HUYHU&OLHQWFRPPXQLFDWLRQEHWZHHQWKHWZRSURJUDPV7KH5DVSEHUU\3LOLPLWHGKDUGZDUH
ZKLFKPDGHLWQRWVXLWDEOHIRUKLJKSHUIRUPDQFHV\VWHPV
7KLVWKHVLVVKRZHGWKDWLWLVSRVVLEOHWRFUHDWHVHQVRUVFRQWURODQGGLUHFWO\WHVWWKHPIURPD3&RU
LPSOHPHQWWKHPRQDLQGXVWULDO3/&)RUWKHXVHUVLWLVJUHDWO\EHQHILFLDOGXHWRWKHIDFWWKDWDFRQWURO
QRGHFDQH[HFXWHFRGHHJILOWHUPHDVXUHPHQWVEHIRUHVHQGLQJGDWDWRWKH3/&
Keywords
KWWSZZZFRQWUROOWKVHSXEOLFDWLRQV