sdf.py
Go to the documentation of this file.
3 
4 # What is the scope of plugins? Model, World, Sensor?
5 
6 xmlr.start_namespace('sdf')
7 
8 
9 class Pose(xmlr.Object):
10  def __init__(self, vec=None, extra=None):
11  self.xyz = None
12  self.rpy = None
13  if vec is not None:
14  assert isinstance(vec, list)
15  count = len(vec)
16  if len == 3:
17  xyz = vec
18  else:
19  self.from_vec(vec)
20  elif extra is not None:
21  assert xyz is None, "Cannot specify 6-length vector and 3-length vector" # noqa
22  assert len(extra) == 3, "Invalid length"
23  self.rpy = extra
24 
25  def from_vec(self, vec):
26  assert len(vec) == 6, "Invalid length"
27  self.xyz = vec[:3]
28  self.rpy = vec[3:6]
29 
30  def as_vec(self):
31  xyz = self.xyz if self.xyz else [0, 0, 0]
32  rpy = self.rpy if self.rpy else [0, 0, 0]
33  return xyz + rpy
34 
35  def read_xml(self, node):
36  # Better way to do this? Define type?
37  vec = get_type('vector6').read_xml(node)
38  self.load_vec(vec)
39 
40  def write_xml(self, node):
41  vec = self.as_vec()
42  get_type('vector6').write_xml(node, vec)
43 
44  def check_valid(self):
45  assert self.xyz is not None or self.rpy is not None
46 
47 
48 name_attribute = xmlr.Attribute('name', str)
49 pose_element = xmlr.Element('pose', Pose, False)
50 
51 
52 class Entity(xmlr.Object):
53  def __init__(self, name=None, pose=None):
54  self.name = name
55  self.pose = pose
56 
57 
58 xmlr.reflect(Entity, params=[
59  name_attribute,
60  pose_element
61 ])
62 
63 
64 class Inertia(xmlr.Object):
65  KEYS = ['ixx', 'ixy', 'ixz', 'iyy', 'iyz', 'izz']
66 
67  def __init__(self, ixx=0.0, ixy=0.0, ixz=0.0, iyy=0.0, iyz=0.0, izz=0.0):
68  self.ixx = ixx
69  self.ixy = ixy
70  self.ixz = ixz
71  self.iyy = iyy
72  self.iyz = iyz
73  self.izz = izz
74 
75  def to_matrix(self):
76  return [
77  [self.ixx, self.ixy, self.ixz],
78  [self.ixy, self.iyy, self.iyz],
79  [self.ixz, self.iyz, self.izz]]
80 
81 
82 xmlr.reflect(Inertia,
83  params=[xmlr.Element(key, float) for key in Inertia.KEYS])
84 
85 # Pretty much copy-paste... Better method?
86 # Use multiple inheritance to separate the objects out so they are unique?
87 
88 
89 class Inertial(xmlr.Object):
90  def __init__(self, mass=0.0, inertia=None, pose=None):
91  self.mass = mass
92  self.inertia = inertia
93  self.pose = pose
94 
95 
96 xmlr.reflect(Inertial, params=[
97  xmlr.Element('mass', float),
98  xmlr.Element('inertia', Inertia),
99  pose_element
100 ])
101 
102 
103 class Link(Entity):
104  def __init__(self, name=None, pose=None, inertial=None, kinematic=False):
105  Entity.__init__(self, name, pose)
106  self.inertial = inertial
107  self.kinematic = kinematic
108 
109 
110 xmlr.reflect(Link, parent_cls=Entity, params=[
111  xmlr.Element('inertial', Inertial),
112  xmlr.Attribute('kinematic', bool, False),
113  xmlr.AggregateElement('visual', Visual, var='visuals'),
114  xmlr.AggregateElement('collision', Collision, var='collisions')
115 ])
116 
117 
118 class Model(Entity):
119  def __init__(self, name=None, pose=None):
120  Entity.__init__(self, name, pose)
121  self.links = []
122  self.joints = []
123  self.plugins = []
124 
125 
126 xmlr.reflect(Model, parent_cls=Entity, params=[
127  xmlr.AggregateElement('link', Link, var='links'),
128  xmlr.AggregateElement('joint', Joint, var='joints'),
129  xmlr.AggregateElement('plugin', Plugin, var='plugins')
130 ])
131 
132 xmlr.end_namespace('sdf')
def read_xml(self, node)
Definition: sdf.py:35
def __init__(self, name=None, pose=None)
Definition: sdf.py:53
def from_vec(self, vec)
Definition: sdf.py:25
def __init__(self, ixx=0.0, ixy=0.0, ixz=0.0, iyy=0.0, iyz=0.0, izz=0.0)
Definition: sdf.py:67
def __init__(self, mass=0.0, inertia=None, pose=None)
Definition: sdf.py:90
def __init__(self, vec=None, extra=None)
Definition: sdf.py:10
def __init__(self, name=None, pose=None)
Definition: sdf.py:119
def write_xml(self, node)
Definition: sdf.py:40
def as_vec(self)
Definition: sdf.py:30
def check_valid(self)
Definition: sdf.py:44
def to_matrix(self)
Definition: sdf.py:75


urdfdom_py
Author(s): Thomas Moulard, David Lu, Kelsey Hawkins, Antonio El Khoury, Eric Cousineau, Ioan Sucan , Jackie Kay
autogenerated on Mon Jun 10 2019 15:36:23