AI Allows Modeling PLC Programs at the Component Level

Component-based modeling can help engineers craft PLC ladder logic programs for electromechanical machine control functions.

Dr. Don Wilcher

February 13, 2024

6 Min Read
123ducu/iStock/Getty Images Plus via Getty Images

At a Glance

  • Component-based modeling can employ computer-aided design tools or artificial intelligence large language models
  • Functions that can be modeled include temperature and pressure switches, electromechanical relay coils, input/output devices
  • Behavior interaction priority prompts help AI identify a potential models and code

There are various approaches to developing programmable logic controller (PLC) applications using experimental techniques. Modifying existing PLC ladder logic programs is another common approach control engineers use to create controls and automation solutions. One unknown method of creating PLC ladder logic programs is to model the PLC ladder diagram system behavior. With the aid of Component-Based Modeling (CBM), PLC ladder logic programs can be developed. 

How Does Component-Based Modeling Work?

CBM is based on using two modeling elements, states, and transitions. States refer to switched outputs initiated by trigger events known as transitions. PLCs are basic reactive units responding to trigger or transition events. A trigger event is traditionally associated with electrical switch contacts. The contacts can be normally closed (NC) or normally open (NO). Upon the appropriate switching contact used in the PLC control application, a triggered event is read by the industrial controller's input module (IM). The ladder logic program reads the switched contact and produces a switched output control signal. The switched control signal is produced using an output module. 

The CBM technique uses an ellipse as a state with arrow lines representing an event. Creating a CBM requires understanding the PLC physical interaction with an input-switching device, and the corresponding actuator allows the model creation. To explore this technique, using the previous description of an electric switch, the state of its contacts is either NO or NC. Let us note that the electric switch contacts are in the NO state. The NO contacts will be considered the initial state. A plunger will actuate the electric switch to change the contact's state. Pressing the plunger with a pushbutton will allow the electric switch NO contact to transition to an NC state. In industrial terms, the pushbutton is known as the operator. Releasing the operator will allow the NC contact to return to a NO switch contact state. The completed CBM is represented using two ellipses with attached transition arrows. The opposite arrowheads represent the electric switch contact’s transition from NO to NC back to NO states. 

Component_Based_Modeling_Representations.jpg

Building Blocks for a Range of Applications

Although this example of a CBM is basic, the power lies in building a complete PLC input wiring diagram from a behavioral perspective. Using this basic CBM as a building block construct, temperature and pressure switches can be modeled accordingly. This modeling technique intends to understand the associated control signals produced by the external switching device and its electrical interaction with the PLC input module. A system interaction behavior is modeled and analyzed at its lowest level of operation or behavior using CBM.

Besides input-switching devices being modeled using this technique, output actuators can be represented similarly. For example, an external electromechanical relay’s coil wired to a PLC output module can be modeled using CBM. An electromechanical relay coil can be in an energized or de-energized state. An ON-control signal and an OFF-control signal represent transition arrows. The initial state of the electromechanical relay coil is in the de-energized state. Upon the PLC output module’s wiring terminal attached to an electromechanical relay coil, the ladder logic program provides an ON-control signal command to the actuator. The electromechanical relay coil is transitioned from a de-energized state to an energized condition. When PLC’s ladder logic program removes the control signal, the electromechanical relay transitions from an energized state back to a de-energized state. The de-energized electromechanical relay coil will be considered the initial state of the subcircuit.

A sequence of events (SoE) can effectively aid in modeling the external I/O devices to a PLC. The SoE is the PLC controller’s system behavior relating to the operation of the controller in the target machine control application. Traditionally, the SoE is documented as a series of sequential steps capturing the PLC control system’s initial conditions, states, and transition of the target machine’s controls. Therefore, software abstraction levels can be realized in creating a PLC CBM. 

The software abstraction levels can aid the controls engineer in creating the PLC CBM through decomposition. As initially discussed, the basic construct of an input-switching device and an output actuator is the state of the contacts being on/off or energized/de-energized, respectively. With this level of knowledge in the electromechanical device behavior, the CBM can validate the effectiveness of the PLC’s I/O modules. 

Computer-Aided Design and Artificial Intelligence Large Language Model Options

CBM diagrams can be created manually using professional computer-aided design (CAD) tools like AutoCAD or produced using an artificial intelligence (AI) large language model (LLM). The AI LLM approach requires typing a prompt. The prompt captures the specific I/O switching or actuating behavior or functional requirements. To illustrate this AI-assisted CBM modeling technique, the following prompt typed into Gemini AI is to model an on/off controller switching behavior:

Please_provide_Python_Code Artificial Intelligence & Component-Based Modeling

Typing the prompt with the behavior interaction priority (BIP) description allows Gemini to look for a specific modeling tool (class) and Python code capable of creating a CBM. The result of this prompt illustrates the BIP tool created for producing the CBM. As illustrated, Gemini provided the Python code to validate the basic on/off controller model: 

Python_code Artificial Intelligence & Component-Based Modeling

Using Google Colaboratory, the Python code was executed and validated: 

Google_Colaboratory_Python_code_executed Artificial Intelligence & Component-Based Modeling

An improvement of the BIP tool was requested of Gemini using the following prompt:

Improved_BIP_tool_requested Artificial Intelligence & Component-Based Modeling

The improved BIP tool was executed and validated with the following output results:

BIP_tool_exectuted_output_response Artificial Intelligence & Component-Based Modeling

The CBM diagram produced with the following output results is shown next:

Electromechanical_Relay_Model Artificial Intelligence & Component-Based Modeling

Several prompt requests (zero-shot learning) sessions were initiated before Gemini could produce the final CBM diagram. Zero-shot learning is primarily the number of prompt requests initiated before the final output response is achieved. The standby state represents the PLC output module enabled before providing the appropriate on/off commands for operating the relay. Although several zero-shot learning exercises were initiated, the final CBM diagram captured the requirements of modeling the relay's behavior.

Conclusions

The response of the CBM models illustrated in these examples provided insights into the approach of building PLC controllers using basic state and transition elements. Gemini AI provided another level of critical analysis and understanding of the electromechanical or switching device's electrical behaviors by initiating a series of prompts. These prompts or zero-shot exercises capture the behavior of the input switching device/controller and the actuating response of the electromechanical relay’s energizing/de-energizing functions. Ultimately, these I/O components could be modeled using AI as a PLC modeling assistant. With CBM, a PLC ladder logic program can easily be developed for the specific machine control application.

About the Author(s)

Dr. Don Wilcher

Dr. Don Wilcher, an Electrical Engineer, is an Associate Certified Electronics Technician (CETa), a Technical Education Researcher, Instructor, Maker, Emerging Technology Lecturer, Electronics Project writer, and Book Author. His Learn Electronics with Arduino book, published by Apress, has been cited 80 times in academic journals and referenced on patents. 

He is the Director of Manufacturing and Technology at Jefferson State Community College. His research interest is Embedded Controls, Robotics Education, Machine Learning, and Artificial Intelligence applications and their impact on Personalized Learning, Competency-Based Models curriculum, and instructional development in Mechatronics, Automation, IoT, Electronics, Robotics, and Industrial Maintenance Technologies. He is also the Founder and owner of MaDon Research LLC, an instructional technology consulting, technical training, and electronics project writing company serving Electronics Marketing Media, Technical and Engineering Education companies.

Sign up for the Design News Daily newsletter.

You May Also Like