what happens to a topic after publisher node is killed
i have a publisher node publishing to a "flag" topic, i have tried doing this using two ways:
continuous publishing:
def flag_publisher(coordinate_x, coordinate_y):
rate = rospy.Rate(5)
pub = rospy.Publisher("/flag", Point, queue_size=5)
msg = Point()
msg.x = float(coordinate_x)
msg.y = float(coordinate_y)
msg.z = 0
while not rospy.is_shutdown():
pub.publish(msg)
rate.sleep()
and publish once only when connected:
def flag_publisher(coordinate_x, coordinate_y):
rate = rospy.Rate(5)
pub = rospy.Publisher("/flag", Point, queue_size=5)
msg = Point()
msg.x = float(coordinate_x)
msg.y = float(coordinate_y)
msg.z = 0
while True:
if pub.get_num_connections() > 0:
pub.publish(msg)
break
else:
rate.sleep()
both ways work fine, but my question is this:
- since the flag is a static point, which way to do this be preferred and why?
- in this case, can i use the latch parameter in rospy.publisher to just publish the flag once and exit the node? will my subscribers still be able to get to the last message from the publisher?