4 from threading
import Timer
11 A proxy for calling actions. 18 def __init__(self, topics={}, wait_duration=10):
20 Initializes the proxy with optionally a given set of clients. 22 @type topics: dictionary string - message class 23 @param topics: A dictionay containing a collection of topic - message type pairs. 25 @type wait_duration: int 26 @param wait_duration: Defines how long to wait for each client in the 27 given set to become available (if it is not already available). 29 for topic, msg_type
in topics.items():
34 Tries to set up an action client for calling it later. 37 @param topic: The topic of the action to call. 39 @type msg_type: msg type 40 @param msg_type: The type of messages of this action client. 42 @type wait_duration: int 43 @param wait_duration: Defines how long to wait for the given client if it is not available right now. 45 if topic
not in ProxyActionClient._clients:
51 Performs an action call on the given topic. 54 @param topic: The topic to call. 56 @type goal: action goal 57 @param goal: The request to send to the action server. 60 raise ValueError(
'Cannot send goal for action client %s: Topic not available.' % topic)
62 ProxyActionClient._result[topic] =
None 63 ProxyActionClient._feedback[topic] =
None 65 ProxyActionClient._clients[topic].
send_goal(
72 ProxyActionClient._result[topic] = result
75 ProxyActionClient._feedback[topic] = feedback
79 Checks if the client on the given action topic is available. 82 @param topic: The topic of interest. 88 Checks if the given action call already has a result. 91 @param topic: The topic of interest. 93 return ProxyActionClient._result.get(topic)
is not None 97 Returns the result message of the given action call. 100 @param topic: The topic of interest. 102 return ProxyActionClient._result.get(topic)
106 Removes the latest result message of the given action call. 109 @param topic: The topic of interest. 111 ProxyActionClient._result[topic] =
None 115 Checks if the given action call has any feedback. 118 @param topic: The topic of interest. 120 return ProxyActionClient._feedback.get(topic)
is not None 124 Returns the latest feedback message of the given action call. 127 @param topic: The topic of interest. 129 return ProxyActionClient._feedback.get(topic)
133 Removes the latest feedback message of the given action call. 136 @param topic: The topic of interest. 138 ProxyActionClient._feedback[topic] =
None 142 Determines the current actionlib state of the given action topic. 143 A list of possible states is defined in actionlib_msgs/GoalStatus. 146 @param topic: The topic of interest. 148 return ProxyActionClient._clients[topic].
get_state()
152 Determines if an action request is already being processed on the given topic. 155 @param topic: The topic of interest. 157 return ProxyActionClient._clients[topic].simple_state != actionlib.SimpleGoalState.DONE
161 Cancels the current action call on the given action topic. 164 @param topic: The topic of interest. 166 ProxyActionClient._clients[topic].cancel_goal()
170 Checks whether a topic is available. 173 @param topic: The topic of the action. 175 @type wait_duration: int 176 @param wait_duration: Defines how long to wait for the given client if it is not available right now. 178 client = ProxyActionClient._clients.get(topic)
180 Logger.logerr(
"Action client %s not yet registered, need to add it first!" % topic)
184 available = client.wait_for_server(rospy.Duration.from_sec(wait_duration))
193 Logger.logerr(
"Action client %s timed out!" % topic)
197 Logger.loginfo(
"Finally found action client %s..." % (topic))
201 Logger.logwarn(
"Waiting for action client %s..." % (topic))
def get_result(self, topic)
def _done_callback(self, topic, terminal_state, result)
def _check_topic_available(self, topic, wait_duration=1)
def send_goal(self, topic, goal)
def __init__(self, topics={}, wait_duration=10)
def remove_result(self, topic)
def get_state(self, topic)
def is_active(self, topic)
def is_available(self, topic)
def _print_wait_warning(self, topic)
def _feedback_callback(self, topic, feedback)
def setupClient(self, topic, msg_type, wait_duration=10)
def remove_feedback(self, topic)
def has_result(self, topic)
def get_feedback(self, topic)
def has_feedback(self, topic)