ROS 2 Mobile Robotics Series — Part 1

Sharad Maheshwari
4 min readMay 8, 2022

--

Note — This series is a technical documentation of me building/learning — Mobile Robotics in ROS2.
Check out Part 0 to understand how this series is set up

Hello there!
As discussed in Part 0, we begin with setting up our ROS 2 workspace for our mobile robotics project. In this series, we will use TurtleBot 3 in simulation as our robot.
Sooooo, shall we begin?

Step 1 — Install ROS 2

We of course need to have ROS 2 installed on our system before anything else.

We are using ubuntu Focal (20.04.3 LTS) in this lesson, which supports ROS 2 Galactic. Here’s a link explaining ROS 2 installation really well. They do a better job than me explaining installation 😃

I used Debian binary packages during my installation process.

Step 2 — Set up TurtleBot3 in simulation

  1. Setup turtlebot3 (https://ubuntu.com/blog/simulate-the-turtlebot3)
  • Install vcstool
    vcstool is a version control system tool designed to make working with multiple repositories easier. It is most commonly used for getting open source repositories from GitHub, without having to maintain them yourselves in your project.
    And that’s how we will get a copy of all turtlebot3 repos for our project.
sudo apt install python3-vcstool
  • Make a new workspace for our project (turtlebot3_ws)
mkdir -p ~/turtlebot3_ws/src
cd ~/turtlebot3_ws
  • Make a YAML format file to get turtlebot3 repos using vcstool
gedit turtlebot3.repos

Add the following to this file —

Note — If you’re using another ros2 distro, replace “galactic-devel” with the appropriate github branch name (check the corresponding repo on github for name)

  • Get turtlebot3 repos in src directory
vcs import src < turtlebot3.repos
  • Install gazebo_ros_pkgs

The set of ROS 2 packages for interfacing with Gazebo are contained within a meta package named gazebo_ros_pkgs. So that’s what we install.

sudo apt install ros-galactic-gazebo-ros-pkgs
  • Build all turtlebot3 ROS 2 packages

Note — Like ROS 1, we always need to source the terminal for ROS 2

source /opt/ros/galactic/setup.bash
colcon build --symlink-install

Notes—
1. My cmake version is 3.13.4 (I had issues with 3.2X.X)
2. If there’s an error about incorrect gazebo during build — Could not find a configuration file for package “ignition-common3-graphics”
that exactly matches requested version “3.XX.X”), check this link

  • Export turtlebot3 model

First up, source the project from turtlebot3_ws directory—

source ./install/setup.bash

Now, export turtlebot3 model from the terminal (we use waffle_pi) —

export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/modelsexport TURTLEBOT3_MODEL=waffle_pi
  • Launch turtlebot3 gazebo simulation
cd ~/turtlebot3_ws
ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py

If everything was done correctly, we will have gazebo running with waffle_pi robot in a simulated house

Note — If gazebo doesn’t start with an error saying “Was Gazebo started with GazeboRosFactory?”, it means a gazebo server is already running. you first want to kill it and run gazebo again.

  • Visualize in Rviz

In a new terminal, source ROS 2 and launch rviz2

source /opt/ros/galactic/setup.bash
rviz2

On the left side display panel, set the following —

  • Add correct Fixed Frame — odom
  • Add transforms (add->tf)
  • Add Image (add->image) — Select topic /camera/image_raw and choose Reliability Policy as Best Effort
  • Add laser scan — Select topic /scan and choose Reliability Policy as Best Effort

Note — The reliability setting determines whether message delivery is guaranteed. Using “best-effort,” the publisher will attempt to deliver the message once, useful when new data will make the old obsolete (e.g., sensor data). Set to “reliable,” the publisher will continue to send data until the receiver acknowledges receipt.

Here’s a thread about reliability policy if you’re interested to know more

  • Explore topics and nodes

To list currently running topics in a new terminal —

source /opt/ros/galactic/setup.bash
ros2 node list
ros2 node info nodename

To list current topics in a new terminal —

source /opt/ros/galactic/setup.bash
ros2 topic list
ros2 topic info topicname
  • Look at transforms using tf2

If tf2_tools is not installed, please look at this link for installation

To look at the transform tree in a new terminal—

source /opt/ros/galactic/setup.bash
ros2 run tf2_tools view_frames

This will generate frames.pdf in the same directory, which looks like this —

Here’s an official tf2 guide for more information

  • Move the robot

To move the robot using teleop in a new terminal —

source /opt/ros/galactic/setup.bash
ros2 run teleop_twist_keyboard teleop_twist_keyboard

Try using the keyboard and you’ll see the robot move in both RViz and Gazebo

If you look at RViz with TF enabled, the transforms will move in space as per our teleop command!

Parting Notes —

There we go! We set up ROS 2, created a workspace, and ran TurtleBot3 in simulation(gazebo). This established the necessary base for further learning and experiments 😉

Sooo, see you in the next one?

Cheers!
Sharad

--

--