ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Using two static layered costmaps to make restricted areas

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?

edit retag 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 ?

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

Sort by » oldest newest most voted

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.

more

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 http://wiki.ros.org/costmap_2d/hydro/....

For example, you can use the following

### global_costmap configuration yaml file

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

static_layer1:
map_topic: "map"

static_layer2:
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"/>
</node>

more