moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
test_basic_integration.test.py
Go to the documentation of this file.
1import launch_testing
2import os
3import sys
4import unittest
5
6from ament_index_python.packages import get_package_share_directory
7from launch import LaunchDescription
8from launch.actions import DeclareLaunchArgument, RegisterEventHandler, TimerAction
9from launch.event_handlers import OnProcessExit
10from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
11from launch_ros.actions import Node
12from moveit_configs_utils import MoveItConfigsBuilder
13
14sys.path.append(os.path.dirname(__file__))
15from hybrid_planning_common import (
16 generate_common_hybrid_launch_description,
17 load_yaml,
18)
19
20
22 # generate_common_hybrid_launch_description() returns a list of nodes to launch
23 common_launch = generate_common_hybrid_launch_description()
24 moveit_config = (
25 MoveItConfigsBuilder("moveit_resources_panda")
26 .robot_description(file_path="config/panda.urdf.xacro")
27 .to_moveit_configs()
28 )
29
30 hybrid_planning_gtest = Node(
31 executable=PathJoinSubstitution(
32 [LaunchConfiguration("test_binary_dir"), "test_basic_integration"]
33 ),
34 parameters=[
35 moveit_config.to_dict(),
36 ],
37 output="screen",
38 )
39
40 # Static TF
41 static_tf = Node(
42 package="tf2_ros",
43 executable="static_transform_publisher",
44 name="static_transform_publisher",
45 output="log",
46 arguments=["--frame-id", "world", "--child-frame-id", "panda_link0"],
47 )
48
49 # Publish TF
50 robot_state_publisher = Node(
51 package="robot_state_publisher",
52 executable="robot_state_publisher",
53 name="robot_state_publisher",
54 output="both",
55 parameters=[moveit_config.robot_description],
56 )
57
58 # ros2_control using FakeSystem as hardware
59 ros2_controllers_path = os.path.join(
60 get_package_share_directory("moveit_hybrid_planning"),
61 "config",
62 "demo_controller.yaml",
63 )
64 ros2_control_node = Node(
65 package="controller_manager",
66 executable="ros2_control_node",
67 parameters=[moveit_config.robot_description, ros2_controllers_path],
68 output="screen",
69 )
70
71 joint_state_broadcaster_spawner = Node(
72 package="controller_manager",
73 executable="spawner",
74 arguments=[
75 "joint_state_broadcaster",
76 "--controller-manager",
77 "/controller_manager",
78 ],
79 )
80
81 panda_joint_group_position_controller_spawner = Node(
82 package="controller_manager",
83 executable="spawner",
84 arguments=[
85 "panda_joint_group_position_controller",
86 "-c",
87 "/controller_manager",
88 ],
89 )
90
91 return LaunchDescription(
92 [
93 DeclareLaunchArgument(
94 name="test_binary_dir",
95 description="Binary directory of package "
96 "containing test executables",
97 ),
98 # Gate the gtest launch on the last spawner exiting (== controller
99 # activated). The prior fixed TimerAction raced controller
100 # activation under load and caused this family to flake.
101 RegisterEventHandler(
102 OnProcessExit(
103 target_action=panda_joint_group_position_controller_spawner,
104 on_exit=[hybrid_planning_gtest],
105 )
106 ),
107 launch_testing.actions.ReadyToTest(),
108 ]
109 + common_launch
110 + [
111 static_tf,
112 robot_state_publisher,
113 ros2_control_node,
114 joint_state_broadcaster_spawner,
115 panda_joint_group_position_controller_spawner,
116 ]
117 ), {
118 "hybrid_planning_gtest": hybrid_planning_gtest,
119 }
120
121
122class TestGTestWaitForCompletion(unittest.TestCase):
123 # Waits for test to complete, then waits a bit to make sure result files are generated
124 def test_gtest_run_complete(self, hybrid_planning_gtest):
125 self.proc_info.assertWaitForShutdown(hybrid_planning_gtest, timeout=4000.0)
126
127
128@launch_testing.post_shutdown_test()
129class TestGTestProcessPostShutdown(unittest.TestCase):
130 # Checks if the test has been completed with acceptable exit codes (successful codes)
131 def test_gtest_pass(self, proc_info, hybrid_planning_gtest):
132 launch_testing.asserts.assertExitCodes(proc_info, process=hybrid_planning_gtest)