コード例 #1
0
    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()
コード例 #2
0
 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))
コード例 #3
0
    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))
コード例 #4
0
    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()
コード例 #5
0
ファイル: wait_for_result_test.py プロジェクト: Amit10311/ros
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.")
コード例 #6
0
rospy.init_node('drone_action_client')

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...")
コード例 #7
0

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()
コード例 #8
0
def feedback_callback(feedback):
    global nImage
    print('[Feedback] image n.%d received' % nImage)
    nImage += 1


client = actionlib.SimpleActionClient('/ardrone_action_server', ArdroneAction)
client.wait_for_server()

takeoff_pub = rospy.Publisher('/drone/takeoff', Empty, queue_size=1)
land_pub = rospy.Publisher('/drone/land', Empty, queue_size=1)
cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)

takeoff()
###### goal ######
goal = ArdroneGoal(nseconds=10)  #take picture for 10 seconds
client.send_goal(goal, feedback_cb=feedback_callback)

# Uncomment these lines to test goal preemption:
#time.sleep(3.0)
#client.cancel_goal()  # would cancel the goal 3 seconds after starting

fly_drone()
while not client.wait_for_result():
    rospy.loginfo("State : {}".format(client.get_state()))
    rospy.sleep(3)
stop_drone()
land()

###### status ######
# client.wait_for_result()
コード例 #9
0
    nImage += 1


rospy.init_node(
    'move_photo_drone_action_client')  #initializes the action client node

#create the connection to the action server
client = actionlib.SimpleActionClient('/ardrone_action_server', ArdroneAction)

#waits until the action server is up and running
rospy.loginfo('Waiting fo action server')
client.wait_for_server()
rospy.loginfo('Action Server Found')

#creates a goal to send to the action server
goal = ArdroneGoal()
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)
rate = rospy.Rate(1)

state_result = client.get_state()
rospy.loginfo("state_result:" + str(state_result))

vel = Twist()  #create a var of type Twist

vel.linear.x = 1
vel.angular.z = 0.5

empty = Empty()
コード例 #10
0
 def goalHandling(self, client, secondstofly):
     goal = ArdroneGoal()
     goal.nseconds = secondstofly
     client.send_goal(goal, feedback_cb=self.feedback_callback)