AutoPLC用自然语言生成适配西门子和科世达的PLC代码,提升工业自动化开发效率。
AutoPLC: Generating Vendor-Aware Structured Text for Programmable Logic Controllers
- 基于厂商特有接口库和案例数据库,分四步生成符合平台规范的代码
- 在914个任务上编译成功率超90%,每任务成本仅0.13美元
- 适合需要跨平台开发的PLC工程师,支持真实工业场景应用
在可编程逻辑控制器(PLC)的编程语言中,结构化文本(ST)因其表达力和灵活性被广泛采用。然而,主流厂商对ST实现存在专有扩展和硬件特定库——西门子的SCL与CODESYS的ST在语法和功能上均有差异,导致工程师需在不同平台间重复学习,形成显著生产力障碍。为此,我们提出AutoPLC框架,可直接从自然语言需求自动生成适配厂商的ST代码。该方案构建了两类专有知识源:包含平台独有函数的结构化API库,以及标注真实实施经验的案例数据库。在此基础上,设计了四阶段生成流程:结合轻量级自然语言状态机增强的逐步规划、基于LLM重排序的上下文案例检索、基于工业数据的API推荐,以及通过与厂商IDE直接交互实现的动态验证。该框架已部署于西门子TIA Portal和CODESYS平台,在涵盖通用功能与过程控制的914项任务基准上实现90%以上的编译成功率,优于所有对比基线,平均任务成本仅为0.13美元。经验丰富的PLC工程师对生成代码的实际可用性给予积极评价,包括部分未成功编译的案例。项目已开源:https://github.com/cangkui/AutoPLC。
原文摘要 · Abstract (English)
Among the programming languages for Programmable Logic Controllers (PLCs), Structured Text (ST) is widely adopted for industrial automation due to its expressiveness and flexibility. However, major vendors implement ST with proprietary extensions and hardware-specific libraries - Siemens' SCL and CODESYS' ST each differ in syntax and functionality. This fragmentation forces engineers to relearn implementation details across platforms, creating substantial productivity barriers. To address this challenge, we developed AutoPLC, a framework capable of automatically generating vendor-aware ST code directly from natural language requirements. Our solution begins by building two essential knowledge sources tailored to each vendor's specifications: a structured API library containing platform-exclusive functions, and an annotated case database that captures real-world implementation experience. Building on these foundations, we created a four-stage generation process that combines step-wise planning (enhanced with a lightweight natural language state machine support for control logic), contextual case retrieval using LLM-based reranking, API recommendation guided by industrial data, and dynamic validation through direct interaction with vendor IDEs. Implemented for Siemens TIA Portal and the CODESYS platform, AutoPLC achieves 90%+ compilation success on our 914-task benchmark (covering general-purpose and process control functions), outperforming all selected baselines, at an average cost of only $0.13 per task. Experienced PLC engineers positively assessed the practical utility of the generated code, including cases that failed compilation. We open-source our framework at https://github.com/cangkui/AutoPLC.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。