Navigating Mobile Robot Mapping

To understanding the Mini Turty ROS mobile robot mapping operation, we begin from the simple script that is used to start the robot.

The Starting Point

Typically, for doing mapping users will call:

$ ./

The above file is contained in the ubuntu home directory (‘/home/ubuntu’). If you look in that file, you will see the line similar to:

$ roslaunch mini_turty3 hector_ydlidar_demo.launch

The above is what starts the robot doing mobile robot mapping. Let’s break that down into the pieces. The first part is the ‘roslaunch’ program.

Navigating in a map showing obstacle inflation
Navigating in a map showing obstacle inflation

This program is part of the ROS system itself. It’s used to launch many different ROS nodes via one or more launch files. In the above case, roslaunch is launching a launch file called ector_ydlidar_demo.launch’, and this launch file is contained in the ROS package called ‘mini_turty3’.

So where is this ‘hector_ydlidar_demo.launch’ file, you may be asking. There are a couple of ways of finding that, but one convenient method is to use the ROS bash shell command ‘roscd’. Type the following into a console:

$ source catkin_ws/devel/setup.bash

$ roscd mini_turty3

This will take you to the directory containing the mini_turty3 package. If
you then run ‘pwd’:

$ pwd

You will see:


So ‘roscd’ has taken us to the directory containing the ROS package ‘mini_turty3’. Run ‘ls’:

$ ls

This will show the directory contents similar to:

CMakeLists.txt include launch package.xml param scripts src

Note that we have a sub-directory called ‘launch’ here. This is where the previously mentioned ‘hector_ydlidar_demo.launch’ launch file exists. If you run:

$ ls launch

You will see output similar to:

amcl_rd_demo.launch hector_ydlidar_demo.launch
minimu9-ahrs.launch mini_turty.urdf teleop.launch test.xacro
hector_move_base_demo.launch includes mini_turty3.urdf
robot_pose_ekf.launch test.urdf

Which lists all the launch files in the mini_turty3 package, including the one we are currently interested in (‘hector_ydlidar_demo.launch’). Let’s open our launch file and examine its contents:

$ vi launch/hector_ydlidar_demo.launch

The ‘hector_ydlidar_demo.launch’ launch file launches several ROS nodes.

The LiDAR Node

The first ROS node to be launched is:

  <node name="ydlidar_node"  pkg="ydlidar"  type="ydlidar_node"

This node is the ROS driver for the lidar. It handles all interaction with the lidar device and is responsible for starting/stopping, gathering the data from the lidar, and publishing the lidar data to ROS.

The G2 lidar
The G2 lidar

The Mapping Node

The next node to be launched is:

  <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping"

This node is the “Hector Mapping” node. It’s responsible for the creation of the map, using the data from the lidar. It takes lidar scans and adds them into the map. The map is then published to ROS for other nodes to access.

The Robot Base Node

Moving on, the next important node is:

  <node pkg="mini_turty3" type="mini_turty3" name="mini_turty3"

This node is used to control the robot base. It’s responsible for responding to ROS tele-op commands, and for publishing odometry.

Each of the above launched nodes has a ROS package under the ‘catkin_ws’
directory. If you run the command:

$ ls ~/catkin_ws/src/

You will see several ROS packages (for some robots, there could be many more!):

minimu9-ahrs mini_turty3 raspicam_node ydlidar

You may ‘roscd’ into any of these packages. But let’s stay in our ‘mini_turty3’ package and examine the source code of this node:

$ ls src

You will see:


This is the source file for the ‘mini_turty3’ base. You could open this using many different editors, but let’s use ‘vi’ again:

$ vi src/mini_turty3.cpp

Here you will find the ‘main()’ program for the mini_turty3 base. Please examine this source code to understand how the base operates. Here’s the code snippet of the main function:

int main(int argc, char *argv[])
  int pi;
  int enable_odom_transform;
  pi = init_gpio();
  if(pi) {
    printf("Error initializing pigpio!\n");
    return pi;

  ros::init(argc, argv, "mini_turty");
  ros::NodeHandle private_node_handle_("~");
  ros::Rate loop_rate(50);

  private_node_handle_.param("enable_odom_transform", enable_odom_transform, int(0));

  MiniTurtyBase mini(pi);

  while (ros::ok()) 
    if (got_ctrl_c) {
      ROS_WARN("Got Ctrl-C");


  // set SLEEP (active low)
  gpio_write(pi, GPIO_SLEEP, 0);



Note that most ROS nodes have a ‘src’ directory, and that is where the code for a node is usually kept. For example, you may find the code for the lidar in ‘catkin_ws/src/ydlidar/src’.

Binary Install of ROS Packages

Be aware that many ROS packages are by default ‘binary install’. This means that you currently have pre-built binaries only (to save build time and storage space!). This is the case for ‘hector_mapping’. However, you may access the source code, and even install it onto the robot by going to the github location. To see the source code for hector_mapping, first go
to the ROS wiki:

Then click on the:

Source: git (branch: melodic-devel)

This immediately takes you to the github repository containing the Hector Mapping source code.

If you decide to install any source code, please make sure to back up your SD card first, and then restore it to the original if you find any problem. This will be important if you require support, as it is not possible for us to debug a user-modified installation.

As you can see, navigating your way through the Mini Turty ROS packages is not difficult. Just take it one step at a time and follow the path through in a manner similar to that which is described above. You will soon be getting oriented and making your way in the world of ROS autonomous mobile robot mapping!