Automated PLC Programming Using a Multi-Task LLM System
Abstract
Programmable Logic Controllers (PLCs) are central to industrial automation, yet their programming remains largely manual and time-consuming. While Large Language Models (LLMs) excel at general-purpose code generation, their use in industrial control is limited by tight coupling with physical hardware, constrained I/O signals, and strict safety requirements. We propose a novel approach to PLC code generation that takes as input structured lists of sensors and actuators from electrical CAD tools, together with the required control functionality. The task is formulated as generating machine-specific control functions grounded in available signals, ensuring physical implementability. The system is based on a single LLM adapted through multi-stage fine-tuning and enhanced with Retrieval-Augmented Generation (RAG). Experiments on error detection, code fixing, and code generation show that fine-tuning significantly improves performance. RAG provides strong gains in error detection and code generation, while offering limited benefit for code fixing, highlighting its task-dependent effectiveness.