script_server_android.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 
00017 
00018 import time
00019 import inspect
00020 
00021 import rospy
00022 
00023 from cob_android_msgs.srv import *
00024 from simple_script_server import *
00025 
00026 sss = simple_script_server()
00027 
00028 ## Script server class which inherits from script class.
00029 #
00030 # Implements actionlib interface for the script server.
00031 #
00032 class script_server():
00033         ## Initializes the actionlib interface of the script server.
00034         #
00035         def __init__(self):
00036                 rospy.Service('/script_server_android/script_service', Script, self.service_cb)
00037 
00038         def service_cb(self, req):
00039                 res = ScriptResponse()
00040                 if req.function_name == "trigger":
00041                         if req.parameter_name == "init":
00042                                 handle01 = sss.init(req.component_name, blocking=False)
00043                         elif req.parameter_name == "stop":
00044                                 handle01 = sss.stop(req.component_name, mode=req.mode, blocking=False)
00045                         elif req.parameter_name == "recover":
00046                                 handle01 = sss.recover(req.component_name, blocking=False)
00047                         elif req.parameter_name == "halt":
00048                                 handle01 = sss.halt(req.component_name, blocking=False)
00049                         elif req.parameter_name == "compose_trajectory":
00050                                 handle01 = sss.compose_trajectory(req.component_name, req.parameter_name)
00051                         else:
00052                                 handle01 = sss.trigger(req.component_name, req.parameter_name, blocking=False)
00053                 elif req.function_name == "move":
00054                         handle01 = sss.move(req.component_name,req.parameter_name, blocking=False, mode=req.mode)
00055                 elif req.function_name == "move_base_rel":
00056                         handle01 = sss.move_base_rel(req.component_name,req. parameter_name, blocking=False)
00057                 elif req.function_name == "light":
00058                         handle01 = sss.set_light(req.component_name, req.parameter_name, blocking=False)
00059                 elif req.function_name == "stop":
00060                         handle01 = sss.stop(req.component_name, blocking=False)
00061                 elif req.function_name == "init":
00062                         handle01 = sss.init(req.component_name, blocking=False)
00063                 elif req.function_name == "recover":
00064                         handle01 = sss.recover(req.component_name, blocking=False)
00065                 elif req.function_name == "halt":
00066                         handle01 = sss.halt(req.component_name, blocking=False)
00067                 elif req.function_name == "compose_trajectory":
00068                         handle01 = sss.compose_trajectory(req.component_name, req.parameter_name)
00069                 elif req.function_name == "trigger_action":
00070                         handle01 = sss.trigger_action(req.component_name, req.parameter_name)
00071                 else:
00072                                 rospy.logerr("function <<%s>> not supported", req.function_name)
00073                                 res.error_code = -1
00074                                 return res
00075 
00076                 res.error_code = handle01.get_error_code()
00077                 if res.error_code == 0:
00078                         rospy.logdebug("service result success")
00079                 else:
00080                         rospy.logerr("service result error")
00081                 return res
00082 
00083 ## Main routine for running the script server
00084 #
00085 def script_server_android_main():
00086         rospy.init_node('script_server')
00087         script_server()
00088         rospy.loginfo("script_server is running")
00089         rospy.spin()


cob_android_script_server
Author(s): Benjamin Maidel
autogenerated on Thu Jun 6 2019 21:46:26