00001 #!/usr/bin/python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2010 \n 00007 # Fraunhofer Institute for Manufacturing Engineering 00008 # and Automation (IPA) \n\n 00009 # 00010 ################################################################# 00011 # 00012 # \note 00013 # Project name: care-o-bot 00014 # \note 00015 # ROS stack name: cob_apps 00016 # \note 00017 # ROS package name: cob_script_server 00018 # 00019 # \author 00020 # Author: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00021 # \author 00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00023 # 00024 # \date Date of creation: Aug 2010 00025 # 00026 # \brief 00027 # Implementation of ROS node for script_server. 00028 # 00029 ################################################################# 00030 # 00031 # Redistribution and use in source and binary forms, with or without 00032 # modification, are permitted provided that the following conditions are met: 00033 # 00034 # - Redistributions of source code must retain the above copyright 00035 # notice, this list of conditions and the following disclaimer. \n 00036 # - Redistributions in binary form must reproduce the above copyright 00037 # notice, this list of conditions and the following disclaimer in the 00038 # documentation and/or other materials provided with the distribution. \n 00039 # - Neither the name of the Fraunhofer Institute for Manufacturing 00040 # Engineering and Automation (IPA) nor the names of its 00041 # contributors may be used to endorse or promote products derived from 00042 # this software without specific prior written permission. \n 00043 # 00044 # This program is free software: you can redistribute it and/or modify 00045 # it under the terms of the GNU Lesser General Public License LGPL as 00046 # published by the Free Software Foundation, either version 3 of the 00047 # License, or (at your option) any later version. 00048 # 00049 # This program is distributed in the hope that it will be useful, 00050 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00051 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00052 # GNU Lesser General Public License LGPL for more details. 00053 # 00054 # You should have received a copy of the GNU Lesser General Public 00055 # License LGPL along with this program. 00056 # If not, see <http://www.gnu.org/licenses/>. 00057 # 00058 ################################################################# 00059 00060 import time 00061 00062 import roslib 00063 roslib.load_manifest('cob_script_server') 00064 import rospy 00065 import actionlib 00066 00067 from cob_script_server.msg import * 00068 from simple_script_server import * 00069 00070 ## Script server class which inherits from script class. 00071 # 00072 # Implements actionlib interface for the script server. 00073 # 00074 class script_server(script): 00075 ## Initializes the actionlib interface of the script server. 00076 # 00077 def __init__(self): 00078 script.__init__(self) 00079 self.ns_global_prefix = "/script_server" 00080 self.script_action_server = actionlib.SimpleActionServer(self.ns_global_prefix, ScriptAction, self.execute_cb, True) 00081 #time.sleep(1) 00082 00083 #------------------- Actionlib section -------------------# 00084 ## Executes actionlib callbacks. 00085 # 00086 # \param server_goal ScriptActionGoal 00087 # 00088 def execute_cb(self, server_goal): 00089 server_result = ScriptActionResult().result 00090 if server_goal.function_name == "move": 00091 handle01 = self.sss.move(server_goal.component_name,server_goal.parameter_name) 00092 elif server_goal.function_name == "move_cart_rel": 00093 handle01 = self.sss.move(server_goal.component_name,server_goal.parameter_name) 00094 else: 00095 rospy.logerr("function <<%s>> not supported", server_goal.function_name) 00096 self.script_action_server.set_aborted(server_result) 00097 return 00098 00099 server_result.return_value = handle01.get_error_code() 00100 if server_result.return_value == 0: 00101 rospy.logdebug("action result success") 00102 self.script_action_server.set_succeeded(server_result) 00103 else: 00104 rospy.logerr("action result error") 00105 self.script_action_server.set_aborted(server_result) 00106 00107 ## Main routine for running the script server 00108 # 00109 if __name__ == '__main__': 00110 rospy.init_node('script_server') 00111 SCRIPT = script_server() 00112 SCRIPT.Start() 00113 rospy.loginfo("script_server is running") 00114 rospy.spin()