@@ -200,38 +200,7 @@ ControllerManager::ControllerManager(
200
200
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
201
201
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
202
202
{
203
- if (!get_parameter (" update_rate" , update_rate_))
204
- {
205
- RCLCPP_WARN (
206
- get_logger (), " 'update_rate' parameter not set, using default value of %d Hz." , update_rate_);
207
- }
208
-
209
- robot_description_ = " " ;
210
- // TODO(destogl): remove support at the end of 2023
211
- get_parameter (" robot_description" , robot_description_);
212
- if (robot_description_.empty ())
213
- {
214
- subscribe_to_robot_description_topic ();
215
- }
216
- else
217
- {
218
- RCLCPP_WARN (
219
- get_logger (),
220
- " [Deprecated] Passing the robot description parameter directly to the control_manager node "
221
- " is deprecated. Use the 'robot_description' topic from 'robot_state_publisher' instead." );
222
- init_resource_manager (robot_description_);
223
- if (is_resource_manager_initialized ())
224
- {
225
- RCLCPP_WARN (
226
- get_logger (),
227
- " You have to restart the framework when using robot description from parameter!" );
228
- init_services ();
229
- }
230
- }
231
-
232
- diagnostics_updater_.setHardwareID (" ros2_control" );
233
- diagnostics_updater_.add (
234
- " Controllers Activity" , this , &ControllerManager::controller_activity_diagnostic_callback);
203
+ init_controller_manager ();
235
204
}
236
205
237
206
ControllerManager::ControllerManager (
@@ -251,21 +220,7 @@ ControllerManager::ControllerManager(
251
220
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
252
221
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
253
222
{
254
- if (!get_parameter (" update_rate" , update_rate_))
255
- {
256
- RCLCPP_WARN (
257
- get_logger (), " 'update_rate' parameter not set, using default value of %d Hz." , update_rate_);
258
- }
259
-
260
- if (is_resource_manager_initialized ())
261
- {
262
- init_services ();
263
- }
264
- subscribe_to_robot_description_topic ();
265
-
266
- diagnostics_updater_.setHardwareID (" ros2_control" );
267
- diagnostics_updater_.add (
268
- " Controllers Activity" , this , &ControllerManager::controller_activity_diagnostic_callback);
223
+ init_controller_manager ();
269
224
}
270
225
271
226
ControllerManager::ControllerManager (
@@ -282,6 +237,12 @@ ControllerManager::ControllerManager(
282
237
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
283
238
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
284
239
{
240
+ init_controller_manager ();
241
+ }
242
+
243
+ void ControllerManager::init_controller_manager ()
244
+ {
245
+ // Get parameters needed for RT "update" loop to work
285
246
if (!get_parameter (" update_rate" , update_rate_))
286
247
{
287
248
RCLCPP_WARN (
@@ -292,15 +253,17 @@ ControllerManager::ControllerManager(
292
253
{
293
254
init_services ();
294
255
}
295
- subscribe_to_robot_description_topic ();
296
-
297
- diagnostics_updater_.setHardwareID (" ros2_control" );
298
- diagnostics_updater_.add (
299
- " Controllers Activity" , this , &ControllerManager::controller_activity_diagnostic_callback);
300
- }
256
+ else
257
+ {
258
+ robot_description_notification_timer_ = create_wall_timer (
259
+ std::chrono::seconds (1 ),
260
+ [&]()
261
+ {
262
+ RCLCPP_WARN (
263
+ get_logger (), " Waiting for data on 'robot_description' topic to finish initialization" );
264
+ });
265
+ }
301
266
302
- void ControllerManager::subscribe_to_robot_description_topic ()
303
- {
304
267
// set QoS to transient local to get messages that have already been published
305
268
// (if robot state publisher starts before controller manager)
306
269
robot_description_subscription_ = create_subscription<std_msgs::msg::String>(
@@ -309,6 +272,11 @@ void ControllerManager::subscribe_to_robot_description_topic()
309
272
RCLCPP_INFO (
310
273
get_logger (), " Subscribing to '%s' topic for robot description." ,
311
274
robot_description_subscription_->get_topic_name ());
275
+
276
+ // Setup diagnostics
277
+ diagnostics_updater_.setHardwareID (" ros2_control" );
278
+ diagnostics_updater_.add (
279
+ " Controllers Activity" , this , &ControllerManager::controller_activity_diagnostic_callback);
312
280
}
313
281
314
282
void ControllerManager::robot_description_callback (const std_msgs::msg::String & robot_description)
@@ -321,13 +289,16 @@ void ControllerManager::robot_description_callback(const std_msgs::msg::String &
321
289
{
322
290
RCLCPP_WARN (
323
291
get_logger (),
324
- " ResourceManager has already loaded an urdf file. Ignoring attempt to reload a robot "
325
- " description file." );
292
+ " ResourceManager has already loaded a urdf. Ignoring attempt to reload a robot description." );
326
293
return ;
327
294
}
328
295
init_resource_manager (robot_description_);
329
296
if (is_resource_manager_initialized ())
330
297
{
298
+ RCLCPP_INFO (
299
+ get_logger (),
300
+ " Resource Manager has been successfully initialized. Starting Controller Manager "
301
+ " services..." );
331
302
init_services ();
332
303
}
333
304
}
@@ -397,6 +368,7 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
397
368
State::PRIMARY_STATE_ACTIVE, hardware_interface::lifecycle_state_names::ACTIVE);
398
369
resource_manager_->set_component_state (component, active_state);
399
370
}
371
+ robot_description_notification_timer_->cancel ();
400
372
}
401
373
402
374
void ControllerManager::init_services ()
@@ -898,6 +870,15 @@ controller_interface::return_type ControllerManager::switch_controller(
898
870
const std::vector<std::string> & deactivate_controllers, int strictness, bool activate_asap,
899
871
const rclcpp::Duration & timeout)
900
872
{
873
+ if (!is_resource_manager_initialized ())
874
+ {
875
+ RCLCPP_ERROR (
876
+ get_logger (),
877
+ " Resource Manager is not initialized yet! Please provide robot description on "
878
+ " 'robot_description' topic before trying to switch controllers." );
879
+ return controller_interface::return_type::ERROR;
880
+ }
881
+
901
882
switch_params_ = SwitchParams ();
902
883
903
884
if (!deactivate_request_.empty () || !activate_request_.empty ())
0 commit comments