srdf.py
Go to the documentation of this file.
3 
4 xmlr.start_namespace('srdf')
5 
6 verbose = True
7 
8 # Common stuff
9 name_attribute = xmlr.Attribute('name', str)
10 
11 class Link(xmlr.Object):
12  def __init__(self, name = None):
13  self.name = name
14 
15 xmlr.reflect(Link, params = [
16  name_attribute
17  ])
18 
19 class Joint(xmlr.Object):
20  def __init__(self, name = None):
21  self.name = name
22 
23 xmlr.reflect(Joint, params = [
24  name_attribute
25  ])
26 
27 class JointVal(xmlr.Object):
28  def __init__(self, name = None, value = []):
29  self.name = name
30  self.value = value
31 
32 xmlr.reflect(JointVal, params = [
33  name_attribute,
34  xmlr.Attribute('value', "vector")
35  ])
36 
37 class Sphere(xmlr.Object):
38  def __init__(self, center = None, radius = 0.0):
39  self.center = center
40  self.radius = radius
41 
42 xmlr.reflect(Sphere, params = [
43  xmlr.Attribute('center', str),
44  xmlr.Attribute('radius', float)
45  ])
46 
47 # Common stuff again
48 link_element = xmlr.Element('link', Link, False)
49 
50 class VirtualJoint(xmlr.Object):
51  TYPES = ['unknown', 'fixed', 'floating', 'planar']
52 
53  def __init__(self, name = None, child_link = None, parent_frame = None, joint_type = None):
54  self.name = name
55  self.child_link = child_link
56  self.parent_frame = parent_frame
57  self.type = joint_type
58 
59  def check_valid(self):
60  assert self.type in self.TYPES, "Invalid joint type: {}".format(self.type)
61 
62  # Aliases
63  @property
64  def joint_type(self): return self.type
65  @joint_type.setter
66  def joint_type(self, value): self.type = value
67 
68 xmlr.reflect(VirtualJoint, params = [
69  name_attribute,
70  xmlr.Attribute('child_link', str),
71  xmlr.Attribute('parent_frame', str),
72  xmlr.Attribute('type', str)
73  ])
74 
75 
76 class Chain(xmlr.Object):
77  def __init__(self, base_link = None, tip_link = None):
78  self.base_link = base_link
79  self.tip_link = tip_link
80 
81 xmlr.reflect(Chain, params = [
82  xmlr.Attribute('base_link', str),
83  xmlr.Attribute('tip_link', str)
84  ])
85 
86 class EndEffector(xmlr.Object):
87  def __init__(self, name = None, group = None, parent_link = None, parent_group = None):
88  self.name = name
89  self.group = group
90  self.parent_link = parent_link
91  self.parent_group = parent_group
92 
93 xmlr.reflect(EndEffector, params = [
94  name_attribute,
95  xmlr.Attribute('group', str),
96  xmlr.Attribute('parent_link', str),
97  xmlr.Attribute('parent_group', str, False)
98  ])
99 
100 class PassiveJoint(xmlr.Object):
101  def __init__(self, name = None):
102  self.name = name
103 
104 xmlr.reflect(PassiveJoint, params = [
105  name_attribute
106  ])
107 
108 class DisableCollisions(xmlr.Object):
109  def __init__(self, link1 = None, link2 = None, reason = None):
110  self.link1 = link1
111  self.link2 = link2
112  self.reason = reason
113 
114 xmlr.reflect(DisableCollisions, params = [
115  xmlr.Attribute('link1', str),
116  xmlr.Attribute('link2', str),
117  xmlr.Attribute('reason', str, False)
118  ])
119 
120 
121 class Group(xmlr.Object):
122  def __init__(self, name = None):
123  self.aggregate_init()
124  self.name = name
125  self.links = []
126  self.joints = []
127  self.chains = []
128  self.groups = []
129  self.subgroups = self.groups
130 
131 xmlr.reflect(Group, params = [
132  name_attribute,
133  xmlr.AggregateElement('link', Link),
134  xmlr.AggregateElement('joint', Joint),
135  xmlr.AggregateElement('chain', Chain),
136  xmlr.AggregateElement('group', Group)
137  ])
138 
139 class GroupState(xmlr.Object):
140  def __init__(self, name = None, group = None):
141  self.aggregate_init()
142  self.name = name
143  self.joints = []
144  self.group = group
145 
146 xmlr.reflect(GroupState, params = [
147  name_attribute,
148  xmlr.AggregateElement('joint', JointVal),
149  xmlr.Attribute('group', str)
150  ])
151 
152 
153 class LinkSphereApproximation(xmlr.Object):
154  def __init__(self, link = None):
155  self.aggregate_init()
156  self.link = link
157  self.spheres = []
158 
159 xmlr.reflect(LinkSphereApproximation, params = [
160  xmlr.Attribute('link', str),
161  xmlr.AggregateElement('sphere', Sphere)
162  ])
163 
164 class Robot(xmlr.Object):
165  def __init__(self, name = None):
166  self.aggregate_init()
167 
168  self.name = name
169  self.groups = []
170  self.group_states = []
171  self.end_effectors = []
172  self.virtual_joints = []
174  self.passive_joints = []
176  self.group_map = {}
177  self.group_state_map = {}
178 
179  def add_aggregate(self, typeName, elem):
180  xmlr.Object.add_aggregate(self, typeName, elem)
181 
182  if typeName == 'group':
183  group = elem
184  self.group_map[group.name] = group
185  elif typeName == 'group_state':
186  group_state = elem
187  self.group_state_map[group_state.name] = group_state
188 
189  def add_link(self, link):
190  self.add_aggregate('link', link)
191 
192  def add_joint(self, joint):
193  self.add_aggregate('joint', joint)
194 
195  def add_chain(self, chain):
196  self.add_aggregate('chain', chain)
197 
198  def add_group(self, group):
199  self.add_aggregate('group', group)
200 
201  def add_passive_joint(self, joint):
202  self.add_aggregate('passive_joint', joint)
203 
204  def add_disable_collisions(self, col):
205  self.add_aggregate('disable_collisions', col)
206 
208  self.add_aggregate('link_sphere_approximation', link)
209 
210 
211  @classmethod
212  def from_parameter_server(cls, key = 'robot_description_semantic'):
213  """
214  Retrieve the robot semantic model on the parameter server
215  and parse it to create a SRDF robot structure.
216 
217  Warning: this requires roscore to be running.
218  """
219  # Could move this into xml_reflection
220  import rospy
221  return cls.from_xml_string(rospy.get_param(key))
222 
223 xmlr.reflect(Robot, tag = 'robot', params = [
224 # name_attribute,
225  xmlr.Attribute('name', str, False), # Is 'name' a required attribute?
226  xmlr.AggregateElement('group', Group),
227  xmlr.AggregateElement('group_state', GroupState),
228  xmlr.AggregateElement('end_effector', EndEffector),
229  xmlr.AggregateElement('virtual_joint', VirtualJoint),
230  xmlr.AggregateElement('passive_joint', PassiveJoint),
231  xmlr.AggregateElement('disable_collisions', DisableCollisions),
232  xmlr.AggregateElement('link_sphere_approximation', LinkSphereApproximation)
233  ])
234 
235 # Make an alias
236 SRDF = Robot
237 
238 xmlr.end_namespace()
def add_aggregate(self, typeName, elem)
Definition: srdf.py:179
def add_group(self, group)
Definition: srdf.py:198
link_sphere_approximations
Definition: srdf.py:175
def from_parameter_server(cls, key='robot_description_semantic')
Definition: srdf.py:212
def add_joint(self, joint)
Definition: srdf.py:192
def joint_type(self)
Definition: srdf.py:64
def __init__(self, name=None)
Definition: srdf.py:20
def add_disable_collisions(self, col)
Definition: srdf.py:204
def __init__(self, base_link=None, tip_link=None)
Definition: srdf.py:77
def add_link(self, link)
Definition: srdf.py:189
def __init__(self, center=None, radius=0.0)
Definition: srdf.py:38
def __init__(self, link=None)
Definition: srdf.py:154
def check_valid(self)
Definition: srdf.py:59
def __init__(self, name=None)
Definition: srdf.py:165
def add_passive_joint(self, joint)
Definition: srdf.py:201
def __init__(self, name=None, group=None)
Definition: srdf.py:140
def add_link_sphere_approximation(self, link)
Definition: srdf.py:207
def __init__(self, name=None, value=[])
Definition: srdf.py:28
def add_chain(self, chain)
Definition: srdf.py:195
def __init__(self, name=None, child_link=None, parent_frame=None, joint_type=None)
Definition: srdf.py:53
def __init__(self, link1=None, link2=None, reason=None)
Definition: srdf.py:109
def __init__(self, name=None, group=None, parent_link=None, parent_group=None)
Definition: srdf.py:87
def __init__(self, name=None)
Definition: srdf.py:122
def __init__(self, name=None)
Definition: srdf.py:101


srdfdom
Author(s): Ioan Sucan , Guillaume Walck
autogenerated on Mon Jun 10 2019 15:06:23