$search
00001 #!/usr/bin/python 00002 00003 import time 00004 00005 import roslib 00006 roslib.load_manifest('cob_command_gui_rviz') 00007 import rospy 00008 import actionlib 00009 import thread 00010 00011 from simple_script_server import * 00012 00013 def start(func, largs): 00014 thread.start_new_thread(func,tuple(largs)) 00015 00016 def start_action(data): 00017 data() 00018 00019 class execute_commands(): 00020 00021 #Initializes the actionlib interface of the script server. 00022 def __init__(self): 00023 self.script_action_server = actionlib.SimpleActionServer("cob_command_gui_rviz", ScriptAction, self.execute_cb, False) 00024 self.script_action_server.start() 00025 self.sss = simple_script_server() 00026 00027 #executes actionlib callbacks 00028 def execute_cb(self, server_goal): 00029 server_result = ScriptActionResult().result 00030 function_name = server_goal.function_name 00031 00032 if (function_name == "init") or (function_name == "stop") or (function_name == "recover"): 00033 args = (server_goal.component_name, False) 00034 largs = list(args) 00035 else: 00036 args = (server_goal.component_name, server_goal.parameter_name, False) 00037 largs = list(args) 00038 00039 if server_goal.mode == "diff": 00040 largs.append(server_goal.mode) 00041 elif server_goal.mode == "planned": 00042 largs.append(server_goal.mode) 00043 00044 if server_goal.function_name == "move": 00045 ret = self.execute_move(largs) 00046 elif server_goal.function_name == "move_base_rel": 00047 ret = self.execute_move_base_rel(largs) 00048 elif server_goal.function_name == "trigger": 00049 ret = self.execute_trigger(largs) 00050 elif server_goal.function_name == "stop": 00051 ret = self.execute_stop(largs) 00052 elif server_goal.function_name == "init": 00053 ret = self.execute_init(largs) 00054 elif server_goal.function_name == "recover": 00055 ret = self.execute_recover(largs) 00056 elif server_goal.function_name == "mode": 00057 ret = self.execute_mode(largs) 00058 00059 if self.script_action_server.is_active(): 00060 self.script_action_server.set_succeeded(server_result) 00061 00062 def execute_move(self, largs): 00063 00064 command = lambda func=self.sss.move: start(func, largs) 00065 start_action(command) 00066 00067 def execute_move_base_rel(self, largs): 00068 00069 command = lambda func=self.sss.move_base_rel: start(func, largs) 00070 start_action(command) 00071 00072 def execute_trigger(self, largs): 00073 00074 command = lambda func=self.sss.trigger: start(func, largs) 00075 start_action(command) 00076 00077 def execute_stop(self, largs): 00078 00079 command = lambda func=self.sss.stop: start(func, largs) 00080 start_action(command) 00081 00082 def execute_init(self, largs): 00083 00084 command = lambda func=self.sss.init: start(func, largs) 00085 start_action(command) 00086 00087 def execute_recover(self, largs): 00088 00089 command = lambda func=self.sss.recover: start(func, largs) 00090 start_action(command) 00091 00092 def execute_mode(self, largs): 00093 00094 command = lambda func=self.sss.set_operation_mode: start(func, largs) 00095 start_action(command) 00096 00097 # main routine for running the script server 00098 if __name__ == '__main__': 00099 rospy.init_node('execute_commands') 00100 execute_commands() 00101 rospy.loginfo("execute commands is running") 00102 rospy.spin()