Codesys Ros2 |top|
To continue advancing your implementation, consider exploring the following steps:
We implemented a written in C++ (compiled as a CODESYS External Library) and exposed to IEC code via Function Blocks (FBs).
No standard solution exists for bidirectional, low-latency communication between a CODESYS PLC and a ROS2 system.
Once CODESYS has the linear and angular target velocities, it passes them through a kinematics function block (e.g., differential drive or mecanum wheel equations) to calculate individual wheel velocities. These targets are then sent to the physical motor drives via EtherCAT in real-time. Challenges and Best Practices codesys ros2
Data mapping requires precision. CODESYS uses IEC types like BOOL , INT , REAL , and LREAL , whereas ROS2 utilizes primitive IDL types within its messages ( bool , int32 , float32 , float64 ).
PROGRAM PRG_JointPublisher VAR ros_pub : FB_ROS2_Publisher; joint_pos : ARRAY[0..5] OF LREAL := [0.0, -0.5, 0.5, 0.0, 0.0, 0.0]; trigger : R_TRIG; cycle : UINT := 0; END_VAR
Network communication can drop. Always implement a watchdog timer inside CODESYS. If the PLC does not receive a heartbeat packet from ROS 2 within a strict window (e.g., 100ms), CODESYS must safely ramp down the motors to a dead stop. These targets are then sent to the physical
CODESYS (Controller Development System) is unique among PLC environments because it runs on a real-time operating system (RTOS) kernel (e.g., CODESYS Control RTE on Linux) and can execute IEC 61131-3 code (Ladder Logic, Structured Text, etc.) with sub-millisecond jitter. ROS2, by contrast, prioritizes throughput and scalability over strict determinism but offers a rich ecosystem of packages.
The core challenge of a CODESYS-ROS2 integration is bridge communication. Because the platforms utilize different data structures and network protocols, engineers typically choose one of three architectural approaches:
Simulation is critical for developing and testing robotic systems without physical hardware. The simulator integrates seamlessly with ROS 2, creating a powerful tool for co-simulation with CODESYS. In such a setup, CODESYS serves as the virtual PLC, running the same control logic that will later be deployed on the real hardware. Modbus or other communication protocols transmit data between the CODESYS PLC and the Gazebo environment. Gazebo uses this data to update the simulated robot's state and provides realistic sensor feedback, creating a complete digital twin of the system for comprehensive development and testing. from CANopen to EtherCAT
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.
The primary motivation for integrating CODESYS and ROS 2 is to combine the best of both worlds: the industrial-grade reliability and real-time performance of a PLC with the advanced algorithms and flexibility of a robotic framework. Pure ROS 2-based systems often struggle with the diverse and demanding world of industrial hardware integration. Each protocol, from CANopen to EtherCAT, typically requires its own specialized and often incomplete ROS 2 driver package, introducing significant development complexity and debugging challenges.
