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 modes_to_standby_nonrosh.py
00035
00036 This script is used to bring additional control modes to standby. It also necessarily brings the
00037 controller to operational first.
00038
00039 This replaces the original modes_to_standby rosh nodelet and doesn't depend on rosh and its many
00040 dependencies.
00041
00042 Usage:
00043 rosrun flyer_common/modes_to_standby_nonrosh.py_modes:='mode_1 mode_2 ...'
00044 """
00045 import roslib
00046 roslib.load_manifest('flyer_common')
00047 roslib.load_manifest('flyer_controller')
00048 import rospy
00049 from rospy import loginfo
00050 import rosgraph
00051 from flyer_controller.msg import controller_cmd
00052 from flyer_controller.msg import control_mode_cmd
00053
00054
00055 def get_node_subscriptions(master, node_name):
00056 pubs, subs, svcs = master.getSystemState()
00057 node_subs = []
00058 for topic, subscribers in subs:
00059 if node_name in subscribers:
00060 node_subs.append(topic)
00061 return node_subs
00062
00063 def resolve(name):
00064 return rosgraph.names.resolve_name(name, '')
00065
00066 def is_node_subscribed_to_topic(master, node_name, topic_name):
00067 return resolve(topic_name) in get_node_subscriptions(master, node_name)
00068
00069 rospy.init_node('modes_to_standby')
00070
00071 ns = rospy.get_namespace()
00072 loginfo("namespace: " + ns)
00073 stby_modes = rospy.get_param('~modes').split()
00074 loginfo('The following modes will be brought to STANDBY: %s' % stby_modes)
00075 rospy.sleep(5.0)
00076 rospy.loginfo('Bringing nodes to standby...')
00077
00078 manager_node_name = resolve(ns + 'manager')
00079
00080 master = rosgraph.Master('')
00081
00082 print get_node_subscriptions(master, manager_node_name)
00083
00084 while not (is_node_subscribed_to_topic(master, ns + 'manager', ns + 'controller/cmd')
00085 or is_node_subscribed_to_topic(master, ns + 'controller', ns + 'controller/cmd')):
00086 loginfo('waiting for manager (or controller) to subscribe to controller_cmd...')
00087 rospy.sleep(1.0)
00088
00089 loginfo('I see manager subscribed to controller/cmd, proceeding..')
00090
00091
00092 ccmd_pub = rospy.Publisher(ns + 'controller/cmd', controller_cmd, latch=True)
00093 ccmd_pub.publish(controller_cmd('mode operational'))
00094
00095 rospy.sleep(3.0)
00096
00097
00098 for stby_mode in stby_modes:
00099 loginfo('Bringing mode %s to STANDBY...' % stby_mode)
00100 ccmd_pub.publish(control_mode_cmd('control_mode to_standby %s' % stby_mode))
00101 rospy.sleep(2.0)
00102
00103 loginfo('modes_to_standby script finished')