Codesys Ros2 | Must Try
CODESYS GmbH (now part of Schneider Electric) provides a dedicated for CODESYS. This library introduces special function blocks that act as DDS (Data Distribution Service) publishers and subscribers—directly from IEC 61131-3 code.
Integrating CODESYS—the leading hardware-independent IEC 61131-3 development software—with ROS2 provides a powerful solution to this challenge. This article explores the architecture, benefits, communication strategies, and step-by-step implementation of a CODESYS-ROS2 ecosystem. Understanding the Components What is CODESYS?
import rclpy from geometry_msgs.msg import Twist from rclpy.node import Node codesys ros2
ROS 2 utilizes specific message structures (e.g., sensor_msgs/JointState ). CODESYS utilizes IEC data types (e.g., REAL , INT , STRUCT ). The bridge layer must reliably serialize and deserialize these types, paying close attention to unit conversions (such as converting ROS 2 radians to CODESYS motor encoder ticks).
To understand the value of this integration, we must look at what each platform does best. CODESYS GmbH (now part of Schneider Electric) provides
Select the variables you want to expose to ROS 2 (e.g., Target_Velocity , Current_Position , Status_Word ).
Never let the asynchronous nature of ROS2 stall a real-time CODESYS task. Design the PLC code to use fallback logic. If the ROS2 bridge fails to update a target coordinate within a designated watchdog time frame (e.g., CODESYS utilizes IEC data types (e
This paper presented a practical, real-time capable bridge between CODESYS PLCs and ROS2. By embedding a ROS2 client library into the CODESYS runtime and using a lock-free FIFO between the real-time task and a lower-priority spin thread, we achieve mean latencies of 220μs—suitable for high-speed robotic control. The architecture preserves the determinism of IEC 61131-3 code while leveraging the full ROS2 ecosystem. Source code for the CODESYS ROS2 client library is available under Apache 2.0 license (anonymized for review).
For simpler setups, an intermediate broker like MQTT or direct TCP/IP stream sockets can bridge the gap. CODESYS features standard libraries for TCP/UDP communication and MQTT clients. A bridging ROS2 node handles translation on the Linux side.
: This node will take your PLC data and use ros2 topic pub to push it into the ROS network.
The key to coupling these systems lies in mapping CODESYS variables to ROS2 topics, services, or actions. The primary mechanism for this is , which is the native middleware for ROS2. A. The CODESYS DDS Solution (Native)
