moveit2
The MoveIt Motion Planning Framework for ROS 2.
hybrid_planning_common.py
Go to the documentation of this file.
1 # Return a list of nodes we commonly launch for the demo. Nice for testing use.
2 import os
3 import xacro
4 import yaml
5 
6 from ament_index_python.packages import get_package_share_directory
7 from launch.actions import ExecuteProcess
8 from launch_ros.actions import Node
9 from launch_ros.descriptions import ComposableNode
10 from launch_ros.actions import ComposableNodeContainer
11 
12 
13 def load_file(package_name, file_path):
14  package_path = get_package_share_directory(package_name)
15  absolute_file_path = os.path.join(package_path, file_path)
16 
17  try:
18  with open(absolute_file_path, "r") as file:
19  return file.read()
20  except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
21  return None
22 
23 
24 def load_yaml(package_name, file_path):
25  package_path = get_package_share_directory(package_name)
26  absolute_file_path = os.path.join(package_path, file_path)
27 
28  try:
29  with open(absolute_file_path, "r") as file:
30  return yaml.safe_load(file)
31  except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
32  return None
33 
34 
36  robot_description_config = xacro.process_file(
37  os.path.join(
38  get_package_share_directory("moveit_resources_panda_moveit_config"),
39  "config",
40  "panda.urdf.xacro",
41  )
42  )
43  robot_description = {"robot_description": robot_description_config.toxml()}
44  return robot_description
45 
46 
48  robot_description_semantic_config = load_file(
49  "moveit_resources_panda_moveit_config", "config/panda.srdf"
50  )
51  robot_description_semantic = {
52  "robot_description_semantic": robot_description_semantic_config
53  }
54  return robot_description_semantic
55 
56 
58  robot_description = get_robot_description()
59 
60  robot_description_semantic = get_robot_description_semantic()
61 
62  kinematics_yaml = load_yaml(
63  "moveit_resources_panda_moveit_config", "config/kinematics.yaml"
64  )
65 
66  # The global planner uses the typical OMPL parameters
67  planning_pipelines_config = {
68  "ompl": {
69  "planning_plugin": "ompl_interface/OMPLPlanner",
70  "request_adapters": """default_planner_request_adapters/AddTimeOptimalParameterization default_planner_request_adapters/FixWorkspaceBounds default_planner_request_adapters/FixStartStateBounds default_planner_request_adapters/FixStartStateCollision default_planner_request_adapters/FixStartStatePathConstraints""",
71  "start_state_max_bounds_error": 0.1,
72  }
73  }
74  ompl_planning_yaml = load_yaml(
75  "moveit_resources_panda_moveit_config", "config/ompl_planning.yaml"
76  )
77  planning_pipelines_config["ompl"].update(ompl_planning_yaml)
78 
79  moveit_simple_controllers_yaml = load_yaml(
80  "moveit_resources_panda_moveit_config", "config/moveit_controllers.yaml"
81  )
82  moveit_controllers = {
83  "moveit_simple_controller_manager": moveit_simple_controllers_yaml,
84  "moveit_controller_manager": "moveit_simple_controller_manager/MoveItSimpleControllerManager",
85  }
86 
87  # Any parameters that are unique to your plugins go here
88  common_hybrid_planning_param = load_yaml(
89  "moveit_hybrid_planning", "config/common_hybrid_planning_params.yaml"
90  )
91  global_planner_param = load_yaml(
92  "moveit_hybrid_planning", "config/global_planner.yaml"
93  )
94  local_planner_param = load_yaml(
95  "moveit_hybrid_planning", "config/local_planner.yaml"
96  )
97  hybrid_planning_manager_param = load_yaml(
98  "moveit_hybrid_planning", "config/hybrid_planning_manager.yaml"
99  )
100 
101  # Generate launch description with multiple components
102  container = ComposableNodeContainer(
103  name="hybrid_planning_container",
104  namespace="/",
105  package="rclcpp_components",
106  executable="component_container_mt",
107  composable_node_descriptions=[
108  ComposableNode(
109  package="moveit_hybrid_planning",
110  plugin="moveit::hybrid_planning::GlobalPlannerComponent",
111  name="global_planner",
112  parameters=[
113  common_hybrid_planning_param,
114  global_planner_param,
115  robot_description,
116  robot_description_semantic,
117  kinematics_yaml,
118  planning_pipelines_config,
119  moveit_controllers,
120  ],
121  ),
122  ComposableNode(
123  package="moveit_hybrid_planning",
124  plugin="moveit::hybrid_planning::LocalPlannerComponent",
125  name="local_planner",
126  parameters=[
127  common_hybrid_planning_param,
128  local_planner_param,
129  robot_description,
130  robot_description_semantic,
131  kinematics_yaml,
132  ],
133  ),
134  ComposableNode(
135  package="moveit_hybrid_planning",
136  plugin="moveit::hybrid_planning::HybridPlanningManager",
137  name="hybrid_planning_manager",
138  parameters=[
139  common_hybrid_planning_param,
140  hybrid_planning_manager_param,
141  ],
142  ),
143  ],
144  output="screen",
145  )
146 
147  # RViz
148  rviz_config_file = (
149  get_package_share_directory("moveit_hybrid_planning")
150  + "/config/hybrid_planning_demo.rviz"
151  )
152  rviz_node = Node(
153  package="rviz2",
154  executable="rviz2",
155  name="rviz2",
156  output="log",
157  arguments=["-d", rviz_config_file],
158  parameters=[robot_description, robot_description_semantic],
159  )
160 
161  # Static TF
162  static_tf = Node(
163  package="tf2_ros",
164  executable="static_transform_publisher",
165  name="static_transform_publisher",
166  output="log",
167  arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"],
168  )
169 
170  # Publish TF
171  robot_state_publisher = Node(
172  package="robot_state_publisher",
173  executable="robot_state_publisher",
174  name="robot_state_publisher",
175  output="both",
176  parameters=[robot_description],
177  )
178 
179  # ros2_control using FakeSystem as hardware
180  ros2_controllers_path = os.path.join(
181  get_package_share_directory("moveit_hybrid_planning"),
182  "config",
183  "demo_controller.yaml",
184  )
185  ros2_control_node = Node(
186  package="controller_manager",
187  executable="ros2_control_node",
188  parameters=[robot_description, ros2_controllers_path],
189  output="screen",
190  )
191 
192  joint_state_broadcaster_spawner = Node(
193  package="controller_manager",
194  executable="spawner",
195  arguments=[
196  "joint_state_broadcaster",
197  "--controller-manager",
198  "/controller_manager",
199  ],
200  )
201 
202  panda_joint_group_position_controller_spawner = Node(
203  package="controller_manager",
204  executable="spawner",
205  arguments=[
206  "panda_joint_group_position_controller",
207  "-c",
208  "/controller_manager",
209  ],
210  )
211 
212  launched_nodes = [
213  container,
214  static_tf,
215  rviz_node,
216  robot_state_publisher,
217  ros2_control_node,
218  joint_state_broadcaster_spawner,
219  panda_joint_group_position_controller_spawner,
220  ]
221 
222  return launched_nodes
def load_yaml(package_name, file_path)
def load_file(package_name, file_path)