Skip to content

Commit

Permalink
Running integration tests with mock hardware
Browse files Browse the repository at this point in the history
Added some launch arguments and some checks to avoid connecting to the dashboard interface when using mock hardware, as that will not work. Maybe not the most elegant, but it works for now.
Currently passthrough controller does not work at all with mock hardware, and is bypassed if using that in the test.
test_trajectory_scaled_aborts_on_violation fails, as the hardware doesnt abort.
test_set_io also fails as the controller cant verify that a pin has been set.
  • Loading branch information
URJala committed Jan 9, 2025
1 parent accd58b commit 1c6e90d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ur_robot_driver/launch/ur_control.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def controller_spawner(controllers, active=True):
if activate_joint_controller.perform(context) == "true":
controllers_active.append(initial_joint_controller.perform(context))
controllers_inactive.remove(initial_joint_controller.perform(context))

if use_mock_hardware.perform(context) == "true":
controllers_active.remove("tcp_pose_broadcaster")

controller_spawners = [
controller_spawner(controllers_active),
Expand Down
24 changes: 18 additions & 6 deletions ur_robot_driver/test/robot_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,22 @@
)

TIMEOUT_EXECUTE_TRAJECTORY = 30
MOCK_HARDWARE = False

def set_mock_hardware_flag(use_mock_hardware):
return use_mock_hardware=="true"


@pytest.mark.launch_test
@launch_testing.parametrize(
"tf_prefix",
[(""), ("my_ur_")],
"tf_prefix, use_mock_hardware, mock_sensor_commands",
[("", "false", "false"), ("my_ur_", "false", "false"), ("", "true", "true")]
)
def generate_test_description(tf_prefix):
return generate_driver_test_description(tf_prefix=tf_prefix)

def generate_test_description(tf_prefix, use_mock_hardware, mock_sensor_commands):
global MOCK_HARDWARE
MOCK_HARDWARE = set_mock_hardware_flag(use_mock_hardware)
return generate_driver_test_description(tf_prefix=tf_prefix, use_mock_hardware=use_mock_hardware, mock_sensor_commands=mock_sensor_commands)

class RobotDriverTest(unittest.TestCase):
@classmethod
Expand All @@ -83,7 +89,10 @@ def tearDownClass(cls):
rclpy.shutdown()

def init_robot(self):
self._dashboard_interface = DashboardInterface(self.node)
if(not MOCK_HARDWARE):
self._dashboard_interface = DashboardInterface(self.node)
else:
self._dashboard_interface = None
self._controller_manager_interface = ControllerManagerInterface(self.node)
self._io_status_controller_interface = IoStatusInterface(self.node)
self._configuration_controller_interface = ConfigurationInterface(self.node)
Expand All @@ -100,7 +109,8 @@ def init_robot(self):
)

def setUp(self):
self._dashboard_interface.start_robot()
if(self._dashboard_interface):
self._dashboard_interface.start_robot()
time.sleep(1)
self.assertTrue(self._io_status_controller_interface.resend_robot_program().success)

Expand Down Expand Up @@ -351,6 +361,8 @@ def js_cb(msg):
# self.node.get_logger().info("Received result GOAL_TOLERANCE_VIOLATED")

def test_passthrough_trajectory(self, tf_prefix):
if(MOCK_HARDWARE):
return True
self.assertTrue(
self._controller_manager_interface.switch_controller(
strictness=SwitchController.Request.BEST_EFFORT,
Expand Down
6 changes: 4 additions & 2 deletions ur_robot_driver/test/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ def generate_dashboard_test_description():


def generate_driver_test_description(
tf_prefix="", controller_spawner_timeout=TIMEOUT_WAIT_SERVICE_INITIAL
):
tf_prefix="", controller_spawner_timeout=TIMEOUT_WAIT_SERVICE_INITIAL, use_mock_hardware="false", mock_sensor_commands="false"
):
ur_type = LaunchConfiguration("ur_type")

launch_arguments = {
Expand All @@ -354,6 +354,8 @@ def generate_driver_test_description(
"headless_mode": "true",
"launch_dashboard_client": "true",
"start_joint_controller": "false",
"use_mock_hardware": use_mock_hardware,
"mock_sensor_commands": mock_sensor_commands,
}
if tf_prefix:
launch_arguments["tf_prefix"] = tf_prefix
Expand Down
4 changes: 3 additions & 1 deletion ur_robot_driver/urdf/ur.ros2_control.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@


<gpio name="${tf_prefix}get_robot_software_version">
<state_interface name="get_version_major"/>
<state_interface name="get_version_major">
<param name="initial_value">1</param>
</state_interface>
<state_interface name="get_version_minor"/>
<state_interface name="get_version_build"/>
<state_interface name="get_version_bugfix"/>
Expand Down

0 comments on commit 1c6e90d

Please sign in to comment.