When we start the conversation about which programming languages to use for industrial automation use cases, we usually begin by talking about IEC 61131-3 languages for PLCs, such as the classic Ladder Diagram (LD) or Structured Text (ST). For applications like robotics, we often see compiled, low-level programming languages like those found in the C family.
Until very recently, nobody was talking about using Python on the factory floor. What’s changed to make an interpreted, high-level language become suddenly appealing? Python code typically runs slower than a compiled language that’s closer to machine code, and it’s certainly not up to the task of real-time control, which is a major sticking point when developing industrial systems.
However, we’re now seeing a confluence of factors that are shining a spotlight on Python. First, Industry 4.0 is changing the paradigm for how we think about industrial automation; namely, its emphasis on “smart” machinery with improved autonomy, a rich big data landscape, and full integration with next-gen technologies like additive manufacturing and cloud computing.
Another implication of Industry 4.0 is the Industrial Internet of Things (IIoT), which connects industrial machinery on a local network for real-time machine-to-machine (M2M) communication and to provide a steady stream of sensor data for analytics. As a result, we’re witnessing an IT/OT convergence, a breaking down of the silos that have long separated the Information Technology professionals from their Operational Technology counterparts. After all, IIoT devices use information to optimize their operations.
This brings us back to Python. When we look at the strengths of the world’s most popular programming language, we see some clear advantages for IIoT. Foremost, Python is renowned for its ability to handle huge data sets. Second, Guido Van Rossum, Python’s inventor, designed it for high readability, a key trait when multiple engineers will work on or maintain the same code and a feature that fuels the fire of innovative iteration. And, finally, Python is open source, has an amazing community, and is the go-to choice for many of today’s most compelling applications.
Let’s get into them.
Without a doubt, the arena where Python exerts its most influence is in Machine Learning (ML), a branch of Artificial Intelligence (AI) where algorithms learn from data without anybody explicitly coding any rules. Common industrial applications include predictive maintenance and autonomous robotics. Most of today’s ML is written in Python. Frameworks like PyTorch and Google’s open source TensorFlow use Python. AWS SageMaker, Amazon’s cloud AI service, comes with a built-in Python Software Development Kit (SDK). Simply put, Python is the best tool for the job.
Here’s what a common industrial ML setup looks like. Machine and sensor data are sent to the cloud, where we have easy access to high-performance resources that we can use to train an ML model. Once we have a trained model, for instance one that can analyze data to say how soon a machine is likely to break, we can then ship that model back to the plant floor.
By running either edge computing by embedding GPUs into production devices themselves or by utilizing the resources of a local IIoT gateway for fog computing, we can use our trained model on site. If we look at an autonomous robot, the Python code will interpret the high-level goals, and this in turn, is then interpreted into movements by the low-level, compiled code that directly interfaces with the hardware. An easy analogy is moving your arm: your brain sets the high-level intention, and the low-level nervous system moves your muscles. As we move further into Industry 4.0 and manufacturers find more innovative uses for AI, expect to see Python engineering skills to be an increasingly crucial asset.
For a robotic arm to pick something up, it first needs to know what it’s looking at. Enter computer vision (CV), an AI field that enables machines to use their cameras as eyes and, even more crucially, recognize the objects they see. Simply by considering Python’s outsized role in ML, it’s not hard to see how Python is useful for CV.
Originally developed by Intel in the late 90s, OpenCV is now one of the best options for open source CV development. Even though the library is still written in C++, the Python wrapper, opencv-python, is ideal for ML applications like deep learning for CV because it retains the speed of the original C++ code while still unlocking the benefits of Python.
Plus, since opencv-python creates NumPy arrays as output, we can then immediately port our data over to other Python tools like SciPy, Matplotlib, or your ML platform of choice. The result is a machine that sees much more than pixels, one that can distinguish products, perform quality assurance checks, and manipulate their environments in intricate detail.
Creating a Bridge for a Connected Ecosystem
When machine manufacturers ship devices, they don’t usually prioritize the ability to communicate with anything other than the human machine interface(HMI). When we add the fact that many machines run proprietary code or G-code, which runs incredibly close to the hardware, the IT side of the IT/OT convergence becomes even harder. How do we get machines to talk to each other if they aren’t capable of speaking the same language?
Well, we need a translator—and Python is up to the task. Programs like OpenMTC act as a middleware, or “software glue,” for M2M and IoT applications. For instance, if we put this middleware on a device as simple as a Raspberry Pi, then the Python script takes data from one source, converts it, and sends it to a different machine in a format that it can read.
A simple example is any temperature-sensitive manufacturing process. While the machinery might not be able to adjust the temperature itself, its thermometer can take readings and, if it crosses a certain threshold, then it pings the middleware, which can then tell the heater to lower the thermostat.
We can apply this same logic to any machine that depends on another machine’s output. Furthermore, not only can we use this method to integrate current machinery to boost performance, but this also opens the door to a world of new possibilities. One such horizon domain is driverless cars; by communicating with other vehicles on the road, they will optimize traffic patterns, shorten commutes, and reduce accidents. If we had to bet, we’d say that Python will be a key building block of this interconnected future.
While we may not end up using Python to control robotic hardware or directly interface with manufacturing machinery, that doesn’t mean this programming language doesn’t have industrial applications. When we take a big-picture view of Industry 4.0, we see that data is its defining characteristic. We’re directly overlaying the digital world onto the physical world. And that’s why we need Python: to bridge the gap between them, to handle the unprecedented volumes of data that we’re generating, and to support macroscopic control.