Package rosgraph :: Module rosgraph_main
[frames] | no frames]

Source Code for Module rosgraph.rosgraph_main

  1  #!/usr/bin/env python 
  2  # Software License Agreement (BSD License) 
  3  # 
  4  # Copyright (c) 2008, Willow Garage, Inc. 
  5  # All rights reserved. 
  6  # 
  7  # Redistribution and use in source and binary forms, with or without 
  8  # modification, are permitted provided that the following conditions 
  9  # are met: 
 10  # 
 11  #  * Redistributions of source code must retain the above copyright 
 12  #    notice, this list of conditions and the following disclaimer. 
 13  #  * Redistributions in binary form must reproduce the above 
 14  #    copyright notice, this list of conditions and the following 
 15  #    disclaimer in the documentation and/or other materials provided 
 16  #    with the distribution. 
 17  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 18  #    contributors may be used to endorse or promote products derived 
 19  #    from this software without specific prior written permission. 
 20  # 
 21  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 22  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 23  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 24  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 25  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 26  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 27  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 28  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 29  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 30  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 31  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 32  # POSSIBILITY OF SUCH DAMAGE. 
 33   
 34  from __future__ import print_function 
 35   
 36  import sys 
 37  import time 
 38   
 39  from . import roslogging 
 40  from . import masterapi 
 41   
 42  from .impl import graph 
 43   
44 -def fullusage():
45 print("""rosgraph is a command-line tool for debugging the ROS Computation Graph. 46 47 Usage: 48 \trosgraph 49 """)
50
51 -def rosgraph_main():
52 if len(sys.argv) == 1: 53 pass 54 elif len(sys.argv) == 2 and (sys.argv[1] == '-h' or sys.argv[1] == '--help'): 55 fullusage() 56 return 57 else: 58 fullusage() 59 sys.exit(-1) 60 61 roslogging.configure_logging('rosgraph') 62 63 # make sure master is available 64 master = masterapi.Master('rosgraph') 65 try: 66 master.getPid() 67 except: 68 print("ERROR: Unable to communicate with master!", file=sys.stderr) 69 return 70 71 g = graph.Graph() 72 try: 73 while 1: 74 g.update() 75 76 if not g.nn_nodes and not g.srvs: 77 print("empty") 78 else: 79 print('\n') 80 if g.nn_nodes: 81 print('Nodes:') 82 for n in g.nn_nodes: 83 prefix = n + '|' 84 print(' ' + n + ' :') 85 print(' Inbound:') 86 for k in g.nn_edges.edges_by_end.keys(): 87 if k.startswith(prefix): 88 for c in g.nn_edges.edges_by_end[k]: 89 print(' ' + c.start) 90 print(' Outbound:') 91 for k in g.nn_edges.edges_by_start.keys(): 92 if k.startswith(prefix): 93 for c in g.nn_edges.edges_by_start[k]: 94 print(' ' + c.end) 95 if g.srvs: 96 print('Services:') 97 for s in g.srvs: 98 print(' ' + s) 99 100 time.sleep(1.0) 101 except KeyboardInterrupt: 102 pass
103