Can ChatGPT Be Used For Control System Programming?
Can ChatGPT capture “boots on the ground” domain knowledge specific to control systems? Explore whether the popular AI tool can be used to speed-up development time or replace control engineers altogether.
In the control system realm, development costs associated with the labor of engineers and technicians are high. Once a system is developed, further costs are incurred in maintenance and lost production opportunities with equipment downtime and troubleshooting.
An AI tool such as ChatGPT could accelerate development and maintenance troubleshooting timelines, thus reducing capital costs for new equipment as well as sustaining costs of labor and parts.
Figure 1. Can ChatGPT be used to program control systems? Image used courtesy of irissca - stock.adobe.com
What Is ChatGPT?
This article will examine the responses provided by the AI tool for use in control automation. What better way to begin than to ask Chat GPT to describe itself?
What are you?
I am an AI language model designed to assist and communicate with users in natural language.
Great, ChatGPT is a form of a natural language processing model that can help assist people like you and me with a variety of tasks or questions.
Can ChatGPT Assist in PLC Programming?
Now that we know ChatGPT is an AI assistant, let’s see if it can help us program a PLC. I’ll start with general high-level questions and drill down to more specific questions. Then we can pass a simple ladder logic latching circuit request to the AI model to test how it responds.
Can you assist me in the task of programming control systems such as programmable logic controllers?
Yes, I can certainly help you with programming control systems such as programmable logic controllers (PLCs). Please let me know what specific questions or concerns you have, and I'll do my best to assist you.
What are the top three PLC makes and models in the United States based on market share or sales volume?
As an AI language model, I don't have access to real-time market data. However, based on historical data and industry reports, the top three PLC makes and models in the United States are:
1. Allen-Bradley ControlLogix: This is a modular PLC system that offers high-performance control and communication capabilities. It is widely used in various industries, including manufacturing, automotive, and food and beverage.
2. Siemens S7-1500: This PLC system is known for its advanced features, such as high-speed processing, integrated safety functions, and easy programming. It is commonly used in the automotive, chemical, and pharmaceutical industries.
3. Schneider Electric Modicon M340: This PLC system is designed for medium to large-scale applications and offers flexible configuration options. It is commonly used in the energy, water, and transportation industries.
What PLC software do Allen-Bradley ControlLogix PLCs use?
Allen-Bradley ControlLogix PLCs use the RSLogix 5000 software for programming and configuring the PLCs.
RSLogix 5000 is correct, however, the newer version 21 of the software is now called Studio 5000. In a very short amount of time, I was able to determine the most common PLC in the US and its associated programming software.
How will ChatGPT fare once we start asking the model to program our newly selected PLC?
Latching Circuit Ladder Logic Test
Let’s see if ChatGPT can generate ladder logic for a latching circuit in Studio 5000. This is a foundational and ubiquitous concept in industrial controls, which should give ChatGPT an optimal chance of returning a useful output:
May you write me a simple latching circuit in Studio 5000 ladder logic?
Sure, here's a simple latching circuit in Studio 5000 ladder logic:
|---| |----[ ]----( )----[ ]----| |---|
| | | | | |
| |-| |-| |
| | | | | |
|---| |----------------------| |---|
This circuit uses a single input (I:1/0) and a single output (O:1/0). When the input is turned on, the output will latch on and stay on until it is manually turned off.
The circuit is made up of two rungs. The first rung is a normally open contact (NO) connected to the input. When the input is turned on, this contact will close, allowing power to flow to the second rung.
The second rung is a latch. It consists of a normally closed contact (NC) connected to the output, a set (S) coil, and a reset (R) coil. When power flows through the first rung, the S coil will energize, causing the NC contact to open and the output to turn on. The R coil will remain de-energized, keeping the latch in its current state.
To turn off the output, you can use a normally open contact connected to the reset coil. When this contact is closed, the R coil will energize, causing the output to turn off and the latch to reset.
The explanation is very detailed, but some of the logic describing the latch is vague and would not provide the right information to program the PLC. For example, the explanation text states that in the second rung, an NC contact is connected to the output, a Set, and a Reset. If both the S and R are attached to the same input contact on the same rung, the rung is not properly designed.
Even though the ladder logic diagram output by ChatGPT is creative in using pipes for contacts and parenthesis for outputs in its attempt to build the circuit image, it is not particularly helpful. Additionally, even though the prompt asked for a code according to Studio 5000, the addressing structure (I:1/0 and O:1/0) was provided in a manner like RSLogix 500 for older PLCs.
The above response was generated using the ChatGPT API; thus, I also tested this prompt in the web user interface (UI) and received the following response:
Figure 2. ChatGPT output upon request for ladder logic structure for a latching circuit. Image provided by the author, courtesy of OpenAI
Again, not particularly helpful but creative. A correct form of a latching circuit in ladder logic should resemble something similar to the below image:
Figure 3. Ladder logic structure for a latching circuit.
Latching Circuit Function Block Diagram Test
The second diagram-based language to test is the function block diagram language or FBD. Passing in the request to the ChatGPT API:
May you write me a simple latching circuit in Function Block Diagram language?
Sure, here is an example of a latching circuit in Function Block Diagram language:
![Latching Circuit FBD](https://i.imgur.com/1zV7xKX.png)
In this circuit, a push button (PB) is used to toggle the output (Q) between high and low states. When the PB is pressed, the SR latch (SR) is set, causing Q to go high. When the PB is released, the latch remains in its current state, so Q stays high. To reset the latch and return Q to a low state, a separate reset input (R) can be used. When R is activated, the latch is reset, causing Q to go low.
Using the ChatGPT API above yielded a URL link to a .png image file. Upon the first review of the output, I was hopeful and excited that the AI tool had generated a true image of an FBD for a latching circuit. However, the link resulted in an error upon redirection in a web browser. Therefore, I again turned to the web UI to see if a different result could be obtained:
Figure 4. ChatGPT output upon request for a function block diagram of a latching circuit. Image provided by the author, courtesy of OpenAI
Similar to the ladder logic request, ChatGPT struggled to output a useful diagram but provided helpful text-based information in its response.
Latching Circuit Structured Text Test
Last but not least, we will test a structured text output from ChatGPT:
May you write me a simple latching circuit in structured text for an RSLogix PLC?
Sure, here's an example of a latching circuit in structured text for an RSLogix PLC:
StartButton : BOOL; // Start button input
StopButton : BOOL; // Stop button input
MotorOn : BOOL; // Motor output
// Internal variables
Latch : BOOL := FALSE; // Latch variable
// Latching circuit
IF StartButton AND NOT Latch THEN
Latch := TRUE; // Set latch
MotorOn := TRUE; // Turn motor on
ELSIF StopButton THEN
Latch := FALSE; // Reset latch
MotorOn := FALSE; // Turn motor off
This latching circuit uses two input buttons (StartButton and StopButton) to control an output motor (MotorOn). When the StartButton is pressed and the Latch is not already set, the circuit sets the Latch and turns on the motor. When the StopButton is pressed, the circuit resets the Latch and turns off the motor. The Latch variable is used to "remember" the last state of the circuit and maintain the output until the opposite input is received.
Overall, the result provides a robust framework for building a structured text program. There would likely need to be some changes to the above code in order to have it function with Studio 5000, notably the declaration of tags. An example of such a declaration is below:
Figure 5. Variance in structured text for RSLogix PLCs. Image used courtesy of infoplc
ChatGPT for Programming
ChatGPT currently will not replace skilled engineers and technicians in the control systems sector. The “boots on the ground” domain knowledge specific to the control systems cannot be captured by ChatGPT, and the ladder logic and function block capabilities of the model still have room for improvement. However, ChatGPT can serve as a great resource for engineers and technicians who have a passion for learning and would like to accelerate their knowledge and personal growth.
Interesting test, thanks for writing this up. I’m glad this version is not there yet.
This will sound a little tinfoil hat….
First I propose that the commercially available AI products are not the most advanced that exist, especially if people were deliberately training a model for control systems (CISA?)
Second, it is a given that control systems have been attacked as a war like action.
AI is/will be a tool of war, and infinitely more difficult to defend against than the human version of cyber war.
Maybe I missed something obvious here but ChatGPT got EVERYTHING wrong. Code wrong. Explanations are word salad. Yet your conclusion is it’s a great tool for learning??? If you don’t know any better and everything you are taught is wrong, how can that be a great resource?
Note to editor: do your job. This should not have been published with that conclusion,