1 from __future__
import print_function
9 Construct a PyKDL.Tree from an URDF file.
10 :param filename: URDF file path
13 with open(filename)
as urdf_file:
18 Construct a PyKDL.Tree from an URDF in a ROS parameter.
19 :param param: Parameter name, ``str``
26 Construct a PyKDL.Tree from an URDF xml string.
27 :param xml: URDF xml string, ``str``
34 rpy = pose.rpy
if pose
and pose.rpy
and len(pose.rpy) == 3
else [0, 0, 0]
35 xyz = pose.xyz
if pose
and pose.xyz
and len(pose.xyz) == 3
else [0, 0, 0]
38 kdl.Rotation.RPY(*rpy),
47 return origin.M * kdl.RigidBodyInertia(
49 kdl.RotationalInertia(inertia.ixx, inertia.iyy, inertia.izz, inertia.ixy, inertia.ixz, inertia.iyz));
53 fixed =
lambda j,F: kdl.Joint(
55 getattr(kdl.Joint,
'Fixed')
if hasattr(kdl.Joint,
'Fixed')
else getattr(kdl.Joint,
'None'))
56 rotational =
lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.RotAxis)
57 translational =
lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.TransAxis)
61 'revolute': rotational,
62 'continuous': rotational,
63 'prismatic': translational,
69 return type_map[jnt.type](jnt,
_toKdlPose(jnt.origin))
75 inert = kdl.RigidBodyInertia(0)
80 (parent_joint_name, parent_link_name) = robot_model.parent_map[root.name]
81 parent_joint = robot_model.joint_map[parent_joint_name]
91 if not tree.addSegment(sgm, parent_link_name):
94 if root.name
not in robot_model.child_map:
97 children = [robot_model.link_map[l]
for (j,l)
in robot_model.child_map[root.name]]
100 for child
in children:
108 Construct a PyKDL.Tree from an URDF model from urdf_parser_python.
110 :param robot_model: URDF xml string, ``str``
111 :param quiet: If true suppress messages to stdout, ``bool``
114 root = robot_model.link_map[robot_model.get_root()]
116 if root.inertial
and not quiet:
117 print(
"The root link %s has an inertia specified in the URDF, but KDL does not support a root link with an inertia. As a workaround, you can add an extra dummy link to your URDF." % root.name);
120 tree = kdl.Tree(root.name)
123 for (joint,child)
in robot_model.child_map[root.name]: