38 usage: %prog /action_name action_type 45 from optparse
import OptionParser
51 from cStringIO
import StringIO
52 from library
import to_yaml, yaml_msg_str
53 from dynamic_action
import DynamicAction
54 from actionlib_msgs.msg
import GoalStatus
70 self.status_bg.SetBackgroundColour(color)
71 self.status.SetLabel(label)
75 self.cancel_goal.Enable()
77 self.cancel_goal.Disable()
80 self.server_status_bg.SetBackgroundColour(color)
81 self.server_status.SetLabel(label)
83 self.send_goal.Enable()
85 self.send_goal.Disable()
89 if self.client.wait_for_server(rospy.Duration.from_sec(TIMEOUT)):
91 wx.Colour(192, 252, 253),
True)
94 wx.Colour(200, 0, 0),
False)
98 self.client.cancel_goal()
99 self.
set_status(
"Canceling goal", wx.Colour(211, 34, 243))
104 self.goal.GetValue())
106 self.goal_msg.serialize(buff)
112 self.
set_status(
"Goal is pending", wx.Colour(255, 174, 59))
115 except roslib.message.SerializationError
as e:
117 wx.MessageBox(str(e),
"Error serializing goal", wx.OK)
121 self.result.SetValue(
to_yaml(result))
122 except UnicodeDecodeError:
123 self.result.SetValue(
"Cannot display result due to unprintable characters")
126 return {GoalStatus.PENDING: [
'PENDING', wx.Colour(255, 174, 59)],
127 GoalStatus.ACTIVE: [
'ACTIVE', wx.Colour(0, 255, 0)],
128 GoalStatus.PREEMPTED: [
'PREEMPTED', wx.Colour(255, 252, 16)],
129 GoalStatus.SUCCEEDED: [
'SUCCEEDED', wx.Colour(38, 250, 253)],
130 GoalStatus.ABORTED: [
'ABORTED', wx.Colour(200, 0, 0)],
131 GoalStatus.REJECTED: [
'REJECTED', wx.Colour(253, 38, 159)],
132 GoalStatus.PREEMPTING: [
'PREEMPTING', wx.Colour(253, 38, 159)],
133 GoalStatus.RECALLING: [
'RECALLING', wx.Colour(230, 38, 253)],
134 GoalStatus.RECALLED: [
'RECALLED', wx.Colour(230, 38, 253)],
135 GoalStatus.LOST: [
'LOST', wx.Colour(255, 0, 0)]}[status]
138 status_string, status_color = self.
status_gui(state)
139 wx.CallAfter(self.
set_status,
''.join([
"Goal finished with status: ",
140 status_string]), status_color)
145 wx.CallAfter(self.
set_status,
"Goal is active", wx.Colour(0, 200, 0))
149 self.feedback.SetValue(
to_yaml(feedback))
150 except UnicodeDecodeError:
151 self.feedback.SetValue(
"Cannot display feedback due to unprintable characters")
157 self.server_check_timer.Stop()
163 self.
action_name +
' - ' + self.action_type.name +
' - GUI Client' 166 self.
sz = wx.BoxSizer(wx.VERTICAL)
168 tmp_goal = self.action_type.goal()
170 self.
goal = wx.TextCtrl(self.
frame, -1, style=wx.TE_MULTILINE)
171 self.goal.SetValue(
to_yaml(tmp_goal))
174 self.goal_st.Add(self.
goal, 1, wx.EXPAND)
180 self.feedback_st.Add(self.
feedback, 1, wx.EXPAND)
182 self.
result = wx.TextCtrl(self.
frame, -1, style=(wx.TE_MULTILINE |
186 self.result_st.Add(self.
result, 1, wx.EXPAND)
189 self.send_goal.Bind(wx.EVT_BUTTON, self.
on_goal)
190 self.send_goal.Disable()
193 self.cancel_goal.Bind(wx.EVT_BUTTON, self.
on_cancel)
194 self.cancel_goal.Disable()
197 self.status_bg.SetBackgroundColour(wx.Colour(200, 0, 0))
201 self.server_status_bg.SetBackgroundColour(wx.Colour(200, 0, 0))
204 self.sz.Add(self.
goal_st, 1, wx.EXPAND)
206 self.sz.Add(self.
result_st, 1, wx.EXPAND)
207 self.sz.Add(self.
send_goal, 0, wx.EXPAND)
209 self.sz.Add(self.
status_bg, 0, wx.EXPAND)
212 self.frame.SetSizer(self.
sz)
217 self.server_check_timer.Start(1000)
226 rospy.init_node(
'axclient', anonymous=
True)
228 parser = OptionParser(__doc__.strip())
233 (options, args) = parser.parse_args(rospy.myargv())
237 topic_type = rostopic._get_topic_type(
"%s/goal" % args[1])[0]
239 assert(
"Goal" in topic_type)
240 topic_type = topic_type[0:len(topic_type)-4]
241 elif (len(args) == 3):
244 assert(
"Action" in topic_type)
246 parser.error(
"You must specify the action topic name (and optionally type) Eg: ./axclient.py action_topic actionlib/TwoIntsAction ")
252 rospy.signal_shutdown(
'GUI shutdown')
255 if __name__ ==
'__main__':
def set_status(self, label, color)
def done_cb(self, state, result)
def on_cancel(self, event)
def server_check(self, event)
def status_gui(self, status)
def __init__(self, action_type, action_name)
def set_server_status(self, label, color, enabled)
A Simple client implementation of the ActionInterface which supports only one goal at a time...
def set_cancel_button(self, enabled)
def set_feedback(self, feedback)
def yaml_msg_str(type_, yaml_str, filename=None)
def feedback_cb(self, feedback)
def set_result(self, result)