Skip to content

Commit d38e949

Browse files
committed
Robot driver tests pass with mock hardware
1 parent 1bc0632 commit d38e949

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

ur_robot_driver/test/robot_driver.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,26 @@
5656
)
5757

5858
TIMEOUT_EXECUTE_TRAJECTORY = 30
59-
MOCK_HARDWARE = False
60-
61-
def set_mock_hardware_flag(use_mock_hardware):
62-
return use_mock_hardware=="true"
6359

6460

6561
@pytest.mark.launch_test
6662
@launch_testing.parametrize(
67-
"tf_prefix, use_mock_hardware, mock_sensor_commands",
68-
[("", "false", "false"), ("my_ur_", "false", "false"), ("", "true", "true")]
63+
"tf_prefix, use_mock_hardware", [("", "false"), ("my_ur_", "false"), ("", "true")]
6964
)
65+
def generate_test_description(tf_prefix, use_mock_hardware):
66+
return generate_driver_test_description(
67+
tf_prefix=tf_prefix, use_mock_hardware=use_mock_hardware
68+
)
7069

71-
def generate_test_description(tf_prefix, use_mock_hardware, mock_sensor_commands):
72-
global MOCK_HARDWARE
73-
MOCK_HARDWARE = set_mock_hardware_flag(use_mock_hardware)
74-
return generate_driver_test_description(tf_prefix=tf_prefix, use_mock_hardware=use_mock_hardware, mock_sensor_commands=mock_sensor_commands)
7570

7671
class RobotDriverTest(unittest.TestCase):
7772
@classmethod
78-
def setUpClass(cls):
73+
def setUpClass(cls, use_mock_hardware):
7974
# Initialize the ROS context
8075
rclpy.init()
8176
cls.node = Node("robot_driver_test")
8277
time.sleep(1)
78+
cls.mock_hardware = use_mock_hardware == "true"
8379
cls.init_robot(cls)
8480

8581
@classmethod
@@ -89,7 +85,7 @@ def tearDownClass(cls):
8985
rclpy.shutdown()
9086

9187
def init_robot(self):
92-
if(not MOCK_HARDWARE):
88+
if not self.mock_hardware:
9389
self._dashboard_interface = DashboardInterface(self.node)
9490
else:
9591
self._dashboard_interface = None
@@ -109,7 +105,7 @@ def init_robot(self):
109105
)
110106

111107
def setUp(self):
112-
if(self._dashboard_interface):
108+
if self._dashboard_interface:
113109
self._dashboard_interface.start_robot()
114110
time.sleep(1)
115111
self.assertTrue(self._io_status_controller_interface.resend_robot_program().success)
@@ -149,6 +145,8 @@ def test_start_passthrough_controller(self):
149145

150146
def test_set_io(self):
151147
"""Test to set an IO and check whether it has been set."""
148+
if self.mock_hardware:
149+
return True
152150
# Create io callback to verify result
153151
io_msg = None
154152

@@ -282,6 +280,8 @@ def test_trajectory_scaled(self, tf_prefix):
282280

283281
def test_trajectory_scaled_aborts_on_violation(self, tf_prefix):
284282
"""Test that the robot correctly aborts the trajectory when the constraints are violated."""
283+
if self.mock_hardware:
284+
return True
285285
# Construct test trajectory
286286
test_trajectory = [
287287
(Duration(sec=6, nanosec=0), [0.0 for j in ROBOT_JOINTS]),
@@ -361,7 +361,7 @@ def js_cb(msg):
361361
# self.node.get_logger().info("Received result GOAL_TOLERANCE_VIOLATED")
362362

363363
def test_passthrough_trajectory(self, tf_prefix):
364-
if(MOCK_HARDWARE):
364+
if self.mock_hardware:
365365
return True
366366
self.assertTrue(
367367
self._controller_manager_interface.switch_controller(

ur_robot_driver/test/test_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ def generate_dashboard_test_description():
367367
def generate_driver_test_description(
368368
tf_prefix="",
369369
initial_joint_controller="scaled_joint_trajectory_controller",
370-
controller_spawner_timeout=TIMEOUT_WAIT_SERVICE_INITIAL, use_mock_hardware="false", mock_sensor_commands="false",
371-
):
370+
controller_spawner_timeout=TIMEOUT_WAIT_SERVICE_INITIAL, use_mock_hardware="false",
371+
):
372372
ur_type = LaunchConfiguration("ur_type")
373373

374374
launch_arguments = {
@@ -381,7 +381,7 @@ def generate_driver_test_description(
381381
"launch_dashboard_client": "true",
382382
"start_joint_controller": "false",
383383
"use_mock_hardware": use_mock_hardware,
384-
"mock_sensor_commands": mock_sensor_commands,
384+
"mock_sensor_commands": use_mock_hardware,
385385
}
386386
if tf_prefix:
387387
launch_arguments["tf_prefix"] = tf_prefix

0 commit comments

Comments
 (0)