Ask Your Question
0

Problem with subscriber within costmap layer

asked 2014-06-19 16:55:09 -0500

Federico gravatar image

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

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2020-05-20 05:03:05 -0500

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();
  }
edit flag offensive delete link more
0

answered 2014-06-20 07:05:29 -0500

Federico gravatar image

updated 2014-06-20 08:03:55 -0500

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

edit flag offensive delete link more

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.

fergs gravatar image fergs  ( 2014-06-22 22:33:37 -0500 )edit

Thanks fergs, I'll do it then

Federico gravatar image Federico  ( 2014-06-25 11:48:11 -0500 )edit

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!

Romabrand gravatar image Romabrand  ( 2014-11-04 05:01:46 -0500 )edit

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.

Federico gravatar image Federico  ( 2014-11-04 07:37:17 -0500 )edit

Thanks a lot! Will try to understand it.

Romabrand gravatar image Romabrand  ( 2014-11-04 08:19:49 -0500 )edit

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.

Romabrand gravatar image Romabrand  ( 2014-11-05 10:02:06 -0500 )edit

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

Federico gravatar image Federico  ( 2014-11-05 10:26:27 -0500 )edit

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);

Romabrand gravatar image Romabrand  ( 2014-11-05 10:50:03 -0500 )edit
0

answered 2014-06-19 23:00:46 -0500

fergs gravatar image

updated 2014-06-19 23:01:19 -0500

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?

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

Stats

Asked: 2014-06-19 16:55:09 -0500

Seen: 857 times

Last updated: May 20 '20