moveit2
The MoveIt Motion Planning Framework for ROS 2.
servo_launch_test_common.py
Go to the documentation of this file.
1 import os
2 import launch
3 import launch_ros
4 import launch_testing
5 from launch import LaunchDescription
6 from launch.some_substitutions_type import SomeSubstitutionsType
7 from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
8 from launch_ros.actions import ComposableNodeContainer, Node
9 from launch_ros.descriptions import ComposableNode
10 from ament_index_python.packages import get_package_share_directory
11 from launch.actions import ExecuteProcess, TimerAction
12 from moveit_configs_utils import MoveItConfigsBuilder
13 from launch_param_builder import ParameterBuilder
14 
15 
17  *args,
18  gtest_name: SomeSubstitutionsType,
19  start_position_path: SomeSubstitutionsType = ""
20 ):
21 
22  # Get parameters using the demo config file
23  servo_params = {
24  "moveit_servo": ParameterBuilder("moveit_servo")
25  .yaml("config/panda_simulated_config.yaml")
26  .to_dict()
27  }
28 
29  # Get URDF and SRDF
30  if start_position_path:
31  initial_positions_file = os.path.join(
32  os.path.dirname(__file__), start_position_path
33  )
34  robot_description_mappings = {"initial_positions_file": initial_positions_file}
35  else:
36  robot_description_mappings = None
37 
38  moveit_config = (
39  MoveItConfigsBuilder("moveit_resources_panda")
40  .robot_description(
41  file_path="config/panda.urdf.xacro", mappings=robot_description_mappings
42  )
43  .to_moveit_configs()
44  )
45 
46  # ros2_control using FakeSystem as hardware
47  ros2_controllers_path = os.path.join(
48  get_package_share_directory("moveit_resources_panda_moveit_config"),
49  "config",
50  "ros2_controllers.yaml",
51  )
52  ros2_control_node = Node(
53  package="controller_manager",
54  executable="ros2_control_node",
55  parameters=[moveit_config.robot_description, ros2_controllers_path],
56  output="screen",
57  )
58 
59  joint_state_broadcaster_spawner = Node(
60  package="controller_manager",
61  executable="spawner",
62  arguments=[
63  "joint_state_broadcaster",
64  "--controller-manager-timeout",
65  "300",
66  "--controller-manager",
67  "/controller_manager",
68  ],
69  )
70 
71  panda_arm_controller_spawner = Node(
72  package="controller_manager",
73  executable="spawner",
74  arguments=["panda_arm_controller", "-c", "/controller_manager"],
75  )
76 
77  # Component nodes for tf and Servo
78  test_container = ComposableNodeContainer(
79  name="test_servo_integration_container",
80  namespace="/",
81  package="rclcpp_components",
82  executable="component_container_mt",
83  composable_node_descriptions=[
84  ComposableNode(
85  package="robot_state_publisher",
86  plugin="robot_state_publisher::RobotStatePublisher",
87  name="robot_state_publisher",
88  parameters=[moveit_config.robot_description],
89  ),
90  ComposableNode(
91  package="tf2_ros",
92  plugin="tf2_ros::StaticTransformBroadcasterNode",
93  name="static_tf2_broadcaster",
94  parameters=[{"/child_frame_id": "panda_link0", "/frame_id": "world"}],
95  ),
96  ],
97  output="screen",
98  )
99 
100  servo_node = Node(
101  package="moveit_servo",
102  executable="servo_node_main",
103  output="screen",
104  parameters=[
105  servo_params,
106  moveit_config.robot_description,
107  moveit_config.robot_description_semantic,
108  moveit_config.joint_limits,
109  moveit_config.robot_description_kinematics,
110  ],
111  )
112 
113  # NOTE: The smoothing plugin doesn't seem to be accessible from containers
114  # servo_container = ComposableNodeContainer(
115  # name="servo_container",
116  # namespace="/",
117  # package="rclcpp_components",
118  # executable="component_container_mt",
119  # composable_node_descriptions=[
120  # ComposableNode(
121  # package="moveit_servo",
122  # plugin="moveit_servo::ServoNode",
123  # name="servo_node",
124  # parameters=[
125  # servo_params,
126  # robot_description,
127  # robot_description_semantic,
128  # joint_limits_yaml,
129  # ],
130  # ),
131  # ],
132  # output="screen",
133  # )
134 
135  # Unknown how to set timeout
136  # https://github.com/ros2/launch/issues/466
137  servo_gtest = launch_ros.actions.Node(
138  executable=PathJoinSubstitution(
139  [LaunchConfiguration("test_binary_dir"), gtest_name]
140  ),
141  parameters=[servo_params],
142  output="screen",
143  )
144 
145  return launch.LaunchDescription(
146  [
147  launch.actions.DeclareLaunchArgument(
148  name="test_binary_dir",
149  description="Binary directory of package "
150  "containing test executables",
151  ),
152  ros2_control_node,
153  joint_state_broadcaster_spawner,
154  panda_arm_controller_spawner,
155  servo_node,
156  test_container,
157  TimerAction(period=2.0, actions=[servo_gtest]),
158  launch_testing.actions.ReadyToTest(),
159  ]
160  ), {
161  "servo_node": servo_node,
162  "test_container": test_container,
163  "servo_gtest": servo_gtest,
164  "ros2_control_node": ros2_control_node,
165  }
def generate_servo_test_description(*args, SomeSubstitutionsType gtest_name, SomeSubstitutionsType start_position_path="")