1
+ # Copyright 2019 Open Source Robotics Foundation, Inc.
2
+ # All rights reserved.
3
+ #
4
+ # Software License Agreement (BSD License 2.0)
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions
8
+ # are met:
9
+ #
10
+ # * Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # * Redistributions in binary form must reproduce the above
13
+ # copyright notice, this list of conditions and the following
14
+ # disclaimer in the documentation and/or other materials provided
15
+ # with the distribution.
16
+ # * Neither the name of the copyright holder nor the names of its
17
+ # contributors may be used to endorse or promote products derived
18
+ # from this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23
+ # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
+ # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
+ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
+ # POSSIBILITY OF SUCH DAMAGE.
1
32
from __future__ import print_function
2
33
3
34
import urdf_parser_py .urdf as urdf
7
38
def treeFromFile (filename ):
8
39
"""
9
40
Construct a PyKDL.Tree from an URDF file.
41
+
10
42
:param filename: URDF file path
11
43
"""
12
-
13
44
with open (filename ) as urdf_file :
14
45
return treeFromUrdfModel (urdf .URDF .from_xml_string (urdf_file .read ()))
15
46
16
47
def treeFromParam (param ):
17
48
"""
18
49
Construct a PyKDL.Tree from an URDF in a ROS parameter.
50
+
19
51
:param param: Parameter name, ``str``
20
52
"""
21
-
22
53
return treeFromUrdfModel (urdf .URDF .from_parameter_server ())
23
54
24
55
def treeFromString (xml ):
25
56
"""
26
57
Construct a PyKDL.Tree from an URDF xml string.
58
+
27
59
:param xml: URDF xml string, ``str``
28
60
"""
29
-
30
61
return treeFromUrdfModel (urdf .URDF .from_xml_string (xml ))
31
62
32
63
def _toKdlPose (pose ):
@@ -49,8 +80,7 @@ def _toKdlInertia(i):
49
80
kdl .RotationalInertia (inertia .ixx , inertia .iyy , inertia .izz , inertia .ixy , inertia .ixz , inertia .iyz ));
50
81
51
82
def _toKdlJoint (jnt ):
52
-
53
- fixed = lambda j ,F : kdl .Joint (j .name , kdl .Joint .None )
83
+ fixed = lambda j ,F : kdl .Joint (j .name , kdl .Joint .JointType (8 ))
54
84
rotational = lambda j ,F : kdl .Joint (j .name , F .p , F .M * kdl .Vector (* j .axis ), kdl .Joint .RotAxis )
55
85
translational = lambda j ,F : kdl .Joint (j .name , F .p , F .M * kdl .Vector (* j .axis ), kdl .Joint .TransAxis )
56
86
@@ -67,8 +97,6 @@ def _toKdlJoint(jnt):
67
97
return type_map [jnt .type ](jnt , _toKdlPose (jnt .origin ))
68
98
69
99
def _add_children_to_tree (robot_model , root , tree ):
70
-
71
-
72
100
# constructs the optional inertia
73
101
inert = kdl .RigidBodyInertia (0 )
74
102
if root .inertial :
@@ -108,7 +136,6 @@ def treeFromUrdfModel(robot_model, quiet=False):
108
136
:param robot_model: URDF xml string, ``str``
109
137
:param quiet: If true suppress messages to stdout, ``bool``
110
138
"""
111
-
112
139
root = robot_model .link_map [robot_model .get_root ()]
113
140
114
141
if root .inertial and not quiet :
0 commit comments