Codesys Ros2 [new] Page
"op": "publish", "topic": "/cmd_vel", "msg": "linear": "x": 0.1, "angular": "z": 0.2
Hybrid edge device
import rclpy from rclpy.node import Node from geometry_msgs.msg import Twist from asyncua import Client class CodesysBridgeNode(Node): def __init__(self): super().__init__('codesys_bridge_node') self.subscription = self.create_subscription( Twist, 'cmd_vel', self.cmd_vel_callback, 10) # Connect to CODESYS OPC UA Server self.ua_client = Client("opc.tcp://1192.168.1.50:4840") async def connect_plc(self): await self.ua_client.connect() self.get_logger().info("Connected to CODESYS PLC") # Locate the specific node variable in CODESYS self.target_vel_node = await self.ua_client.nodes.root.get_child( ["0:Objects", "2:DeviceApp", "2:PLC_PRG", "2:Target_Velocity"]) async def cmd_vel_callback(self, msg): # Translate ROS 2 Twist message to PLC variable linear_x = msg.linear.x await self.target_vel_node.write_value(linear_x) def main(args=None): rclpy.init(args=args) node = CodesysBridgeNode() # In practice, use an async loop executor here to handle asyncua concurrently rclpy.spin(node) rclpy.shutdown() Use code with caution. Step 3: Map Topics and Test
🏆
In this scenario, CODESYS acts as a WebSocket client. It connects to the ROS bridge server, then can publish and subscribe to ROS topics by sending appropriately formatted JSON frames. For example, to publish velocity commands on the /cmd_vel topic, CODESYS sends a message like:
Current integration methods focus on bridging data between the ROS2 DDS (Data Distribution Service) layer and the PLC runtime. A. Shared Memory Communication
Inside your codesys_bridge package, create a node script ( bridge_node.py ) utilizing the asyncua library to fetch data from CODESYS and publish it onto a ROS2 topic. codesys ros2
What fits best for your system requirements?
For simpler applications, standard industrial protocols supported by both CODESYS and ROS 2 offer the easiest path.
Lightweight, incredibly fast, easy to implement for basic data exchange. For example, to publish velocity commands on the
I can provide complete C++ alternatives for the ROS2 bridge node if your application demands than Python can provide.
The combination of CODESYS and ROS2 is expanding across several key industrial sectors:
Create structured data types in CODESYS that match the ROS2 message structures ( msg ). Step 2: Configure the ROS2 Nodes What fits best for your system requirements

