How to quit/exit from a subscriber
Hey all, I have two publishers with two topics using rospy. I have a third node that subscribe to each of both topics in sequence. I want to use one subscriber for a specified times (may be 10 or 20) and after that exit from this subscriber. Then I subscribe to second and want it to be automatically stopped after given number of times as above. I scanned the google I came to know subscriber.unregister() but it gives error that "'tuple' has no attribute 'unregister'". Any solution to exit from rospy subscriber automatically with out pressing Crl+C.
sb = None
sb=rospy.Subscriber(topic1,type1,self.callback,(self,sb))
rospy.spin()
sb=rospy.Subscriber(topic2,type2,self.callback,(self,sb))
rospy.spin()
def callback(self,sb):
self.c = self.c + 1
if self.c == 10:
sb.unregister()
Thanks
According to the API that should work. Can you come up with a minimal example to reproduce this.
sb = None; sb=rospy.Subscriber(topic1,type1,self.callback,(sb)); rospy.spin(); sb=rospy.Subscriber(topic2,type2,self.callback,(sb); rospy.spin() def callback(self,sb): self.c = self.c + 1; if self.c == 10: sb.unregister();
Please update your original post with the code. It's not readable in the comment. As far as I can see, something with the parentheses seems wrong.
I have included code up, but its mixed with message. Infact code creates a subscriber and call a callback, I want that callback should be closed after few iteration and then next comes. Both subscriber use the same call back function with differe messagetype. I wanna know how to quit callback.thnx