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

Rqt_myPlugin can't subscribe node

asked 2014-12-19 13:23:34 -0600

Mosa gravatar image

updated 2014-12-22 20:36:02 -0600

Hello guys,

I have a GUI as a rqt plugin and I want to subscribe a topic but I can't see my rqt_plugin node on the rqt_graph. The topic which i want to subscribe is in the same machine, which I want to start my rqt_plugin. I have muliple machines and I start the rqt_graph at the another machine. At the another machine I see all the other topics and I see also the topic which I want to subscribe with my rqt_plugin.

Here is the creation of the publisher at machine A:

 pubCmd = n.advertise<std_msgs::String>("/sci/cmd", 10);

Here is the subscribing of the topic /sci/cmd at my rqt_plugin also at machine A:

ros::Subscriber sub = getNodeHandle().subscribe("/sci/cmd", 10, &ccgui::receiveSC, this);

If now I published something, my rqt plugin receives nothing. I know that the publisher works correctly because I subscribed the topic with a normal node and I receive the messages. https://github.com/Mosa-/rqt_ccgui

I hope someone can help me :)

edit retag flag offensive close merge delete

Comments

If your plugin doesn't appear in rqt_graph or in rostopic list, it's likely that the ROS node in rqt isn't getting initialized properly. That said, I don't see anything wrong with your code.

ahendrix gravatar image ahendrix  ( 2014-12-19 18:25:25 -0600 )edit

I follow this instruction to create the rqt plugin: http://wiki.ros.org/rqt/Tutorials/Cre... in C++. How I can check in which "node universum" i am? Because I have access of the node handle... What should i do?

Mosa gravatar image Mosa  ( 2014-12-19 19:43:40 -0600 )edit

if I do rosnode list I can see the node /rqt_gui_cpp_node_7081, but where I should create the publisher/subscriber. I do it but it wont show...

Mosa gravatar image Mosa  ( 2014-12-22 09:24:18 -0600 )edit

May be it would help if you share your code (e.g. through GitHub) so that other people can take a look. Otherwise it might be difficult to give any specific advice.

Dirk Thomas gravatar image Dirk Thomas  ( 2014-12-22 16:08:04 -0600 )edit

Yeah he you can find the code; https://github.com/Mosa-/rqt_ccgui

Mosa gravatar image Mosa  ( 2014-12-22 20:35:46 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-12-23 01:27:39 -0600

Wolf gravatar image

You are createing a local subscriber in your function call back:

void ccgui::clickLabelhelpBtn_timeout(){
this->deactiveSpeechCommand("move");
ros::Subscriber sub = getNodeHandle().subscribe("/speech_control_interface/cmd", 10, &ccgui::receiveSpeechCommand, this);
ROS_INFO("topics %s %d", sub.getTopic().c_str(), sub.getNumPublishers());
// int ret = QMessageBox::information(widget_, QString("About timeout"),
// QString("Timeout between two commands.\n"
// "in [ms]"),
// QMessageBox::Close);
}

sub is destructed and deleted from stack when the at the end function's code; thereby the subscriber is also shut down and the callback will never be called!

To solve this do the following:

Declare your subscriber somewhere in the header file:

class ccgui
: public rqt_gui_cpp::Plugin
{
Q_OBJECT
public:
<..............>

private:
Ui_Form ui_;
ros::Subcriber sub;
<....................>
}

Then subscribe as you did but without declaring the object

void ccgui::clickLabelhelpBtn_timeout(){
this->deactiveSpeechCommand("move");
sub = getNodeHandle().subscribe("/speech_control_interface/cmd", 10, &ccgui::receiveSpeechCommand, this);
ROS_INFO("topics %s %d", sub.getTopic().c_str(), sub.getNumPublishers());
// int ret = QMessageBox::information(widget_, QString("About timeout"),
// QString("Timeout between two commands.\n"
// "in [ms]"),
// QMessageBox::Close);
}

and shut it down somewhere, at the latest in plugin shutdown() (this is important because the nodehandle your retrieved by getNodeHandle) might live longer than your plugin so if you do not shut down the subscriber your callback might even be called after your plugin was shut down!!

void ccgui::shutdownPlugin()
{
   sub.shutdown();
}
edit flag offensive delete link more

Comments

Danke!

Thanks, this was the problem. I totally failed in a C++-trap :).

Mosa gravatar image Mosa  ( 2014-12-23 08:07:07 -0600 )edit

Question Tools

Stats

Asked: 2014-12-19 13:23:34 -0600

Seen: 1,000 times

Last updated: Dec 23 '14