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')
urdf_parser_py.sdf.Inertial
Definition: sdf.py:89
urdf_parser_py.sdf.Pose
Definition: sdf.py:9
urdf_parser_py.sdf.Model.plugins
plugins
Definition: sdf.py:123
urdf_parser_py.sdf.Entity.__init__
def __init__(self, name=None, pose=None)
Definition: sdf.py:53
urdf_parser_py.sdf.Inertial.mass
mass
Definition: sdf.py:91
urdf_parser_py.sdf.Pose.from_vec
def from_vec(self, vec)
Definition: sdf.py:25
urdf_parser_py.sdf.Pose.check_valid
def check_valid(self)
Definition: sdf.py:44
urdf_parser_py.sdf.Inertial.__init__
def __init__(self, mass=0.0, inertia=None, pose=None)
Definition: sdf.py:90
urdf_parser_py.sdf.Model
Definition: sdf.py:118
urdf_parser_py.sdf.Model.joints
joints
Definition: sdf.py:122
urdf_parser_py.sdf.Inertia.iyz
iyz
Definition: sdf.py:72
urdf_parser_py.sdf.Entity
Definition: sdf.py:52
urdf_parser_py.sdf.Pose.read_xml
def read_xml(self, node)
Definition: sdf.py:35
urdf_parser_py.sdf.Pose.as_vec
def as_vec(self)
Definition: sdf.py:30
urdf_parser_py.sdf.Entity.name
name
Definition: sdf.py:54
urdf_parser_py.xml_reflection
Definition: xml_reflection/__init__.py:1
urdf_parser_py.sdf.Inertia.to_matrix
def to_matrix(self)
Definition: sdf.py:75
urdf_parser_py.sdf.Inertia.ixy
ixy
Definition: sdf.py:69
urdf_parser_py.sdf.Inertia.iyy
iyy
Definition: sdf.py:71
urdf_parser_py.sdf.Model.links
links
Definition: sdf.py:121
urdf_parser_py.sdf.Inertia.ixz
ixz
Definition: sdf.py:70
urdf_parser_py.xml_reflection.core.get_type
def get_type(cur_type)
Definition: core.py:65
urdf_parser_py.sdf.Inertia.__init__
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
urdf_parser_py.sdf.Entity.pose
pose
Definition: sdf.py:55
urdf_parser_py.sdf.Pose.write_xml
def write_xml(self, node)
Definition: sdf.py:40
urdf_parser_py.sdf.Pose.rpy
rpy
Definition: sdf.py:12
urdf_parser_py.sdf.Inertia.izz
izz
Definition: sdf.py:73
urdf_parser_py.xml_reflection.basics
Definition: basics.py:1
urdf_parser_py.sdf.Inertia
Definition: sdf.py:64
urdf_parser_py.sdf.Pose.__init__
def __init__(self, vec=None, extra=None)
Definition: sdf.py:10
urdf_parser_py.sdf.Model.__init__
def __init__(self, name=None, pose=None)
Definition: sdf.py:119
urdf_parser_py.sdf.Inertial.inertia
inertia
Definition: sdf.py:92
urdf_parser_py.sdf.Pose.xyz
xyz
Definition: sdf.py:11
urdf_parser_py.sdf.Inertial.pose
pose
Definition: sdf.py:93
urdf_parser_py.sdf.Inertia.ixx
ixx
Definition: sdf.py:68


urdfdom_py
Author(s): Thomas Moulard, David Lu, Kelsey Hawkins, Antonio El Khoury, Eric Cousineau, Ioan Sucan , Jackie Kay
autogenerated on Wed Mar 2 2022 01:08:39