|  | 
|  | 1 | +import pytest | 
|  | 2 | +import unittest | 
|  | 3 | + | 
|  | 4 | +from launch import LaunchDescription | 
|  | 5 | +import launch_testing | 
|  | 6 | +from launch_testing.actions import ReadyToTest | 
|  | 7 | +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution | 
|  | 8 | +from launch.actions import ( | 
|  | 9 | +    DeclareLaunchArgument, | 
|  | 10 | +    ExecuteProcess, | 
|  | 11 | +    IncludeLaunchDescription, | 
|  | 12 | +    RegisterEventHandler, | 
|  | 13 | +) | 
|  | 14 | +from launch.launch_description_sources import PythonLaunchDescriptionSource | 
|  | 15 | +from launch_ros.substitutions import FindPackagePrefix, FindPackageShare | 
|  | 16 | +from launch.event_handlers import OnProcessExit | 
|  | 17 | + | 
|  | 18 | +TIMEOUT_WAIT_SERVICE_INITIAL = 120  # If we download the docker image simultaneously to the tests, it can take quite some time until the dashboard server is reachable and usable. | 
|  | 19 | + | 
|  | 20 | + | 
|  | 21 | +@pytest.mark.launch_test | 
|  | 22 | +def generate_test_description(): | 
|  | 23 | +    controller_spawner_timeout = TIMEOUT_WAIT_SERVICE_INITIAL | 
|  | 24 | +    declared_arguments = [] | 
|  | 25 | + | 
|  | 26 | +    declared_arguments.append( | 
|  | 27 | +        DeclareLaunchArgument( | 
|  | 28 | +            "ur_type", | 
|  | 29 | +            default_value="ur5e", | 
|  | 30 | +            description="Type/series of used UR robot.", | 
|  | 31 | +            choices=[ | 
|  | 32 | +                "ur3", | 
|  | 33 | +                "ur3e", | 
|  | 34 | +                "ur5", | 
|  | 35 | +                "ur5e", | 
|  | 36 | +                "ur10", | 
|  | 37 | +                "ur10e", | 
|  | 38 | +                "ur16e", | 
|  | 39 | +                "ur20", | 
|  | 40 | +                "ur30", | 
|  | 41 | +            ], | 
|  | 42 | +        ) | 
|  | 43 | +    ) | 
|  | 44 | + | 
|  | 45 | +    ur_type = LaunchConfiguration("ur_type") | 
|  | 46 | + | 
|  | 47 | +    robot_driver = IncludeLaunchDescription( | 
|  | 48 | +        PythonLaunchDescriptionSource( | 
|  | 49 | +            PathJoinSubstitution( | 
|  | 50 | +                [FindPackageShare("ur_robot_driver"), "launch", "ur_control.launch.py"] | 
|  | 51 | +            ) | 
|  | 52 | +        ), | 
|  | 53 | +        launch_arguments={ | 
|  | 54 | +            "robot_ip": "192.168.56.101", | 
|  | 55 | +            "ur_type": ur_type, | 
|  | 56 | +            "launch_rviz": "false", | 
|  | 57 | +            "controller_spawner_timeout": str(controller_spawner_timeout), | 
|  | 58 | +            "initial_joint_controller": "scaled_joint_trajectory_controller", | 
|  | 59 | +            "headless_mode": "true", | 
|  | 60 | +            "launch_dashboard_client": "false", | 
|  | 61 | +            "start_joint_controller": "false", | 
|  | 62 | +        }.items(), | 
|  | 63 | +    ) | 
|  | 64 | +    wait_dashboard_server = ExecuteProcess( | 
|  | 65 | +        cmd=[ | 
|  | 66 | +            PathJoinSubstitution( | 
|  | 67 | +                [ | 
|  | 68 | +                    FindPackagePrefix("ur_robot_driver"), | 
|  | 69 | +                    "bin", | 
|  | 70 | +                    "wait_dashboard_server.sh", | 
|  | 71 | +                ] | 
|  | 72 | +            ) | 
|  | 73 | +        ], | 
|  | 74 | +        name="wait_dashboard_server", | 
|  | 75 | +        output="screen", | 
|  | 76 | +    ) | 
|  | 77 | +    driver_starter = RegisterEventHandler( | 
|  | 78 | +        OnProcessExit(target_action=wait_dashboard_server, on_exit=robot_driver) | 
|  | 79 | +    ) | 
|  | 80 | +    moveit_setup = IncludeLaunchDescription( | 
|  | 81 | +        PythonLaunchDescriptionSource( | 
|  | 82 | +            PathJoinSubstitution( | 
|  | 83 | +                [FindPackageShare("ur_moveit_config"), "launch", "ur_moveit.launch.py"] | 
|  | 84 | +            ) | 
|  | 85 | +        ), | 
|  | 86 | +        launch_arguments={ | 
|  | 87 | +            "ur_type": ur_type, | 
|  | 88 | +            "launch_rviz": "false", | 
|  | 89 | +        }.items(), | 
|  | 90 | +    ) | 
|  | 91 | + | 
|  | 92 | +    return LaunchDescription( | 
|  | 93 | +        declared_arguments | 
|  | 94 | +        + [ReadyToTest(), wait_dashboard_server, _ursim_action(), driver_starter, moveit_setup] | 
|  | 95 | +    ) | 
|  | 96 | + | 
|  | 97 | + | 
|  | 98 | +def _ursim_action(): | 
|  | 99 | +    ur_type = LaunchConfiguration("ur_type") | 
|  | 100 | + | 
|  | 101 | +    return ExecuteProcess( | 
|  | 102 | +        cmd=[ | 
|  | 103 | +            PathJoinSubstitution( | 
|  | 104 | +                [ | 
|  | 105 | +                    FindPackagePrefix("ur_client_library"), | 
|  | 106 | +                    "lib", | 
|  | 107 | +                    "ur_client_library", | 
|  | 108 | +                    "start_ursim.sh", | 
|  | 109 | +                ] | 
|  | 110 | +            ), | 
|  | 111 | +            " ", | 
|  | 112 | +            "-m ", | 
|  | 113 | +            ur_type, | 
|  | 114 | +        ], | 
|  | 115 | +        name="start_ursim", | 
|  | 116 | +        output="screen", | 
|  | 117 | +    ) | 
|  | 118 | + | 
|  | 119 | + | 
|  | 120 | +class TestReadyForPlanning(unittest.TestCase): | 
|  | 121 | +    def test_read_stdout(self, proc_output): | 
|  | 122 | +        """Check if 'You can start planning now!' was found in the stdout.""" | 
|  | 123 | +        proc_output.assertWaitFor("You can start planning now!", timeout=120, stream="stdout") | 
|  | 124 | + | 
|  | 125 | + | 
|  | 126 | +@launch_testing.post_shutdown_test() | 
|  | 127 | +class TestProcessExitCode(unittest.TestCase): | 
|  | 128 | +    def test_exit_code(self, proc_info): | 
|  | 129 | +        launch_testing.asserts.assertExitCodes(proc_info) | 
0 commit comments