Codesys Ros2 _hot_
This is a game-changer. It allows a developer to run the CODESYS runtime and the ROS2 middleware on the same edge computer. This eliminates the need for external cabling or gateway hardware. It allows for shared memory communication between the real-time CODESYS memory space and the ROS2 nodes, drastically reducing latency.
import rclpy from geometry_msgs.msg import Twist from rclpy.node import Node
On a modern i7 with Preempt-RT Linux, you can achieve 2-5 ms end-to-end (PLC input → ROS 2 processing → PLC output). This is suitable for mobile robots, but not for sub-millisecond servo drives (which should stay internal to CODESYS soft motion).
return 0;
Mastering this integration empowers you to build automation systems that are deeply robust, incredibly intelligent, and ready for the future of Industry 4.0.
For more complex, high-performance needs, dedicated bridges are the best solution.
CODESYS data types are mapped to ROS2 messages as follows: codesys ros2
Engineers use CODESYS because it offers hard real-time performance. The scan cycle of a PLC is sacred; inputs are read, logic is processed, and outputs are written in a guaranteed timeframe. It is designed to handle the "low-level" reality of hardware: turning on hydraulic valves, reading safety light curtains, and managing motor drives via EtherCAT.
Bridging the Industrial-Robotic Divide: CODESYS and ROS2 Integration
Before deploying physical hardware, engineers can run a virtual CODESYS PLC (SoftPLC) on a local machine and connect it to a ROS2 simulation running in Gazebo or Isaac Sim. This allows complete validation of the control logic and robotics algorithms in a risk-free virtual environment. Key Challenges and Best Practices This is a game-changer
The integration of CoDeSys and ROS 2 is achieved through a combination of software components and development tools. Some of the key technical details include:
In this section, we set up the PLC to read sensor data and publish it via MQTT.
: Modern Industrial PCs (IPCs) can run a real-time Linux kernel (like Ubuntu with PREEMPT_RT ). This allows CODESYS Control and ROS2 nodes to execute on the exact same physical hardware, minimizing wiring and latency. It allows for shared memory communication between the
We implemented a written in C++ (compiled as a CODESYS External Library) and exposed to IEC code via Function Blocks (FBs).
CODESYS executes tasks in strict real-time, often with cycle times down to 1 millisecond.
