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 Returns the result status text if any.
109 @param topic: The topic of interest.
112 if (
not topic
in ProxyActionClient._clients):
113 return "Failed to get status text: Invalid action topic = [" + topic +
"]"
119 return "Failed to retrieve goal status text for topic = [" + topic +
"]"
123 Removes the latest result message of the given action call.
126 @param topic: The topic of interest.
128 ProxyActionClient._result[topic] =
None
132 Checks if the given action call has any feedback.
135 @param topic: The topic of interest.
137 return ProxyActionClient._feedback.get(topic)
is not None
141 Returns the latest feedback message of the given action call.
144 @param topic: The topic of interest.
146 return ProxyActionClient._feedback.get(topic)
150 Removes the latest feedback message of the given action call.
153 @param topic: The topic of interest.
155 ProxyActionClient._feedback[topic] =
None
159 Determines the current actionlib state of the given action topic.
160 A list of possible states is defined in actionlib_msgs/GoalStatus.
163 @param topic: The topic of interest.
165 return ProxyActionClient._clients[topic].
get_state()
169 Determines if an action request is already being processed on the given topic.
172 @param topic: The topic of interest.
174 return ProxyActionClient._clients[topic].simple_state != actionlib.SimpleGoalState.DONE
178 Cancels the current action call on the given action topic.
181 @param topic: The topic of interest.
183 ProxyActionClient._clients[topic].cancel_goal()
187 Checks whether a topic is available.
190 @param topic: The topic of the action.
192 @type wait_duration: int
193 @param wait_duration: Defines how long to wait for the given client if it is not available right now.
195 client = ProxyActionClient._clients.get(topic)
197 Logger.logerr(
"Action client %s not yet registered, need to add it first!" % topic)
201 available = client.wait_for_server(rospy.Duration.from_sec(wait_duration))
210 Logger.logerr(
"Action client %s timed out!" % topic)
214 Logger.loginfo(
"Finally found action client %s..." % (topic))
218 Logger.logwarn(
"Waiting for action client %s..." % (topic))