Abstract
AutoPLC is a novel framework designed to automate the generation of vendor-specific Structured Text (ST) for industrial controllers. By combining specialized knowledge bases with a four-stage LLM pipeline and iterative compiler feedback, it achieves over 90% compilation success across major platforms like Siemens TIA Portal and CODESYS, significantly outperforming general-purpose models.
Introduction: The Challenge of PLC Programming Fragmentation
In industrial automation, Programmable Logic Controllers (PLCs) serve as the primary control units. While the IEC 61131-3 standard defines Structured Text (ST) as a high-level language for these devices, implementation is highly fragmented. Major vendors implement proprietary extensions—such as Siemens’ SCL or CODESYS’ ST—each with unique syntax, specialized functions, and hardware-specific libraries.
This fragmentation creates two major hurdles:
- Human Effort: Engineers must manually port logic between platforms, a process prone to error and high "relearning" costs.
- LLM Limitations: Standard Large Language Models (LLMs) struggle with ST because high-quality public datasets are scarce. Furthermore, LLMs often "hallucinate" generic Pascal or C-style syntax that fails to compile in strict industrial environments.
Methodology: The AutoPLC Framework
AutoPLC bridges the gap between natural language requirements and compilable, vendor-aware code through a four-stage process supported by a vendor-specific knowledge base.
1. Vendor-Specific Knowledge Construction
The system relies on two curated sources:
- APILib: A structured library of platform-exclusive functions (APIs) with metadata on parameters and usage.
- Rq2ST: A case library of "Requirement-Plan-Code" triplets that capture real-world implementation patterns.
2. The Four-Stage Pipeline
- Planning: Instead of jumping straight to code, the LLM creates a step-by-step plan. For control logic, it uses a natural language state machine approach to define transitions, which avoids the "syntactic noise" often introduced by pseudocode.
- Retrieval and Recommendation: The framework uses Retrieval-Augmented Generation (RAG) to find similar past cases and recommends specific vendor APIs based on functional intent and I/O type matching.
- Code Generation: The model synthesizes the final ST code based on the plan and recommended APIs.
- Iterative Self-Improvement: This is the "closed-loop" part of the system. AutoPLC interfaces directly with actual vendor IDEs (like Siemens TIA Portal). If the code fails to compile, the system analyzes the specific error messages and iteratively patches the code until it passes.
Datasets and Evaluation
The researchers built a comprehensive benchmark of 914 tasks categorized into four datasets: OSCAT (718 cases), Siemens LGF (151 cases), Siemens Competition (45 cases), and Agents4PLC (23 tasks).
AutoPLC achieved a compilation pass rate exceeding 90% across all datasets. Notably, on the Siemens LGF dataset, AutoPLC reached a 92.7% pass rate, while the next best general model (Claude-3.5) managed only 15.2%. The system is also efficient, with an average cost of approximately $0.13 and a processing time of about 52 seconds per task.
Key Insights
- Natural Language Planning: Planning in natural language prevents the LLM from accidentally leaking "hallucinated" pseudocode syntax into the final ST output.
- Declaration-First Strategy: When fixing errors, AutoPLC prioritizes fixing variable declaration issues before implementation logic, preventing a "cascade" of downstream compiler complaints.
- Interaction with Real IDEs: AutoPLC’s use of TIA Openness to talk to real Siemens software ensures the code is truly production-ready, unlike models tested only on open-source compilers.
Conclusion
AutoPLC demonstrates that specialized knowledge bases and iterative compiler feedback are essential for generating production-ready industrial code. While the system currently focuses on syntax and compilation, future work will address runtime logic verification and large-scale system integration involving multiple devices and complex HMI interactions.
Summary updated