Robotics StackExchange | Archived questions

Problem with subscriber within costmap layer

Hi all,

A question for those familiar with the Creating a New Layer (in costmap_2d/Tutorials) tutorial

I got stuck with this problem: I want to define a custom layer to extend a costmap_2d::Layer which contains a subscriber to retrieve some infomation from an external publisher node.

Following the tutorial I created the SimpleLayer class (see paragraph 2). Then I added to the class SimpleLayer the private member ros::Subscriber sub_ and a callback function (as a private method). To initialize the subscriber I added the following line to SimpleLayer::OnInitialize() right before the assignment of the dynamic_reconfigure server:

sub_ = nh.subscribe("the_published_topic", 1000, &SimpleLayer::MyCallbackFunction, this);

where SimpleLayer::MyCallbackFunction should print on screen the message published by the_published_topic. The plugin is correctly installed and launching move_base it is alse loaded, anyway it seems that SimpleLayer::MyCallbackFunction is not called during the execution (output is already set to screen).

I Hope not to be too detailed.

Regards, Federico

Asked by Federico on 2014-06-19 16:55:09 UTC

Comments

Answers

Is it possible that "nh" is a private nodehandle? Have you tried fully specifying the topic name with "/the_published_topic"? Does "rosnode info" or "rostopic info" show that you are subscribed to the topic you think you are subscribed to?

Asked by fergs on 2014-06-19 23:00:46 UTC

Comments

Hi,

apparently I solved the problem. Basically the publisher node cannot be run after the move_base node. More precisely it seems that the publisher node should be already on when the method SimpleLayer::onInitialize() is invoked.

Cheers,
Federico

Asked by Federico on 2014-06-20 07:05:29 UTC

Comments

That shouldn't be needed, I would say this is possibly a bug somewhere, if you have a minimal example piece of code, it might be worth opening an issue against navigation.

Asked by fergs on 2014-06-22 22:33:37 UTC

Thanks fergs, I'll do it then

Asked by Federico on 2014-06-25 11:48:11 UTC

Hallo Federico, I'm struggling now with the same problem, can not subscribe to a topic within a layer-plugin. Unfortunately the answers here didn't brought me success. Would you be so kind as to publish here your header and cpp file, or just the important sequences? Thanks in advance!

Asked by Romabrand on 2014-11-04 06:01:46 UTC

As far as I remember, the solution I found was to run the node with the publisher first. Once the topic is published, run the move_base node (eventually with your plugin). Take a look at my github account (federico-b), the pedestrian_layer repository, there should still be the whole source code.

Asked by Federico on 2014-11-04 08:37:17 UTC

Thanks a lot! Will try to understand it.

Asked by Romabrand on 2014-11-04 09:19:49 UTC

I went through the headers and cpp files and could understand a big part of it, but I could not find the subscriber. In the question you wrote that you added the subscriber to SimpleLayer::OnInitialize(). Sorry if I do not understand something right or ask stupid questions, I'm quite a newbie.

Asked by Romabrand on 2014-11-05 11:02:06 UTC

Probably you're looking the wrong branch. pedestrian-layer should be the right branch to check.

Asked by Federico on 2014-11-05 11:26:27 UTC

No, I've been looking to the right one, but somehow I can not find the line which is looking somehow like this: sub_ = nh.subscribe("the_published_topic", 1000, &SimpleLayer::MyCallbackFunction, this);

Asked by Romabrand on 2014-11-05 11:50:03 UTC

You should add a loop to check if the map is received like this (it couldn't receive the map at first) right below the subscriber. (remember to set map_received_ = true in your callback so the rest of the code can continue to run after it receives the map)

  ros::Rate r(10);
  while (!map_received_ && nh.ok())
  {
    ros::spinOnce();
    r.sleep();
  }

Asked by Phong Vu on 2020-05-20 05:01:18 UTC

Comments