Technical Article

Can ChatGPT Be Used For Control System Programming?

April 25, 2023 by Michael Levanduski

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.

 

Can OpenAI ChatGPT be used to program control systems?

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:

```

|---| |----[ ]----( )----[ ]----| |---|

| | | | | |

| |-| |-| |

| | | | | |

|---| |----------------------| |---|

```

Explanation:

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:

 

ChatGPT output upon request for ladder logic structure for a latching circuit.

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:

 

Ladder logic structure for a latch circuit, latching circuit, latched circuit

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:

 

ChatGPT output upon request for a function block diagram of a latching circuit

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:

```

// Inputs

VAR_INPUT

StartButton : BOOL; // Start button input

StopButton : BOOL; // Stop button input

END_VAR

// Outputs

VAR_OUTPUT

MotorOn : BOOL; // Motor output

END_VAR

// Internal variables

VAR

Latch : BOOL := FALSE; // Latch variable

END_VAR

// 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

END_IF

```

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:

 

Variance in structured text for RSLogix PLCs.

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.


 

*Inspiration to test ChatGPT’s capability for industrial programming came from Jakob Sagatowski’s walkthrough on the topic.
3 Comments
  • J
    JohnDaley April 28, 2023

    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.

     

    Like. Reply
  • Paulengr April 28, 2023

    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,

    Like. Reply
    • D
      David Peterson April 28, 2023
      No, it did not get everything wrong. The ladder logic was wrong, and that was stated clearly in the article analysis. The function block explanation is correct as per IEC 61131 which uses Q, S, and R terms. The structured text is also correct, including the use of the latch as a local variable. Some syntax might need to be adjusted based on language, a point which was also noted in the article. Useful as a resource for learning? Yes. Trust everything it tells you without thinking? No. The conclusion is that it will not replace engineers for programming anytime soon. But it can serve as a resource. The conclusion is correct.
      Like. Reply