Unable to stop publishing on a topic (Resolved)
Hi,
I want to stop publishing a message to a topic after 20 iterations. For that I have written the following piece of code, but however the counter reaches to 20, the program is still publishing the message to the topic and it seems that it is disregarding the counter variable's value. How can I resolve this issue?
class node():
def __init__(self):
rosInstance = rospy
pub = rosInstance.Publisher('cmd_vel', Twist)
r = rosInstance.Rate(1)
ctrlArgs = Twist()
iteration = 0
speed = -0.1
while not rospy.is_shutdown():
self.iterate()
if iteration < 20:
cntrlArgs.linear.x = 0.2
pub.publish(ctrlArgs)
r.sleep()
def iterate(self):
iteration = iteration + 1
And then I run the program:
if __name__ == '__main__':
rospy.init_node('iterator', anonymous=False)
try:
nn = node()
except rospy.ROSInterruptException: pass
Thank you