ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

someonekarl's profile - activity

2020-01-20 14:08:08 -0500 received badge  Famous Question (source)
2020-01-20 14:08:08 -0500 received badge  Notable Question (source)
2018-11-08 02:16:53 -0500 received badge  Supporter (source)
2018-11-08 02:16:45 -0500 marked best answer 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:

  1. since the flag is a static point, which way to do this be preferred and why?
  2. 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?
2018-11-08 02:16:45 -0500 received badge  Scholar (source)
2018-10-25 03:51:25 -0500 received badge  Popular Question (source)
2018-10-25 01:06:57 -0500 asked a question what happens to a topic after publisher node is killed

what happens to a topic after publisher node is killed i have a publisher node publishing to a "flag" topic, i have trie