The Zero-Friction Communication Layer Between ROS2 and Embedded Microcontrollers
Forget the immense complexity of micro-ROS. Get your STM32 talking to ROS2 in under 3 minutes.
Features • Quick Start • Architecture • Documentation • Contributing
Every robotics engineer faces the exact same challenge: "How do I get my microcontroller to talk to my ROS2 PC reliably without going crazy?"
Common solutions like micro-ROS are incredibly powerful but severely over-engineered for simple sensor/actuator bridges. ros2-hardware-bridge provides the ultimate middle ground:
- ⚡ Zero Configuration: No complex build systems, no DDS agents to configure.
- 🛡️ Type Safety: Pre-defined packet structures mapped directly to native ROS2 types (Twist, Pose, Battery, Encoders).
- 🧩 Fault Tolerant: Built-in CRC checksums silently drop noisy serial garbage.
- 🪶 Ultra-Lightweight: The C-firmware library is
< 1KBand has zero external dependencies.
Get up and running in 3 commands.
Clone and build the package in your ROS2 workspace:
cd ~/ros2_ws/src
git clone https://github.com/EngineerAbdullahBinZafar/ros2-hardware-bridge.git
cd ~/ros2_ws
colcon build --packages-select ros2_hardware_bridge
source install/setup.bash
# Launch the bridge on your serial port
ros2 run ros2_hardware_bridge bridge_node --ros-args -p port:=/dev/ttyACM0Simply include the single header file ros2_bridge.h and use the serialization functions.
#include "ros2_bridge.h"
// Example: Send battery voltage to ROS2
float voltage = 12.6f;
uint8_t tx_buf[32];
// Serialize data (ID 0x10 = Battery Voltage)
int len = bridge_serialize(0x10, (uint8_t*)&voltage, sizeof(float), tx_buf);
// Transmit via UART (STM32 HAL example)
HAL_UART_Transmit(&huart1, tx_buf, len, 10);Our custom packet protocol guarantees that your ROS2 ecosystem never sees corrupted data.
graph LR
subgraph "Embedded System (STM32 / ESP32)"
style A fill:#03234B,stroke:#fff,stroke-width:2px,color:#fff
style B fill:#03234B,stroke:#fff,stroke-width:2px,color:#fff
A[Firmware Logic] -->|Raw Sensor Data| B[ros2_bridge.h]
B -->|CRC Packed Serial| C((UART / Serial))
end
C <==>|USB / Serial Cable| D((Serial / USB))
subgraph "ROS2 Host (PC / Pi / Jetson)"
style E fill:#22314E,stroke:#fff,stroke-width:2px,color:#fff
style F fill:#22314E,stroke:#fff,stroke-width:2px,color:#fff
style G fill:#22314E,stroke:#fff,stroke-width:2px,color:#fff
style H fill:#22314E,stroke:#fff,stroke-width:2px,color:#fff
D <==>|CRC Packed Serial| E[bridge_node.py]
E -->|Publish Twist| F[/cmd_vel/]
E -->|Publish Float32| G[/hw/battery/]
E -->|Publish Int32| H[/hw/encoder/]
end
| Packet ID | Description | ROS2 Topic Name | Standard Data Type |
|---|---|---|---|
0x01 |
Velocity Command | /cmd_vel |
geometry_msgs/Twist |
0x10 |
Battery Voltage | /hw/battery |
std_msgs/Float32 |
0x11 |
Encoder Ticks | /hw/encoder |
std_msgs/Int32 |
(Need more messages? See Contributing to easily add your own!)
We want to make this the universal standard for simple ROS2 hardware interfacing.
- Read our Contributing Guidelines and Code of Conduct.
- Fork the repository.
- Submit a Pull Request.
High-Priority Bounties:
- Adding support for
sensor_msgs/Imuandsensor_msgs/LaserScan. - High-performance C++ implementation of the ROS2 host node.
Distributed under the MIT License. See LICENSE for more information.
Developed with passion by Engineer Abdullah Bin Zafar.
If this project saved you hours of debugging micro-ROS, consider dropping a ⭐!