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

Revision history [back]

click to hide/show revision 1
initial version

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 a method:

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

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)
    self._rosdata = {}

    self._subscribed_topics_changed()

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

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

In shutdown_plugin you can do basically whichever way you usually do to finish your ROS process .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 a methodshutdown_plugin defined as:

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

The 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)
    self._rosdata = {}

    self._subscribed_topics_changed()
:

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

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

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]