Ask Your Question
0

what happens to a topic after publisher node is killed

asked 2018-10-24 22:37:46 -0500

someonekarl gravatar image

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?
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-25 01:37:40 -0500

mgruhler gravatar image

updated 2018-10-25 01:37:49 -0500

If this is actually static, i.e. not changing at all, or at least just very infrequently, it would be best to just publish it in the beginning (make sure, that there is enough time from creating your publisher to actually publish it) and latch it. And then just let the node do nothing.

This way you don't produce any traffic on the topic ("continuous publishing") when it is not needed, and you don't need to check the connections all the time ("publish once when connected"). So this would make your code even more simple.

I'm not sure, but I guess you cannot exit the node when doing this though, as this will also deregister the publisher and thus, even though latched, it will not send the data to new nodes.

edit flag offensive delete link more

Comments

2

I'm not sure, but I guess you cannot exit the node when doing this

that is correct.

To answer the question in the topic title: when a publisher exits, and it is the only publisher on a topic, no further msgs will be seen on that topic by suscribers. In essence, the topic 'disappears' as well.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-25 01:41:38 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-10-24 22:37:46 -0500

Seen: 321 times

Last updated: Oct 25 '18