ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Using two static layered costmaps to make restricted areas

asked 2021-03-02 15:55:57 -0600

FFelizpe gravatar image

Hi there!

I have a small question, that seems to be simple, but it's been bothering me a lot for weeks on end. I've been working trying to make a robot capable of navigating autonomously, and it's been working fine. However, I'd like to restrict some parts of the map, even if the robot theorically should be able to navigate through them, for the sake of making a better navigation and creating restricted spaces.

I've struggled a lot with that recently, until I stumbled into that the solution might be using layered costmaps. I've been using layered costmaps (VoxelLayer for dynamic obstacles, StaticLayer for the map, Inflation, etc), but not for this purpose. I'd like to make a map for dynamic obstacles, that won't be detected by the LIDAR but they will still be restricted. And, for this, I've read that I can make a second costmap with my restricted map.

However, how do I do this? As far as I understand, I'd need to call the map from another topic that's not /map, but how do I publish the second map in this new topic? I've been using the map_server in the launch for the /map to run, and I don't know how to make that work to another topic in a new map. Besides, is this really the right approach? Will the use of two layered static costmaps help my case?

Thanks in advance!

edit retag flag offensive close merge delete


Hi, did you manage to stack the two static_layer ? I'm trying the exact same approach in ROS2 Foxy, but the resulting global_costmap only uses one of the static_layer (the last one published it seems) (while both map can be visualized correctly independently in rviz2 and used correctly in the costmap if there is only one static_layer) Setting the map_topic and use_maximum as suggested below and here for ROS1 did not solve the problem... Did you succeed ?

PatoInso gravatar image PatoInso  ( 2021-11-24 07:52:26 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2021-03-04 08:36:45 -0600

Maybe a different and more flexible approach is to write your own costmap layer and give it a geometry_message::polygon as input for the restricted areas. Like this you don't have to define the areas before the navigation starts, but you can change the restricted areas during navigation.

Take a look at the create a new layer tutorial in the wiki. Even though i must admit, that it is very low level. For more information i recommend the costmap layer package from David Lu as a reference.

I did something similar for road navigation to prevent the robot from entering the left lane when the right one is free.

edit flag offensive delete link more

answered 2021-03-04 07:44:29 -0600

miura gravatar image

I think this is a good way to add obstacle information.

To make a second map public with a topic other than "map", use the map_topic parameter.

map_topic (string, default: "map") This parameter is useful when you have multiple costmap instances within a single node that you want to use different static maps. New in navigation 1.3.1

Stacking cost maps can be achieved by using the use_maximum parameter.

use_maximum (bool, default: false) Only matters if the static layer is not the bottom layer. If true, only the maximum value will be written to the master costmap.

The above is taken from the documentation at

For example, you can use the following

global_costmap configuration yaml file

    - {name: static_layer1, type: "costmap_2d::StaticLayer"}
    - {name: static_layer2, type: "costmap_2d::StaticLayer"}

    map_topic: "map" 

    map_topic: "map2"
    use_maximum: true

Excerpt from launch file

<node name="static_layer1" pkg="map_server" type="map_server" args="$(find XXX)/maps/YYY.yaml"/>
<node name="static_layer2" pkg="map_server" type="map_server" args="$(find XXX)/maps/ZZZ.yaml">
    <remap from="map" to="map2"/>
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-03-02 15:55:57 -0600

Seen: 411 times

Last updated: Mar 04 '21