master_info.py
Go to the documentation of this file.
00001 #
00002 # License: BSD
00003 #   https://raw.github.com/robotics-in-concert/rocon_tools/license/LICENSE
00004 #
00005 ##############################################################################
00006 # Imports
00007 ##############################################################################
00008 
00009 import os
00010 import sys
00011 import rospy
00012 import rocon_python_comms
00013 import rocon_python_utils
00014 import rocon_console.console as rocon_console
00015 import rocon_std_msgs.msg as rocon_std_msgs
00016 
00017 ##############################################################################
00018 # Methods
00019 ##############################################################################
00020 
00021 
00022 def get_master_info(timeout=1.0):
00023     '''
00024       Tries to gather the rocon master info but if not available, return
00025       with useful information explaining that it could not be found.
00026 
00027       :param double timeout: how long to blather around looking for the master info topic.
00028 
00029       :return master_info: a rocon_std_msgs.MasterInfo() object
00030     '''
00031     # default values
00032     master_info = rocon_std_msgs.MasterInfo()
00033     master_info.name = "Unknown Master"
00034     master_info.description = "Unknown"
00035     master_info.version = rocon_std_msgs.Strings.ROCON_VERSION
00036     master_info.icon = rocon_python_utils.ros.icon_resource_to_msg('rocon_icons/unknown.png')
00037 
00038     try:
00039         topic_name = rocon_python_comms.find_topic('rocon_std_msgs/MasterInfo', timeout=rospy.rostime.Duration(timeout), unique=True)
00040     except rocon_python_comms.NotFoundException as e:
00041         print(rocon_console.red + "failed to find unique topic of type 'rocon_std_msgs/MasterInfo' [%s]" % str(e) + rocon_console.reset)
00042         master_info.description = "Is it rocon enabled? See http://wiki.ros.org/rocon_master_info"
00043         return master_info
00044 
00045     master_info_proxy = rocon_python_comms.SubscriberProxy(topic_name, rocon_std_msgs.MasterInfo)
00046     try:
00047         master_info_proxy.wait_for_publishers()
00048     except rospy.exceptions.ROSInterruptException:
00049         rospy.logwarn("Concert Info : ros shut down before rocon master info could be retrieved.")
00050         master_info.description = "Unkonwn"
00051         return master_info
00052 
00053     result = master_info_proxy(rospy.Duration(0.2))
00054     if result:
00055         master_info = result  # rocon_std_msgs.MasterInfo
00056     return master_info
00057 
00058 
00059 ##############################################################################
00060 # Main
00061 ##############################################################################
00062 
00063 def console_only_main(node_name='master_info', title='Master Information'):
00064     '''
00065       Establishes a connection and prints master information to the console.
00066     '''
00067 
00068     rospy.init_node(node_name)
00069     master_info = get_master_info()
00070 #     display_available = True if 'DISPLAY' in os.environ.keys() else False
00071 
00072     rocon_console.pretty_println(title, rocon_console.bold)
00073     print(rocon_console.cyan + "  Name       : " + rocon_console.yellow + master_info.name + rocon_console.reset)
00074     print(rocon_console.cyan + "  Description: " + rocon_console.yellow + master_info.description + rocon_console.reset)
00075     print(rocon_console.cyan + "  Icon       : " + rocon_console.yellow + master_info.icon.resource_name + rocon_console.reset)
00076     print(rocon_console.cyan + "  Version    : " + rocon_console.yellow + master_info.version + rocon_console.reset)
00077 
00078 
00079 def main(node_name='master_info', title='Master Information', console=True):
00080     display_available = True if 'DISPLAY' in os.environ.keys() else False
00081     try:
00082         import rocon_qt_master_info
00083         from rqt_gui.main import Main
00084         qt_available = True
00085     except ImportError:
00086         qt_available = False
00087         if display_available and not console:
00088             print(rocon_console.red + "WARNING: rqt plugin not found, console output only (hint: install rocon_qt_master_info)." + rocon_console.reset)
00089 
00090     if console or not display_available or not qt_available:
00091         console_only_main(node_name, title)
00092     else:
00093         main = Main()
00094         sys.exit(main.main(argv=sys.argv, standalone='rocon_qt_master_info'))


rocon_master_info
Author(s): Daniel Stonier
autogenerated on Fri May 2 2014 10:35:44