예제 #1
0
from basics.msg import TimerAction, TimerGoal, TimerResult, TimerFeedback


# BEGIN PART_1
def feedback_cb(feedback):
    print('[Feedback] Time elapsed: %f' % (feedback.time_elapsed.to_sec()))
    print('[Feedback] Time remaining: %f' % (feedback.time_remaining.to_sec()))


# END PART_1

rospy.init_node('timer_action_client')
client = actionlib.SimpleActionClient('timer', TimerAction)
client.wait_for_server()

goal = TimerGoal()
goal.time_to_wait = rospy.Duration.from_sec(5.0)
# BEGIN PART_5
# Uncomment this line to test server-side abort:
goal.time_to_wait = rospy.Duration.from_sec(500.0)
# END PART_5
# BEGIN PART_2
client.send_goal(goal, feedback_cb=feedback_cb)
# END PART_2

# BEGIN PART_4
# Uncomment these lines to test goal preemption:
# time.sleep(3.0)
# client.cancel_goal()
# END PART_4
예제 #2
0
# 'timer'.

# The second argument is the type of the action,
# which must also match the server:
# TimerAction.

# Having created the client,
# we tell it to wait for the action server to come up,
# which it does by checking for the five advertised topics
# that we saw earlier when testing the server.
# Similar to rospy.wait_for_service(),
# which we used to wait for a service to be ready,
# SimpleActionClient.wait_for_server() will block until
# the server is ready:

goal = TimerGoal()  # Now we create a goal of type TimerGoal
# and fill in the amount of time we want the
goal.time_to_wait = rospy.Duration.from_sec(
    5.0)  # timer to wait, which is five seconds.
client.send_goal(goal)  # Then we send the goal,
# which causes the transmission
# of the goal message to the server:

client.wait_for_result()  # Next, we wait for a result from the server.
# If things are working properly, we expect to
# block here for about five seconds.
print(
    'Time elapsed: %f' %
    (client.get_result().time_elapsed.to_sec()))  # After the result comes in,
# we use get_result() to retrieve it
# from within the client object and
# -*- coding: utf-8 -*-
#Created by Chukwunyere Igbokwe on August 01, 2016 by 12:51 PM

import rospy
import time, actionlib
from basics.msg import TimerAction, TimerGoal, TimerResult, TimerFeedback

def feedback_cb(feedback):
    print ('[Feedback] Time elapsed: %f'%(feedback.time_elapsed.to_sec()))
    print ('[Feedback] Time remaining: %f' % (feedback.time_remaining.to_sec()))


rospy.init_node('timer_action_client')
client = actionlib.SimpleActionClient('timer', TimerAction)
client.wait_for_server()
goal = TimerGoal()
goal.time_to_wait = rospy.Duration.from_sec(5.0)
#Uncomment this line to test server-side abort:
goal.time_to_wait = rospy.Duration.from_sec(500.0)
client.send_goal(goal,feedback_cb=feedback_cb)

# Uncomment these lines to test goal preemption:
# time.sleep(3.0)
# client.cancel_goal()

client.wait_for_result()
print ("[Result] State : %d"%(client.get_state()))
print ("[Result] Status : %s"% (client.get_goal_status_text()))
print ("[Result] Time elapsed : %f"%(client.get_result().time_elapsed.to_sec()))
print ("[Result] Updates sent : %d"%(client.get_result().updates_sent))
예제 #4
0
def feedback_cb(feedback):
	# Print contents of feedback message
	print('[Feedback] Time elapsed: %f'%(feedback.time_elapsed.to_sec()))
	print('[Feedback] Time remaining: %f'%(feedback.time_remaining.to_sec()))

# Initialize the node
rospy.init_node('timer_action_client')

# Create a SimpleActionClient (server_name, action_type)
client = actionlib.SimpleActionClient('timer', TimerAction)

# Wait for the action server to come up
client.wait_for_server()

# Create the goal
goal = TimerGoal()
goal.time_to_wait = rospy.Duration.from_sec(5.0)	# Fixed time: 5.0 sec
# Uncomment this line to test server-side abort:
#goal.time_to_wait = rospy.Duration.from_sec(500.0)

# Send the goal to the server (declare the feedback callback)
client.send_goal(goal, feedback_cb=feedback_cb)

# Uncomment these lines to test goal preemption:
time.sleep(3.0)
client.cancel_goal()

# Wait for the result and print it
client.wait_for_result()
print('[Result] State: %d'%(client.get_state()))
print('[Result] Status: %s'%(client.get_goal_status_text()))