|
| 1 | +import unittest |
| 2 | +import os |
| 3 | + |
| 4 | +from ament_index_python.packages import get_package_share_directory |
| 5 | +import launch_testing |
| 6 | +import pytest |
| 7 | +from launch import LaunchDescription |
| 8 | +from launch.actions import DeclareLaunchArgument |
| 9 | +from launch.substitutions import LaunchConfiguration |
| 10 | +from launch_ros.actions import Node |
| 11 | +from launch_testing.actions import ReadyToTest |
| 12 | +from launch_testing.util import KeepAliveProc |
| 13 | +from moveit_configs_utils import MoveItConfigsBuilder |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.launch_test |
| 17 | +def generate_test_description(): |
| 18 | + moveit_config = ( |
| 19 | + MoveItConfigsBuilder("moveit_resources_panda") |
| 20 | + .planning_pipelines(pipelines=["ompl"]) |
| 21 | + .robot_description(file_path="config/panda.urdf.xacro") |
| 22 | + .to_moveit_configs() |
| 23 | + ) |
| 24 | + |
| 25 | + # Load ExecuteTaskSolutionCapability so we can test executing solutions |
| 26 | + move_group_capabilities = {"capabilities": "move_group/ExecuteTaskSolutionCapability"} |
| 27 | + |
| 28 | + # Start the actual move_group node/action server |
| 29 | + move_group_node = Node( |
| 30 | + package="moveit_ros_move_group", |
| 31 | + executable="move_group", |
| 32 | + output="screen", |
| 33 | + parameters=[ |
| 34 | + moveit_config.to_dict(), |
| 35 | + move_group_capabilities, |
| 36 | + ], |
| 37 | + ) |
| 38 | + |
| 39 | + # Static TF |
| 40 | + static_tf = Node( |
| 41 | + package="tf2_ros", |
| 42 | + executable="static_transform_publisher", |
| 43 | + name="static_transform_publisher", |
| 44 | + output="log", |
| 45 | + arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"], |
| 46 | + ) |
| 47 | + |
| 48 | + # Publish joint states to TF |
| 49 | + robot_state_publisher = Node( |
| 50 | + package="robot_state_publisher", |
| 51 | + executable="robot_state_publisher", |
| 52 | + name="robot_state_publisher", |
| 53 | + output="both", |
| 54 | + parameters=[moveit_config.robot_description], |
| 55 | + ) |
| 56 | + |
| 57 | + # ros2_control using FakeSystem as hardware |
| 58 | + ros2_controllers_path = os.path.join( |
| 59 | + get_package_share_directory("moveit_resources_panda_moveit_config"), |
| 60 | + "config", |
| 61 | + "ros2_controllers.yaml", |
| 62 | + ) |
| 63 | + ros2_control_node = Node( |
| 64 | + package="controller_manager", |
| 65 | + executable="ros2_control_node", |
| 66 | + parameters=[moveit_config.robot_description, ros2_controllers_path], |
| 67 | + output="both", |
| 68 | + ) |
| 69 | + |
| 70 | + controller_spawner = Node( |
| 71 | + package="controller_manager", |
| 72 | + executable="spawner", |
| 73 | + arguments=[ |
| 74 | + "panda_arm_controller", |
| 75 | + "joint_state_broadcaster", |
| 76 | + "--controller-manager", |
| 77 | + "/controller_manager", |
| 78 | + ], |
| 79 | + ) |
| 80 | + |
| 81 | + test_exec = Node( |
| 82 | + executable=[ |
| 83 | + LaunchConfiguration("test_binary"), |
| 84 | + ], |
| 85 | + output="screen", |
| 86 | + parameters=[ |
| 87 | + moveit_config.robot_description, |
| 88 | + moveit_config.robot_description_semantic, |
| 89 | + moveit_config.robot_description_kinematics, |
| 90 | + moveit_config.joint_limits, |
| 91 | + ], |
| 92 | + ) |
| 93 | + |
| 94 | + return ( |
| 95 | + LaunchDescription( |
| 96 | + [ |
| 97 | + static_tf, |
| 98 | + robot_state_publisher, |
| 99 | + move_group_node, |
| 100 | + ros2_control_node, |
| 101 | + controller_spawner, |
| 102 | + DeclareLaunchArgument( |
| 103 | + name="test_binary", |
| 104 | + description="Test executable", |
| 105 | + ), |
| 106 | + test_exec, |
| 107 | + KeepAliveProc(), |
| 108 | + ReadyToTest(), |
| 109 | + ] |
| 110 | + ), |
| 111 | + {"test_exec": test_exec}, |
| 112 | + ) |
| 113 | + |
| 114 | + |
| 115 | +class TestTerminatingProcessStops(unittest.TestCase): |
| 116 | + def test_gtest_run_complete(self, proc_info, test_exec): |
| 117 | + proc_info.assertWaitForShutdown(process=test_exec, timeout=4000.0) |
| 118 | + |
| 119 | + |
| 120 | +@launch_testing.post_shutdown_test() |
| 121 | +class TaskModelTestAfterShutdown(unittest.TestCase): |
| 122 | + def test_exit_code(self, proc_info): |
| 123 | + # Check that all processes in the launch exit with code 0 |
| 124 | + launch_testing.asserts.assertExitCodes(proc_info) |
0 commit comments