How to set map resolution properly with ROS2 cartographer?

Hi,

I am working on the ROS2 Navigation Rosject.

I am doing the first section - mapping the arena with the robot (currently on the simulation).

I am trying to get a better resolution with the cartographer mapping package.
Since resolution is not mentioned in the ROS2 Navigation course, I found the way to set it from this link: cartographer/trajectory_builder_2d.lua at master · cartographer-project/cartographer · GitHub

So I added the following line to my cartographer.lua:

TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.resolution = 0.010

This change works on RViz2. I can visually see that since I tried with 0.10 and 0.010, and 0.010 had smaller pixels on the map.

But the problem is, when I save the map with the following command:

user:~/ros2_ws/src/my_turtlebot_mapping/maps$ ros2 run nav2_map_server map_saver_ccli -f my_map
[INFO] [1673947833.445084384] [map_saver]:
        map_saver lifecycle node launched.
        Waiting on external lifecycle transitions to activate                    tion.
        See https://design.ros2.org/articles/node_lifecycle.html for more information.                                                                            ' file
[INFO] [1673947833.445283004] [map_saver]: Creating                               to defa[INFO] [1673947833.445549014] [map_saver]: Saving map from 'map' topic to 'my_map' file                                                                           g it to[WARN] [1673947833.445589683] [map_saver]: Free threshold unspecified. Setting it to default value: 0.250000
[WARN] [1673947833.445629247] [map_saver]: Occupied threshold unspecified. Setting it to default value: 0.650000
[WARN] [map_io]: Image format unspecified. Setting it to: pgm
[INFO] [map_io]: Received a 54 X 50 map @ 0.05 m/pix
[INFO] [map_io]: Writing map occupancy data to my_map.pgm
[INFO] [map_io]: Writing map metadata to my_map.yaml
[INFO] [map_io]: Map saved
[INFO] [1673947834.721467877] [map_saver]: Map saved successfully
[INFO] [1673947834.721555064] [map_saver]: Destroying
user:~/ros2_ws/src/my_turtlebot_mapping/maps$

The map that is saved is of resolution 0.05 m/pix instead of 0.010 m/pix

[INFO] [map_io]: Received a 54 X 50 map @ 0.05 m/pix   # see this line above ^

So, how do I change the occupancy grid map resolution the correct way?
Also, I am unable to go less than 0.010, like 0.005.
EDIT: I realized that 0.01 already means 1 centimeter. So, 0.005 would be 0.5 centimeters and that much “fine” resolution for mapping would be foolish considering the size of the sensor and the robot.

I need some help / advice.

Thanks,
Girish

Hello @girishkumar.kannan,

I quickly skimmed through the cartographer code, but I could not find a resolution limit in that very quick review. Probably there is a function that rounds up to 0.01.
That being said I think it totally makes sense to limit the resolution for mapping. Just imagine a map that is 20x20 meters in size, that is not a very big map for operating a mobile robot. In that case with a resolution of 0.01 you will have 4.000.000 grid cells. The more grid cells you have to slower your path planning is. In the worst case you algorithm will have to traverse all those grid cells to find the shortest path. And then you could also have multiple layers, like keep-out zones, or the like, those would have the same resolution, so you could easily have 2 or 3 times that amount of grid cells. All this becomes quickly very computationally expensive (and also consumers a lot of your network bandwidth). So you have to find a balance between a resolution that works well enough for your application and a map that does not get too big and navigation becomes very slow because of path planning.

Hope these thoughts on the matter help.

Roberto

Hi @rzegers ,

Thanks for the reply. Your explanation makes sense. I forgot to consider path planning in 3D with small resolution.
I guess the minimum value that map_saver could do is 0.05 (5 centimeters per pixel).

My problem basically is that I cannot change map_saver’s default resolution of 0.05. I will experiment with numbers bigger than 0.05 and post my results here.

Thanks,
Girish

Hi @rzegers ,

I did my experiment with cartographer.lua parameter for resolution of occupancy grid map.

Here are my observations (as images):

  1. Resolution: 0.01 m/pix

  2. Resolution: 0.05 m/pix

  3. Resolution: 0.10 m/pix

  4. Resolution: 0.50 m/pix

Things NOT TO consider:

  1. The drift in the map - the robot drifted clockwise, therefore the map drifted clockwise.
  2. Size of map that is saved - this is not a problem.

Things TO consider:

  1. Pixel density of the map on Rviz2 with respect to change in resolution parameter in cartographer.lua.
  2. The unchanged value for resolution when saved with map_saver.

Conclusion:
Whatever may be the resolution value set in cartographer.lua file, the map_saver always saves the map with 0.05 m/pix.

My Problem:
How to save the map with correct resolution value that is set in the cartographer.lua file?
In simpler words, if my resolution in my cartographer.lua file is 0.10, I want the map_server to save the map with 0.10 m/pix and not with 0.05 m/pix.
How can I do this?

I searched Google for quite some time and could not find favorable results.
[Sorry for the long post !]

Thanks again,
Girish

Hi,

I have fixed this issue myself !

Solution:
I had to change the resolution parameter of occupancy_grid_node in cartographer.launch.py.

Node(package="cartographer_ros",
     executable="occupancy_grid_node",
     name="occupancy_grid_node",
     output="screen",
     parameters=[{"use_sim_time": True}],
     arguments=["-resolution", "0.010",   <--- change this parameter here!
                "-publish_period_sec", "1.0"],
     emulate_tty=True),

Now everything works as expected !

~~~ Update: ~~~
DO NOT USE the following line in the cartographer.lua config file.

TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.resolution = 0.010

The above line has no effect when the resolution parameter is set in the occupancy_grid_node and priority is given to this value in the launch file.
~~~ End of Update ~~~

– Girish

I am glad that you got it solved! Thanks for posting your findings and how you solved it, it will certainly help others!

1 Like