Codesys Ros2 -

We will implement a Publish/Subscribe model using MQTT.


As of 2025 (and looking beyond), several trends are accelerating this integration:

CODESYS GmbH (now part of Schneider Electric) provides a dedicated ROS 2 library for CODESYS. This library introduces special function blocks that act as DDS (Data Distribution Service) publishers and subscribers—directly from IEC 61131-3 code. codesys ros2

How data flows:

Under the hood, the bridge uses the DDS protocol, the mandatory middleware of ROS 2. This means zero custom serialization. The CODESYS runtime on Windows/Linux connects to the same DDS domain as the ROS 2 nodes. We will implement a Publish/Subscribe model using MQTT

On the ROS 2 side, a simple node publishes to /cmd_vel:

import rclpy
from geometry_msgs.msg import Twist
from rclpy.node import Node

class Commander(Node): def init(self): super().init('plc_commander') self.pub = self.create_publisher(Twist, '/cmd_vel', 10) timer_period = 0.05 # 50ms self.timer = self.create_timer(timer_period, self.timer_callback) As of 2025 (and looking beyond), several trends

def timer_callback(self):
    msg = Twist()
    msg.linear.x = 1.0  # go forward at 1 m/s
    msg.angular.z = 0.5 # turn slightly
    self.pub.publish(msg)