32 import actionlib_msgs.msg
37 * @class ServerGoalHandle 38 * @brief Encapsulates a state machine for a given goal that the user can 39 * trigger transisions on. All ROS interfaces for the goal are managed by 40 * the ActionServer to lessen the burden on the user. 44 def __init__(self, status_tracker=None, action_server=None, handle_tracker=None):
46 A private constructor used by the ActionServer to initialize a ServerGoalHandle. 47 @node The default constructor was not ported. 54 self.
goal = status_tracker.goal
59 return self.action_server.ActionResultType()
63 Accept the goal referenced by the goal handle. This will 64 transition to the ACTIVE state or the PREEMPTING state depending 65 on whether a cancel request has been received for the goal 68 rospy.logdebug(
"Accepting goal, id: %s, stamp: %.2f", self.
get_goal_id().id, self.
get_goal_id().stamp.to_sec())
70 with self.action_server.lock:
71 status = self.status_tracker.status.status
74 if status == actionlib_msgs.msg.GoalStatus.PENDING:
75 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.ACTIVE
76 self.status_tracker.status.text = text
77 self.action_server.publish_status()
80 elif status == actionlib_msgs.msg.GoalStatus.RECALLING:
81 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.PREEMPTING
82 self.status_tracker.status.text = text
83 self.action_server.publish_status()
86 rospy.logerr(
"To transition to an active state, the goal must be in a pending or recalling state, it is currently in state: %d", self.status_tracker.status.status)
89 rospy.logerr(
"Attempt to set status on an uninitialized ServerGoalHandle")
93 Set the status of the goal associated with the ServerGoalHandle to RECALLED or PREEMPTED 94 depending on what the current status of the goal is 95 @param result Optionally, the user can pass in a result to be sent to any clients of the goal 100 rospy.logdebug(
"Setting status to canceled on goal, id: %s, stamp: %.2f", self.
get_goal_id().id, self.
get_goal_id().stamp.to_sec())
103 with self.action_server.lock:
104 status = self.status_tracker.status.status
105 if status == actionlib_msgs.msg.GoalStatus.PENDING
or status == actionlib_msgs.msg.GoalStatus.RECALLING:
106 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.RECALLED
107 self.status_tracker.status.text = text
109 self.status_tracker.handle_destruction_time = rospy.Time.now()
110 self.action_server.publish_result(self.status_tracker.status, result)
111 elif status == actionlib_msgs.msg.GoalStatus.ACTIVE
or status == actionlib_msgs.msg.GoalStatus.PREEMPTING:
112 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.PREEMPTED
113 self.status_tracker.status.text = text
115 self.status_tracker.handle_destruction_time = rospy.Time.now()
116 self.action_server.publish_result(self.status_tracker.status, result)
119 rospy.logerr(
"To transition to a cancelled state, the goal must be in a pending, recalling, active, or preempting state, it is currently in state: %d",
120 self.status_tracker.status.status)
123 rospy.logerr(
"Attempt to set status on an uninitialized ServerGoalHandle")
127 * @brief Set the status of the goal associated with the ServerGoalHandle to rejected 128 * @param result Optionally, the user can pass in a result to be sent to any clients of the goal 133 rospy.logdebug(
"Setting status to rejected on goal, id: %s, stamp: %.2f", self.
get_goal_id().id, self.
get_goal_id().stamp.to_sec())
135 with self.action_server.lock:
136 status = self.status_tracker.status.status
137 if status == actionlib_msgs.msg.GoalStatus.PENDING
or status == actionlib_msgs.msg.GoalStatus.RECALLING:
138 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.REJECTED
139 self.status_tracker.status.text = text
141 self.status_tracker.handle_destruction_time = rospy.Time.now()
142 self.action_server.publish_result(self.status_tracker.status, result)
145 rospy.logerr(
"To transition to a rejected state, the goal must be in a pending or recalling state, it is currently in state: %d",
146 self.status_tracker.status.status)
149 rospy.logerr(
"Attempt to set status on an uninitialized ServerGoalHandle")
153 Set the status of the goal associated with the ServerGoalHandle to aborted 154 @param result Optionally, the user can pass in a result to be sent to any clients of the goal 159 rospy.logdebug(
"Setting status to aborted on goal, id: %s, stamp: %.2f", self.
get_goal_id().id, self.
get_goal_id().stamp.to_sec())
161 with self.action_server.lock:
162 status = self.status_tracker.status.status
163 if status == actionlib_msgs.msg.GoalStatus.PREEMPTING
or status == actionlib_msgs.msg.GoalStatus.ACTIVE:
164 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.ABORTED
165 self.status_tracker.status.text = text
167 self.status_tracker.handle_destruction_time = rospy.Time.now()
168 self.action_server.publish_result(self.status_tracker.status, result)
171 rospy.logerr(
"To transition to an aborted state, the goal must be in a preempting or active state, it is currently in state: %d",
175 rospy.logerr(
"Attempt to set status on an uninitialized ServerGoalHandle")
179 Set the status of the goal associated with the ServerGoalHandle to succeeded 180 @param result Optionally, the user can pass in a result to be sent to any clients of the goal 185 rospy.logdebug(
"Setting status to succeeded on goal, id: %s, stamp: %.2f",
188 with self.action_server.lock:
189 status = self.status_tracker.status.status
190 if status == actionlib_msgs.msg.GoalStatus.PREEMPTING
or status == actionlib_msgs.msg.GoalStatus.ACTIVE:
191 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.SUCCEEDED
192 self.status_tracker.status.text = text
194 self.status_tracker.handle_destruction_time = rospy.Time.now()
195 self.action_server.publish_result(self.status_tracker.status, result)
198 rospy.logerr(
"To transition to a succeeded state, the goal must be in a preempting or active state, it is currently in state: %d",
202 rospy.logerr(
"Attempt to set status on an uninitialized ServerGoalHandle")
206 Send feedback to any clients of the goal associated with this ServerGoalHandle 207 @param feedback The feedback to send to the client 209 rospy.logdebug(
"Publishing feedback for goal, id: %s, stamp: %.2f",
212 with self.action_server.lock:
213 self.action_server.publish_feedback(self.status_tracker.status, feedback)
215 rospy.logerr(
"Attempt to publish feedback on an uninitialized ServerGoalHandle")
219 Accessor for the goal associated with the ServerGoalHandle 220 @return A shared_ptr to the goal object 228 return self.goal.goal
234 Accessor for the goal id associated with the ServerGoalHandle 238 with self.action_server.lock:
239 return self.status_tracker.status.goal_id
241 rospy.logerr(
"Attempt to get a goal id on an uninitialized ServerGoalHandle")
242 return actionlib_msgs.msg.GoalID()
246 Accessor for the status associated with the ServerGoalHandle 247 @return The goal status 250 with self.action_server.lock:
251 return self.status_tracker.status
253 rospy.logerr(
"Attempt to get goal status on an uninitialized ServerGoalHandle")
254 return actionlib_msgs.msg.GoalStatus()
258 Equals operator for ServerGoalHandles 259 @param other The ServerGoalHandle to compare to 260 @return True if the ServerGoalHandles refer to the same goal, false otherwise 263 if not self.
goal or not other.goal:
266 their_id = other.get_goal_id()
267 return my_id.id == their_id.id
271 != operator for ServerGoalHandles 272 @param other The ServerGoalHandle to compare to 273 @return True if the ServerGoalHandles refer to different goals, false otherwise 275 if not self.
goal or not other.goal:
278 their_id = other.get_goal_id()
280 return my_id.id != their_id.id
284 hash function for ServerGoalHandles 285 @return hash of the goal ID 291 A private method to set status to PENDING or RECALLING 292 @return True if the cancel request should be passed on to the user, false otherwise 294 rospy.logdebug(
"Transisitoning to a cancel requested state on goal id: %s, stamp: %.2f",
297 with self.action_server.lock:
298 status = self.status_tracker.status.status
299 if status == actionlib_msgs.msg.GoalStatus.PENDING:
300 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.RECALLING
301 self.action_server.publish_status()
304 if status == actionlib_msgs.msg.GoalStatus.ACTIVE:
305 self.status_tracker.status.status = actionlib_msgs.msg.GoalStatus.PREEMPTING
306 self.action_server.publish_status()
def __init__(self, status_tracker=None, action_server=None, handle_tracker=None)
def publish_feedback(self, feedback)
def set_canceled(self, result=None, text="")
def set_accepted(self, text="")
def set_aborted(self, result=None, text="")
def get_default_result(self)
def set_rejected(self, result=None, text="")
def set_cancel_requested(self)
def get_goal_status(self)
def set_succeeded(self, result=None, text="")