Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

That is expected behavior the way your functions are written. The callback immediately increments self.tracker every time, and after 5 seconds, the print function displays whatever value it finds there. If you want to print the old value, pass it as an argument to the print function, so it won't matter what happens to self.tracker in the mean time:

class listener:
    def printer(self, value):
        print (value)
        print("Look Above for value")

    def callback(self, data):
        rospy.loginfo("I heard %s", data)
        self.tracker = self.tracker + 1

    def __init__(self):

        rospy.init_node('listener', anonymous=True)
        self.tracker = 0
        rospy.Subscriber('/path_query', PathQuery, self.callback,

if __name__ == '__main__':