8 xmlr.start_namespace(
'urdf')
10 xmlr.add_type(
'element_link', xmlr.SimpleElementType(
'link', str))
11 xmlr.add_type(
'element_xyz', xmlr.SimpleElementType(
'xyz',
'vector3'))
15 class Pose(xmlr.Object):
16 def __init__(self, xyz=None, rpy=None):
20 def check_valid(self):
21 assert self.xyz
is not None or self.rpy
is not None 25 def rotation(self):
return self.rpy
27 def rotation(self, value): self.rpy = value
31 def position(self, value): self.xyz = value
33 xmlr.reflect(Pose, params = [
34 xmlr.Attribute(
'xyz',
'vector3',
False),
35 xmlr.Attribute(
'rpy',
'vector3',
False)
40 name_attribute = xmlr.Attribute(
'name', str)
41 origin_element = xmlr.Element(
'origin', Pose,
False)
43 class Color(xmlr.Object):
44 def __init__(self, *args):
47 if count == 4
or count == 3:
53 if self.rgba
is not None:
54 if len(self.rgba) == 3:
56 if len(self.rgba) != 4:
57 raise Exception(
'Invalid color argument count')
59 xmlr.reflect(Color, params = [
60 xmlr.Attribute(
'rgba',
'vector4')
65 def __init__(self, damping=None, friction=None):
66 self.damping = damping
67 self.friction = friction
69 xmlr.reflect(JointDynamics, params = [
70 xmlr.Attribute(
'damping', float,
False),
71 xmlr.Attribute(
'friction', float,
False)
75 class Box(xmlr.Object):
76 def __init__(self, size = None):
79 xmlr.reflect(Box, params = [
80 xmlr.Attribute(
'size',
'vector3')
85 def __init__(self, radius = 0.0, length = 0.0):
89 xmlr.reflect(Cylinder, params = [
90 xmlr.Attribute(
'radius', float),
91 xmlr.Attribute(
'length', float)
96 def __init__(self, radius=0.0):
99 xmlr.reflect(Sphere, params = [
100 xmlr.Attribute(
'radius', float)
104 class Mesh(xmlr.Object):
105 def __init__(self, filename = None, scale = None):
106 self.filename = filename
109 xmlr.reflect(Mesh, params = [
110 xmlr.Attribute(
'filename', str),
111 xmlr.Attribute(
'scale',
'vector3', required=
False)
117 self.factory = xmlr.FactoryType(
'geometric', {
119 'cylinder': Cylinder,
124 def from_xml(self, node):
125 children = xml_children(node)
126 assert len(children) == 1,
'One element only for geometric' 127 return self.factory.from_xml(children[0])
129 def write_xml(self, node, obj):
130 name = self.factory.get_name(obj)
131 child = node_add(node, name)
137 def __init__(self, geometry = None, origin = None):
138 self.geometry = geometry
141 xmlr.reflect(Collision, params = [
143 xmlr.Element(
'geometry',
'geometric')
148 def __init__(self, filename = None):
149 self.filename = filename
151 xmlr.reflect(Texture, params = [
152 xmlr.Attribute(
'filename', str)
157 def __init__(self, name=None, color=None, texture=None):
160 self.texture = texture
162 def check_valid(self):
163 if self.color
is None and self.texture
is None:
164 xmlr.on_error(
"Material has neither a color nor texture")
166 xmlr.reflect(Material, params = [
168 xmlr.Element(
'color', Color,
False),
169 xmlr.Element(
'texture', Texture,
False)
173 class Visual(xmlr.Object):
174 def __init__(self, geometry = None, material = None, origin = None):
175 self.geometry = geometry
176 self.material = material
179 xmlr.reflect(Visual, params = [
181 xmlr.Element(
'geometry',
'geometric'),
182 xmlr.Element(
'material', Material,
False)
187 KEYS = [
'ixx',
'ixy',
'ixz',
'iyy',
'iyz',
'izz']
189 def __init__(self, ixx=0.0, ixy=0.0, ixz=0.0, iyy=0.0, iyz=0.0, izz=0.0):
199 [self.ixx, self.ixy, self.ixz],
200 [self.ixy, self.iyy, self.iyz],
201 [self.ixz, self.iyz, self.izz]]
203 xmlr.reflect(Inertia, params = [xmlr.Attribute(key, float)
for key
in Inertia.KEYS])
207 def __init__(self, mass = 0.0, inertia = None, origin=None):
209 self.inertia = inertia
212 xmlr.reflect(Inertial, params = [
214 xmlr.Element(
'mass',
'element_value'),
215 xmlr.Element(
'inertia', Inertia,
False)
222 def __init__(self, rising=None, falling=None):
224 self.falling = falling
226 xmlr.reflect(JointCalibration, params = [
227 xmlr.Attribute(
'rising', float,
False),
228 xmlr.Attribute(
'falling', float,
False)
232 def __init__(self, effort=None, velocity=None, lower=None, upper=None):
234 self.velocity = velocity
238 xmlr.reflect(JointLimit, params = [
239 xmlr.Attribute(
'effort', float),
240 xmlr.Attribute(
'lower', float,
False, 0),
241 xmlr.Attribute(
'upper', float,
False, 0),
242 xmlr.Attribute(
'velocity', float)
247 def __init__(self, joint_name=None, multiplier=None, offset=None):
248 self.joint = joint_name
249 self.multiplier = multiplier
252 xmlr.reflect(JointMimic, params = [
253 xmlr.Attribute(
'joint', str),
254 xmlr.Attribute(
'multiplier', float,
False),
255 xmlr.Attribute(
'offset', float,
False)
259 def __init__(self, velocity=None, position=None, lower=None, upper=None):
260 self.k_velocity = velocity
261 self.k_position = position
262 self.soft_lower_limit = lower
263 self.soft_upper_limit = upper
265 xmlr.reflect(SafetyController, params = [
266 xmlr.Attribute(
'k_velocity', float),
267 xmlr.Attribute(
'k_position', float,
False, 0),
268 xmlr.Attribute(
'soft_lower_limit', float,
False, 0),
269 xmlr.Attribute(
'soft_upper_limit', float,
False, 0)
272 class Joint(xmlr.Object):
273 TYPES = [
'unknown',
'revolute',
'continuous',
'prismatic',
'floating',
'planar',
'fixed']
275 def __init__(self, name=None, parent=None, child=None, joint_type=None,
276 axis=
None, origin=
None,
277 limit=
None, dynamics=
None, safety_controller=
None, calibration=
None,
282 self.type = joint_type
286 self.dynamics = dynamics
287 self.safety_controller = safety_controller
288 self.calibration = calibration
291 def check_valid(self):
292 assert self.type
in self.TYPES,
"Invalid joint type: {}".format(self.type)
296 def joint_type(self):
return self.type
298 def joint_type(self, value): self.type = value
300 xmlr.reflect(Joint, params = [
302 xmlr.Attribute(
'type', str),
304 xmlr.Element(
'axis',
'element_xyz',
False),
305 xmlr.Element(
'parent',
'element_link'),
306 xmlr.Element(
'child',
'element_link'),
307 xmlr.Element(
'limit', JointLimit,
False),
308 xmlr.Element(
'dynamics', JointDynamics,
False),
309 xmlr.Element(
'safety_controller', SafetyController,
False),
310 xmlr.Element(
'calibration', JointCalibration,
False),
311 xmlr.Element(
'mimic', JointMimic,
False)
315 class Link(xmlr.Object):
316 def __init__(self, name=None, visual=None, inertial=None, collision=None, origin = None):
319 self.inertial = inertial
320 self.collision = collision
323 xmlr.reflect(Link, params = [
326 xmlr.Element(
'inertial', Inertial,
False),
327 xmlr.Element(
'visual', Visual,
False),
328 xmlr.Element(
'collision', Collision,
False)
333 def __init__(self, name = None, hardwareInterface = None, mechanicalReduction = 1):
335 self.hardwareInterface =
None 336 self.mechanicalReduction =
None 338 xmlr.reflect(Actuator, tag =
'actuator', params = [
340 xmlr.Element(
'hardwareInterface', str),
341 xmlr.Element(
'mechanicalReduction', float, required =
False)
345 def __init__(self, name = None, joint = None, actuator = None):
348 self.actuator = actuator
350 xmlr.reflect(Transmission, tag =
'new_transmission', params = [
352 xmlr.Attribute(
'type', str),
353 xmlr.Element(
'joint',
'element_name'),
354 xmlr.Element(
'actuator', Actuator),
358 def __init__(self, k_belt=4000.0, kd_motor=10.0, lambda_combined=0.0, lambda_joint=60.0, lambda_motor=60.0, mass_motor=0.05):
366 xmlr.reflect(PR2Compensator, tag =
'compensator', params = [
367 xmlr.Attribute(
'k_belt', float),
368 xmlr.Attribute(
'kd_motor', float),
369 xmlr.Attribute(
'lambda_combined', float),
370 xmlr.Attribute(
'lambda_joint', float),
371 xmlr.Attribute(
'lambda_motor', float),
372 xmlr.Attribute(
'mass_motor', float)
376 def __init__(self, name = None, simulated_reduction = 3000, passive_actuated_joint = None):
381 xmlr.reflect(PR2SimulatedActuatedJoint, tag =
'simulated_actuated_joint', params = [
383 xmlr.Attribute(
'simulated_reduction', float),
384 xmlr.Attribute(
'passive_actuated_joint', str,
False)
388 def __init__(self, name = None, joint = None, actuator = None, mechanicalReduction = None, compensator = None, simulated_actuated_joint = None):
391 self.actuator = actuator
392 self.mechanicalReduction = mechanicalReduction
393 self.compensator = compensator
394 self.simulated_actuated_joint = simulated_actuated_joint
396 xmlr.reflect(PR2Transmission, tag =
'pr2_transmission', params = [
398 xmlr.Attribute(
'type', str),
399 xmlr.Element(
'joint',
'element_name'),
400 xmlr.Element(
'actuator',
'element_name'),
401 xmlr.Element(
'mechanicalReduction', float),
402 xmlr.Element(
'compensator', PR2Compensator,
False),
403 xmlr.Element(
'simulated_actuated_joint', PR2SimulatedActuatedJoint,
False)
407 def __init__(self, name = None, mechanicalReduction = 1):
411 xmlr.reflect(PR2Actuator, tag =
'pr2_actuator', params = [
413 xmlr.Attribute(
'mechanicalReduction', float)
417 def __init__(self, name = None, type = None, rightActuator = None, leftActuator = None, flexJoint = None, rollJoint = None):
425 xmlr.reflect(PR2WristTransmission, tag =
'pr2_wrist_transmission', params = [
427 xmlr.Attribute(
'type', str),
428 xmlr.Element(
'rightActuator', PR2Actuator),
429 xmlr.Element(
'leftActuator', PR2Actuator),
430 xmlr.Element(
'flexJoint', PR2Actuator),
431 xmlr.Element(
'rollJoint', PR2Actuator)
436 def __init__(self, L0=0.0, a=0.0, b=0.0, gear_ratio=40.0, h=0.0, mechanical_reduction=1.0, name=None, phi0=0.5, r=0.0, screw_reduction=0.0, t0=0.0, theta0=0.0):
450 xmlr.reflect(PR2GapJoint, tag =
'pr2_gap_joint', params = [
451 xmlr.Attribute(
'L0', float),
452 xmlr.Attribute(
'a', float),
453 xmlr.Attribute(
'b', float),
454 xmlr.Attribute(
'gear_ratio', float),
455 xmlr.Attribute(
'h', float),
456 xmlr.Attribute(
'mechanical_reduction', float),
457 xmlr.Attribute(
'name', str),
458 xmlr.Attribute(
'phi0', float),
459 xmlr.Attribute(
'r', float), 460 xmlr.Attribute('screw_reduction', float),
461 xmlr.Attribute(
't0', float),
462 xmlr.Attribute(
'theta0', float)
466 def __init__(self, name = None, type = None, actuator = None, gap_joint = None, use_simulated_gripper_joint = None, passive_joint = [], simulated_actuated_joint = None):
467 self.aggregate_init()
476 xmlr.reflect(PR2GripperTransmission, tag =
'pr2_gripper_transmission', params = [
478 xmlr.Attribute(
'type', str),
479 xmlr.Element(
'actuator',
'element_name'),
480 xmlr.Element(
'gap_joint', PR2GapJoint),
481 xmlr.Element(
'use_simulated_gripper_joint',
'element_name'),
482 xmlr.AggregateElement(
'passive_joint',
'element_name',
'passive_joint'),
483 xmlr.Element(
'simulated_actuated_joint', PR2SimulatedActuatedJoint),
487 xmlr.add_type(
'transmission', xmlr.DuckTypedFactory(
'transmission', [Transmission, PR2Transmission, PR2WristTransmission, PR2GripperTransmission]))
490 class Robot(xmlr.Object):
492 self.aggregate_init()
499 self.transmissions = []
507 def add_aggregate(self, typeName, elem):
508 xmlr.Object.add_aggregate(self, typeName, elem)
510 if typeName ==
'joint':
512 self.joint_map[joint.name] = joint
513 self.parent_map[ joint.child ] = (joint.name, joint.parent)
514 if joint.parent
in self.child_map:
515 self.child_map[joint.parent].append( (joint.name, joint.child) )
517 self.child_map[joint.parent] = [ (joint.name, joint.child) ]
518 elif typeName ==
'link':
520 self.link_map[link.name] = link
522 def add_link(self, link):
523 self.add_aggregate(
'link', link)
525 def add_joint(self, joint):
526 self.add_aggregate(
'joint', joint)
528 def get_chain(self, root, tip, joints=True, links=True, fixed=True):
534 (joint, parent) = self.parent_map[link]
536 if fixed
or self.joint_map[joint].joint_type !=
'fixed':
546 for link
in self.link_map:
547 if link
not in self.parent_map:
548 assert root
is None,
"Multiple roots detected, invalid URDF." 550 assert root
is not None,
"No roots detected, invalid URDF." 554 def from_parameter_server(cls, key = 'robot_description'):
556 Retrieve the robot model on the parameter server 557 and parse it to create a URDF robot structure. 559 Warning: this requires roscore to be running. 563 return cls.from_xml_string(rospy.get_param(key))
565 xmlr.reflect(Robot, tag =
'robot', params = [
567 xmlr.Attribute(
'name', str,
False),
568 xmlr.AggregateElement(
'link', Link),
569 xmlr.AggregateElement(
'joint', Joint),
570 xmlr.AggregateElement(
'gazebo', xmlr.RawType()),
571 xmlr.AggregateElement(
'transmission',
'transmission'),
572 xmlr.AggregateElement(
'material', Material)
def __init__(self, name=None, type=None, rightActuator=None, leftActuator=None, flexJoint=None, rollJoint=None)
def __init__(self, name=None, type=None, actuator=None, gap_joint=None, use_simulated_gripper_joint=None, passive_joint=[], simulated_actuated_joint=None)
use_simulated_gripper_joint
def __init__(self, name=None, simulated_reduction=3000, passive_actuated_joint=None)
def __init__(self, name=None, mechanicalReduction=1)
def __init__(self, L0=0.0, a=0.0, b=0.0, gear_ratio=40.0, h=0.0, mechanical_reduction=1.0, name=None, phi0=0.5, r=0.0, screw_reduction=0.0, t0=0.0, theta0=0.0)
def __init__(self, k_belt=4000.0, kd_motor=10.0, lambda_combined=0.0, lambda_joint=60.0, lambda_motor=60.0, mass_motor=0.05)