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 import roslib; roslib.load_manifest('application_client')
00038 import rospy
00039 import actionlib
00040 import sys
00041
00042 from application_msgs.msg import RunApplicationAction, RunApplicationGoal
00043
00044 class ApplicationClient:
00045 def __init__(self):
00046 self.client = actionlib.SimpleActionClient('application_manager/run_application', RunApplicationAction)
00047 self.client.wait_for_server()
00048
00049
00050 rospy.on_shutdown(self.shutdown)
00051
00052 self.application_name = rospy.get_param('~application_name')
00053 self.daemonize = rospy.get_param('~daemonize', False)
00054
00055 self.intentional_shutdown = False
00056
00057 def run_application(self):
00058 if self.application_name is None:
00059 rospy.logerr("You are attempting to run an application client without giving it the name \
00060 of an application to launch. This won't work, this client won't do anything.")
00061 return
00062
00063 goal = RunApplicationGoal()
00064 goal.daemonize = self.daemonize
00065 goal.application_name = self.application_name
00066 self.client.send_goal(goal, self.goal_done)
00067
00068 def goal_done(self, terminal_state, result):
00069 if not self.intentional_shutdown:
00070 rospy.logwarn("The application associated with this client shut down without the client requesting it")
00071 sys.exit(0)
00072
00073 def shutdown(self):
00074 rospy.loginfo("Shutting down application before the node is killed")
00075 self.intentional_shutdown = True
00076 self.client.cancel_goal()
00077 self.client.wait_for_result()
00078 rospy.loginfo("Sent shut down signal to application")
00079 sys.exit(0)
00080
00081 def main():
00082 rospy.init_node('application_client')
00083 app_client = ApplicationClient()
00084 app_client.run_application()
00085 rospy.spin()
00086
00087 if __name__ == '__main__':
00088 main()