|
29 | 29 | # Author: Denis Stogl |
30 | 30 |
|
31 | 31 | 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 |
35 | 32 | from launch_ros.substitutions import FindPackageShare |
36 | | -from launch_ros.parameter_descriptions import ParameterValue |
37 | 33 |
|
| 34 | +from launch.actions import IncludeLaunchDescription |
| 35 | +from launch.launch_description_sources import FrontendLaunchDescriptionSource |
| 36 | +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution |
38 | 37 |
|
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") |
120 | 38 |
|
121 | | - robot_description_content = Command( |
| 39 | +def generate_launch_description(): |
| 40 | + return LaunchDescription( |
122 | 41 | [ |
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 | + ) |
144 | 58 | ] |
145 | 59 | ) |
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) |
0 commit comments