Abstract
Structured Text (ST) is a cornerstone of industrial automation, yet its implementation remains highly fragmented across vendors like Siemens and CODESYS. This proprietary divergence forces engineers to manually adapt code for different hardware, hindering productivity. We present AutoPLC, a framework that automatically generates vendor-aware ST code from natural language requirements. By leveraging specialized knowledge bases and a four-stage generation pipeline—including planning with state machine support, contextual retrieval, and iterative validation via actual vendor IDEs—AutoPLC achieves a 90%+ compilation success rate on a 914-task benchmark.
The Challenge: A Fragmented Industrial Landscape
In industrial automation, Programmable Logic Controllers (PLCs) serve as the central control units. While the IEC 61131-3 standard defines Structured Text (ST) as a high-level programming language for these devices, major vendors have introduced significant proprietary extensions. Siemens uses SCL (Structured Control Language), while CODESYS and Beckhoff implement their own variations of ST.
As shown in the figure above, these variations include different data types (e.g., Siemens' VARIANT), specific memory control mechanisms (e.g., Beckhoff's POINTER), and unique syntax for metadata or readability markers. For engineers, this creates a "Tower of Babel" effect where code is not portable. General-purpose Large Language Models (LLMs) often fail in this domain because they lack exposure to these vendor-specific nuances, leading to "hallucinations" of generic, non-compilable code.
The AutoPLC Framework
To bridge this gap, AutoPLC moves beyond simple prompting by integrating vendor-specific knowledge with a robust generation pipeline.
1. Vendor-Specific Knowledge Bases
AutoPLC relies on two foundational knowledge sources:
- APILib: A structured library of vendor-exclusive functions, including descriptions, parameters, and usage examples crawled from online manuals.
- Rq2ST: A case library of requirement-plan-code triplets. This allows the model to learn from proven, real-world implementations rather than relying solely on its pre-trained weights.
2. A Four-Stage Generation Workflow
The framework employs a sophisticated pipeline to ensure code quality and vendor compliance:
- Step 1: Planning: The model first decomposes the natural language requirement into a step-by-step plan. For control-oriented tasks, it utilizes a natural language "state machine" to explicitly track transitions, preventing the logical errors common in AI-generated control logic.
- Step 2: Case Retrieving: Relevant examples are fetched from the Rq2ST library. An LLM-based reranker ensures the most contextually appropriate cases are used as few-shot prompts.
- Step 3: API Recommendation: Based on the plan and I/O types, the system identifies the necessary vendor-specific APIs from the APILib.
- Step 4: Code Generation & Self-Improvement: The model generates the ST code and enters an iterative refinement loop. Crucially, AutoPLC communicates directly with vendor IDEs (such as Siemens TIA Portal) to receive real compiler feedback. If errors occur, the model analyzes the root cause and patches the code until it compiles successfully.
Evaluation and Results
We evaluated AutoPLC on a comprehensive benchmark of 914 tasks, including general-purpose functions (OSCAT), industrial-standard libraries (Siemens LGF), and real-world process control challenges.
The results demonstrate a significant breakthrough:
- High Success Rate: AutoPLC achieved a 90%+ compilation success rate across all datasets. In contrast, leading models like Claude-3.5-Sonnet managed only a 15.23% pass rate on the Siemens LGF dataset without the AutoPLC framework.
- Cost-Effectiveness: The average cost per task was approximately $0.13, making it a highly scalable solution for industrial engineering.
- Expert Validation: Experienced PLC engineers reviewed the generated code, praising its correctness and safety. They noted that even in rare cases where the code failed to compile, it provided a high-quality "draft" that significantly reduced manual effort.
Conclusion and Future Outlook
AutoPLC demonstrates that combining LLMs with vendor-specific RAG and real-world IDE validation can overcome the fragmentation of industrial programming. While the current framework excels at individual function blocks, future work will focus on integrating these components into larger, multi-device systems and enhancing formal verification for safety-critical environments.
By open-sourcing the framework, we aim to provide the industrial automation community with a powerful tool to enhance productivity and reduce the barriers between proprietary platforms.
Paper Citation: Donghao Yang, et al. "AutoPLC: Generating Vendor-Aware Structured Text for Programmable Logic Controllers." arXiv:2412.02410v2 [cs.SE], 2025. GitHub Repository
Summary updated