moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
launches.py
Go to the documentation of this file.
1import os
2
3from launch import LaunchDescription
4from launch.actions import (
5 DeclareLaunchArgument,
6 IncludeLaunchDescription,
7)
8from launch.conditions import IfCondition
9from launch.launch_description_sources import PythonLaunchDescriptionSource
10from launch.substitutions import LaunchConfiguration
11
12from launch_ros.actions import Node
13from launch_ros.parameter_descriptions import ParameterValue
14
15from srdfdom.srdf import SRDF
16
18 add_debuggable_node,
19 DeclareBooleanLaunchArg,
20)
21
22
23def generate_rsp_launch(moveit_config):
24 """Launch file for robot state publisher (rsp)"""
25
26 ld = LaunchDescription()
27 ld.add_action(DeclareLaunchArgument("publish_frequency", default_value="15.0"))
28
29 # Given the published joint states, publish tf for the robot links and the robot description
30 rsp_node = Node(
31 package="robot_state_publisher",
32 executable="robot_state_publisher",
33 respawn=True,
34 output="screen",
35 parameters=[
36 moveit_config.robot_description,
37 {
38 "publish_frequency": LaunchConfiguration("publish_frequency"),
39 },
40 ],
41 )
42 ld.add_action(rsp_node)
43
44 return ld
45
46
47def generate_moveit_rviz_launch(moveit_config):
48 """Launch file for rviz"""
49 ld = LaunchDescription()
50
51 ld.add_action(DeclareBooleanLaunchArg("debug", default_value=False))
52 ld.add_action(
53 DeclareLaunchArgument(
54 "rviz_config",
55 default_value=str(moveit_config.package_path / "config/moveit.rviz"),
56 )
57 )
58
59 rviz_parameters = [
60 moveit_config.planning_pipelines,
61 moveit_config.robot_description_kinematics,
62 moveit_config.joint_limits,
63 ]
64
65 add_debuggable_node(
66 ld,
67 package="rviz2",
68 executable="rviz2",
69 output="log",
70 respawn=False,
71 arguments=["-d", LaunchConfiguration("rviz_config")],
72 parameters=rviz_parameters,
73 )
74
75 return ld
76
77
79 """Launch file for MoveIt Setup Assistant"""
80 ld = LaunchDescription()
81
82 ld.add_action(DeclareBooleanLaunchArg("debug", default_value=False))
83 add_debuggable_node(
84 ld,
85 package="moveit_setup_assistant",
86 executable="moveit_setup_assistant",
87 arguments=[["--config_pkg=", str(moveit_config.package_path)]],
88 )
89
90 return ld
91
92
94 ld = LaunchDescription()
95
96 name_counter = 0
97
98 for key, xml_contents in moveit_config.robot_description_semantic.items():
99 srdf = SRDF.from_xml_string(xml_contents)
100 for vj in srdf.virtual_joints:
101 ld.add_action(
102 Node(
103 package="tf2_ros",
104 executable="static_transform_publisher",
105 name=f"static_transform_publisher{name_counter}",
106 output="log",
107 arguments=[
108 "--frame-id",
109 vj.parent_frame,
110 "--child-frame-id",
111 vj.child_link,
112 ],
113 )
114 )
115 name_counter += 1
116 return ld
117
118
119def generate_spawn_controllers_launch(moveit_config, controller_manager_timeout=None):
120 controller_names = moveit_config.trajectory_execution.get(
121 "moveit_simple_controller_manager", {}
122 ).get("controller_names", [])
123 ld = LaunchDescription()
124 # Pass the same ros2_controllers.yaml to the controller spawners as to the controller_manager
125 ros2_controllers_path = moveit_config.package_path / "config/ros2_controllers.yaml"
126 spawner_args = (
127 ["--param-file", str(ros2_controllers_path)]
128 if ros2_controllers_path.exists()
129 else []
130 )
131 # Callers that start the controller_manager in the same launch file may need
132 # to wait longer than the spawner's default for it to come up.
133 if controller_manager_timeout is not None:
134 spawner_args += [
135 "--controller-manager-timeout",
136 str(controller_manager_timeout),
137 ]
138 for controller in controller_names + ["joint_state_broadcaster"]:
139 ld.add_action(
140 Node(
141 package="controller_manager",
142 executable="spawner",
143 arguments=[controller] + spawner_args,
144 output="screen",
145 )
146 )
147 return ld
148
149
151 """Launch file for warehouse database"""
152 ld = LaunchDescription()
153 ld.add_action(
154 DeclareLaunchArgument(
155 "moveit_warehouse_database_path",
156 default_value=str(
157 moveit_config.package_path / "default_warehouse_mongo_db"
158 ),
159 )
160 )
161 ld.add_action(DeclareBooleanLaunchArg("reset", default_value=False))
162
163 # The default DB port for moveit (not default MongoDB port to avoid potential conflicts)
164 ld.add_action(DeclareLaunchArgument("moveit_warehouse_port", default_value="33829"))
165
166 # The default DB host for moveit
167 ld.add_action(
168 DeclareLaunchArgument("moveit_warehouse_host", default_value="localhost")
169 )
170
171 # Load warehouse parameters
172 db_parameters = [
173 {
174 "overwrite": False,
175 "database_path": LaunchConfiguration("moveit_warehouse_database_path"),
176 "warehouse_port": LaunchConfiguration("moveit_warehouse_port"),
177 "warehouse_host": LaunchConfiguration("moveit_warehouse_host"),
178 "warehouse_exec": "mongod",
179 "warehouse_plugin": "warehouse_ros_mongo::MongoDatabaseConnection",
180 },
181 ]
182 # Run the DB server
183 db_node = Node(
184 package="warehouse_ros_mongo",
185 executable="mongo_wrapper_ros.py",
186 # TODO(dlu): Figure out if this needs to be run in a specific directory
187 # (ROS 1 version set cwd="ROS_HOME")
188 parameters=db_parameters,
189 )
190 ld.add_action(db_node)
191
192 # If we want to reset the database, run this node
193 reset_node = Node(
194 package="moveit_ros_warehouse",
195 executable="moveit_init_demo_warehouse",
196 output="screen",
197 condition=IfCondition(LaunchConfiguration("reset")),
198 )
199 ld.add_action(reset_node)
200
201 return ld
202
203
204def generate_move_group_launch(moveit_config):
205 ld = LaunchDescription()
206
207 ld.add_action(DeclareBooleanLaunchArg("debug", default_value=False))
208 ld.add_action(
209 DeclareBooleanLaunchArg("allow_trajectory_execution", default_value=True)
210 )
211 ld.add_action(
212 DeclareBooleanLaunchArg("publish_monitored_planning_scene", default_value=True)
213 )
214 # load non-default MoveGroup capabilities (space separated)
215 ld.add_action(
216 DeclareLaunchArgument(
217 "capabilities",
218 default_value=moveit_config.move_group_capabilities["capabilities"],
219 )
220 )
221 # inhibit these default MoveGroup capabilities (space separated)
222 ld.add_action(
223 DeclareLaunchArgument(
224 "disable_capabilities",
225 default_value=moveit_config.move_group_capabilities["disable_capabilities"],
226 )
227 )
228
229 # do not copy dynamics information from /joint_states to internal robot monitoring
230 # default to false, because almost nothing in move_group relies on this information
231 ld.add_action(DeclareBooleanLaunchArg("monitor_dynamics", default_value=False))
232
233 should_publish = LaunchConfiguration("publish_monitored_planning_scene")
234
235 move_group_configuration = {
236 "publish_robot_description_semantic": True,
237 "allow_trajectory_execution": LaunchConfiguration("allow_trajectory_execution"),
238 # Note: Wrapping the following values is necessary so that the parameter value can be the empty string
239 "capabilities": ParameterValue(
240 LaunchConfiguration("capabilities"), value_type=str
241 ),
242 "disable_capabilities": ParameterValue(
243 LaunchConfiguration("disable_capabilities"), value_type=str
244 ),
245 # Publish the planning scene of the physical robot so that rviz plugin can know actual robot
246 "publish_planning_scene": should_publish,
247 "publish_geometry_updates": should_publish,
248 "publish_state_updates": should_publish,
249 "publish_transforms_updates": should_publish,
250 "monitor_dynamics": False,
251 }
252
253 move_group_params = [
254 moveit_config.to_dict(),
255 move_group_configuration,
256 ]
257
258 add_debuggable_node(
259 ld,
260 package="moveit_ros_move_group",
261 executable="move_group",
262 commands_file=str(moveit_config.package_path / "launch" / "gdb_settings.gdb"),
263 output="screen",
264 parameters=move_group_params,
265 extra_debug_args=["--debug"],
266 # Set the display variable, in case OpenGL code is used internally
267 additional_env={"DISPLAY": os.environ.get("DISPLAY", "")},
268 )
269 return ld
270
271
272def generate_demo_launch(moveit_config, launch_package_path=None):
273 """
274 Launches a self contained demo
275
276 launch_package_path is optional to use different launch and config packages
277
278 Includes
279 * static_virtual_joint_tfs
280 * robot_state_publisher
281 * move_group
282 * moveit_rviz
283 * warehouse_db (optional)
284 * ros2_control_node + controller spawners
285 """
286 if launch_package_path == None:
287 launch_package_path = moveit_config.package_path
288
289 ld = LaunchDescription()
290 ld.add_action(
292 "db",
293 default_value=False,
294 description="By default, we do not start a database (it can be large)",
295 )
296 )
297 ld.add_action(
299 "debug",
300 default_value=False,
301 description="By default, we are not in debug mode",
302 )
303 )
304 ld.add_action(DeclareBooleanLaunchArg("use_rviz", default_value=True))
305 # If there are virtual joints, broadcast static tf by including virtual_joints launch
306 virtual_joints_launch = (
307 launch_package_path / "launch/static_virtual_joint_tfs.launch.py"
308 )
309
310 if virtual_joints_launch.exists():
311 ld.add_action(
312 IncludeLaunchDescription(
313 PythonLaunchDescriptionSource(str(virtual_joints_launch)),
314 )
315 )
316
317 # Given the published joint states, publish tf for the robot links
318 ld.add_action(
319 IncludeLaunchDescription(
320 PythonLaunchDescriptionSource(
321 str(launch_package_path / "launch/rsp.launch.py")
322 ),
323 )
324 )
325
326 ld.add_action(
327 IncludeLaunchDescription(
328 PythonLaunchDescriptionSource(
329 str(launch_package_path / "launch/move_group.launch.py")
330 ),
331 )
332 )
333
334 # Run Rviz and load the default config to see the state of the move_group node
335 ld.add_action(
336 IncludeLaunchDescription(
337 PythonLaunchDescriptionSource(
338 str(launch_package_path / "launch/moveit_rviz.launch.py")
339 ),
340 condition=IfCondition(LaunchConfiguration("use_rviz")),
341 )
342 )
343
344 # If database loading was enabled, start mongodb as well
345 ld.add_action(
346 IncludeLaunchDescription(
347 PythonLaunchDescriptionSource(
348 str(launch_package_path / "launch/warehouse_db.launch.py")
349 ),
350 condition=IfCondition(LaunchConfiguration("db")),
351 )
352 )
353
354 # Fake joint driver
355 ld.add_action(
356 Node(
357 package="controller_manager",
358 executable="ros2_control_node",
359 parameters=[
360 str(moveit_config.package_path / "config/ros2_controllers.yaml"),
361 ],
362 remappings=[
363 ("/controller_manager/robot_description", "/robot_description"),
364 ],
365 )
366 )
367
368 ld.add_action(
369 IncludeLaunchDescription(
370 PythonLaunchDescriptionSource(
371 str(launch_package_path / "launch/spawn_controllers.launch.py")
372 ),
373 )
374 )
375
376 return ld
generate_setup_assistant_launch(moveit_config)
Definition launches.py:78
generate_spawn_controllers_launch(moveit_config, controller_manager_timeout=None)
Definition launches.py:119
generate_warehouse_db_launch(moveit_config)
Definition launches.py:150
generate_demo_launch(moveit_config, launch_package_path=None)
Definition launches.py:272
generate_move_group_launch(moveit_config)
Definition launches.py:204
generate_static_virtual_joint_tfs_launch(moveit_config)
Definition launches.py:93
generate_rsp_launch(moveit_config)
Definition launches.py:23
generate_moveit_rviz_launch(moveit_config)
Definition launches.py:47