4 from unittest
import TestCase
5 from parameterized
import parameterized_class
6 from .urdf_test_case
import UrdfTestCase, PKG
7 from urdf_parser_py.urdf
import URDF, Mesh, Cylinder, Sphere
10 @parameterized_class((
'robot',), [(
"panda",), (
"fr3",)])
15 return os.path.join(self.robot, self.robot +
'.urdf.xacro')
30 joint =
'panda_joint%s' % i
36 self.
links_with(urdf,
lambda link:
'hand' in link),
37 'Found one or more links containing "hand", probably URDF contains a franka_gripper' 40 self.
joints_with(urdf,
lambda joint:
'hand' in joint),
41 'Found one or more joints containing "hand", probably URDF contains a franka_gripper' 48 link =
'%s_link%s' % (arm_id, i)
50 self.assertGreaterEqual(len(collisions), 1,
"Link '%s' does not have any collision meshes assigned to it" % link)
51 self.assertIsInstance(
53 "Link '%s' is expected to have mesh geometries in <collision> not '%s'" % (link, collisions[0].__class__.__name__)
58 for name
in urdf.link_map:
59 if not name.endswith(
'_sc'):
continue 61 for geometry
in geometries:
62 self.assertIsInstance(
63 geometry, (Cylinder, Sphere),
64 "Link '%s' is expected to define only a capsule <collision> geometry (made from Cylinders and Spheres, not '%s')" % (name, geometry.__class__.__name__)
69 for name, link
in urdf.link_map.items():
72 "Link '%s' is expected to have no <inertial> defined but actually has one:\n%s" % (name, link.inertial)
76 urdf = self.
xacro(self.
file, args=
'hand:=true')
77 for name, link
in urdf.link_map.items():
80 "Link '%s' is expected to have no <inertial> defined but actually has one:\n%s" % (name, link.inertial)
85 urdf = self.
xacro(self.
file, args=
'arm_id:=%s' % arm_id)
86 for link
in urdf.link_map.keys():
87 self.assertIn(arm_id, link)
91 urdf = self.
xacro(self.
file, args=
'arm_id:=%s' % arm_id)
92 for joint
in urdf.joint_map.keys():
93 self.assertIn(arm_id, joint)
97 urdf = self.
xacro(self.
file, args=
'hand:=true')
98 for name
in [
'hand',
'hand_tcp',
'leftfinger',
'rightfinger']:
99 link =
'%s_%s' % (arm_id, name)
102 for name
in [
'hand_joint',
'hand_tcp_joint',
'finger_joint1',
'finger_joint2']:
103 joint =
'%s_%s' % (arm_id, name)
108 urdf = self.
xacro(self.
file, args=
'arm_id:=%s hand:=true' % arm_id)
109 for name
in [
'hand',
'hand_tcp',
'leftfinger',
'rightfinger']:
110 link =
'%s_%s' % (arm_id, name)
113 for name
in [
'hand_joint',
'hand_tcp_joint',
'finger_joint1',
'finger_joint2']:
114 joint =
'%s_%s' % (arm_id, name)
119 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
122 self.assertEqual(
'world', urdf.get_root())
128 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
130 for gazebo
in urdf.gazebos:
132 if child.tag ==
'plugin':
133 self.assertIn(
'name', child.attrib,
'<plugin> tag does not have a "name" attribute')
134 self.assertEqual(
'gazebo_ros_control', child.attrib[
'name'])
144 self.fail(
'No <plugin name="gazebo_ros_control"> found in URDF')
148 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
149 for joint
in [
'%s_joint%s' % (arm_id, i)
for i
in range(1,8)]:
154 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
155 for joint
in [
'%s_joint%s' % (arm_id, i)
for i
in range(1,8)]:
160 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
161 for joint
in [
'%s_joint%s' % (arm_id, i)
for i
in range(1,8)]:
166 urdf = self.
xacro(self.
file,
'gazebo:=true')
167 for transmission
in urdf.transmissions:
168 if transmission.type ==
'franka_hw/FrankaStateInterface':
169 self.assertListEqual(
170 [
'%s_joint%s' % (arm_id, i)
for i
in range(1,8)],
171 [joint.name
for joint
in transmission.joints]
176 self.fail(
'No franka_hw/FrankaStateInterface found in URDF')
180 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
181 for transmission
in urdf.transmissions:
182 if transmission.type ==
'franka_hw/FrankaModelInterface':
184 arm_id +
'_joint1', transmission.joints[0].name,
185 "First joint in the FrankaModelInterface transmission must be the root of the chain, i.e. '$(arm_id)_joint1' not '%s'" % transmission.joints[0].name
188 arm_id +
'_joint8', transmission.joints[1].name,
189 "Second joint in the FrankaModelInterface transmission must be the tip of the chain, i.e. '$(arm_id)_joint8' not '%s'" % transmission.joints[1].name
194 self.fail(
'No franka_hw/FrankaModelInterface found in URDF')
198 urdf = self.
xacro(self.
file, args=
'gazebo:=true hand:=true')
199 for joint
in [arm_id +
'_finger_joint1', arm_id +
'_finger_joint2']:
203 urdf = self.
xacro(self.
file, args=
'gazebo:=true')
204 for name, link
in urdf.link_map.items():
205 if not name.endswith(
'_sc'):
continue 207 len(link.collisions), 0,
208 "Link '%s' is expected to have no <collision> tags defined but has %s" % (name, len(link.collisions))
212 urdf = self.
xacro(self.
file, args=
'gazebo:=true hand:=true')
213 for name, link
in urdf.link_map.items():
214 if not name.endswith(
'_sc'):
continue 216 len(link.collisions), 0,
217 "Link '%s' is expected to have no <collision> tags defined but has %s" % (name, len(link.collisions))
222 urdf = self.
xacro(self.
file, args=
'hand:=true')
223 joint = urdf.joint_map[arm_id +
'_hand_tcp_joint']
224 self.assertListEqual(joint.origin.xyz, [0, 0, 0.1034])
225 self.assertListEqual(joint.origin.rpy, [0, 0, 0])
229 urdf = self.
xacro(self.
file, args=
'hand:=true tcp_xyz:="1 2 3"')
230 joint = urdf.joint_map[arm_id +
'_hand_tcp_joint']
231 self.assertListEqual(joint.origin.xyz, [1, 2, 3])
235 urdf = self.
xacro(self.
file, args=
'hand:=true tcp_rpy:="3.1415 0.123 42"')
236 joint = urdf.joint_map[arm_id +
'_hand_tcp_joint']
237 self.assertListEqual(joint.origin.rpy, [3.1415, 0.123, 42])
239 if __name__ ==
'__main__':
241 rosunit.unitrun(PKG,
'URDF', FrankaRobotUrdfTest)
def test_generate_urdf_without_xacro_args_contains_link0_up_to_link8(self)
def assertJointBetween(self, urdf, parent, child, type=None)
def test_gazebo_arg_will_add_top_level_world_link(self)
def test_gazebo_arg_will_insert_velocity_interfaces(self)
def test_gazebo_arg_will_insert_franka_state_interface(self)
def joints_with(self, urdf, predicate)
def test_setting_gazebo_arg_forces_to_have_no_geometries_inside_sc_links(self)
def test_gazebo_arg_and_hand_will_insert_effort_interfaces_for_fingers(self)
def test_custom_arm_id_renames_links(self)
def test_generate_urdf_with_hand_puts_franka_gripper_into_urdf(self)
def test_generate_urdf_without_xacro_args_uses_fine_collision_models(self)
def assertJointHasTransmission(self, urdf, joint, type)
def links_with(self, urdf, predicate)
def assertContainsLink(self, urdf, link)
def test_setting_tcp_xyz_arg_moves_the_hand_tcp_link(self)
def test_setting_tcp_rpy_arg_rotates_the_hand_tcp_link(self)
def test_gazebo_arg_will_insert_gazebo_ros_control_plugin(self)
def assertContainsJoint(self, urdf, joint)
def test_generate_urdf_without_xacro_args_contains_joint1_up_to_joint8(self)
def test_custom_arm_id_with_hand_renames_hand_joints_and_links(self)
def test_gazebo_arg_will_insert_franka_model_interface(self)
def test_generate_urdf_with_hand_but_not_gazebo_doesnt_insert_inertial_tags_for_any_link(self)
def test_generate_urdf_without_xacro_args_dont_use_gripper(self)
def test_custom_arm_id_renames_joints(self)
def test_gazebo_arg_will_insert_effort_interfaces(self)
def test_generate_urdf_without_xacro_args_is_possible(self)
def test_setting_gazebo_arg_with_hand_forces_to_have_no_geometries_inside_sc_links(self)
def xacro(self, file, args='')
def test_gazebo_arg_will_insert_position_interfaces(self)
def test_generate_urdf_without_tcp_args_uses_default_10_34_cm_hand_tcp_offset(self)
def test_generate_urdf_without_xacro_args_uses_coarse_collision_models_for_sc_links(self)
def test_generate_urdf_without_xacro_args_doesnt_insert_inertial_tags_for_any_link(self)
def collision_geometries(self, urdf, link)