Subscribing to global_costmap

asked 2016-11-12 12:14:16 -0600

gpldecha gravatar image

updated 2016-11-14 07:07:41 -0600

I have been trying out the navigation stack with the turtlebot tutorial. My objective is to be able to write a node (ex: costmap_subscriber_node.cpp) which subscribes to /move_base/global_costmap/costmap.

Example of node I am trying to write:

#include <ros/ros.h>

void occupancygrid_callback(const nav_msgs::OccupancyGrid::ConstPtr& msg){
      std::cout<< "occupancygrid_callback !! " << std::endl;
}

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

    ros::init(argc, argv, "costmap_subscriber");
    ros::NodeHandle nh;
    ros::Subscriber sub =
    nh.subscribe("/move_base/global_costmap/costmap_update",100,occupancygrid_callback);

    ros::Rate rate(60);
    while(nh.ok()){

          ros::spinOnce();
          rate.sleep();
    }

    return 0;
}

I checked first with the following command:

rostopic echo /move_base/global_costmap/costmap_updates

I get messages published every 5 seconds. The low frequency is the reason for the message:

rostopic hz /move_base/global_costmap/costmap
    subscribed to [/move_base/global_costmap/costmap]
    WARNING: may be using simulated time

However I am still unable to have my ros node callback pick up the messages. Similar problem here costmap-subscribe-problem-in-hydro.

Update

  • I can subscribe to /map
  • Output of roswtf gives :
ERROR The following nodes should be connected but aren't:
* /move_base->/move_base (/move_base/global_costmap/footprint)
* /move_base->/move_base (/move_base/local_costmap/footprint)
edit retag flag offensive close merge delete

Comments

Can you be clear about "in my own node"? Do you mean rostopic by that (it's also a node when it's running)? Or are you writing a code for your node?

130s gravatar image130s ( 2016-11-14 06:14:18 -0600 )edit

I updated the description of the question to make it clear: I am writing my own node.

gpldecha gravatar imagegpldecha ( 2016-11-14 06:22:47 -0600 )edit
1

Maybe that is a typo in your question, but based on this, you are subscribing to "/move_base/global_costmap/costmap_update", whereas you are echoing /move_base/global_costmap/costmap_updates. Note the missing trailing s in the subscriber...

mgruhler gravatar imagemgruhler ( 2016-11-15 01:15:42 -0600 )edit