Skip to content

Commit 922c20b

Browse files
author
Felix Exner
committed
Add tests for generated description
1 parent c74070f commit 922c20b

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

ur_simulation_gazebo/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ install(DIRECTORY config launch urdf
77
DESTINATION share/${PROJECT_NAME}
88
)
99

10+
if(BUILD_TESTING)
11+
find_package(ament_cmake_pytest REQUIRED)
12+
13+
ament_add_pytest_test(description test/test_description.py)
14+
endif()
15+
1016
ament_package()

ur_simulation_gazebo/package.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
<exec_depend>urdf</exec_depend>
3131
<exec_depend>xacro</exec_depend>
3232

33+
<test_depend>ament_cmake_pytest</test_depend>
34+
<test_depend>launch_testing_ament_cmake</test_depend>
35+
<test_depend>launch_testing_ros</test_depend>
36+
<test_depend>liburdfdom-tools</test_depend>
37+
<test_depend>xacro</test_depend>
38+
3339
<export>
3440
<build_type>ament_cmake</build_type>
3541
</export>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Copyright (c) 2023 FZI Forschungszentrum Informatik
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
#
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# * Neither the name of the {copyright_holder} nor the names of its
14+
# contributors may be used to endorse or promote products derived from
15+
# this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Author: Lukas Sackewitz
30+
31+
import os
32+
import shutil
33+
import subprocess
34+
import tempfile
35+
import pytest
36+
37+
from ament_index_python.packages import get_package_share_directory
38+
39+
40+
@pytest.mark.parametrize(
41+
"ur_type", ["ur3", "ur3e", "ur5", "ur5e", "ur10", "ur10e", "ur16e", "ur20"]
42+
)
43+
@pytest.mark.parametrize("prefix", ["", "my_ur_"])
44+
def test_ur_urdf_xacro(ur_type, prefix):
45+
# Initialize Arguments
46+
safety_limits = "true"
47+
safety_pos_margin = "0.15"
48+
safety_k_position = "20"
49+
# General Arguments
50+
description_package = "ur_description"
51+
52+
joint_limit_params = os.path.join(
53+
get_package_share_directory(description_package), "config", ur_type, "joint_limits.yaml"
54+
)
55+
kinematics_params = os.path.join(
56+
get_package_share_directory(description_package),
57+
"config",
58+
ur_type,
59+
"default_kinematics.yaml",
60+
)
61+
physical_params = os.path.join(
62+
get_package_share_directory(description_package),
63+
"config",
64+
ur_type,
65+
"physical_parameters.yaml",
66+
)
67+
visual_params = os.path.join(
68+
get_package_share_directory(description_package),
69+
"config",
70+
ur_type,
71+
"visual_parameters.yaml",
72+
)
73+
74+
description_file_path = os.path.join(
75+
get_package_share_directory("ur_simulation_gazebo"), "urdf", "ur_gazebo.urdf.xacro"
76+
)
77+
78+
(_, tmp_urdf_output_file) = tempfile.mkstemp(suffix=".urdf")
79+
80+
# Compose `xacro` and `check_urdf` command
81+
xacro_command = (
82+
f"{shutil.which('xacro')}"
83+
f" {description_file_path}"
84+
f" joint_limit_params:={joint_limit_params}"
85+
f" kinematics_params:={kinematics_params}"
86+
f" physical_params:={physical_params}"
87+
f" visual_params:={visual_params}"
88+
f" safety_limits:={safety_limits}"
89+
f" safety_pos_margin:={safety_pos_margin}"
90+
f" safety_k_position:={safety_k_position}"
91+
f" name:={ur_type}"
92+
f" prefix:={prefix}"
93+
f" > {tmp_urdf_output_file}"
94+
)
95+
check_urdf_command = f"{shutil.which('check_urdf')} {tmp_urdf_output_file}"
96+
97+
# Try to call processes but finally remove the temp file
98+
try:
99+
xacro_process = subprocess.run(
100+
xacro_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
101+
)
102+
103+
assert xacro_process.returncode == 0, " --- XACRO command failed ---"
104+
105+
check_urdf_process = subprocess.run(
106+
check_urdf_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
107+
)
108+
109+
assert (
110+
check_urdf_process.returncode == 0
111+
), "\n --- URDF check failed! --- \nYour xacro does not unfold into a proper urdf robot description. Please check your xacro file."
112+
113+
finally:
114+
os.remove(tmp_urdf_output_file)
115+
116+
117+
if __name__ == "__main__":
118+
test_ur_urdf_xacro()

0 commit comments

Comments
 (0)