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

rospy rqt - shutdown?

asked 2014-05-08 22:50:08 -0600

Hendrik Wiese gravatar image

Hi folks,

this tutorial asks to shutdown publishers and subscribers in the overloaded shutdown_plugin method but doesn't explain how this is done. I couldn't find any advice on how to shutdown a publisher and unsubscribe a subscriber. Could anyone guide me? Thanks

Cheers, Hendrik

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-05-08 23:42:11 -0600

130s gravatar image

updated 2014-05-09 00:47:10 -0600

Example of stopping Subscriber in rqt plugin in rospy

In shutdown_plugin you can do basically whichever way you usually do to finish your ROS process.

I'll take rqt_plot as an example. In a class derived from rqt_gui_py.plugin (which I'm sure you've already made in your case), there's shutdown_plugin defined as:

def shutdown_plugin(self):
    self._widget.clean_up_subscribers()

Then the method called above is defined here in a widget class

def clean_up_subscribers(self):
    for topic_name, rosdata in self._rosdata.items():
        rosdata.close()
        self.data_plot.remove_curve(topic_name)
    :

rosdata.close() is defined here that internally calls rospy.Subscriber.unregister.

This isn't the simplest example but you should get the idea.


(Update) Example of stopping Publisher in rqt plugin in rospy

There aren't many rqt plugins out there that explicitly stop publishing topics, but looks like rqt_bag does in the following sequence (indices at the beginning of each line are linking to the actual code):

1

def shutdown_plugin(self):
    self._widget.shutdown_all()

2

def shutdown_all(self):
    self._timeline.handle_close()

3

def handle_close(self):
    :
    for topic in self._get_topics():
        self.stop_publishing(topic)
        self._message_loaders[topic].stop()
    :

4

def stop_publishing(self, topic):
    if not self._player:
        return False

    self._player.stop_publishing(topic)

And 5

    :
    if topic in self._publishers:
        self._publishers[topic].unregister()
        del self._publishers[topic]
edit flag offensive delete link more

Comments

My question more relates to the actual shutdown of publishers and subscribers than the plugin. I should have made that clearer. You answered on how to shutdown a subscriber. Is it the same for publishers?

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-08 23:48:26 -0600 )edit

I added my finding about publisher to my answer.

130s gravatar image 130s  ( 2014-05-09 00:47:44 -0600 )edit

Thanks a lot. Looks like it's a bit more complex to shutdown a publisher... is it actually really necessary?

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-09 01:05:39 -0600 )edit

Answer should be "no"; I just referred to the entire steps only because I have no experience in stopping publisher with rqt python plugin. In essence you should just be able to stop by calling `unregister`.

130s gravatar image 130s  ( 2014-05-09 01:43:41 -0600 )edit

Alright, I'll do it by just calling unregister. It basically shouldn't be that much of an issue in my config anyway. So... thanks a lot!

Hendrik Wiese gravatar image Hendrik Wiese  ( 2014-05-09 02:26:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-05-08 22:50:08 -0600

Seen: 828 times

Last updated: May 09 '14