sdf.py
Go to the documentation of this file.
00001 from urdf_parser_py.xml_reflection.basics import *
00002 import urdf_parser_py.xml_reflection as xmlr
00003 
00004 # What is the scope of plugins? Model, World, Sensor?
00005 
00006 xmlr.start_namespace('sdf')
00007 
00008 class Pose(xmlr.Object):
00009         def __init__(self, vec=None, extra=None):
00010                 self.xyz = None
00011                 self.rpy = None
00012                 if vec is not None:
00013                         assert isinstance(vec, list)
00014                         count = len(vec)
00015                         if len == 3:
00016                                 xyz = vec
00017                         else:
00018                                 self.from_vec(vec)
00019                 elif extra is not None:
00020                         assert xyz is None, "Cannot specify 6-length vector and 3-length vector"
00021                         assert len(extra) == 3, "Invalid length"
00022                         self.rpy = extra
00023         
00024         def from_vec(self, vec):
00025                 assert len(vec) == 6, "Invalid length"
00026                 self.xyz = vec[:3]
00027                 self.rpy = vec[3:6]
00028         
00029         def as_vec(self):
00030                 xyz = self.xyz if self.xyz else [0, 0, 0]
00031                 rpy = self.rpy if self.rpy else [0, 0, 0]
00032                 return xyz + rpy
00033         
00034         def read_xml(self, node):
00035                 # Better way to do this? Define type?
00036                 vec = get_type('vector6').read_xml(node)
00037                 self.load_vec(vec)
00038         
00039         def write_xml(self, node):
00040                 vec = self.as_vec()
00041                 get_type('vector6').write_xml(node, vec)
00042         
00043         def check_valid(self):
00044                 assert self.xyz is not None or self.rpy is not None
00045 
00046 name_attribute = xmlr.Attribute('name', str)
00047 pose_element = xmlr.Element('pose', Pose, False)
00048 
00049 class Entity(xmlr.Object):
00050         def __init__(self, name = None, pose = None):
00051                 self.name = name
00052                 self.pose = pose
00053 
00054 xmlr.reflect(Entity, params = [
00055         name_attribute,
00056         pose_element
00057         ])
00058 
00059 
00060 class Inertia(xmlr.Object):
00061         KEYS = ['ixx', 'ixy', 'ixz', 'iyy', 'iyz', 'izz']
00062         
00063         def __init__(self, ixx=0.0, ixy=0.0, ixz=0.0, iyy=0.0, iyz=0.0, izz=0.0):
00064                 self.ixx = ixx
00065                 self.ixy = ixy
00066                 self.ixz = ixz
00067                 self.iyy = iyy
00068                 self.iyz = iyz
00069                 self.izz = izz
00070         
00071         def to_matrix(self):
00072                 return [
00073                         [self.ixx, self.ixy, self.ixz],
00074                         [self.ixy, self.iyy, self.iyz],
00075                         [self.ixz, self.iyz, self.izz]]
00076 
00077 xmlr.reflect(Inertia, params = [xmlr.Element(key, float) for key in Inertia.KEYS])
00078 
00079 # Pretty much copy-paste... Better method?
00080 # Use multiple inheritance to separate the objects out so they are unique?
00081 class Inertial(xmlr.Object):
00082         def __init__(self, mass = 0.0, inertia = None, pose=None):
00083                 self.mass = mass
00084                 self.inertia = inertia
00085                 self.pose = pose
00086 
00087 xmlr.reflect(Inertial, params = [
00088         xmlr.Element('mass', float),
00089         xmlr.Element('inertia', Inertia),
00090         pose_element
00091         ])
00092 
00093 
00094 class Link(Entity):
00095         def __init__(self, name = None, pose = None, inertial = None, kinematic = False):
00096                 Entity.__init__(self, name, pose)
00097                 self.inertial = inertial
00098                 self.kinematic = kinematic
00099 
00100 xmlr.reflect(Link, parent_cls = Entity, params = [
00101         xmlr.Element('inertial', Inertial),
00102         xmlr.Attribute('kinematic', bool, False),
00103         xmlr.AggregateElement('visual', Visual, var = 'visuals'),
00104         xmlr.AggregateElement('collision', Collision, var = 'collisions')
00105         ])
00106 
00107 
00108 class Model(Entity):
00109         def __init__(self, name = None, pose=None):
00110                 Entity.__init__(self, name, pose)
00111                 self.links = []
00112                 self.joints = []
00113                 self.plugins = []
00114 
00115 xmlr.reflect(Model, parent_cls = Entity, params = [
00116         xmlr.AggregateElement('link', Link, var = 'links'),
00117         xmlr.AggregateElement('joint', Joint, var = 'joints'),
00118         xmlr.AggregateElement('plugin', Plugin, var = 'plugins')
00119         ])
00120 
00121 xmlr.end_namespace('sdf')


pr2_calibration_launch
Author(s): Vijay Pradeep
autogenerated on Fri Aug 28 2015 12:06:40