moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
demo.launch.py
Go to the documentation of this file.
1import os
2import yaml
3from launch import LaunchDescription
4from launch.actions import DeclareLaunchArgument
5from launch.substitutions import LaunchConfiguration
6from launch.conditions import IfCondition, UnlessCondition
7from launch_ros.actions import Node
8from launch.actions import ExecuteProcess
9from ament_index_python.packages import get_package_share_directory
10import xacro
11
12
13def 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 (
21 EnvironmentError
22 ): # parent of IOError, OSError *and* WindowsError where available
23 return None
24
25
26def load_yaml(package_name, file_path):
27 package_path = get_package_share_directory(package_name)
28 absolute_file_path = os.path.join(package_path, file_path)
29
30 try:
31 with open(absolute_file_path, "r") as file:
32 return yaml.safe_load(file)
33 except (
34 EnvironmentError
35 ): # parent of IOError, OSError *and* WindowsError where available
36 return None
37
38
40 # planning_context
41 robot_description_config = xacro.process_file(
42 os.path.join(
43 get_package_share_directory("moveit_resources_prbt_support"),
44 "urdf",
45 "prbt.xacro",
46 )
47 )
48 robot_description = {"robot_description": robot_description_config.toxml()}
49
50 robot_description_semantic_config = xacro.process_file(
51 os.path.join(
52 get_package_share_directory("moveit_resources_prbt_moveit_config"),
53 "config",
54 "prbt.srdf.xacro",
55 )
56 )
57
58 robot_description_semantic = {
59 "robot_description_semantic": robot_description_semantic_config.toxml()
60 }
61
62 joint_limits_yaml = load_yaml(
63 "moveit_resources_prbt_moveit_config", "config/joint_limits.yaml"
64 )
65 pilz_cartesian_limits_yaml = load_yaml(
66 "moveit_resources_prbt_moveit_config", "config/pilz_cartesian_limits.yaml"
67 )
68 robot_description_planning = {
69 "robot_description_planning": {
70 **joint_limits_yaml,
71 **pilz_cartesian_limits_yaml,
72 }
73 }
74 kinematics_yaml = load_yaml(
75 "moveit_resources_prbt_moveit_config", "config/kinematics.yaml"
76 )
77 robot_description_kinematics = {"robot_description_kinematics": kinematics_yaml}
78
79 # Planning Functionality
80 planning_pipelines_config = {
81 "default_planning_pipeline": "ompl",
82 "planning_pipelines": ["pilz", "ompl"],
83 "pilz": {
84 "planning_plugins": ["pilz_industrial_motion_planner/CommandPlanner"],
85 },
86 "ompl": {
87 "planning_plugins": ["ompl_interface/OMPLPlanner"],
88 "request_adapters": [
89 "default_planning_request_adapters/ResolveConstraintFrames",
90 "default_planning_request_adapters/ValidateWorkspaceBounds",
91 "default_planning_request_adapters/CheckStartStateBounds",
92 "default_planning_request_adapters/CheckStartStateCollision",
93 ],
94 "response_adapters": [
95 "default_planning_response_adapters/AddTimeOptimalParameterization",
96 "default_planning_response_adapters/ValidateSolution",
97 ],
98 },
99 }
100 ompl_planning_yaml = load_yaml(
101 "moveit_resources_prbt_moveit_config", "config/ompl_planning.yaml"
102 )
103 planning_pipelines_config["ompl"].update(ompl_planning_yaml)
104
105 # Trajectory Execution Functionality
106 moveit_simple_controllers_yaml = load_yaml(
107 "moveit_resources_prbt_moveit_config", "config/prbt_controllers.yaml"
108 )
109 moveit_controllers = {
110 "moveit_simple_controller_manager": moveit_simple_controllers_yaml,
111 "moveit_controller_manager": "moveit_simple_controller_manager/MoveItSimpleControllerManager",
112 }
113
114 trajectory_execution = {
115 "moveit_manage_controllers": True,
116 "trajectory_execution.allowed_execution_duration_scaling": 1.2,
117 "trajectory_execution.allowed_goal_duration_margin": 0.5,
118 "trajectory_execution.allowed_start_tolerance": 0.01,
119 }
120
121 planning_scene_monitor_parameters = {
122 "publish_planning_scene": True,
123 "publish_geometry_updates": True,
124 "publish_state_updates": True,
125 "publish_transforms_updates": True,
126 }
127
128 # Start the actual move_group node/action server
129 run_move_group_node = Node(
130 package="moveit_ros_move_group",
131 executable="move_group",
132 output="screen",
133 parameters=[
134 robot_description,
135 robot_description_semantic,
136 robot_description_kinematics,
137 robot_description_planning,
138 planning_pipelines_config,
139 trajectory_execution,
140 moveit_controllers,
141 planning_scene_monitor_parameters,
142 ],
143 )
144
145 # RViz
146 rviz_base = os.path.join(
147 get_package_share_directory("moveit_resources_prbt_moveit_config"), "launch"
148 )
149 rviz_full_config = os.path.join(rviz_base, "moveit.rviz")
150 rviz_node = Node(
151 package="rviz2",
152 executable="rviz2",
153 name="rviz2",
154 output="log",
155 arguments=["-d", rviz_full_config],
156 parameters=[
157 robot_description,
158 robot_description_semantic,
159 robot_description_planning,
160 robot_description_kinematics,
161 planning_pipelines_config,
162 ],
163 )
164
165 # Static TF
166 static_tf = Node(
167 package="tf2_ros",
168 executable="static_transform_publisher",
169 name="static_transform_publisher",
170 output="log",
171 arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "prbt_link0"],
172 )
173
174 # Publish TF
175 robot_state_publisher = Node(
176 package="robot_state_publisher",
177 executable="robot_state_publisher",
178 name="robot_state_publisher",
179 output="both",
180 parameters=[robot_description],
181 )
182
183 # ros2_control using FakeSystem as hardware
184 ros2_controllers_path = os.path.join(
185 get_package_share_directory("moveit_resources_prbt_moveit_config"),
186 "config",
187 "prbt_ros_controllers.yaml",
188 )
189 ros2_control_node = Node(
190 package="controller_manager",
191 executable="ros2_control_node",
192 parameters=[ros2_controllers_path],
193 remappings=[
194 ("/controller_manager/robot_description", "/robot_description"),
195 ],
196 output="screen",
197 )
198
199 joint_state_broadcaster_spawner = Node(
200 package="controller_manager",
201 executable="spawner",
202 arguments=[
203 "joint_state_broadcaster",
204 "--controller-manager",
205 "/controller_manager",
206 ],
207 )
208
209 prbt_arm_controller_spawner = Node(
210 package="controller_manager",
211 executable="spawner",
212 arguments=[
213 "panda_joint_group_position_controller",
214 "-c",
215 "/controller_manager",
216 ],
217 )
218
219 # Warehouse mongodb server
220 mongodb_server_node = Node(
221 package="warehouse_ros_mongo",
222 executable="mongo_wrapper_ros.py",
223 parameters=[
224 {"warehouse_port": 33829},
225 {"warehouse_host": "localhost"},
226 {"warehouse_plugin": "warehouse_ros_mongo::MongoDatabaseConnection"},
227 ],
228 output="screen",
229 )
230
231 return LaunchDescription(
232 [
233 rviz_node,
234 static_tf,
235 robot_state_publisher,
236 run_move_group_node,
237 ros2_control_node,
238 joint_state_broadcaster_spawner,
239 prbt_arm_controller_spawner,
240 mongodb_server_node,
241 ]
242 )
load_file(package_name, file_path)
generate_launch_description()