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()
srdfdom.srdf.Robot.group_map
group_map
Definition: srdf.py:176
srdfdom.srdf.GroupState.group
group
Definition: srdf.py:144
srdfdom.srdf.Group
Definition: srdf.py:121
srdfdom.srdf.PassiveJoint.name
name
Definition: srdf.py:102
srdfdom.srdf.Robot.add_passive_joint
def add_passive_joint(self, joint)
Definition: srdf.py:201
srdfdom.srdf.Group.name
name
Definition: srdf.py:124
srdfdom.srdf.VirtualJoint.parent_frame
parent_frame
Definition: srdf.py:56
srdfdom.srdf.Chain
Definition: srdf.py:76
srdfdom.srdf.Robot.group_states
group_states
Definition: srdf.py:170
srdfdom.srdf.EndEffector.parent_group
parent_group
Definition: srdf.py:91
srdfdom.srdf.Robot
Definition: srdf.py:164
srdfdom.srdf.Robot.name
name
Definition: srdf.py:168
srdfdom.srdf.VirtualJoint
Definition: srdf.py:50
srdfdom.srdf.Robot.group_state_map
group_state_map
Definition: srdf.py:177
srdfdom.srdf.Robot.add_joint
def add_joint(self, joint)
Definition: srdf.py:192
srdfdom.srdf.JointVal.__init__
def __init__(self, name=None, value=[])
Definition: srdf.py:28
srdfdom.srdf.JointVal.name
name
Definition: srdf.py:29
srdfdom.srdf.Robot.virtual_joints
virtual_joints
Definition: srdf.py:172
srdfdom.srdf.GroupState.joints
joints
Definition: srdf.py:143
srdfdom.srdf.EndEffector.__init__
def __init__(self, name=None, group=None, parent_link=None, parent_group=None)
Definition: srdf.py:87
srdfdom.srdf.VirtualJoint.name
name
Definition: srdf.py:54
srdfdom.srdf.Joint
Definition: srdf.py:19
srdfdom.srdf.VirtualJoint.child_link
child_link
Definition: srdf.py:55
srdfdom.srdf.Sphere.radius
radius
Definition: srdf.py:40
srdfdom.srdf.EndEffector.group
group
Definition: srdf.py:89
srdfdom.srdf.PassiveJoint.__init__
def __init__(self, name=None)
Definition: srdf.py:101
srdfdom.srdf.VirtualJoint.check_valid
def check_valid(self)
Definition: srdf.py:59
srdfdom.srdf.Robot.add_chain
def add_chain(self, chain)
Definition: srdf.py:195
srdfdom.srdf.Chain.tip_link
tip_link
Definition: srdf.py:79
srdfdom.srdf.Robot.add_aggregate
def add_aggregate(self, typeName, elem)
Definition: srdf.py:179
urdf_parser_py::xml_reflection
srdfdom.srdf.Robot.from_parameter_server
def from_parameter_server(cls, key='robot_description_semantic')
Definition: srdf.py:212
srdfdom.srdf.GroupState.__init__
def __init__(self, name=None, group=None)
Definition: srdf.py:140
srdfdom.srdf.VirtualJoint.__init__
def __init__(self, name=None, child_link=None, parent_frame=None, joint_type=None)
Definition: srdf.py:53
srdfdom.srdf.LinkSphereApproximation.link
link
Definition: srdf.py:156
srdfdom.srdf.GroupState
Definition: srdf.py:139
srdfdom.srdf.GroupState.name
name
Definition: srdf.py:142
srdfdom.srdf.Group.__init__
def __init__(self, name=None)
Definition: srdf.py:122
srdfdom.srdf.JointVal
Definition: srdf.py:27
srdfdom.srdf.JointVal.value
value
Definition: srdf.py:30
srdfdom.srdf.DisableCollisions
Definition: srdf.py:108
srdfdom.srdf.LinkSphereApproximation.spheres
spheres
Definition: srdf.py:157
srdfdom.srdf.Robot.disable_collisionss
disable_collisionss
Definition: srdf.py:173
srdfdom.srdf.Group.links
links
Definition: srdf.py:125
srdfdom.srdf.Group.joints
joints
Definition: srdf.py:126
srdfdom.srdf.DisableCollisions.link1
link1
Definition: srdf.py:110
srdfdom.srdf.Sphere.__init__
def __init__(self, center=None, radius=0.0)
Definition: srdf.py:38
srdfdom.srdf.DisableCollisions.link2
link2
Definition: srdf.py:111
srdfdom.srdf.Joint.__init__
def __init__(self, name=None)
Definition: srdf.py:20
srdfdom.srdf.DisableCollisions.__init__
def __init__(self, link1=None, link2=None, reason=None)
Definition: srdf.py:109
srdfdom.srdf.Chain.__init__
def __init__(self, base_link=None, tip_link=None)
Definition: srdf.py:77
srdfdom.srdf.Robot.__init__
def __init__(self, name=None)
Definition: srdf.py:165
srdfdom.srdf.VirtualJoint.joint_type
def joint_type(self)
Definition: srdf.py:64
srdfdom.srdf.VirtualJoint.TYPES
TYPES
Definition: srdf.py:51
srdfdom.srdf.Joint.name
name
Definition: srdf.py:21
srdfdom.srdf.Sphere
Definition: srdf.py:37
srdfdom.srdf.Robot.link_sphere_approximations
link_sphere_approximations
Definition: srdf.py:175
srdfdom.srdf.Robot.end_effectors
end_effectors
Definition: srdf.py:171
srdfdom.srdf.Robot.add_link_sphere_approximation
def add_link_sphere_approximation(self, link)
Definition: srdf.py:207
urdf_parser_py::xml_reflection::basics
srdfdom.srdf.DisableCollisions.reason
reason
Definition: srdf.py:112
srdfdom.srdf.Robot.add_link
def add_link(self, link)
Definition: srdf.py:189
srdfdom.srdf.Sphere.center
center
Definition: srdf.py:39
srdfdom.srdf.Robot.add_disable_collisions
def add_disable_collisions(self, col)
Definition: srdf.py:204
srdfdom.srdf.LinkSphereApproximation.__init__
def __init__(self, link=None)
Definition: srdf.py:154
srdfdom.srdf.PassiveJoint
Definition: srdf.py:100
srdfdom.srdf.Group.chains
chains
Definition: srdf.py:127
srdfdom.srdf.Robot.passive_joints
passive_joints
Definition: srdf.py:174
srdfdom.srdf.LinkSphereApproximation
Definition: srdf.py:153
srdfdom.srdf.Chain.base_link
base_link
Definition: srdf.py:78
srdfdom.srdf.Group.subgroups
subgroups
Definition: srdf.py:129
srdfdom.srdf.EndEffector
Definition: srdf.py:86
srdfdom.srdf.Robot.groups
groups
Definition: srdf.py:169
srdfdom.srdf.EndEffector.parent_link
parent_link
Definition: srdf.py:90
srdfdom.srdf.EndEffector.name
name
Definition: srdf.py:88
srdfdom.srdf.Group.groups
groups
Definition: srdf.py:128
srdfdom.srdf.Robot.add_group
def add_group(self, group)
Definition: srdf.py:198
srdfdom.srdf.VirtualJoint.type
type
Definition: srdf.py:57


srdfdom
Author(s): Ioan Sucan , Guillaume Walck
autogenerated on Wed Oct 16 2024 02:22:59