Not exactly. We are not setting the “rate” of the action server here. Here’s what happens in those three lines, explained in comments:
# send the goal to the action server and specify the callback function
# that the action server will call from time to time to give feedback
client.send_goal(goal, feedback_cb=feedback_callback)
# get the state of the action (is it done?)
state_result = client.get_state()
# create a Rate object to be used later on. We have not used it at his point
rate = rospy.Rate(1)
What this code block does simply is publish the takeoff command three times, once per second. When you use time.sleep(x)
, the code pauses for x
seconds. Each time we publish, we are also increasing i
by 1, so that the loop can exit after we have published the third time. Execution of the loop has nothing to do with the ROS_MASTER, it’s just pure Python.
rospy.Rate.sleep()
works differently:
time.sleep(x)
- pause the Python code forx
seconds. Can be used anywhere in the program - inside or outside a loop.- rospy.Rate.sleep() - Only used within a loop. Tries to ensure that the loop runs at the defined rate per second. In this case, it will try to make the loop run 1 time per second. Read more about rospy.Rate here: Proper use of rospy.Rate or ros::Rate
The messages [Feedback] image n.x received
appearing between the Taking off...
messages are coming from the callback function feedback_callback
, which is running in a sepate thread from the main program (so nothing in the main program affects it. It’s independent.).
What you call “action server calls” are actually feedback messages from the action server, coming from the callback function feedback_callback
. The action server was only called once in the line
client.send_goal(goal, feedback_cb=feedback_callback)
In conclusion, I think you have so many questions because you’re probably new to both Python and ROS. Don’t worry, you will pick both up with more practise. Cheers!