Integrating CODESYS with ROS 2 (Robot Operating System 2) creates a powerful "Brain-Muscle" architecture for industrial automation. While ROS 2 excels at high-level "thinking" tasks like AI-driven path planning and 3D perception, CODESYS provides the deterministic "muscle" needed for real-time hardware control and safety-critical execution. Why Pair CODESYS with ROS 2?
Combining these two frameworks allows developers to bridge the gap between flexible open-source robotics and stable industrial standards:
Deterministic Control: CODESYS handles low-level hardware (e.g., EtherCAT, CANopen) with millisecond precision, which is often difficult to achieve reliably in a pure ROS 2 environment.
Advanced Capabilities: ROS 2 provides access to millions of lines of open-source code for complex tasks like SLAM (Simultaneous Localization and Mapping) and computer vision.
Reduced Vendor Lock-in: By using standardized interfaces like OPC UA or shared memory, you can swap hardware components without rewriting your entire high-level logic. Common Integration Methods codesys ros2
There isn't a single "official" driver, but several proven architectural patterns exist: ScalABLE40/robin: The ROS-CODESYS Bridge - GitHub
Integrating CODESYS with ROS 2 allows you to combine the deterministic hardware control of industrial PLCs with the advanced motion planning and perception capabilities of the Robot Operating System. 🚀 Direct Integration Methods
Shared Memory Bridge (Recommended for High Speed): Use the ROBIN project (ScalABLE40/robin) for high-performance data exchange on the same hardware (e.g., Raspberry Pi, Beaglebone).
OPC UA Bridge: Set up an OPC UA Server in CODESYS and use a ROS 2 node as an OPC UA Client with libraries like asyncua (Python) or open62541 (C++). Integrating CODESYS with ROS 2 (Robot Operating System
MQTT Messaging: Use the CODESYS MQTT library to publish PLC variables to a broker and subscribe to them via a ros2_mqtt bridge for non-real-time tasks.
Micro-ROS Agent: For microcontrollers or lightweight PLCs, run a micro-ROS node directly on the target hardware to communicate with the ROS 2 Global Data Space. 🛠️ Strategic Setup: Why use both?
CoDeSys is a popular software tool for programming and configuring industrial controllers, such as programmable logic controllers (PLCs). It provides a comprehensive development environment for creating and testing control applications.
Current limitations:
Future directions:
.msg via a CLI tool.Presentation QoS to attach hardware timestamps from EtherCAT cycle.ROS2_Connector.library – function blocks, data types, visualization templates.codesys_bridge – contains launch files, example .msg definitions, and a diagnostic node.SysSock, SysSockets, and SL Iot MQTT Client libraries if not already present.Inserting the CODESYS→ROS2 publisher at 1kHz increased the maximum PLC cycle time from 1.02ms to 1.19ms (17% increase). The worst-case occurred during DDS discovery heartbeats (every 3s). Using rclcpp::Publisher::publish() with pre-allocated messages eliminated dynamic memory inside the RT task.
Why not just write everything in C++ (ROS2) or everything in Structured Text (CODESYS)?
.msg definitions (including complex data types like arrays, structs, enums).