Subscribe to a topic in rqt plugin
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..