def execute_and_wait_for_result(self): ''' Example to show that an action is asynchronous''' goal = ArdroneGoal() goal.nseconds = 30 action = self.action_ action.wait_for_server() action.send_goal(goal, feedback_cb=self.feedback_callback) while not action.wait_for_result(): rospy.loginfo( "Doing Stuff while waiting for the Server to give a result...." ) self.rate_.sleep()
def execute_action_wait_and_stop(self): ''' Example to show that an action is asynchronous''' goal = ArdroneGoal() goal.nseconds = 30 action = self.action_ action.wait_for_server() action.send_goal(goal, feedback_cb=self.feedback_callback) time.sleep(10) rospy.loginfo('It is asynchronous!!') status = action.get_state() rospy.loginfo('The status is = {:d}'.format(status)) action.cancel_goal() # would cancel the goal 3 seconds after starting status = action.get_state() rospy.loginfo('just after cancel = {:d}'.format(status)) time.sleep(2) status = action.get_state() rospy.loginfo('The status is = {:d}'.format(status))
def execute_and_wait_for_result(self): ''' Example to show that an action is asynchronous''' goal = ArdroneGoal() goal.nseconds = 30 action = self.action_ action.wait_for_server() action.send_goal(goal, feedback_cb=self.feedback_callback) action_state = action.get_state() while action_state < SimpleGoalState.DONE: rospy.loginfo( "Doing Stuff while waiting for the Server to give a result...." ) self.rate_.sleep() action_state = action.get_state() rospy.loginfo("action state: {:d}".format(action_state))
def execute_action_wait_and_stop(self): ''' Example to show that an action is asynchronous''' goal = ArdroneGoal() goal.nseconds = 30 action = self.action_ action.wait_for_server() action.send_goal(goal, feedback_cb=self.feedback_callback) for _ in range(10): self.rate_.sleep() self.takeoff_drone() action_state = action.get_state() while action_state < SimpleGoalState.DONE: self.move_drone() action_state = action.get_state() self.land_drone()
def feedback_callback(feedback): global nImage print('[Feedback] image n.%d received' % nImage) nImage += 1 # initializes the action client node rospy.init_node('example_with_waitforresult_action_client_node') action_server_name = '/ardrone_action_server' client = actionlib.SimpleActionClient(action_server_name, ArdroneAction) # waits until the action server is up and running rospy.loginfo('Waiting for action Server ' + action_server_name) client.wait_for_server() rospy.loginfo('Action Server Found...' + action_server_name) # creates a goal to send to the action server goal = ArdroneGoal() goal.nseconds = 10 # indicates, take pictures along 10 seconds client.send_goal(goal, feedback_cb=feedback_callback) rate = rospy.Rate(1) rospy.loginfo("Lets Start The Wait for the Action To finish Loop...") while not client.wait_for_result(): rospy.loginfo( "Doing Stuff while waiting for the Server to give a result....") rate.sleep() rospy.loginfo("Example with WaitForResult Finished.")
action_server_name = '/ardrone_action_server' client = actionlib.SimpleActionClient(action_server_name, ArdroneAction) move = rospy.Publisher('/cmd_vel', Twist, queue_size=1) move_msg = Twist() takeoff = rospy.Publisher('drone/takeoff', Empty, queue_size=1) takeoff_msg = Empty() land = rospy.Publisher('drone/land', Empty, queue_size=1) land_msg = Empty() rospy.loginfo('Waiting for action server' + action_server_name) client.wait_for_server() rospy.loginfo('Action server found-' + action_server_name) goal = ArdroneGoal() goal.nseconds = 10 client.send_goal(goal, feedback_cb=feedback_callback) state_result = client.get_state() rate = rospy.Rate(1) rospy.loginfo("state_result: " + str(state_result)) #we takeoff the drone for 3 seconds i = 0 while not i == 3: takeoff.publish(takeoff_msg) rospy.loginfo("Taking off...") time.sleep(1)
def feedback_callback(feedback): global nImage print('[Feedback] image n. %d received' % nImage) nImage += 1 rospy.init_node('drone_action_client') #initializes the action client node #create the connection to the action server client = actionlib.SimpleActionClient('/ardrone_action_server', ArdroneAction) client.wait_for_server() #waits until the action server is up and running goal = ArdroneGoal() #creates a goal to send to the action server goal.nseconds = 10 #indicates the time for taking pictures #sends the goal to the action server, specifying which feedback function to call when feedback is received client.send_goal(goal, feedback_cb=feedback_callback) #goal preemption #time.sleep(3.0) #client.cancel_goal() #cancel the goal 3 seconds after starting #wait until the result is obtained and check status periodically #in the meantime you can do other stuff status = client.get_state() client.wait_for_result() print('[Result] State: %d' % (client.get_state()))
def goalHandling(self, client, secondstofly): goal = ArdroneGoal() goal.nseconds = secondstofly client.send_goal(goal, feedback_cb=self.feedback_callback)