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