Open powerlink on Raspberry pi 3

Introduction on how to get POWERLINK working on Raspberry PI 3

The Open Source Real-time Ethernet on Raspberry Pi 3 article would have given a good idea on running the POWERLINK on Raspberry Pi3 using pre-build binaries. Now let us see how to build our own POWERLINK binaries and also access the raspberry Pi 3 GPIO’s using POWERLINK application.

What hardware do I need?

The demo uses three Raspberry Pi3 boards, one acting as the network master (POWERLINK Managing Node / MN) and the other two as network slaves (POWERLINK Controlled Node / CN). List of hardware needed:

  • 1 Raspberry Pi3 board to act as the master
  • 1 or 2 Raspberry Pi3 boards to act as the slaves
  • 1 Network Switch
  • 4 Ethernet Cables
  • 1 Micro SD Card Reader
  • 3 sets of HDMI display, USB keyboard and mouse
  • 3 sets of micro USB cables to power the Raspberry Pi2 boards
  • VNC viewer on Both Master and Slave Raspberry PI
  • 1 windows PC

open terminal and type the below commands on all Raspberry pi:
sudo su
sudo mkdir /home/pi/openpowerlink
cd /home/pi/openpowerlink
wget http://ftp.debian.org/debian/pool/main/libp/libpcap/libpcap-dev_1.6.2-2_all.deb
wget http://ftp.debian.org/debian/pool/main/libp/libpcap/libpcap0.8_1.6.2-2_armhf.deb
wget http://ftp.debian.org/debian/pool/main/libp/libpcap/libpcap0.8-dev_1.6.2-2_armhf.deb
wget https://www.kalycito.com/images/articles/rpi2/Dev_oplk_Pi.tar.gz
sudo mkdir /home/pi/oplk_Pi2
sudo chmod -R +x /home/pi/oplk_Pi2
cp -r /home/pi/openpowerlink/* /home/pi/oplk_Pi2
cd /home/pi/oplk_Pi2
tar -xcv Dev_oplk_Pi.tar.gz
sudo dpkg -i libpcap-dev_1.6.2-2_all.deb libpcap0.8_1.6.2-2_armhf.deb libpcap0.8-dev_1.6.2-2_armhf.deb
sudo apt-get install cmake
sudo apt-get install wiringpi
cmake-gui

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/stack and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/stack/build/linux and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

Un-check all other libraries except MNAPP_USERINTF and MNDRV_PCAP

Here the CMAKE_BUILD_TYPE will be in “Release” by default

Click “Configure” and then click Generate

Now in the terminal navigate to build to binaries path and type in “make install”. This will install the stack binaries in release mode

Now switch over to cmake-gui and replace the CMAKE_BUILD_TYPE to “Debug” and rest of the configurations the same

Click “Configure” and then click “Generate”

In the terminal navigate to the build to binaries path and type in “make install”. This will install the stack binaries in “Debug” mode

Building pcap driver

Switch to cmake-gui

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/drivers/linux/drv_daemon_pcap and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/drivers/linux/drv_daemon_pcap/build and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

In the configuration settings, check the CFG_OPLK_MN and click “Configure” then “Generate”

In the terminal navigate to the build to binaries path and type in “make install”. This will install the pcap binaries

Building a Demo Application

Switch to cmake-gui

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_mn_console and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_mn_console/build/linux and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

In the configuration settings select “Linux Userspace Daemon” for CFG_BUILD_KERNEL_STACK

Click “Configure” twice then “Generate”

In the terminal, navigate to the build to binaries path and type in “make install”. This will install the application binaries

  1. Compile and build CN
    Following are the code changes to be carried out to control the ON/OFF state of the openPOWERLINK slave GPIOs from openPOWERLINK master via PDO over POWERLINK network.

Following are the code changes to be carried out to control the ON/OFF state of the openPOWERLINK slave GPIOs from openPOWERLINK master via PDO over POWERLINK network.

sudo su
cd /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_cn_console
rm linux.cmake
wget https://www.kalycito.com/images/articles/cn_build/linux.cmake

cd /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_cn_console/src
rm app.c
wget https://www.kalycito.com/images/articles/cn_build/app.c

Building Stack libraries:

open terminal and type in cmake-gui. A user interface dialog box opens

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/stack and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/stack/build/linux and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

Un-check all other libraries except CNAPP_USERINTF and CNDRV_PCAP

Here the CMAKE_BUILD_TYPE will be in “Release” by default

Once the build is completed successfully, CN stack binaries will be installed in “Release” mode

Now switch over to cmake-gui and replace the CMAKE_BUILD_TYPE to “Debug” and rest of the configurations the same

Click “Configure” and then click “Generate”

In the terminal navigate to the build to binaries path and type in “make install”. This will install the stack binaries in “Debug” mode

Building a Linux PCAP User Space Daemon

Switch to cmake-gui

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/drivers/linux/drv_daemon_pcap and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/drivers/linux/drv_daemon_pcap/build and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

Un-check the “OPLK_CFG_MN” which will configure as CN

In the terminal navigate to the build to binaries path and type in “make install”. This will install the pcap binaries

Building a Demo Application

Open cmake-gui.

In the source code space click “Browse Source” and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_cn_console and click open

In “Where to build the binaries” click browse build and give the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_cn_console/build/linux and click open

Click “Configure”. A dialog box opens. Click “Use default native compilers” and click “Finish”

In the configuration settings select “Linux Userspace Daemon” for CFG_BUILD_KERNEL_STACK

Click “Configure” twice then “Generate”

In the terminal, navigate to the build to binaries path and type in “make install”. This will install the application binaries

On Raspberry Pi 3(On Slave board)

Configuration steps to configure Raspberry Pi 2 as openPOWERLINK Slave node:

Repeat the steps as carried out for “Slave 1” before making the following changes:

Open the file from the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_mn_console/src/main.c and change the NODEID to 32 as shown below

Environment setup to run openPOWERLINK On Raspberry Pi3 (On Master board)

All the binaries will be installed in the bin folder of the oplk_v2.1.1 directory.

Open terminal

sudo su
cd /home/pi/oplk_Pi2/Dev_oplk_Pi/bin/linux/armv7l/oplkd-pcap
modprobe tun
./oplkmnd-pcap

sudo su
cd /home/pi/oplk_Pi2/Dev_oplk_Pi/bin/linux/armv7l/demo_mn_console
./demo_mn_console

On Raspberry Pi 2 (On Slave board – 2)

Configuration steps to configure Raspberry Pi 2 as openPOWERLINK Slave node:

Repeat the steps as carried out for “Slave 1” before making the following changes:

  • Open the file from the path /home/pi/oplk_Pi2/Dev_oplk_Pi/apps/demo_cn_console/src/main.c and change the NODEID to 32 as shown below

Open terminal

sudo su
cd /home/pi/oplk_Pi2/Dev_oplk_Pi/bin/linux/armv7l/oplkd-pcap
modprobe tun
./oplkcnd-pcap

sudo su
cd /home/pi/oplk_Pi2/Dev_oplk_Pi/bin/linux/armv7l/demo_cn_console
./demo_cn_console

Raspberry pi Master
Raspberry pi Slave
Connections

Leave a comment