Skip to content

Commit 31a04ce

Browse files
authored
Add XML launchfile (backport #382) (#383)
* Add view_robot.launch.xml * Include in python launchfile * Update documentation
1 parent 68a10c2 commit 31a04ce

3 files changed

Lines changed: 71 additions & 141 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The most relevant files are:
3535
To visualize the robot install this repository to you workspace and execute the following:
3636

3737
``` bash
38-
ros2 launch ur_description view_ur.launch.py ur_type:=ur5e
38+
ros2 launch ur_description view_ur.launch.xml ur_type:=ur5e
3939
```
4040

4141
To test other descriptions change the `ur_type` argument.

launch/view_ur.launch.py

Lines changed: 21 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -29,150 +29,31 @@
2929
# Author: Denis Stogl
3030

3131
from launch import LaunchDescription
32-
from launch.actions import DeclareLaunchArgument
33-
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
34-
from launch_ros.actions import Node
3532
from launch_ros.substitutions import FindPackageShare
36-
from launch_ros.parameter_descriptions import ParameterValue
3733

34+
from launch.actions import IncludeLaunchDescription
35+
from launch.launch_description_sources import FrontendLaunchDescriptionSource
36+
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
3837

39-
def generate_launch_description():
40-
declared_arguments = []
41-
# UR specific arguments
42-
declared_arguments.append(
43-
DeclareLaunchArgument(
44-
"ur_type",
45-
description="Type/series of used UR robot.",
46-
choices=[
47-
"ur3",
48-
"ur5",
49-
"ur10",
50-
"ur3e",
51-
"ur5e",
52-
"ur7e",
53-
"ur10e",
54-
"ur12e",
55-
"ur16e",
56-
"ur8long",
57-
"ur15",
58-
"ur18",
59-
"ur20",
60-
"ur30",
61-
],
62-
)
63-
)
64-
declared_arguments.append(
65-
DeclareLaunchArgument(
66-
"safety_limits",
67-
default_value="true",
68-
description="Enables the safety limits controller if true.",
69-
)
70-
)
71-
declared_arguments.append(
72-
DeclareLaunchArgument(
73-
"safety_pos_margin",
74-
default_value="0.15",
75-
description="The margin to lower and upper limits in the safety controller.",
76-
)
77-
)
78-
declared_arguments.append(
79-
DeclareLaunchArgument(
80-
"safety_k_position",
81-
default_value="20",
82-
description="k-position factor in the safety controller.",
83-
)
84-
)
85-
# General arguments
86-
declared_arguments.append(
87-
DeclareLaunchArgument(
88-
"description_package",
89-
default_value="ur_description",
90-
description="Description package with robot URDF/XACRO files. Usually the argument "
91-
"is not set, it enables use of a custom description.",
92-
)
93-
)
94-
declared_arguments.append(
95-
DeclareLaunchArgument(
96-
"description_file",
97-
default_value="ur.urdf.xacro",
98-
description="URDF/XACRO description file with the robot.",
99-
)
100-
)
101-
declared_arguments.append(
102-
DeclareLaunchArgument(
103-
"tf_prefix",
104-
default_value='""',
105-
description="Prefix of the joint names, useful for "
106-
"multi-robot setup. If changed than also joint names in the controllers' configuration "
107-
"have to be updated.",
108-
)
109-
)
110-
111-
# Initialize Arguments
112-
ur_type = LaunchConfiguration("ur_type")
113-
safety_limits = LaunchConfiguration("safety_limits")
114-
safety_pos_margin = LaunchConfiguration("safety_pos_margin")
115-
safety_k_position = LaunchConfiguration("safety_k_position")
116-
# General arguments
117-
description_package = LaunchConfiguration("description_package")
118-
description_file = LaunchConfiguration("description_file")
119-
tf_prefix = LaunchConfiguration("tf_prefix")
12038

121-
robot_description_content = Command(
39+
def generate_launch_description():
40+
return LaunchDescription(
12241
[
123-
PathJoinSubstitution([FindExecutable(name="xacro")]),
124-
" ",
125-
PathJoinSubstitution([FindPackageShare(description_package), "urdf", description_file]),
126-
" ",
127-
"safety_limits:=",
128-
safety_limits,
129-
" ",
130-
"safety_pos_margin:=",
131-
safety_pos_margin,
132-
" ",
133-
"safety_k_position:=",
134-
safety_k_position,
135-
" ",
136-
"name:=",
137-
"ur",
138-
" ",
139-
"ur_type:=",
140-
ur_type,
141-
" ",
142-
"tf_prefix:=",
143-
tf_prefix,
42+
IncludeLaunchDescription(
43+
FrontendLaunchDescriptionSource(
44+
[
45+
PathJoinSubstitution(
46+
[
47+
FindPackageShare("ur_description"),
48+
"launch",
49+
"view_ur.launch.xml",
50+
]
51+
)
52+
]
53+
),
54+
launch_arguments={
55+
"ur_type": LaunchConfiguration("ur_type"),
56+
}.items(),
57+
)
14458
]
14559
)
146-
robot_description = {
147-
"robot_description": ParameterValue(value=robot_description_content, value_type=str)
148-
}
149-
150-
rviz_config_file = PathJoinSubstitution(
151-
[FindPackageShare(description_package), "rviz", "view_robot.rviz"]
152-
)
153-
154-
joint_state_publisher_node = Node(
155-
package="joint_state_publisher_gui",
156-
executable="joint_state_publisher_gui",
157-
)
158-
robot_state_publisher_node = Node(
159-
package="robot_state_publisher",
160-
executable="robot_state_publisher",
161-
output="both",
162-
parameters=[robot_description],
163-
)
164-
rviz_node = Node(
165-
package="rviz2",
166-
executable="rviz2",
167-
name="rviz2",
168-
output="log",
169-
arguments=["-d", rviz_config_file],
170-
)
171-
172-
nodes_to_start = [
173-
joint_state_publisher_node,
174-
robot_state_publisher_node,
175-
rviz_node,
176-
]
177-
178-
return LaunchDescription(declared_arguments + nodes_to_start)

launch/view_ur.launch.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<launch>
3+
<arg name="description_package"
4+
default="ur_description"
5+
description="Description package with robot URDF/XACRO files. Usually the argument is not set, it enables use of a custom description." />
6+
<arg name="description_file"
7+
default="ur.urdf.xacro"
8+
description="URDF/XACRO description file with the robot." />
9+
<arg name="ur_type" description="Type/series of used UR robot.">
10+
<choice value="ur3"/>
11+
<choice value="ur5"/>
12+
<choice value="ur10"/>
13+
<choice value="ur3e"/>
14+
<choice value="ur5e"/>
15+
<choice value="ur7e"/>
16+
<choice value="ur10e"/>
17+
<choice value="ur12e"/>
18+
<choice value="ur16e"/>
19+
<choice value="ur8long"/>
20+
<choice value="ur15"/>
21+
<choice value="ur18"/>
22+
<choice value="ur20"/>
23+
<choice value="ur30"/>
24+
</arg>
25+
<arg name="tf_prefix"
26+
default=""
27+
description="Prefix of the joint names, useful for multi-robot setup. If changed than also joint names in the controllers' configuration have to be updated." />
28+
<arg name="safety_limits"
29+
default="true"
30+
description="Enables the safety limits controller if true." />
31+
<arg name="safety_pos_margin"
32+
default="0.15"
33+
description="The margin to lower and upper limits in the safety controller." />
34+
<arg name="safety_k_position"
35+
default="20"
36+
description="The gain for the position controller in the safety controller." />
37+
38+
<node pkg="joint_state_publisher_gui" exec="joint_state_publisher_gui" />
39+
<node pkg="rviz2" exec="rviz2" args="-d $(find-pkg-share $(var description_package))/rviz/view_robot.rviz" />
40+
<node pkg="robot_state_publisher" exec="robot_state_publisher">
41+
<param name="robot_description" value="$(command '$(find-exec xacro) $(find-pkg-share $(var description_package))/urdf/$(var description_file)
42+
ur_type:=$(var ur_type)
43+
name:=ur
44+
safety_limits:=$(var safety_limits)
45+
safety_pos_margin:=$(var safety_pos_margin)
46+
safety_k_position:=$(var safety_k_position)
47+
tf_prefix:=$(var tf_prefix)')"/>
48+
</node>
49+
</launch>

0 commit comments

Comments
 (0)