Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 import rospy
00061 from simple_script_server import *
00062
00063
00064 class command_gui_buttons:
00065 def __init__(self):
00066 self.sss = simple_script_server()
00067 self.panels = []
00068 self.stop_buttons = []
00069 self.init_buttons = []
00070 self.recover_buttons = []
00071 self.CreateControlPanel()
00072
00073
00074 def CreateControlPanel(self):
00075 param_prefix = "~control_buttons"
00076 if not rospy.has_param(param_prefix):
00077 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",param_prefix)
00078 return False
00079 group_param = rospy.get_param(param_prefix)
00080
00081 group_param = self.SortDict(group_param)
00082
00083
00084 for group in group_param:
00085 group_name = group[1]["group_name"]
00086 component_name = group[1]["component_name"]
00087 button_list = group[1]["buttons"]
00088 buttons = []
00089 for button in button_list:
00090
00091 if button[1] == "move":
00092 buttons.append(self.CreateButton(button[0],self.sss.move,component_name,button[2]))
00093 elif button[1] == "move_base_rel":
00094 buttons.append(self.CreateButton(button[0],self.sss.move_base_rel,component_name,button[2]))
00095 elif button[1] == "trigger":
00096 buttons.append(self.CreateButton(button[0],self.sss.trigger,component_name,button[2]))
00097 if button[2] == "stop":
00098 self.stop_buttons.append(component_name)
00099 if button[2] == "init":
00100 self.init_buttons.append(component_name)
00101 if button[2] == "recover":
00102 self.recover_buttons.append(component_name)
00103 elif button[1] == "stop":
00104 buttons.append(self.CreateButton(button[0],self.sss.stop,component_name,button[2]))
00105 self.stop_buttons.append(component_name)
00106 elif button[1] == "mode":
00107 buttons.append(self.CreateButton(button[0],self.sss.set_operation_mode,component_name,button[2]))
00108 else:
00109 rospy.logerr("Function <<%s>> not known to command gui",button[1])
00110 return False
00111 group = (group_name,buttons)
00112
00113
00114 if component_name == "base":
00115 param_prefix = "~nav_buttons"
00116 if rospy.has_param(param_prefix):
00117 nav_buttons_param = rospy.get_param(param_prefix)
00118 nav_button_list = nav_buttons_param["buttons"]
00119
00120 for button in nav_button_list:
00121
00122 buttons.append(self.CreateButton(button[0],self.sss.move,component_name,button[2]))
00123 else:
00124 rospy.logwarn("parameter %s does not exist on ROS Parameter Server, no nav buttons will be available.",param_prefix)
00125 self.panels.append(group)
00126
00127
00128 self.stop_buttons = self.uniqify_list(self.stop_buttons)
00129 self.init_buttons = self.uniqify_list(self.init_buttons)
00130 self.recover_buttons = self.uniqify_list(self.recover_buttons)
00131
00132
00133
00134 def CreateButton(self,button_name,function,component_name,parameter_name):
00135 button = (button_name,function,(component_name,parameter_name,False))
00136 return button
00137
00138
00139 def SortDict(self,dictionary):
00140 keys = sorted(dictionary.iterkeys())
00141 k=[]
00142
00143
00144
00145 return [[key,dictionary[key]] for key in keys]
00146
00147
00148 def uniqify_list(self,seq, idfun=None):
00149
00150 if idfun is None:
00151 def idfun(x): return x
00152 seen = {}
00153 result = []
00154 for item in seq:
00155 marker = idfun(item)
00156
00157
00158
00159 if marker in seen: continue
00160 seen[marker] = 1
00161 result.append(item)
00162 return result