moveit2
The MoveIt Motion Planning Framework for ROS 2.
move_group_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.actions import ExecuteProcess, TimerAction
6 from launch.some_substitutions_type import SomeSubstitutionsType
7 from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
8 from launch_ros.actions import Node
9 from ament_index_python.packages import get_package_share_directory
10 from moveit_configs_utils import MoveItConfigsBuilder
11 
12 
13 def generate_move_group_test_description(*args, gtest_name: SomeSubstitutionsType):
14  moveit_config = (
15  MoveItConfigsBuilder("moveit_resources_panda")
16  .robot_description(file_path="config/panda.urdf.xacro")
17  .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml")
18  .to_moveit_configs()
19  )
20 
21  moveit_config.planning_pipelines["ompl"]["panda_arm"][
22  "enforce_constrained_state_space"
23  ] = True
24  moveit_config.planning_pipelines["ompl"]["panda_arm"][
25  "projection_evaluator"
26  ] = "joints(panda_joint1,panda_joint2)"
27 
28  # Start the actual move_group node/action server
29  run_move_group_node = Node(
30  package="moveit_ros_move_group",
31  executable="move_group",
32  output="screen",
33  parameters=[moveit_config.to_dict()],
34  )
35 
36  # Static TF
37  static_tf = Node(
38  package="tf2_ros",
39  executable="static_transform_publisher",
40  name="static_transform_publisher",
41  output="log",
42  arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"],
43  )
44 
45  # Publish TF
46  robot_state_publisher = Node(
47  package="robot_state_publisher",
48  executable="robot_state_publisher",
49  name="robot_state_publisher",
50  output="both",
51  parameters=[moveit_config.robot_description],
52  )
53 
54  # ros2_control using FakeSystem as hardware
55  ros2_controllers_path = os.path.join(
56  get_package_share_directory("moveit_resources_panda_moveit_config"),
57  "config",
58  "ros2_controllers.yaml",
59  )
60  ros2_control_node = Node(
61  package="controller_manager",
62  executable="ros2_control_node",
63  parameters=[moveit_config.robot_description, ros2_controllers_path],
64  output="screen",
65  )
66 
67  joint_state_broadcaster_spawner = Node(
68  package="controller_manager",
69  executable="spawner",
70  arguments=[
71  "joint_state_broadcaster",
72  "--controller-manager",
73  "/controller_manager",
74  ],
75  )
76 
77  panda_arm_controller_spawner = Node(
78  package="controller_manager",
79  executable="spawner",
80  arguments=["panda_arm_controller", "-c", "/controller_manager"],
81  )
82 
83  panda_hand_controller_spawner = Node(
84  package="controller_manager",
85  executable="spawner",
86  arguments=["panda_hand_controller", "-c", "/controller_manager"],
87  )
88 
89  # test executable
90  ompl_constraint_test = launch_ros.actions.Node(
91  executable=PathJoinSubstitution(
92  [LaunchConfiguration("test_binary_dir"), gtest_name]
93  ),
94  parameters=[
95  moveit_config.robot_description,
96  moveit_config.robot_description_semantic,
97  moveit_config.robot_description_kinematics,
98  ],
99  output="screen",
100  )
101 
102  return launch.LaunchDescription(
103  [
104  launch.actions.DeclareLaunchArgument(
105  name="test_binary_dir",
106  description="Binary directory of package "
107  "containing test executables",
108  ),
109  run_move_group_node,
110  static_tf,
111  robot_state_publisher,
112  ros2_control_node,
113  joint_state_broadcaster_spawner,
114  panda_arm_controller_spawner,
115  panda_hand_controller_spawner,
116  TimerAction(period=2.0, actions=[ompl_constraint_test]),
117  launch_testing.actions.ReadyToTest(),
118  ]
119  ), {
120  "run_move_group_node": run_move_group_node,
121  "static_tf": static_tf,
122  "robot_state_publisher": robot_state_publisher,
123  "ros2_control_node": ros2_control_node,
124  "ompl_constraint_test": ompl_constraint_test,
125  }
def generate_move_group_test_description(*args, SomeSubstitutionsType gtest_name)