13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
16
+ # Import necessary modules
16
17
from launch import LaunchDescription
17
- from launch .actions import DeclareLaunchArgument
18
+ from launch .actions import DeclareLaunchArgument , TimerAction
18
19
from launch .conditions import UnlessCondition
19
20
from launch .substitutions import (
20
21
Command ,
27
28
from launch_ros .substitutions import FindPackageShare
28
29
from nav2_common .launch import ReplaceString
29
30
30
-
31
31
def generate_launch_description ():
32
+ # Declare launch arguments
32
33
namespace = LaunchConfiguration ("namespace" )
33
34
declare_namespace_arg = DeclareLaunchArgument (
34
35
"namespace" ,
35
36
default_value = "" ,
36
- description = "Namespace for all topics and tfs " ,
37
+ description = "Namespace for all topics and TFs " ,
37
38
)
38
39
39
40
mecanum = LaunchConfiguration ("mecanum" )
@@ -71,7 +72,7 @@ def generate_launch_description():
71
72
[
72
73
"'mecanum_drive_controller.yaml' if " ,
73
74
mecanum ,
74
- " else 'diff_drive_controller.yaml'" ,
75
+ " == 'True' else 'diff_drive_controller.yaml'" ,
75
76
]
76
77
)
77
78
@@ -106,29 +107,35 @@ def generate_launch_description():
106
107
simulation_engine ,
107
108
" namespace:=" ,
108
109
namespace ,
110
+ # Uncomment the line below if you need to include the 'use_ros2_control' parameter
111
+ # " use_ros2_control:=True",
109
112
]
110
113
)
111
114
robot_description = {"robot_description" : robot_description_content }
112
115
113
- robot_controllers_config = PathJoinSubstitution (
116
+ # Controller configurations
117
+ # robot_controllers_config = PathJoinSubstitution(
118
+ robot_controllers = PathJoinSubstitution (
114
119
[
115
120
FindPackageShare ("rosbot_controller" ),
116
121
"config" ,
117
122
controller_config_name ,
118
123
]
119
124
)
120
125
121
- namespaced_robot_controllers_config = ReplaceString (
122
- source_file = robot_controllers_config ,
123
- replacements = {"<robot_namespace>" : namespace , "//" : "/" },
124
- )
126
+ # namespaced_robot_controllers_config = ReplaceString(
127
+ # source_file=robot_controllers_config,
128
+ # replacements={"<robot_namespace>": namespace, "//": "/"},
129
+ # )
125
130
131
+ # Define nodes
126
132
control_node = Node (
127
133
package = "controller_manager" ,
128
134
executable = "ros2_control_node" ,
129
135
parameters = [
130
136
robot_description ,
131
- namespaced_robot_controllers_config ,
137
+ # namespaced_robot_controllers_config,
138
+ robot_controllers ,
132
139
],
133
140
remappings = [
134
141
("imu_sensor_node/imu" , "/_imu/data_raw" ),
@@ -140,6 +147,8 @@ def generate_launch_description():
140
147
],
141
148
condition = UnlessCondition (use_sim ),
142
149
namespace = namespace ,
150
+ respawn = True ,
151
+ respawn_delay = 2.0 ,
143
152
)
144
153
145
154
robot_state_pub_node = Node (
@@ -150,6 +159,7 @@ def generate_launch_description():
150
159
namespace = namespace ,
151
160
)
152
161
162
+ # Create spawner nodes
153
163
joint_state_broadcaster_spawner = Node (
154
164
package = "controller_manager" ,
155
165
executable = "spawner" ,
@@ -158,9 +168,9 @@ def generate_launch_description():
158
168
"--controller-manager" ,
159
169
controller_manager_name ,
160
170
"--controller-manager-timeout" ,
161
- "120 " ,
162
- "--namespace" ,
163
- namespace ,
171
+ "10 " ,
172
+ # "--namespace",
173
+ # namespace,
164
174
],
165
175
)
166
176
@@ -172,9 +182,9 @@ def generate_launch_description():
172
182
"--controller-manager" ,
173
183
controller_manager_name ,
174
184
"--controller-manager-timeout" ,
175
- "120 " ,
176
- "--namespace" ,
177
- namespace ,
185
+ "10 " ,
186
+ # "--namespace",
187
+ # namespace,
178
188
],
179
189
)
180
190
@@ -186,12 +196,27 @@ def generate_launch_description():
186
196
"--controller-manager" ,
187
197
controller_manager_name ,
188
198
"--controller-manager-timeout" ,
189
- "120 " ,
190
- "--namespace" ,
191
- namespace ,
199
+ "10 " ,
200
+ # "--namespace",
201
+ # namespace,
192
202
],
193
203
)
194
204
205
+ # Wrap the spawner nodes in a TimerAction to delay execution by 2 seconds
206
+ delayed_spawner_nodes = TimerAction (
207
+ period = 1.0 ,
208
+ actions = [
209
+ control_node ,
210
+ joint_state_broadcaster_spawner ,
211
+ robot_controller_spawner ,
212
+ imu_broadcaster_spawner ,
213
+ ],
214
+ )
215
+
216
+ # Set 'use_sim_time' parameter
217
+ # set_use_sim_time = SetParameter('use_sim_time', value=use_sim)fr
218
+
219
+ # Assemble the LaunchDescription
195
220
return LaunchDescription (
196
221
[
197
222
declare_namespace_arg ,
@@ -200,10 +225,7 @@ def generate_launch_description():
200
225
declare_use_gpu_arg ,
201
226
declare_simulation_engine_arg ,
202
227
SetParameter ("use_sim_time" , value = use_sim ),
203
- control_node ,
204
228
robot_state_pub_node ,
205
- joint_state_broadcaster_spawner ,
206
- robot_controller_spawner ,
207
- imu_broadcaster_spawner ,
229
+ delayed_spawner_nodes , # Add the delayed spawner nodes here
208
230
]
209
231
)
0 commit comments