Exemplo n.º 1
0
 def start_logging_cb(self):
     master.addMachine('default', rospy.getRosRoot(), 'localhost', 22, '','')
     #print self.nodes
     #print self.flows
     for i in range(0, len(self.cb)):
         #            print self.cbval[i].get()
         if self.cbval[i].get() == 1:
             master.setParam('logging_node%s.name'%i,'hello_world')
             master.addNode('', 'logging_node%s'%i,'roslogger', 'logging_node','default',0)
             master.connectFlow(self.flows[i][0], 'logging_node%s.input'%i, 1)
     
     print "This will eventually start up nodes as specified and all"
Exemplo n.º 2
0
    def start_logging_cb(self):
        master.addMachine('default', rospy.getRosRoot(), 'localhost', 22, '',
                          '')
        #print self.nodes
        #print self.flows
        for i in range(0, len(self.cb)):
            #            print self.cbval[i].get()
            if self.cbval[i].get() == 1:
                master.setParam('logging_node%s.name' % i, 'hello_world')
                master.addNode('', 'logging_node%s' % i, 'roslogger',
                               'logging_node', 'default', 0)
                master.connectFlow(self.flows[i][0],
                                   'logging_node%s.input' % i, 1)

        print "This will eventually start up nodes as specified and all"
Exemplo n.º 3
0
def renderGraphMain(argv, stdout, env):
    # default arguments
    server = "http://localhost"
    server_port = rospy.DEFAULT_TEST_PORT

    #check arguments for a help flag
    optlist, args = getopt.getopt(argv[1:], "h?p:s:",
                                  ["help", "port=", "server=", "test"])
    for o, a in optlist:
        if o in ("-h", "-?", "--help"):
            usage(stdout, argv[0])
            return
        elif o in ("--test"):
            server_port = rospy.DEFAULT_TEST_PORT
        elif o in ("-p", "--port"):
            server_port = a
        elif o in ("-s", "--server"):
            server = a

    serverUri = '%s:%s/' % (server, server_port)
    print "Looking for server at %s" % serverUri
    os.environ[rospy.ROS_MASTER_URI] = serverUri
    os.environ[rospy.ROS_NODE] = NAME
    os.environ[rospy.ROS_PORT] = str(0)  # any

    master = rospy.getMaster()

    out_FlowImageString = OutflowpyImageString(".imageOut")
    require(
        master.addMachine('default', rospy.getRosRoot(), 'localhost', 22, '',
                          ''))
    require(
        master.addNode('', 'imageViewer', 'pyImageViewer', 'imageViewer',
                       'default', 0))

    rospy.ready()

    require(
        master.connectFlow(out_FlowImageString.locator, "imageViewer:imageIn",
                           1))
    while not rospy.isShutdown():
        status_code, statusMessage, [nodes, flows] = master.getGraph()
        #        print 'nodes' + str(nodes)
        #        print 'flows ' + str(flows)

        print '--------------------------------------------'
        print 'This is the graph:'
        print 'refreshing every ' + str(sleep_time) + ' seconds'
        print '--------------------------------------------'

        for anode in nodes:
            status_code, statusMessage, [machine, address,
                                         port] = master.getNodeAddress(anode)
            print 'NODE: ' + str(anode) + ' on ' + str(machine) + ' at ' + str(
                address) + ' on port: ' + str(port)
            for aflow in flows:
                aflow_split = str(aflow[1]).split('.')
                destination = aflow_split[0]
                aflow_split_source = str(aflow[0]).split('.')
                source = aflow_split_source[0]
                if destination == anode:
                    print '\tINFLOW: ' + str(aflow_split[1]) + ' from: ' + str(
                        aflow[0])
                if source == anode:
                    print '\tOUTFLOW: ' + str(
                        aflow_split_source[1]) + ' to: ' + str(aflow[1])

        output_file = 'ROSGraph.jpeg'
        pid = os.fork(
        )  # This is a hack to get around an underlying memory leak in
        # the agraph library.
        if pid == 0:
            #print "starting yapgvb process"
            try:
                print '--------------------------------------------'
                ygraph = yapgvb.Digraph('ROSGraph')
                gnodes = {}
                for anode in nodes:
                    gnodes[anode] = ygraph.add_node(label=anode)
                #print "added allnodes"
                #print flows
                for aflow in flows:
                    aflow_split = str(aflow[1]).split(':')
                    destination = aflow_split[0]
                    aflow_split_source = str(aflow[0]).split(':')
                    source = aflow_split_source[0]
                    gnodes[source] >> gnodes[destination]
                #print "done setting up graph for rendering"
                ygraph.layout(yapgvb.engines.dot)
                ygraph.render(output_file)
            finally:
                mpid = os.getpid()
                os.kill(mpid, 9)
        else:
            os.wait()

        # Wrap up the image and send it out over a flow
        imToSend = Image.open(output_file)

        future_packet = pyImageString()
        future_packet.imageString = imToSend.tostring()

        future_packet.imageFormat = "RGB"
        future_packet.width, future_packet.height = imToSend.size

        out_FlowImageString.publish(future_packet)

        # don't loop too fast
        time.sleep(sleep_time)
Exemplo n.º 4
0
def renderGraphMain(argv, stdout, env):
    # default arguments
    server = "http://localhost"
    server_port = rospy.DEFAULT_TEST_PORT

    #check arguments for a help flag
    optlist, args = getopt.getopt(argv[1:], "h?p:s:", ["help","port=","server=","test"])
    for o, a in optlist:
        if o in ("-h","-?","--help"):
            usage(stdout, argv[0])
            return
        elif o in ("--test"):
            server_port = rospy.DEFAULT_TEST_PORT
        elif o in ("-p", "--port"):
            server_port = a
        elif o in ("-s", "--server"):
            server = a


    serverUri = '%s:%s/'%(server,server_port)
    print "Looking for server at %s"%serverUri
    os.environ[rospy.ROS_MASTER_URI] = serverUri
    os.environ[rospy.ROS_NODE] = NAME
    os.environ[rospy.ROS_PORT] = str(0) # any

            
    master = rospy.getMaster()

    out_FlowImageString = OutflowpyImageString(".imageOut")
    require(master.addMachine('default', rospy.getRosRoot(), 'localhost', 22, '', ''))
    require(master.addNode('','imageViewer','pyImageViewer','imageViewer','default',0))

    rospy.ready()

    require(master.connectFlow(out_FlowImageString.locator, "imageViewer:imageIn",1))
    while not rospy.isShutdown():
        status_code, statusMessage, [nodes,flows] = master.getGraph()
        #        print 'nodes' + str(nodes)
        #        print 'flows ' + str(flows)
        
        print '--------------------------------------------'
        print 'This is the graph:'
        print 'refreshing every '+str(sleep_time)+' seconds'
        print '--------------------------------------------'
        
        for anode in nodes:
            status_code, statusMessage, [machine, address, port] = master.getNodeAddress(anode)
            print 'NODE: ' + str(anode) + ' on ' + str(machine) + ' at ' + str(address) + ' on port: ' + str(port)
            for aflow in flows:
                aflow_split= str(aflow[1]).split('.')
                destination = aflow_split[0]
                aflow_split_source = str(aflow[0]).split('.')
                source = aflow_split_source[0]
                if destination == anode:
                    print '\tINFLOW: ' + str(aflow_split[1]) + ' from: ' + str(aflow[0])
                if source == anode:
                    print '\tOUTFLOW: ' + str(aflow_split_source[1]) + ' to: ' + str(aflow[1])

        output_file = 'ROSGraph.jpeg'
        pid = os.fork()  # This is a hack to get around an underlying memory leak in
        # the agraph library.  
        if pid == 0:
            #print "starting yapgvb process"
            try:
                print '--------------------------------------------'
                ygraph = yapgvb.Digraph('ROSGraph');
                gnodes = {}
                for anode in nodes:
                    gnodes[anode] = ygraph.add_node(label = anode)
                #print "added allnodes"
                #print flows
                for aflow in flows:
                    aflow_split= str(aflow[1]).split(':')
                    destination = aflow_split[0]
                    aflow_split_source = str(aflow[0]).split(':')
                    source = aflow_split_source[0]
                    gnodes[source] >> gnodes[destination]
                #print "done setting up graph for rendering"
                ygraph.layout(yapgvb.engines.dot)
                ygraph.render(output_file)
            finally:
                mpid = os.getpid()
                os.kill(mpid,9)
        else:
            os.wait()
            
        # Wrap up the image and send it out over a flow
        imToSend = Image.open(output_file)

        future_packet = pyImageString()
        future_packet.imageString = imToSend.tostring()

        future_packet.imageFormat = "RGB"
        future_packet.width, future_packet.height = imToSend.size

        out_FlowImageString.publish(future_packet)

        # don't loop too fast
        time.sleep(sleep_time)