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


pr2_calibration_launch
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:59