importrospyimporttimeimportactionlibfromardrone_as.msgimportArdroneAction,ArdroneGoal,ArdroneResult,ArdroneFeedbacknImage=1# Feedback callbackdeffeedback_callback(feedback):globalnImageprint('[Feedback] image n.%d received'%nImage)nImage+=1# Init the action client noderospy.init_node('drone_action_client')# Create connection to the action serverclient=actionlib.SimpleActionClient('/ardrone_action_server',ArdroneAction)# waits until the action server is up and runningclient.wait_for_server()# create a goal to send to the action servergoal=ArdroneGoal()goal.nseconds=10# Send the goal to the action server, specifying which feedback function# to call when feeback receivedclient.send_goal(goal,feeback_cb=feedback_callback)client.wait_for_result()print('[Result] State: %d'%(client.get_state()))
Wait for Result
Using ```wait_for_result()`` is like using a service.
Get State
Instead of waiting for result, you can call get_state() and continue to run while it is running.
1
2
3
4
5
0=PENDING1=ACTIVE2=DONE3=WARN4=ERROR
Use a While loop and while the value returned is less than 2, you know it is still running.
...PENDING=0ACTIVE=1DONE=2WARN=3ERROR=4state_result=client.get_state()rate=rospy.Rate(1)rospy.loginfo("state_result "+str(state_result))whilestate_result<DONE:rospy.loginfo("Doing Stuff while waiting for the server to give a result...")rate.sleep()state_result=client.get_state()rospy.loginfo("state_result: "+str(state_result))rospy.loginfo("[Result] State: "+str(state_result))ifstate_result==ERROR:rospy.logerr("Something went wrong in the server side")ifstate_result==WARN:rospy.logwarn("There is a warning in the Server Side")