Skip to content

Commit ef2ff8a

Browse files
committed
Port kdl_parser_py to ROS 2
1 parent 77d8ab5 commit ef2ff8a

12 files changed

+206
-59
lines changed

kdl_parser_py/CMakeLists.txt

-22
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.
32+
from kdl_parser_py import *

kdl_parser_py/kdl_parser_py/urdf.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
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.
132
from __future__ import print_function
233

334
import urdf_parser_py.urdf as urdf
@@ -7,26 +38,26 @@
738
def treeFromFile(filename):
839
"""
940
Construct a PyKDL.Tree from an URDF file.
41+
1042
:param filename: URDF file path
1143
"""
12-
1344
with open(filename) as urdf_file:
1445
return treeFromUrdfModel(urdf.URDF.from_xml_string(urdf_file.read()))
1546

1647
def treeFromParam(param):
1748
"""
1849
Construct a PyKDL.Tree from an URDF in a ROS parameter.
50+
1951
:param param: Parameter name, ``str``
2052
"""
21-
2253
return treeFromUrdfModel(urdf.URDF.from_parameter_server())
2354

2455
def treeFromString(xml):
2556
"""
2657
Construct a PyKDL.Tree from an URDF xml string.
58+
2759
:param xml: URDF xml string, ``str``
2860
"""
29-
3061
return treeFromUrdfModel(urdf.URDF.from_xml_string(xml))
3162

3263
def _toKdlPose(pose):
@@ -49,8 +80,7 @@ def _toKdlInertia(i):
4980
kdl.RotationalInertia(inertia.ixx, inertia.iyy, inertia.izz, inertia.ixy, inertia.ixz, inertia.iyz));
5081

5182
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))
5484
rotational = lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.RotAxis)
5585
translational = lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.TransAxis)
5686

@@ -67,8 +97,6 @@ def _toKdlJoint(jnt):
6797
return type_map[jnt.type](jnt, _toKdlPose(jnt.origin))
6898

6999
def _add_children_to_tree(robot_model, root, tree):
70-
71-
72100
# constructs the optional inertia
73101
inert = kdl.RigidBodyInertia(0)
74102
if root.inertial:
@@ -108,7 +136,6 @@ def treeFromUrdfModel(robot_model, quiet=False):
108136
:param robot_model: URDF xml string, ``str``
109137
:param quiet: If true suppress messages to stdout, ``bool``
110138
"""
111-
112139
root = robot_model.link_map[robot_model.get_root()]
113140

114141
if root.inertial and not quiet:

kdl_parser_py/package.xml

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<package>
1+
<package format="3">
22
<name>kdl_parser_py</name>
33
<version>2.3.0</version>
44
<description>
@@ -19,16 +19,19 @@
1919
<url type="repository">https://github.com/ros2/kdl_parser</url>
2020
<url type="bugtracker">https://github.com/ros2/kdl_parser/issues</url>
2121

22-
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
23-
<buildtool_depend>python-catkin-pkg</buildtool_depend>
2422

25-
<build_depend version_gte="1.3.0">orocos_kdl</build_depend>
26-
<build_depend>urdf</build_depend>
27-
<build_depend>rostest</build_depend>
23+
<depend>version_gte="1.4.0">orocos_kdl</depend>
24+
<depend>urdf</depend>
25+
<depend>rostest</depend>
26+
<depend>urdfdom_py</depend>
27+
<depend>python_orocos_kdl</depend>
2828

29-
<run_depend version_gte="1.3.0">orocos_kdl</run_depend>
30-
<run_depend>urdf</run_depend>
31-
<run_depend>urdfdom_py</run_depend>
32-
<run_depend>python_orocos_kdl</run_depend>
29+
<test_depend>ament_copyright</test_depend>
30+
<test_depend>ament_flake8</test_depend>
31+
<test_depend>ament_pep257</test_depend>
32+
<test_depend>python3-pytest</test_depend>
3333

34+
<export>
35+
<build_type>ament_python</build_type>
36+
</export>
3437
</package>
File renamed without changes.

kdl_parser_py/setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[develop]
2+
script-dir=$base/lib/kdl_parser_py
3+
[install]
4+
install-scripts=$base/lib/kdl_parser_py

kdl_parser_py/setup.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
#!/usr/bin/env python
1+
from setuptools import setup
22

3-
from distutils.core import setup
4-
from catkin_pkg.python_setup import generate_distutils_setup
3+
package_name = 'kdl_parser_py'
54

6-
d = generate_distutils_setup(
7-
packages=['kdl_parser_py'],
8-
package_dir={'': ''}
5+
setup(
6+
name=package_name,
7+
version='2.3.0',
8+
packages=[package_name],
9+
data_files=[
10+
('share/ament_index/resource_index/packages',
11+
['resource/' + package_name]),
12+
('share/' + package_name, ['package.xml']),
13+
('share/' + package_name, ['test/test.urdf'])
14+
],
15+
install_requires=['setuptools'],
16+
zip_safe=True,
17+
maintainer='Chris Lalancette',
18+
maintainer_email='[email protected]"',
19+
description='The Kinematics and Dynamics Library (KDL)'
20+
'defines a tree structure to represent the kinematic and'
21+
'dynamic parameters of a robot mechanism. <tt>kdl_parser_py</tt>'
22+
'provides Python tools to construct a KDL tree from an XML robot representation in URDF.',
23+
license='BSD',
24+
tests_require=['pytest'],
25+
entry_points={
26+
'console_scripts': [
27+
],
28+
},
929
)
10-
11-
setup(**d)

kdl_parser_py/test/test_copyright.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2015 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_copyright.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.copyright
20+
@pytest.mark.linter
21+
def test_copyright():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found errors'

kdl_parser_py/test/test_flake8.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2017 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_flake8.main import main_with_errors
16+
import pytest
17+
18+
19+
@pytest.mark.flake8
20+
@pytest.mark.linter
21+
def test_flake8():
22+
rc, errors = main_with_errors(argv=[])
23+
assert rc == 0, \
24+
'Found %d code style errors / warnings:\n' % len(errors) + \
25+
'\n'.join(errors)

kdl_parser_py/test/test_kdl_parser.launch

-3
This file was deleted.

kdl_parser_py/test/test_kdl_parser.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
#!/usr/bin/env python
22

3+
# Copyright 2021 Open Source Robotics Foundation, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
import sys
18+
import os
419

520
import kdl_parser_py.urdf
621
import unittest
7-
8-
import rostest
22+
from ament_index_python.packages import get_package_share_directory
923

1024
PKG = "kdl_parser_py"
1125
NAME = "test_kdl_parser"
1226

1327
class TestKdlParser(unittest.TestCase):
1428
def runTest(self):
15-
filename = None
16-
if (sys.argv > 1):
17-
filename = sys.argv[1]
18-
else:
19-
self.fail("Expected filename!")
29+
# filename = None
30+
# if (sys.argv > 1):
31+
# filename = sys.argv[1]
32+
# else:
33+
# self.fail("Expected filename!")
34+
package_dir = get_package_share_directory(PKG)
35+
36+
filename = os.path.join(package_dir, "test.urdf")
2037
(ok, tree) = kdl_parser_py.urdf.treeFromFile(filename)
2138
self.assertTrue(ok)
2239
# KDL doesn't count fixed joints (since they aren't kinematic)
@@ -35,4 +52,4 @@ def runTest(self):
3552
self.assertAlmostEqual(inertia.getCOG().z(), 3.0)
3653

3754
if __name__ == '__main__':
38-
rostest.run(PKG, NAME, TestKdlParser, sys.argv)
55+
unittest.main()

kdl_parser_py/test/test_pep257.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2015 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_pep257.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.linter
20+
@pytest.mark.pep257
21+
def test_pep257():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found code style errors / warnings'

0 commit comments

Comments
 (0)