Skip to content

PLCnext Python and its Library

Dear PLCnext Team,

First, I would like to express my appreciation for the work you’ve done in developing PLCnext. It has truly been a game-changer for us here in Indonesia, allowing us to approach industrial automation in new and innovative ways. We are excited about using Python programming alongside the traditional ladder logic and function blocks.

However, before we can fully implement Python-based solutions, we have some questions regarding how to get our Python programs running on the PLCnext device. Specifically, we are interested in creating our own Docker images that come pre-installed with Python and libraries such as NumPy and TensorFlow Lite.

I came across a post by Paguilar Maker Blog post that mentioned the need to cross-compile TensorFlow Lite for the device, but this process seems quite resource-intensive and requires powerful hardware, which we currently don’t have available at our company.

Could you provide more details on how we can run Python programs on PLCnext and whether there are pre-built Docker images or downloadable files that include the necessary libraries (like Python, NumPy, TensorFlow Lite, etc.)? If cross-compiling is required, is there an alternative method or a simplified process we can use to avoid the need for high-performance PCs?

Your guidance on this matter would be greatly appreciated.

Thank you for your time and support!

Sincerely,

Piko Prasetyo

Comments

  • Hello Piko Prasetyo,

    In generally it is possible to use the Docker solution described above, it is also possible to integrate the Docker image into the PLCnext app. Before starting the integration, the following questions need to be clarified:

    1. How must be the reaction time of your application program?
    2. Is the real-time execution needed (defined task cyclic)?
    3. Are the process data needed (Axio-Modules or PN-devices)?
    4. Is it neccessary to run the complete application program into docker or only a part?

    Please find the following projects, I think it can help you:

    GitHub - PLCnext/Container-App-Template-for-PLCnext: This project aims to create app's. This app's can run on the PLCnext controllers (like the one's that are deployed on the plcnextstore).

    GitHub - PLCnext/PLCnext-ROS-bridge: The PLCnext-ROS-bridge enables the whole power of the open source Roboter Operating System (ROS) for the IEC61131 world.

    App development: App types

    BR Eduard

  • The python images on docker hub should be suitable, for example:

    ... for AXC F 1152 and AXC F 2152 controllers.

    For pre-compiled python packages for arm32v7, I believe that others have had some success using the piwheels package repository, which intended for 32 bit Raspberry Pi devices.

    Phoenix Contact does not support or endorse these docker images or piwheels packages, but hopefully the PLCnext Community can help with any questions on these topics.

  • edited November 2024

    Hello Piko Prasetyo,

    Here some comments that may help you in what you want to do.

    1.  Cross compilation is necessary if the library is not available for the hardware (sadly the case for many libraries)
    2.  In theory, when you try to install the libraries using PIP and they recognize that no python wheel is available for the hardware, they will try to compile themselves on the fly and proceed with the installation.
    3. As you may have already discovered, the limitations of the hardware make the step listed above impossible to happen when executed directly on the PLC (especially if we are talking about the 2152).
    4. What I do is then create the container in my computer while emulating the hardware. This is doable if you use QEMU.
    5. QEMU is easy to set up in an Ubuntu machine. You can easily find instructions online if you search for “how to run ARM-based Docker Images on non-ARM based platforms”.
    6. Now, using QEMU will help you setting up your containers in your personal computer and then you just need to transfer them to the PLC. In this way, you will be able to install Numpy for example and it will run on the PLC.
    7. Pay attention, however, that this approach does not work for every library. TensorFlow lite runtime being one of them (hence the post of my own making that you referenced here).
    8. Regarding the need for powerful hardware, I dare to say that this is only required for the cross compilation of TensorFlow. Although I have only one computer and all the other libraries that I have compiled using this approach basically made use of the same specs, I think you will be fine without so much RAM nor processor cores for, let’s say Numpy for example. It will just take longer to execute the process.

    I hope this helps you, remember that this is kind of a “trick”, and that hardware emulation is not (always) perfect (google it). Therefore, you should thoroughly test the libraries obtained in this way using the real hardware and check that the behavior is as expected. This is specially relevant if you intend to use them in production and critical processes.

    Finally, if later, when running a library obtained in this way you see the error “illegal instruction”, it means the trick has only taken you so far and the cross compilation needs to be carried out differently. 

  • Thank you for your response! I’ll go ahead and try the suggestions you provided right away.

Sign In or Register to comment.