Micro-ROS puts ROS 2 onto microcontrollers. In ROS2 micro-ROS is used for connecting microcontrollers to ROS2. This documentation aims to help to getting start with micro-ROS in ESP32 using arduino IDE. We will try to make it simple, you can also visit the micro-ROS official documentation
Different methods available for compiling and uploading micro-ROS libraries to ESP32. Here in this tutorial we are using arduino IDE. You will learn to connect ESP32 and micro-ROS agent. Also how to install micro ros agent on Ubuntu.
In ROS1 rosserial is the library used for connecting microcontroller and ROS. Read difference between micro-ROS and rosserial for more details.
System specificationUbuntu 22.04 and ROS2 humble
Development Board used : DOIT ESP32 DEVKIT
Installation micro-ROS agentInstall ROS2 humble by following the instructions on official documentation.
Open the terminal and excecute the following commands
Set up your environment by sourcing the following file.
source /opt/ros/humble/setup.bash
For using ROS2 commands you need to run source
/opt/ros/humble/setup.bash
everytime when you open a new terminal for avoiding this we can put the source command on bashrc file. Commands inside bashrc is excecuted everytime when you open a new terminal
For opening .bashr
c j:
gedit ~/.bashrc
Add the following command to this file
source /opt/ros/humble/setup.bash
Create a workspace and download the micro-ROS tools:
cd
mkdir microros_ws
cd microros_ws
Cloning micro-ROS src file from github
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
Installing rosdep
sudo apt install python3-rosdep2
Update dependencies using rosdep
sudo apt update && rosdep update
rosdep install --from-paths src --ignore-src -y
Install pip
sudo apt-get install python3-pip
Build micro-ROS tools and source them
colcon build
source install/local_setup.bash
To install the micro-ros Agent follow the steps below
ros2 run micro_ros_setup create_agent_ws.sh
We will now build the agent packages and, when this is done, source the installation:
# Build step
ros2 run micro_ros_setup build_agent.sh
For using micro-ROS commands you need to run the command :
source ~/microros_ws/install/local_setup.bash
everytime when you open a new terminal for avoiding this we can put the source command on bashrc file as shown above.
Setup Arduino IDEFollow this tutorial for Installing the ESP32 Board in Arduino IDE (IMPORTANT)
Download precompiled micro-ROS library for arduino IDE from here
After downloading unzip the file and put it in the location /home/$USERNAME/Arduino/libraries/
If libraries folder is not present inside Arduino folder create it and put the file as shown below.
After completing this, check the example folder below
If you don't see micro_ros_arduino in example, the library is not installed properly.
Open the micro_ros_publisher program on the example shown above. Compile it and upload to ESP32. This program publishes integer values to the topic /micro_ros_arduino_node_publisher
.
Make sure to source ros2 path as shown below
source /opt/ros/humble/setup.bash
then run the agent program
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0
output of the above command is
then press the reset button(EN) of ESP32
It will show like below
Open a new terminal without closing the above and run the below command for showing all the available topics
ros2 topic list
it shows
for showing the msg published to the topic /micro_ros_ardunio_node_publisher
run the following command
ros2 topic echo /micro_ros_arduino_node_publisher
it will gives the output
Here we can see that data is successfully published from ESP32.
For the graphical visualization run
rqt_graph
it will show
Here we can see /micro_ros_arduino_node
publishes to topic /micro_ros_arduino_node_publisher
.
Comments