ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
2 Steps : Flag set to 0 in the class __init__ method. Step 1 : I believe a better alternate is to define the call back method in a class along with the subscriber. And then setting a flag which will be set to one once the callback method has been called for the first time.
Step 2 : Once the Flag has been set 1, in the subscriber declaration block, return to the called block.
An Example is given below : (Tested Works)
class frontCam : def __init__(self): self.flag = 0 rospy.init_node("DFC") self.getVideo()
def getVideo(self) :
rospy.Rate(1)
self.image_sub = rospy.Subscriber('Subscribed TOPIC', Message_Type, self.callback )
print 'Getting Video Feed . . . '
if (self.flag == 1)
return
try :
rospy.spin()
except KeyboardInterrupt :
print "Shutting Down"
def callback(self, data) :
self.flag = 1
However if you guys want, can close the callback method after a certain period using the ropy.sleep() and the return statement as well.