ros_parser.py
Go to the documentation of this file.
00001 import xml.etree.ElementTree as ET
00002 import xml.dom.minidom
00003 from ros_topology import *
00004 # [db] dan@danbrooks.net
00005 #
00006 # Parses ros:v2 xml syntax and generates a RosSystemGraph object
00007 #
00008 # TODO:
00009 # - Sort Nodes intelligently
00010 # - give warnings about topics which are not fully connected (are not connected
00011 #   on one side or another)
00012 #
00013 # BUGS:
00014 # - Topics with / vs without / show up differently
00015 
00016 
00017 def parseFile(filename):
00018     return parseTree(ET.parse(filename))
00019 
00020 def parseTree(tree):
00021     root = tree.getroot()
00022     
00023     ros = RosSystemGraph()
00024 
00025     for xmlNode in root.findall("node"):
00026         # Create new node
00027         node = Node(ros)
00028         node.name = xmlNode.attrib["name"].strip()
00029         node.location = xmlNode.attrib["location"].strip()
00030         node.pid = xmlNode.attrib["pid"].strip()
00031         print "Adding Node",node.name
00032 
00033         # Setup Publishers and Subscribers
00034         # Before we can create a connection, we need to add the topic
00035         # to our SystemGraph. 
00036         for xmlTopic in xmlNode.find("topics"):
00037             name = xmlTopic.attrib["name"]
00038             msgType = xmlTopic.attrib["type"]
00039             # Grab existing topic if available 
00040             topic = None
00041             if (name,msgType) not in ros.topics.keys():
00042                 print "Adding Topic ",name,msgType
00043                 topic = Topic(ros)
00044                 topic.name = name
00045                 topic.msgType = msgType
00046             else:
00047                 topic = ros.topics[(name,msgType)]
00048                 
00049             if xmlTopic.tag == "publishes":
00050                 print "Adding publisher",node.name,topic.name
00051                 conn = Publisher(ros,node,topic)
00052             if xmlTopic.tag == "subscribes":
00053                 print "Adding subscriber",node.name,topic.name
00054                 conn = Subscriber(ros,node,topic)
00055             conn.bandwidth = int(xmlTopic.attrib["bw"].strip())
00056             conn.freq = int(xmlTopic.attrib["freq"].strip())
00057 
00058     return ros


rqt_graphprofiler
Author(s): Dan Brooks
autogenerated on Thu Jun 6 2019 20:29:31