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

You could probably destroy the subscriber in the callback like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        del self.sub

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

Though I haven't yet tested if it works. I don't now any other means using topics.

You could probably destroy the subscriber in the callback like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        del self.sub
delete(self.sub)

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

Though I haven't yet tested if it works. I don't now any other means using topics.

You could probably destroy the subscriber in the callback like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        delete(self.sub)

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

Though I haven't yet tested if it works. I don't now any other means using topics.

You could probably destroy the subscriber in the callback like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        delete(self.sub)
del self.sub

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

Though I haven't yet tested if it works. I don't now any other means using topics.

You could probably can also destroy the subscriber in the callback use unregister fonction like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        del self.sub
self.sub.unregister()

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        rospy.Subscriber('/sometopic', self.sub.rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

Though I haven't yet tested if it works. I don't now any other means using topics.

You could can also destroy use the unregister fonction like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        self.sub.unregister()

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        self.sub.rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

You could can also destroy use the unregister fonction like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        self.sub.unregister()

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        self.sub.rospy.Subscriber('/sometopic', self.sub = rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

You could can also destroy use the unregister fonction like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        self.sub.unregister()

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        self.sub = rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        print self.data
        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()

You could can also destroy use the unregister fonction like this :

import rospy
from std_msgs.msg import Int8

class SomeClass:
    def __init__(self):
        self.data = None
        self.sub = None

    def get_data_callback(self, data):
        self.data = data
        print self.data
        self.sub.unregister()

    def run(self):
        rospy.init_node('myNodeName', anonymous=True)
        self.sub = rospy.Subscriber('/sometopic', Int8, self.get_data_callback)

        rospy.spin()

if __name__ == "__main__":
    foo = SomeClass()
    foo.run()