33 from actionlib_msgs.msg
import GoalID, GoalStatus, GoalStatusArray
63 def __init__(self, ns, ActionSpec, goal_cb, cancel_cb=nop_cb, auto_start=True):
74 except AttributeError:
75 raise ActionException(
"Type is not an action spec: %s" % str(ActionSpec))
83 self.
lock = threading.RLock()
103 rospy.logwarn(
"You've passed in true for auto_start to the python action server, you should always pass "
104 "in false to avoid race conditions.")
140 self.
status_pub = rospy.Publisher(rospy.remap_name(self.
ns)+
"/status", GoalStatusArray, latch=
True, queue_size=self.
pub_queue_size)
153 resolved_status_frequency_name = rospy.remap_name(self.
ns)+
"/status_frequency"
154 if rospy.has_param(resolved_status_frequency_name):
156 rospy.logwarn(
"You're using the deprecated status_frequency parameter, please switch to actionlib_status_frequency.")
158 search_status_frequency_name = rospy.search_param(
"actionlib_status_frequency")
159 if search_status_frequency_name
is None:
164 status_list_timeout = rospy.get_param(rospy.remap_name(self.
ns)+
"/status_list_timeout", 5.0)
177 ar.header.stamp = rospy.Time.now()
180 if not rospy.is_shutdown():
190 af.header.stamp = rospy.Time.now()
192 af.feedback = feedback
193 if not rospy.is_shutdown():
205 rospy.logdebug(
"The action server has received a new cancel request")
207 goal_id_found =
False
212 cancel_everything = (goal_id.id ==
"" and goal_id.stamp == rospy.Time())
213 cancel_this_one = (goal_id.id == st.status.goal_id.id)
214 cancel_before_stamp = (goal_id.stamp != rospy.Time()
and st.status.goal_id.stamp <= goal_id.stamp)
216 if cancel_everything
or cancel_this_one
or cancel_before_stamp:
218 if goal_id.id == st.status.goal_id.id:
222 handle_tracker = st.handle_tracker
224 if handle_tracker
is None:
227 st.handle_tracker = handle_tracker
230 st.handle_destruction_time = rospy.Time.now()
235 if gh.set_cancel_requested():
240 if goal_id.id !=
"" and not goal_id_found:
244 tracker.handle_destruction_time = rospy.Time.now()
257 rospy.logdebug(
"The action server has received a new goal request")
261 if goal.goal_id.id == st.status.goal_id.id:
262 rospy.logdebug(
"Goal %s was already in the status list with status %i" % (goal.goal_id.id, st.status.status))
264 if st.status.status == GoalStatus.RECALLING:
265 st.status.status = GoalStatus.RECALLED
270 if st.handle_tracker
is None:
271 st.handle_destruction_time = rospy.Time.now()
283 st.handle_tracker = handle_tracker
287 if goal.goal_id.stamp != rospy.Time()
and goal.goal_id.stamp <= self.
last_cancel:
289 gh.set_canceled(
None,
"This goal handle was canceled by the action server because its timestamp is before the timestamp of the last cancel request")
306 status_array = GoalStatusArray()
314 if st.handle_destruction_time != rospy.Time()
and st.handle_destruction_time + self.
status_list_timeout < rospy.Time.now():
315 rospy.logdebug(
"Item %s with destruction time of %.3f being removed from list. Now = %.3f" %
316 (st.status.goal_id, st.handle_destruction_time.to_sec(), rospy.Time.now().to_sec()))
319 status_array.status_list.append(st.status)
322 status_array.header.stamp = rospy.Time.now()
323 if not rospy.is_shutdown():