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

Subscribe to a topic in rqt plugin

asked 2013-09-20 04:29:45 -0500

alu gravatar image

updated 2013-09-20 04:36:35 -0500

I want to subscribe to a very simple topic (/chatter) from within an rqt plugin but I cannot get it to work. After I boiled down the code it looks essentially like this:

void MyPlugin::initPlugin(qt_gui_cpp::PluginContext& context)
{
  mainWidget = new MainWindow();

  if (context.serialNumber() > 1)
  {
    mainWidget->setWindowTitle(mainWidget->windowTitle() + " (" + QString::number(context.serialNumber()) + ")");    
  }
  context.addWidget(mainWidget);

  // this is where want to subscribe
  sub = n.subscribe("chatter", 1000, &MyPlugin::chatterCallback, this);
}


// this is my callback function 
void MyPlugin::chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

Of course sub and n are declared in the header and the code compiles.

Only problem is: Nothing happens..

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-09-23 08:23:09 -0500

alu gravatar image

Ok, I found the problem. It is important to get the NodeHandle from the plugin and not to create one yourself.

edit flag offensive delete link more

Comments

How do you get the NodeHandle from the plugin? sub_ = getNodeHandle().subscribe("/topic",10,callback); results on a: Failed to load nodelet ...

bapclenet gravatar image bapclenet  ( 2014-07-29 17:25:45 -0500 )edit
1

answered 2013-09-22 23:01:35 -0500

felix k gravatar image

Have you checked e.g. via rqt_graph or rosnode info that your nodes are actually connected on that topic?

If your NodeHandle would be initialized with "~", therefore being private, you would subscribe to /node_name/chatter, unless you add a / to the subscribe call.

edit flag offensive delete link more

Comments

Yes, it seems that my node appears when I do not "hide Debug" and it also subscribed to the topic. I do not initialize my node handle at all, so its going to be standard constructed. It seems like the problem is in the callback, which does not get called

alu gravatar image alu  ( 2013-09-23 03:09:55 -0500 )edit
0

answered 2013-09-22 23:09:47 -0500

130s gravatar image

Besides that looking at rqt_graph is good, rqt_topic might give you simpler hint. Hopefully taking a look at its code would help you although you might want examples in C++ whereas most of existing rqt plugins are using Python.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-20 04:29:45 -0500

Seen: 2,002 times

Last updated: Sep 23 '13