Doubt in Solution for Exercise 7.6

I was going the Exercise Solution 7.6 (Understanding ROS Actions - Clients) and stumbled upon this snippet :

#We takeoff the drone during the first 3 seconds
i=0
while not i == 3:
    takeoff.publish(takeoff_msg)
    rospy.loginfo('Taking off...')
    time.sleep(1)
    i += 1

I understand that the takeoff_msg is being published multiple times, is this because of the fact that the 1st message published into a topic may fail (because the topic connections are not ready yet) ?

If yes,

  1. can we use latched messages instead of publishing the same message multiple times ?
    or
  2. check if the number of connections are greater than 0 and then publish the message ?

TIA

1 Like

Number 2 is correct (nice job). This is something that will be introduced soon, you will then get and check the number of connections.

2 Likes