Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This code should help accomplish what you want. It will simply print out the entire ROSGraph nodes and edges. You can infer subscribers from here.

#!/usr/bin/env python import roslib; 
roslib.load_manifest('ssnode') import 
rospy import roslib 
import roslib.message
import rosgraph
import rostopic 
from rostopic import ROSTopicHz 
from rosgraph.impl import graph

def mygraph():
    g = graph.Graph()
    try:
        while 1:
          g.update()

          if not g.nn_nodes and not g.srvs:
              print("empty")
          else:
              print('\n')
          if g.nn_nodes:
              print('Nodes:')
              for n in g.nn_nodes:
                  prefix = n + '|'
                  print('  ' + n + ' :')
                  print('    Inbound:')
                  for k in g.nn_edges.edges_by_end.iterkeys():
                      if k.startswith(prefix):
                          for c in g.nn_edges.edges_by_end[k]:
                              print('      ' + c.start + ' label = '

+ c.label) print(' Outbound:') for k in g.nn_edges.edges_by_start.iterkeys(): if k.startswith(prefix): for c in g.nn_edges.edges_by_start[k]: print(' ' + c.end + ' label = ' + c.label) if g.srvs: print('Services:') for s in g.srvs: print(' ' + s) except KeyboardInterrupt: pass

This code should help accomplish what you want. It will simply print out the entire ROSGraph nodes and edges. You can infer subscribers from here.

#!/usr/bin/env python import roslib; 
roslib.load_manifest('ssnode') import 
rospy import roslib 
import roslib.message
import rosgraph
import rostopic 
from rostopic import ROSTopicHz 
from rosgraph.impl import graph

def mygraph():
    g = graph.Graph()
    try:
        while 1:
          g.update()

          if not g.nn_nodes and not g.srvs:
              print("empty")
          else:
              print('\n')
          if g.nn_nodes:
              print('Nodes:')
              for n in g.nn_nodes:
                  prefix = n + '|'
                  print('  ' + n + ' :')
                  print('    Inbound:')
                  for k in g.nn_edges.edges_by_end.iterkeys():
                      if k.startswith(prefix):
                          for c in g.nn_edges.edges_by_end[k]:
                              print('      ' + c.start + ' label = '

' + c.label) print(' Outbound:') for k in g.nn_edges.edges_by_start.iterkeys(): if k.startswith(prefix): for c in g.nn_edges.edges_by_start[k]: print(' ' + c.end + ' label = ' + + c.label) if g.srvs: print('Services:') for s in g.srvs: print(' ' + s) except KeyboardInterrupt: pass

pass
click to hide/show revision 3
Forgot the method call

This code should help accomplish what you want. It will simply print out the entire ROSGraph nodes and edges. You can infer subscribers from here.here. (Sorry about __main__ formatting, apparently I cannot figure it out)

#!/usr/bin/env python import roslib; 
roslib.load_manifest('ssnode') import 
rospy import roslib 
import roslib.message
import rosgraph
import rostopic 
from rostopic import ROSTopicHz 
from rosgraph.impl import graph

def mygraph():
    g = graph.Graph()
    try:
        while 1:
          g.update()

          if not g.nn_nodes and not g.srvs:
              print("empty")
          else:
              print('\n')
          if g.nn_nodes:
              print('Nodes:')
              for n in g.nn_nodes:
                  prefix = n + '|'
                  print('  ' + n + ' :')
                  print('    Inbound:')
                  for k in g.nn_edges.edges_by_end.iterkeys():
                      if k.startswith(prefix):
                          for c in g.nn_edges.edges_by_end[k]:
                              print('      ' + c.start + ' label = ' + c.label)
                  print('    Outbound:')
                  for k in g.nn_edges.edges_by_start.iterkeys():
                      if k.startswith(prefix):
                          for c in g.nn_edges.edges_by_start[k]:
                              print('      ' + c.end + ' label = ' + c.label)
          if g.srvs:
              print('Services:')
              for s in g.srvs:
                  print('  ' + s)
    except KeyboardInterrupt:
        pass

if __name__ == '__main__': try: mygraph() except rospy.ROSInterruptException: pass

This code should help accomplish what you want. It will simply print out the entire ROSGraph nodes and edges. You can infer subscribers from here. (Sorry about __main__ formatting, apparently I cannot figure it out)

 #!/usr/bin/env python import roslib; 
 roslib.load_manifest('ssnode') import 
 rospy import roslib 
 import roslib.message
 import rosgraph
 import rostopic 
 from rostopic import ROSTopicHz 
 from rosgraph.impl import graph

 def mygraph():
     g = graph.Graph()
     try:
         while 1:
           g.update()

           if not g.nn_nodes and not g.srvs:
               print("empty")
           else:
               print('\n')
           if g.nn_nodes:
               print('Nodes:')
               for n in g.nn_nodes:
                   prefix = n + '|'
                   print('  ' + n + ' :')
                   print('    Inbound:')
                   for k in g.nn_edges.edges_by_end.iterkeys():
                       if k.startswith(prefix):
                           for c in g.nn_edges.edges_by_end[k]:
                               print('      ' + c.start + ' label = ' + c.label)
                   print('    Outbound:')
                   for k in g.nn_edges.edges_by_start.iterkeys():
                       if k.startswith(prefix):
                           for c in g.nn_edges.edges_by_start[k]:
                               print('      ' + c.end + ' label = ' + c.label)
           if g.srvs:
               print('Services:')
               for s in g.srvs:
                   print('  ' + s)
     except KeyboardInterrupt:
         pass

if __name__ == '__main__': try: mygraph() except rospy.ROSInterruptException: pass

pass

This code should help accomplish what you want. It will simply print out the entire ROSGraph nodes and edges. You can infer subscribers from here. (Sorry about __main__ formatting, apparently I cannot figure it out)

 #!/usr/bin/env python import roslib; 
 roslib.load_manifest('ssnode') import 
 rospy import roslib 
 import roslib.message
 import rosgraph
 import rostopic 
 from rostopic import ROSTopicHz 
 from rosgraph.impl import graph

 def mygraph():
     g = graph.Graph()
     try:
         while 1:
           g.update()

           if not g.nn_nodes and not g.srvs:
               print("empty")
           else:
               print('\n')
           if g.nn_nodes:
               print('Nodes:')
               for n in g.nn_nodes:
                   prefix = n + '|'
                   print('  ' + n + ' :')
                   print('    Inbound:')
                   for k in g.nn_edges.edges_by_end.iterkeys():
                       if k.startswith(prefix):
                           for c in g.nn_edges.edges_by_end[k]:
                               print('      ' + c.start + ' label = ' + c.label)
                   print('    Outbound:')
                   for k in g.nn_edges.edges_by_start.iterkeys():
                       if k.startswith(prefix):
                           for c in g.nn_edges.edges_by_start[k]:
                               print('      ' + c.end + ' label = ' + c.label)
           if g.srvs:
               print('Services:')
               for s in g.srvs:
                   print('  ' + s)
     except KeyboardInterrupt:
         pass
if __name__ == '__main__':
    try:
        mygraph()
    except rospy.ROSInterruptException: pass