ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to subscribe a new costmap2dROS object to the global_costmap/costmap

asked 2015-07-24 23:39:38 -0500

Naman gravatar image

updated 2015-07-25 15:37:46 -0500

Hi all,

I am planning to write my own node in ROS and I need to access the global_costmap which is being published. For that, I have created a new Costmap2DROS object:

int main(int argc, char** argv){

    ros::NodeHandle n;

    tf::TransformListener tf_(ros::Duration(10));

    costmap_ros_ = new costmap_2d::Costmap2DROS("my_costmap", tf_);

    costmap_ = costmap_ros_->getCostmap();

    return 0;

Now, I have a my_costmap_params.yaml file where I have specified the map_topic : /move_base_node/global_costmap/costmap (this is being published by move_base) so that the new costmap2DROS object subscribes to it:

  #Set the global and robot frames for the costmap
  global_frame: /map
  robot_base_frame: /base_link

  #Set the update and publish frequency of the costmap
  update_frequency: 2.0
  publish_frequency: 2.0

  #We'll use a map served by the map_server to initialize this costmap
  static_map: true
  rolling_window: false

  use_dijkstra: false

  - {name: static_layer, type: "costmap_2d::StaticLayer"}
  - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"}
  - {name: inflation_layer, type: "costmap_2d::InflationLayer"}

    map_topic: /move_base_node/global_costmap/costmap

  #Configuration for the sensors that the costmap will use to update a map
    observation_sources: base_scan
    base_scan: {data_type: LaserScan, sensor_frame: /base_laser_link_1, topic: /base_scan, expected_update_rate: 0.4,
      observation_persistence: 0.0, marking: true, clearing: true, max_obstacle_height: 0.4, min_obstacle_height: 0.0}

I am loading the above parameters to parameter_server here:


 <node pkg="publish_multiple_goals" type="publish_multiple_goals" respawn="false" name="publish_multiple_goals" output="screen">
    <rosparam file="$(find drsim_control)/move_base_config/my_costmap_params.yaml" command="load" />

Now the problem is it still subscribes to the "map" topic published by the map_server and does not subscribe to the map_topic I mentioned above that is /move_base_node/global_costmap/costmap using the costmap2DROS object I created above. I want to make sure that the costmap2DROS object created above subscribes to the map_topic to get the global_costmap. Does anyone have any idea what is going wrong here or what can I do to achieve the above mentioned task? Let me know if you need more information from me.

I think I am able to subscribe to the global_costmap but still when I use functions like: costmap_ros_->getRobotFootprint() , it gives me wrong readings (when I use this function in the global planner plugin, it gives me the correct values). Also, the Cost values of the costmap is either 0 or 254. Shouldn't the inflation be there according to ? Any help will be appreciated.

Thanks in advance.
Naman Kumar

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-25 12:41:04 -0500

David Lu gravatar image

updated 2015-07-25 22:24:54 -0500

The map_topic parameter needs to be in the static_layer namespace.

Edit There is no way to create a replica C++ object from simply subscribing to a few topics. The solution I described using the static layer will fill in the costmap data, but if you want everything to be the same, you need to change all of the additional parameters (like those specifying footprint) as well. Which leads to the question, why are you copying the original costmap to begin with? Why not just have it subscribe to the same data sources?

edit flag offensive delete link more


Thanks @David for the reply. I have made the change you suggested but it looks like I am still having the same problem. Any suggestions? Thanks again.

Naman gravatar image Naman  ( 2015-07-25 13:01:40 -0500 )edit

perhaps to use the costmap to create the world model and directly check for legality of the robot footprint in the given map at a specified pose?

is there a another easier way of doing so David?

hc gravatar image hc  ( 2018-06-18 11:10:30 -0500 )edit

Question Tools



Asked: 2015-07-24 23:39:38 -0500

Seen: 2,186 times

Last updated: Jul 25 '15