Codesys Ros2 Info
We evaluated the system on a dual-core x86_64 Linux with PREEMPT_RT (5.15 kernel), CODESYS Control RTE V3.5 SP19, and ROS2 Humble.
The integration of CODESYS and ROS2 represents the maturation of the robotics industry. We are moving away from "hobbyist" control systems and toward a hybrid model where ROS2 provides the intelligence and CODESYS provides the discipline.
For automation engineers, learning how to interface their PLCs with ROS2 is no longer a niche skill—it is becoming a requirement for building the next generation of intelligent machinery. As the tools for bridging these environments improve, the line between the "Industrial Controller" and the "Robot Brain" will continue to blur.
Integrating CODESYS with ROS 2 (Robot Operating System 2) creates a powerful bridge between traditional industrial automation and modern robotic intelligence. This combination allows engineers to leverage the determinism and safety of a PLC (Programmable Logic Controller) alongside the advanced perception, mapping, and navigation capabilities of ROS 2. 1. The Core Synergy
CODESYS (The Deterministic Core): Acts as the "lower-level" controller, handling time-critical tasks like motor synchronization, functional safety, and real-time fieldbus communication (e.g., EtherCAT). According to RealPars, CODESYS is a hardware-independent software suite that follows the IEC 61131-3 standard for industrial programming.
ROS 2 (The Intelligent Layer): Provides the "higher-level" intelligence, including computer vision, SLAM (Simultaneous Localization and Mapping), and path planning. ROS 2 is designed for distributed systems and asynchronous communication using the Data Distribution Service (DDS) middleware. 2. Common Integration Methods
Connecting these two systems typically involves a gateway that allows them to "speak" to one another:
OPC UA: Many CODESYS-compatible controllers support OPC UA, which can be bridged to ROS 2 using standard nodes like ros2_opcua_gateway. codesys ros2
Shared Memory/MQTT: For low-latency data exchange on a single hardware unit (like a Raspberry Pi running both CODESYS and ROS 2), developers often use shared memory interfaces or MQTT brokers to pass variables between the PLC runtime and ROS nodes.
DDS Library for CODESYS: Some advanced implementations involve integrating a DDS client directly within the CODESYS environment, allowing the PLC to appear as a native participant in the ROS 2 network. 3. Key Use Cases
Mobile Robotics (AGVs/AMRs): ROS 2 handles the complex navigation and obstacle avoidance, while CODESYS manages the physical drive train and safety interlocks.
Smart Factories: Merging traditional assembly line control (PLC) with robotic vision systems to identify and sort parts on the fly.
Rapid Prototyping: Using free tools from the CODESYS Store to test industrial control logic on hardware that also supports ROS 2. 4. Implementation Example: CODESYS on Raspberry Pi
A popular entry point for developers is running the CODESYS Control for Raspberry Pi SL runtime. This allows you to turn a standard Raspberry Pi into a PLC, which can then communicate with ROS 2 nodes running on the same board or over a local network.
Integrating CODESYS with ROS 2 (Robot Operating System 2) creates a powerful "Brain-Muscle" architecture for industrial automation. While ROS 2 excels at high-level "thinking" tasks like AI-driven path planning and 3D perception, CODESYS provides the deterministic "muscle" needed for real-time hardware control and safety-critical execution. Why Pair CODESYS with ROS 2? We evaluated the system on a dual-core x86_64
Combining these two frameworks allows developers to bridge the gap between flexible open-source robotics and stable industrial standards:
Deterministic Control: CODESYS handles low-level hardware (e.g., EtherCAT, CANopen) with millisecond precision, which is often difficult to achieve reliably in a pure ROS 2 environment.
Advanced Capabilities: ROS 2 provides access to millions of lines of open-source code for complex tasks like SLAM (Simultaneous Localization and Mapping) and computer vision.
Reduced Vendor Lock-in: By using standardized interfaces like OPC UA or shared memory, you can swap hardware components without rewriting your entire high-level logic. Common Integration Methods
There isn't a single "official" driver, but several proven architectural patterns exist: ScalABLE40/robin: The ROS-CODESYS Bridge - GitHub
Robot-centric (ROS 2 master)
Hybrid edge device
Gateway-based
Here's an example code snippet in C++ that demonstrates how to integrate a CoDeSys controller with ROS 2:
#include <ros2/ros2.hpp>
#include <industrial_ros2/industrial_ros2.hpp>
int main(int argc, char* argv[])
// Initialize ROS 2
rclcpp::init(argc, argv);
// Create a ROS 2 node
auto node = rclcpp::Node::create_node("co_de_sys_node");
// Create a CoDeSys controller object
industrial_ros2::CoDeSysController controller;
// Configure the CoDeSys controller
controller.configure("co_de_sys_controller");
// Start the CoDeSys controller
controller.start();
// Create a ROS 2 publisher
auto publisher = node->create_publisher<std_msgs::msg::String>("co_de_sys_topic", 10);
// Publish data from the CoDeSys controller
while (rclcpp::ok())
std_msgs::msg::String msg;
msg.data = controller.read_data();
publisher->publish(msg);
// Shutdown ROS 2
rclcpp::shutdown();
return 0;
Integrating CODESYS with ROS 2 allows you to use high-level robotics algorithms (Navigation, SLAM, Computer Vision) running in ROS 2 nodes while maintaining hard real-time control of motors and sensors using IEC 61131-3 logic in CODESYS.
There is no native "ROS 2 Driver" built into standard CODESYS. The industry-standard method is the CODESYS MQTT Broker approach. ROS 2 speaks MQTT natively, and CODESYS acts as a client.
Inserting the CODESYS→ROS2 publisher at 1kHz increased the maximum PLC cycle time from 1.02ms to 1.19ms (17% increase). The worst-case occurred during DDS discovery heartbeats (every 3s). Using rclcpp::Publisher::publish() with pre-allocated messages eliminated dynamic memory inside the RT task.
ROS2 uses DDS as its middleware, providing:
Hardware/Software:
Libraries to Install:













