Codesys Ros2 «LEGIT»

CODESYS data types are mapped to ROS2 messages as follows:

| CODESYS type | ROS2 message type | Example | |--------------|------------------|---------| | BOOL | std_msgs/Bool | – | | INT, DINT, LINT | std_msgs/Int32, Int64 | – | | REAL, LREAL | std_msgs/Float32, Float64 | – | | ARRAY[0..5] OF REAL | std_msgs/Float32MultiArray | layout dim [6] | | STRUCT | Custom .msg | field-by-field |

A code generator parses CODESYS struct definitions and emits ROS2 .msg files and serialization/deserialization code.

The lock-free bridge adds ~135μs overhead compared to native DDS, acceptable for most mechatronic systems (e.g., mobile robot base control, conveyor tracking). The OPC UA path is unsuitable for real-time control but remains viable for configuration and non-critical logging.

Let's simulate a simple project: ROS 2 sends a target speed to a CODESYS motor controller.

We are moving toward a hybrid future. The notion that "robotics runs on Linux and automation runs on PLCs" is obsolete. The machine that can do both will win. codesys ros2

CODESYS ROS 2 allows industrial machine builders to finally adopt the rapid development cycle of the ROS ecosystem without sacrificing the deterministic control and safety features of a PLC.

Are you currently using ROS on industrial hardware? Let me know in the comments if you have tried this integration yet.


Disclaimer: Feature availability depends on your specific CODESYS license level and hardware capabilities.

Bridging Industry 4.0: Integrating CODESYS with ROS 2 The integration of CODESYS, the global standard for industrial controller programming, with ROS 2 (Robot Operating System), the premier framework for advanced robotics, represents a significant leap for Industry 4.0. By combining the deterministic reliability of PLCs with the advanced perception and planning capabilities of ROS 2, engineers can build sophisticated, safety-critical robotic systems. Why Integrate CODESYS and ROS 2?

Traditional industrial automation often operates in "silos," where PLCs handle high-speed I/O and motor control, while robotic frameworks manage complex tasks like SLAM (Simultaneous Localization and Mapping) or computer vision. Integrating them allows for: CODESYS data types are mapped to ROS2 messages

Hardware Abstraction: Using CODESYS to manage industrial fieldbuses (EtherCAT, PROFINET) while ROS 2 handles high-level motion planning.

Safety and Real-Time Control: Running mission-critical logic in the CODESYS real-time environment while ROS 2 provides external intelligence.

Hybrid Systems: A robot can adjust its behavior based on factory sensor data coming through a PLC, such as slowing down if a temperature sensor exceeds a threshold. Common Integration Strategies

There is no single "native" driver for ROS 2 in CODESYS, so developers typically use one of the following bridging methods:


Recognizing the need for connectivity, CODESYS Group released the CODESYS Edge Gateway. This software component runs on the PLC (or a Linux container alongside it) and can map PLC variables to different protocols. Recognizing the need for connectivity

Developers can map IEC variables to MQTT or other standard protocols, which can then be ingested by a ROS2 node. This abstracts away the complex socket programming, allowing the PLC engineer to "tag" a variable in the development environment and have it instantly available to the network.

By integrating the two, you build a hybrid system:

| Feature | Handled by CODESYS (PLC side) | Handled by ROS 2 (Edge/PC side) | | :--- | :--- | :--- | | Real-time control | Servo drives, hydraulic valves, temperature loops (<1ms) | High-level trajectory following (>10ms) | | Safety | Safety-rated PLC (ISO 13849) | Monitoring, but not SIL-rated logic | | I/O Handling | 24V digital, 4-20mA analog, EtherCAT slaves | Cameras, LiDARs, 3D sensors, microphones | | Algorithms | PID, motion control (CNC/Robotics) | SLAM, A*, MoveIt motion planning, YOLO vision | | Communication | Modbus TCP, Profinet, OPC UA | DDS (Fast-DDS, CycloneDDS), MQTT, WebSockets | | Deployment | Flash to non-volatile PLC memory | Docker containers, Kubernetes, snap packages |

We implemented a CODESYS ROS2 Client Library written in C++ (compiled as a CODESYS External Library) and exposed to IEC code via Function Blocks (FBs).

Before diving into the technical "how," let's establish the business and engineering "why."