OpenPLC Software PLC

OpenPLC* is an open-source Programmable Logic Controller (PLC) that is based on an easy-to-use software. It is the first fully functional standardized open source PLC, both in software and hardware. The OpenPLC project was created in accordance with the IEC 61131-3 standard, which defines the basic software architecture and programming languages for PLCs.

For more information, refer to the OpenPLC Project.

Install OpenPLC Runtime and Editor

The following section is applicable to:

../_images/target1.png

The OpenPLC Project consists of two parts: Runtime and Editor. Do the following to install OpenPLC runtime and editor:

  1. Install and enable a graphical Desktop Environment.

  2. Setup the ECI repository

  3. Run the following command to install the OpenPLC components:

    $ sudo apt install eci-softplc-plcopen
    
  4. Set up the IgH EtherCAT Master Stack.

  5. Run the OpenPLC installation script:

    $ # Install OpenPLC Runtime
    $ sudo chmod +x /opt/plcopen/openplc-runtime/install_openplc_runtime.sh
    $ /opt/plcopen/openplc-runtime/install_openplc_runtime.sh
    $ # Install OpenPLC Editor
    $ sudo chmod +x /opt/plcopen/openplc-editor/install_openplc_editor.sh
    $ /opt/plcopen/openplc-editor/install_openplc_editor.sh
    
    Note:

    If you are trying to install OpenPLC Editor on Debian, please read OpenPLC Installation Issue & Solution and install Python 3.9 first. If you meet installation issue, refer to OpenPLC Installation Issue & Solution section for solution.

OpenPLC Sample Applications

This section describes the procedure to build a demo to drive a single motor with OpenPLC.

Write PLC Program

The sample program file is also located at /opt/plcopen/openplc-editor/Solo_Axis_Sample.zip for your reference. You can simply unzip it and open with OpenPLC Editor.

The following figure shows sample demo of driving a single motor to a specific velocity.

../_images/solo-motor-program.png

You can drag RTmotion function blocks from the Library tab, on the right, and place it in the program.

To enable the PLC control program work smoothly with EtherCAT, add a global variable called enifile to resource (For example, Res0 in the Project tab). The initial value of enifile should be the same as the name of XML file that describes the EtherCAT slave topology.

../_images/program-resource.png

Click Generate program for OpenPLC Runtime, available on the toolbar, which looks like a download button, to generate an ST file as normalized PLC program.

Execute PLC Program in OpenPLC Runtime

The OpenPLC runtime has a built-in web server, which provides a web UI for configuration. To access the web UI, open a browser and use the machine IP address on port 8080 as the URL.

For the initial login page, the default username and password is openplc and openplc respectively.

After logging in, from the left menu, click Hardware, choose EtherCAT then click Save changes. The OpenPLC runtime will be able to control EtherCAT slaves with EtherCAT as a hardware layer.

Then, from the left menu, click Programs and upload the ST program generated from Write PLC Program. The ST program file is also provided at /opt/plcopen/openplc-runtime/solo_axis.st for reference.

Copy the ENI XML file, with the name same as that of the initial value of global variable enifile in PLC program, to OpenPLC_v3/webserver. If all configurations are correct, click Start PLC from the left menu to instruct OpenPLC to drive the motor.

OpenPLC Misc

Change CPU Affinity of OpenPLC Runtime

In default setting of ECI patched OpenPLC runtime, affinity of thread for RT task is set to CPU core 1. It can be configured at OpenPLC_v3/webserver/core/main.cpp:360:

cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(1, &cpuset); // Change CPU set of affinity as your requirement
if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset))
    perror("pthread_setaffinity_np");

Change Axis Position Unit Scale

If axis reports following error or moves too fast or too slow compared to set velocity in program (e.g. 10 rpm), it may need to calibrate the axis position unit scale. For example, if program use round as position unit in program, and one round of axis correspond to 10000 units of encoder, then axis position unit scale should be set to 10000. Position unit can be millimeter, degree, etc.

To change axis position unit scale, modify OpenPLC_v3/webserver/core/main.cpp:93:

/* Change 1<<17 according to your hardware config */
config[i].encoder_count_per_unit_ = 1<<17;

To make it effective after modification, access to OpenPLC runtime web UI, click Hardware from the left menu, choose EtherCAT then click Save changes.

OpenPLC Installation Issue & Solution

  • Outdated Python version 3.9

    OpenPLC Editor uses Python* 3.9 to build its GUI, which is outdated version in Debian 11 (Bullseye), Debian 12 (Bookworm), Canonical® Ubuntu® 22.04 (Jammy Jellyfish) or Canonical® Ubuntu® 24.04 (Noble Numbat).

    On Canonical® Ubuntu®, installation script will add deadsnakes PPA for Python3.9 support on newer distributions. On Debian, you may need to manually compile and install Python 3.9 before installing OpenPLC Editor. Refer following steps to install Python3.9 from source:

    $ sudo apt-get update && sudo apt-get install libssl-dev openssl libffi-dev
    $ wget https://www.python.org/ftp/python/3.9.19/Python-3.9.19.tgz
    $ tar zxf Python-3.9.19.tgz
    $ cd Python-3.9.19/
    $ ./configure --prefix=/usr/local/python3.9
    $ make
    $ sudo make install
    $ ln -s /usr/local/python3.9/bin/python3.9 /usr/bin/python3.9
    $ ln -s /usr/local/python3.9/bin/python3.9-config /usr/bin/python3.9-config
    
  • Building wheel for wxPython failed

    If installation fail at Building wheel for wxPython (this step may consume a long period before succeed), you may need to manually download wxPython-4.2.0-cp39-cp39-linux_x86_64.whl according to your distribution, install it by ./.venv/bin/pip install wxPython-4.2.0-cp39-cp39-linux_x86_64.whl under OpenPLC Editor directory, then re-execute ./install.sh to install OpenPLC Editor.