-
Notifications
You must be signed in to change notification settings - Fork 27
/
view.launch.py
executable file
·242 lines (231 loc) · 8.37 KB
/
view.launch.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
#!/usr/bin/env -S ros2 launch
"""Visualisation of URDF model for panda in RViz2"""
from os import path
from typing import List
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import (
Command,
FindExecutable,
LaunchConfiguration,
PathJoinSubstitution,
)
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description() -> LaunchDescription:
# Declare all launch arguments
declared_arguments = generate_declared_arguments()
# Get substitution for all arguments
description_package = LaunchConfiguration("description_package")
description_filepath = LaunchConfiguration("description_filepath")
name = LaunchConfiguration("name")
prefix = LaunchConfiguration("prefix")
gripper = LaunchConfiguration("gripper")
collision_arm = LaunchConfiguration("collision_arm")
collision_gripper = LaunchConfiguration("collision_gripper")
safety_limits = LaunchConfiguration("safety_limits")
safety_position_margin = LaunchConfiguration("safety_position_margin")
safety_k_position = LaunchConfiguration("safety_k_position")
safety_k_velocity = LaunchConfiguration("safety_k_velocity")
ros2_control = LaunchConfiguration("ros2_control")
ros2_control_plugin = LaunchConfiguration("ros2_control_plugin")
ros2_control_command_interface = LaunchConfiguration(
"ros2_control_command_interface"
)
gazebo_preserve_fixed_joint = LaunchConfiguration("gazebo_preserve_fixed_joint")
rviz_config = LaunchConfiguration("rviz_config")
use_sim_time = LaunchConfiguration("use_sim_time")
log_level = LaunchConfiguration("log_level")
# Extract URDF from description file
robot_description_content = Command(
[
PathJoinSubstitution([FindExecutable(name="xacro")]),
" ",
PathJoinSubstitution(
[FindPackageShare(description_package), description_filepath]
),
" ",
"name:=",
name,
" ",
"prefix:=",
prefix,
" ",
"gripper:=",
gripper,
" ",
"collision_arm:=",
collision_arm,
" ",
"collision_gripper:=",
collision_gripper,
" ",
"safety_limits:=",
safety_limits,
" ",
"safety_position_margin:=",
safety_position_margin,
" ",
"safety_k_position:=",
safety_k_position,
" ",
"safety_k_velocity:=",
safety_k_velocity,
" ",
"ros2_control:=",
ros2_control,
" ",
"ros2_control_plugin:=",
ros2_control_plugin,
" ",
"ros2_control_command_interface:=",
ros2_control_command_interface,
" ",
"gazebo_preserve_fixed_joint:=",
gazebo_preserve_fixed_joint,
]
)
robot_description = {"robot_description": robot_description_content}
# List of nodes to be launched
nodes = [
# robot_state_publisher
Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="log",
arguments=["--ros-args", "--log-level", log_level],
parameters=[robot_description, {"use_sim_time": use_sim_time}],
),
# rviz2
Node(
package="rviz2",
executable="rviz2",
output="log",
arguments=[
"--display-config",
rviz_config,
"--ros-args",
"--log-level",
log_level,
],
parameters=[{"use_sim_time": use_sim_time}],
),
# joint_state_publisher_gui
Node(
package="joint_state_publisher_gui",
executable="joint_state_publisher_gui",
output="log",
arguments=["--ros-args", "--log-level", log_level],
parameters=[{"use_sim_time": use_sim_time}],
),
]
return LaunchDescription(declared_arguments + nodes)
def generate_declared_arguments() -> List[DeclareLaunchArgument]:
"""
Generate list of all launch arguments that are declared for this launch script.
"""
return [
# Location of xacro/URDF to visualise
DeclareLaunchArgument(
"description_package",
default_value="panda_description",
description="Custom package with robot description.",
),
DeclareLaunchArgument(
"description_filepath",
default_value=path.join("urdf", "panda.urdf.xacro"),
description="Path to xacro or URDF description of the robot, relative to share of `description_package`.",
),
# Naming of the robot
DeclareLaunchArgument(
"name",
default_value="panda",
description="Name of the robot.",
),
DeclareLaunchArgument(
"prefix",
default_value="panda_",
description="Prefix for all robot entities. If modified, then joint names in the configuration of controllers must also be updated.",
),
# Gripper
DeclareLaunchArgument(
"gripper",
default_value="true",
description="Flag to enable default gripper.",
),
# Collision geometry
DeclareLaunchArgument(
"collision_arm",
default_value="true",
description="Flag to enable collision geometry for manipulator's arm.",
),
DeclareLaunchArgument(
"collision_gripper",
default_value="true",
description="Flag to enable collision geometry for manipulator's gripper (hand and fingers).",
),
# Safety controller
DeclareLaunchArgument(
"safety_limits",
default_value="true",
description="Flag to enable safety limits controllers on manipulator joints.",
),
DeclareLaunchArgument(
"safety_position_margin",
default_value="0.15",
description="Lower and upper margin for position limits of all safety controllers.",
),
DeclareLaunchArgument(
"safety_k_position",
default_value="100.0",
description="Parametric k-position factor of all safety controllers.",
),
DeclareLaunchArgument(
"safety_k_velocity",
default_value="40.0",
description="Parametric k-velocity factor of all safety controllers.",
),
# ROS 2 control
DeclareLaunchArgument(
"ros2_control",
default_value="true",
description="Flag to enable ros2 controllers for manipulator.",
),
DeclareLaunchArgument(
"ros2_control_plugin",
default_value="ign",
description="The ros2_control plugin that should be loaded for the manipulator ('fake', 'ign', 'real' or custom).",
),
DeclareLaunchArgument(
"ros2_control_command_interface",
default_value="effort",
description="The output control command interface provided by ros2_control ('position', 'velocity', 'effort' or certain combinations 'position,velocity').",
),
# Gazebo
DeclareLaunchArgument(
"gazebo_preserve_fixed_joint",
default_value="false",
description="Flag to preserve fixed joints and prevent lumping when generating SDF for Gazebo.",
),
# Miscellaneous
DeclareLaunchArgument(
"rviz_config",
default_value=path.join(
get_package_share_directory("panda_description"),
"rviz",
"view.rviz",
),
description="Path to configuration for RViz2.",
),
DeclareLaunchArgument(
"use_sim_time",
default_value="false",
description="If true, use simulated clock.",
),
DeclareLaunchArgument(
"log_level",
default_value="warn",
description="The level of logging that is applied to all ROS 2 nodes launched by this script.",
),
]