๐งช [Plant Simulation Study #20] – Let’s Operate Virtual Factory by ChatGPT Plant Simulation

๐ฌ Overview
In this study, I demonstrate how to connect Siemens Plant Simulation with OpenAI’s ChatGPT API, enabling an AI to make real-time decisions and control the flow of a virtual factory.
Using Python as a bridge, the simulation continuously sends live data to ChatGPT, receives its response, and dynamically changes simulation variables such as conveyor directions.
This structure shows how AI-powered digital twins can simulate autonomous decision-making systems in a smart factory environment.
YouTube : https://youtu.be/mDQOXU9y6mk
๐ป Integration Architecture & Key Components
| Tech Stack | Plant Simulation + Python + OpenAI ChatGPT API |
| Main Goal | AI-driven exit strategy logic for production flow |
| Communication | Data sent to ChatGPT every 5 seconds → Response received → Variables applied |
| Real-Time Loop | Python script executes on interval trigger |
๐ง Python Core Logic (Simplified)
import openai
import pandas as pd
obj = root.EXIT_Seq_SET.Value
set_A = root.Con1_nummu.Value
set_B = root.Con2_nummu.Value
# OpenAI API ํค ์ค์
api_key = "PUT API HERE" # ์ฌ๊ธฐ์ ์ค์ OpenAI API ํค๋ฅผ ์
๋ ฅํ์ธ์.
openai.api_key = api_key
# ChatGPT API ํธ์ถ ํจ์
def chat_with_gpt(prompt, model="gpt-4", temperature=0):
response = openai.ChatCompletion.create(
model=model,
messages=[
{"role": "system", "content": "You are a decision-making assistant."},
{"role": "user", "content": prompt}
],
temperature=temperature
)
return response.choices[0].message['content'].strip()
# ํ๋กฌํํธ ์ค์
user_input = f"""
Con1 ์ ์ ํ ๊ฐ์ :
{set_A}
Con2 ์ ์ ํ ๊ฐ์ :
{set_B}
0. ์๋ ์กฐ๊ฑด๋ค์ ํ์ธํ๊ณ Con1 ๊ณผ Con2 ์ค ํ ๊ณณ์ ์ถ๋ ฅํด๋ผ.
1. if {set_A} > {set_B} , Con1 ์ถ๋ ฅ
2. if {set_A} < {set_B} , Con2 ์ถ๋ ฅ
2. if {set_A} = {set_B} , Con2 or Con1 50% ํ๋ฅ ๋ก ๋๋ค ์ถ๋ ฅ
5. ์ค๋ช
์์ด ์ ํํ ๋์ค ํ๋์ ์ด๋ฆ๋ง ์ ์ด์ฃผ์ธ์.
"""
# API ํธ์ถ ๋ฐ ์๋ต์ obj ๋ณ์์ ์ ์ฅ
try:
reply = chat_with_gpt(user_input)
print("๐น ChatGPT Answer (์๋ณธ):\n", reply)
# ์๋ต์ obj ๋ณ์์ ์ง์ ์ ์ฅ
obj = reply # ๊ธฐ๋ํ ๋จ์ผ ๊ฐ์ธ A1, A2, A3, A4, A5 ์ค ํ๋๋ฅผ ์ ์ฅ
print("๐น done:", obj)
except Exception as e:
print("API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์:", str(e))
root.EXIT_Seq_SET.value = obj
- The prompt includes context and current simulation data.
- The AI’s response is parsed and applied to simulation variables (e.g., Con1, Con2) to alter the model’s flow.
โ๏ธ Simulation Flow
- Python executes every 5 seconds
(Run Python – 5 Sec Interval
- ChatGPT processes the prompt
- Response appears in the log window
- Label: “Answered by ChatGPT”
- Simulation reacts dynamically
- Conveyor logic and decision paths are changed
- “Line Operated by ChatGPT” appears in the model view

๐ Use Cases & Possibilities
โ
AI-in-the-loop simulation for smart factory development
โ
Educational content for AI-powered Digital Twin modeling
โ
Prototype for decision support systems using LLMs (Large Language Models)
โ
Expandable to KPI-based optimization, multi-agent decision-making, or RAG-enhanced scenarios
๐ง Final Thoughts
This demo shows a practical example of autonomous factory control using ChatGPT inside a discrete-event simulation.
No longer is simulation only about modeling logic — it’s about collaborating with AI to make decisions and operate the factory in real time.