1
import xml.etree.ElementTree as ET
3
from Grasp import Grasp
9
Parses a XML file describing a grasp.
16
def parse_tree(self, xml_filename="grasps.xml"):
18
parses a given tree, returns a Grasp
21
xml_filename -- the filename where the grasp is defined
22
if no filename is provided, then the default
27
self.xml_tree = ET.parse(xml_filename)
28
except Exception, inst:
29
print "Unexpected error opening %s: %s" % (xml_filename, inst)
32
tree_root = self.xml_tree.getroot()
33
tree_grasp = tree_root.findall("grasp")
35
for grasp in tree_grasp:
37
grasp_tmp.grasp_name = grasp.attrib.get("name")
39
print "Grasp "+ grasp_tmp.grasp_name
41
joints = grasp.findall("joint")
43
joint_name = j.attrib.get("name")
44
joint_position = float(j.text)
46
print " "+ joint_name + ": "+ str(joint_position)
48
grasp_tmp.joints_and_positions.update({joint_name:joint_position})
50
self.grasps.update({grasp_tmp.grasp_name: grasp_tmp})
52
############################
53
# MAIN - simple test #
54
############################
56
parser = GraspParser()
63
if __name__ == "__main__":