8 @package manage_actionlib 9 This module provides utility methods for setting up actionlib calls through an overarching actionlib server. 16 action_name="current action",
17 time_limit=float(
"inf"),
19 """Send and monitor an action goal to a given action client. 21 The monitor will return in case of the client reporting success, preemption or 22 abortion, and will also pass through any incoming preemptions to the action server. 24 @param action_server Action server that is calling the action client. If the action server is preempted, this is passed to the action client. 25 @param action_client The action client that is called by the action server. If the action server is preempted, the goal sent to this client is preempted as well. 26 @param action_goal The action goal to be sent to the action client. 27 @param action_name Optional name for the action. Will be displayed in the logs. 28 @param time_limit An optional time limit for the action. If exceeded, the action client is preempted 32 rospy.loginfo(
"Sending goal to " + action_name)
33 action_client.send_goal(action_goal)
34 init_time = rospy.Time(0)
36 while init_time == rospy.Time(0):
37 init_time = rospy.Time.now()
40 while action_server.is_active():
41 if (rospy.Time.now() - init_time).to_sec() > time_limit:
42 rospy.logwarn(
"Timeout of request")
43 action_client.cancel_goal()
47 if action_server.is_preempt_requested():
48 rospy.logwarn(
"Preempting " + action_name)
49 action_client.cancel_goal()
50 finished = action_client.wait_for_result(
51 timeout=rospy.Duration(1.0))
54 rospy.logerr(action_name +
55 " failed to preempt! This should never happen")
56 action_server.set_aborted(text=
"Aborted due to action " +
57 action_name +
" failing to preempt")
59 action_server.set_preempted(
60 text=
"Preempted while running " + action_name)
61 rospy.loginfo(
"Preempted while running")
64 if action_client.get_state() == actionlib.GoalStatus.ABORTED:
65 rospy.logerr(action_name +
" aborted!")
68 action_server.set_aborted(text=action_name +
" aborted")
71 if action_client.get_state() == actionlib.GoalStatus.PREEMPTED:
72 rospy.logerr(action_name +
" preempted!")
75 action_server.set_aborted(text=action_name +
" was preempted")
78 if action_client.get_state() == actionlib.GoalStatus.SUCCEEDED:
79 rospy.loginfo(action_name +
" succeeded!")