Hello Dear Community (@bayodesegun @rickt ),
I was following the Unit4 (ROS Actions) and currently attempted the first exercise (exercise_46). I had few doubts about the implementation of the action server.
Diving to the exercise, in the solution code, I see the following:
client.send_goal(goal, feedback_cb=feedback_callback)
state_result = client.get_state()
rate = rospy.Rate(1)
This means that we send the goal to the action server which will run at 1 Hz and give us update at 1 Hz
Afterwards, we implement:
i=0
while not i == 3:
takeoff.publish(takeoff_msg)
rospy.loginfo(‘Taking off…’)
time.sleep(1)
i += 1
From this I understand that takeoff msg will be published and then sleep function is called with an argument of 1 sec (meaning you will not get back to this loop in next 1 second) . or else You give back the control to ROS MASTER for 1 second. Now, ROS MASTER decides to execute the action in that 1 second. After executing the action it will wait untill the sleep time for the while loop is over. When the time is over, it will jump back into the while loop and this thing repeats for next 3 iterations.
After 3 iterations we have:
#We move the drone in a circle wile the state of the Action is not DONE yet
while state_result < DONE:
move_msg.linear.x = 1
move_msg.angular.z = 1
move.publish(move_msg)
rate.sleep()
state_result = client.get_state()
rospy.loginfo(‘Moving around…’)
rospy.loginfo("state_result: "+str(state_result))
Now here I see we have used rate.sleep instead of time.sleep and I am not sure why? But anyways from what I understand, it will sleep for any amount of time and I guess ROS MASTER will make that decision. It means that the ROS MASTER will execute the action if it is the time to execute it or else it will keep inside the while loop which means you can execute the statement inside the while loop for multiple time between two actions call. Please correct me if I am wrong? Later part is quite straight forward.
At last, talking about my output, here it is:
[INFO] [1585433782.566912, 0.000000]: Waiting for action Server /ardrone_action_server
[INFO] [1585433782.621251, 412.150000]: Action Server Found…/ardrone_action_server
[INFO] [1585433782.621949, 412.150000]: state_result: 0
[INFO] [1585433782.622334, 412.150000]: Taking off…
[Feedback] image n.1 received
[INFO] [1585433783.623082, 413.043000]: Taking off…
[Feedback] image n.2 received
[INFO] [1585433784.625353, 414.035000]: Taking off…
[Feedback] image n.3 received
[INFO] [1585433785.626763, 415.012000]: Moving around…
[INFO] [1585433785.627757, 415.013000]: state_result: 1
[INFO] [1585433785.628484, 415.014000]: Moving around…
[INFO] [1585433785.629190, 415.015000]: state_result: 1
[INFO] [1585433785.764920, 415.151000]: Moving around…
[INFO] [1585433785.766478, 415.152000]: state_result: 1
[Feedback] image n.4 received
[INFO] [1585433786.794592, 416.150000]: Moving around…
[INFO] [1585433786.799794, 416.155000]: state_result: 1
[Feedback] image n.5 received
[INFO] [1585433787.833864, 417.150000]: Moving around…
[INFO] [1585433787.834655, 417.151000]: state_result: 1
[Feedback] image n.6 received
[INFO] [1585433788.834386, 418.150000]: Moving around…
[INFO] [1585433788.835344, 418.151000]: state_result: 1
[Feedback] image n.7 received
[INFO] [1585433789.841681, 419.150000]: Moving around…
[INFO] [1585433789.842586, 419.151000]: state_result: 1
[Feedback] image n.8 received
[INFO] [1585433790.927491, 420.150000]: Moving around…
[INFO] [1585433790.929047, 420.150000]: state_result: 1
[Feedback] image n.9 received
[INFO] [1585433792.168385, 421.151000]: Moving around…
[INFO] [1585433792.168867, 421.151000]: state_result: 1
[INFO] [1585433793.228869, 422.150000]: Moving around…
[INFO] [1585433793.229588, 422.151000]: state_result: 3
[INFO] [1585433793.230408, 422.152000]: [Result] State: 3
[WARN] [1585433793.231163, 422.153000]: There is a warning in the Server Side
[INFO] [1585433793.231952, 422.154000]: Landing…
[INFO] [1585433794.233841, 423.149000]: Landing…
[INFO] [1585433795.238726, 424.139000]: Landing…
I see here that for time.sleep call in while loop, Taking off… is executed only once between each action pair call namely 0, 1 and 1,2 and 2,3 (see above). However, if we look at the output after 3 seconds between 3rd and 4th action, publishing is done three times. Also, another thing that I noted was in later action calls, publishing was only executed once between the consecutive action calls. Lastly, between 9th and 10th publishing was done twice.
If someone can explain how this scheduling is happening, it will be great!
I will be really thankful for the reply.
Regards,
Kashish Dhal