In this documentation we will implementing micro-ROS and testing it with Ping Pong application, which will help start learning micro-ROS and understand its architecture.
It is really recommended to visit micro.ros.org to get more information.
Note: These instructions have been done on Ubuntu 20.04 LTS
.
- Install ROS 2 and the micro-ROS framework and tools.
- Testing the micro-ROS Ping Pong app.
- Multiple Ping Pong nodes.
- Problems faced while implementing this project.
- Resources.
start by making sure that you have a locale which supports UTF-8, if not please visit Installing ROS 2 via Debian Packages
locale # check for UTF-8
setup sources and add the ROS 2 apt repositories to your system
sudo apt update && sudo apt install curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
now Iinstall ROS 2 packages
sudo apt update # Update your apt repository caches
sudo apt install ros-foxy-desktop
set up the environment by sourcing to the following file
source /opt/ros/foxy/setup.bash
since we installed ros-foxy-desktop we can try some examples, we will try running the talker and listener apps which will verifies that both the C++ and Python APIs are working properly.
In new terminal, source the setup file and then run talker
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_cpp talker
In another terminal source the setup file and then run listener
source /opt/ros/foxy/setup.bash
ros2 run demo_nodes_py listener
you will see that the talker is Publishing messages [Hello world], and the listener is hearing those messages
as showing in below video:
example.talker.and.listener.mp4
# Source the ROS 2 installation
source /opt/ros/foxy/setup.bash
# Create a workspace and download the micro-ROS tools
mkdir microros_ws
cd microros_ws
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
# Update dependencies using rosdep
sudo apt update && rosdep update
rosdep install --from-path 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
now that the build system is installed, we will create a firmware workspace to get the required codes and tools
ros2 run micro_ros_setup create_firmware_ws.sh host
ros2 run micro_ros_setup build_firmware.sh
source install/local_setup.bash
The app now is ready to be connecte to a micro-ROS agent to start talking with the rest of the ROS2.
so to create and build a micro-ROS agent run the following commands
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh
source install/local_setup.bash
now that you have both the client and the agent correctly installed in your machine, you must give micro-ROS access to the ROS 2 dataspace and run the agent
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
in new terminal run the micro-ROS node and by sourcing the ROS 2 and micro-ROS , and setting the RMW Micro XRCE-DDS implementation
source /opt/ros/foxt/setup.bash
source install/local_setup.bash
export RMW_IMPLEMENTATION=rmw_microxrcedds
ros2 run micro_ros_demos_rclc ping_pong
We are going to listen to the ping topic with ROS 2, to check whether the micro-ROS Ping Pong node is publishing the expected pings.
so, in a new terminal source the setup file and then subscribe to micro-ROS ping topic, every few seconds you will see the topic messages published by the Ping Pong node.
source /opt/ros/foxy/setup.bash
ros2 topic echo /microROS/ping
now our app is publishing pings, we will check if it will answers to other's pings. if it's true then it will publish a pong.
in new terminal, subscribe with ROS 2 to the pong topic. initially we don't expect to receive pong yet.
source /opt/ros/foxy/setup.bash
ros2 topic echo /microROS/pong
in new terminal, publish a fake_ping with ROS 2
source /opt/ros/foxy/setup.bash
ros2 topic pub --once /microROS/ping std_msgs/msg/Header '{frame_id: "fake_ping"}'
you will see the fake_ping in the ping subscriber terminal with the micro-ROS pings, since we have received the fake_ping, the micro-ROS node will answer with a pong. Then in the pong subscriber terminal, you will see the micro-ROS app answer to the fake_ping as showing in below video:
Run.a.micro-ROS.ping_pong.node.Demo.mp4
run the same micro-ROS agent as we did above, and open a number of different terminals and run the following commands on each one under microros_ws directory
source /opt/ros/foxy/setup.bash
source install/local_setup.bash
export RMW_IMPLEMENTATION=rmw_microxrcedds
ros2 run micro_ros_demos_rclc ping_pong
multi.ping.mp4
1- I had to install git separately before install the micro-ROS, to do so run this command
sudo apt install git
2- when trying to build micro-ROS tools and source them using the command colcon build
. I needed to install colcon tool separately using the following command
sudo apt install python3-colcon-common-extensions