This repository contains an implementation of a simple ROS2 Micro-ROS publisher using ESP32. The project publishes an integer counter to the /count_pub topic.
sim_pub.hpp: Header file defining thesimPubclass, which handles the ROS2 publisher.sim_pub.cpp: Implementation of thesimPubclass, including initialization and timer callback function.main.cpp: Entry point of the program, initializing the ROS2 Micro-ROS node and adding the publisher component.
To run this project, you need:
- ESP-IDF with Micro-ROS support
- Micro-ROS Agent running on a host system
- ROS2 (Humble or newer) installed on the host
- Micro-ROS ESP32 Component: micro_ros_espidf_component
- Custom Micro Handler: urosHandler
git clone https://github.com/Chinmay-ESP/PUB_MicroRos_IDF.git
cd PUB_MicroRos_IDFFollow the official Micro-ROS on ESP32 guide to set up ESP-IDF and Micro-ROS.
git clone https://github.com/micro-ROS/micro_ros_espidf_component.git components/micro_ros_espidf_component
git clone https://github.com/gawar55/urosHandler.git components/urosHandleridf.py set-target esp32
idf.py build
idf.py flashOn your host machine, start the Micro-ROS Agent:
docker run -it --rm --ipc host --network host --privileged microros/micro-ros-agent:humble serial -b 115200 --dev /dev/ttyUSB0-
simPubClass:- Creates a publisher on the
/count_pubtopic. - Uses a timer callback to publish an increasing integer value.
- Publishes data at a frequency of 10 Hz.
- Creates a publisher on the
-
Main Execution (
app_main):- Initializes the
uros_master_node. - Registers the
simPubpublisher.
- Initializes the
Once the ESP32 is running and the Micro-ROS Agent is active, you should see messages being published in ROS2:
ros2 topic echo /count_pubOutput:
data: 0
data: 1
data: 2
...