@@ -239,6 +239,7 @@ ControllerManager::ControllerManager(
239
239
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
240
240
cm_node_options_(options)
241
241
{
242
+ initialize_parameters ();
242
243
init_controller_manager ();
243
244
}
244
245
@@ -247,10 +248,6 @@ ControllerManager::ControllerManager(
247
248
bool activate_all_hw_components, const std::string & manager_node_name,
248
249
const std::string & node_namespace, const rclcpp::NodeOptions & options)
249
250
: rclcpp::Node(manager_node_name, node_namespace, options),
250
- update_rate_(get_parameter_or<int >(" update_rate" , 100 )),
251
- resource_manager_(std::make_unique<hardware_interface::ResourceManager>(
252
- urdf, this ->get_node_clock_interface (), this->get_node_logging_interface(),
253
- activate_all_hw_components, update_rate_)),
254
251
diagnostics_updater_(this ),
255
252
executor_(executor),
256
253
loader_(std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
@@ -260,6 +257,10 @@ ControllerManager::ControllerManager(
260
257
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
261
258
cm_node_options_(options)
262
259
{
260
+ initialize_parameters ();
261
+ resource_manager_ = std::make_unique<hardware_interface::ResourceManager>(
262
+ urdf, this ->get_node_clock_interface (), this ->get_node_logging_interface (),
263
+ activate_all_hw_components, params_->update_rate );
263
264
init_controller_manager ();
264
265
}
265
266
@@ -278,18 +279,13 @@ ControllerManager::ControllerManager(
278
279
kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
279
280
cm_node_options_(options)
280
281
{
282
+ initialize_parameters ();
281
283
init_controller_manager ();
282
284
}
283
285
284
286
void ControllerManager::init_controller_manager ()
285
287
{
286
288
// Get parameters needed for RT "update" loop to work
287
- if (!get_parameter (" update_rate" , update_rate_))
288
- {
289
- RCLCPP_WARN (
290
- get_logger (), " 'update_rate' parameter not set, using default value of %d Hz." , update_rate_);
291
- }
292
-
293
289
if (is_resource_manager_initialized ())
294
290
{
295
291
init_services ();
@@ -327,6 +323,25 @@ void ControllerManager::init_controller_manager()
327
323
&ControllerManager::controller_manager_diagnostic_callback);
328
324
}
329
325
326
+ void ControllerManager::initialize_parameters ()
327
+ {
328
+ // Initialize parameters
329
+ try
330
+ {
331
+ cm_param_listener_ = std::make_shared<controller_manager::ParamListener>(
332
+ this ->get_node_parameters_interface (), this ->get_logger ());
333
+ params_ = std::make_shared<controller_manager::Params>(cm_param_listener_->get_params ());
334
+ update_rate_ = static_cast <unsigned int >(params_->update_rate );
335
+ }
336
+ catch (const std::exception & e)
337
+ {
338
+ RCLCPP_ERROR (
339
+ this ->get_logger (),
340
+ " Exception thrown while initializing controller manager parameters: %s \n " , e.what ());
341
+ throw e;
342
+ }
343
+ }
344
+
330
345
void ControllerManager::robot_description_callback (const std_msgs::msg::String & robot_description)
331
346
{
332
347
RCLCPP_INFO (get_logger (), " Received robot description from topic." );
@@ -3072,31 +3087,14 @@ void ControllerManager::controller_activity_diagnostic_callback(
3072
3087
std::lock_guard<std::recursive_mutex> guard (rt_controllers_wrapper_.controllers_lock_ );
3073
3088
const std::vector<ControllerSpec> & controllers = rt_controllers_wrapper_.get_updated_list (guard);
3074
3089
bool all_active = true ;
3075
- const std::string param_prefix = " diagnostics.threshold.controllers" ;
3076
3090
const std::string periodicity_suffix = " .periodicity" ;
3077
3091
const std::string exec_time_suffix = " .execution_time" ;
3078
- const std::string mean_error_suffix = " .mean_error" ;
3079
- const std::string std_dev_suffix = " .standard_deviation" ;
3080
3092
const std::string state_suffix = " .state" ;
3081
3093
3082
- // Get threshold values from param server
3083
- const double periodicity_mean_warn_threshold =
3084
- this ->get_parameter_or (param_prefix + periodicity_suffix + mean_error_suffix + " .warn" , 5.0 );
3085
- const double periodicity_mean_error_threshold =
3086
- this ->get_parameter_or (param_prefix + periodicity_suffix + mean_error_suffix + " .error" , 10.0 );
3087
- const double periodicity_std_dev_warn_threshold =
3088
- this ->get_parameter_or (param_prefix + periodicity_suffix + std_dev_suffix + " .warn" , 5.0 );
3089
- const double periodicity_std_dev_error_threshold =
3090
- this ->get_parameter_or (param_prefix + periodicity_suffix + std_dev_suffix + " .error" , 10.0 );
3091
-
3092
- const double exec_time_mean_warn_threshold =
3093
- this ->get_parameter_or (param_prefix + exec_time_suffix + mean_error_suffix + " .warn" , 1000.0 );
3094
- const double exec_time_mean_error_threshold =
3095
- this ->get_parameter_or (param_prefix + exec_time_suffix + mean_error_suffix + " .error" , 2000.0 );
3096
- const double exec_time_std_dev_warn_threshold =
3097
- this ->get_parameter_or (param_prefix + exec_time_suffix + std_dev_suffix + " .warn" , 100.0 );
3098
- const double exec_time_std_dev_error_threshold =
3099
- this ->get_parameter_or (param_prefix + exec_time_suffix + std_dev_suffix + " .error" , 200.0 );
3094
+ if (cm_param_listener_->is_old (*params_))
3095
+ {
3096
+ *params_ = cm_param_listener_->get_params ();
3097
+ }
3100
3098
3101
3099
auto make_stats_string =
3102
3100
[](const auto & statistics_data, const std::string & measurement_unit) -> std::string
@@ -3138,15 +3136,19 @@ void ControllerManager::controller_activity_diagnostic_callback(
3138
3136
const double periodicity_error = std::abs (
3139
3137
periodicity_stats.average - static_cast <double >(controllers[i].c ->get_update_rate ()));
3140
3138
if (
3141
- periodicity_error > periodicity_mean_error_threshold ||
3142
- periodicity_stats.standard_deviation > periodicity_std_dev_error_threshold)
3139
+ periodicity_error >
3140
+ params_->diagnostics .threshold .controllers .periodicity .mean_error .error ||
3141
+ periodicity_stats.standard_deviation >
3142
+ params_->diagnostics .threshold .controllers .periodicity .standard_deviation .error )
3143
3143
{
3144
3144
level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
3145
3145
add_element_to_list (bad_periodicity_async_controllers, controllers[i].info .name );
3146
3146
}
3147
3147
else if (
3148
- periodicity_error > periodicity_mean_warn_threshold ||
3149
- periodicity_stats.standard_deviation > periodicity_std_dev_warn_threshold)
3148
+ periodicity_error >
3149
+ params_->diagnostics .threshold .controllers .periodicity .mean_error .warn ||
3150
+ periodicity_stats.standard_deviation >
3151
+ params_->diagnostics .threshold .controllers .periodicity .standard_deviation .warn )
3150
3152
{
3151
3153
if (level != diagnostic_msgs::msg::DiagnosticStatus::ERROR)
3152
3154
{
@@ -3157,15 +3159,19 @@ void ControllerManager::controller_activity_diagnostic_callback(
3157
3159
}
3158
3160
const double max_exp_exec_time = is_async ? 1 .e6 / controllers[i].c ->get_update_rate () : 0.0 ;
3159
3161
if (
3160
- (exec_time_stats.average - max_exp_exec_time) > exec_time_mean_error_threshold ||
3161
- exec_time_stats.standard_deviation > exec_time_std_dev_error_threshold)
3162
+ (exec_time_stats.average - max_exp_exec_time) >
3163
+ params_->diagnostics .threshold .controllers .execution_time .mean_error .error ||
3164
+ exec_time_stats.standard_deviation >
3165
+ params_->diagnostics .threshold .controllers .execution_time .standard_deviation .error )
3162
3166
{
3163
3167
level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
3164
3168
high_exec_time_controllers.push_back (controllers[i].info .name );
3165
3169
}
3166
3170
else if (
3167
- (exec_time_stats.average - max_exp_exec_time) > exec_time_mean_warn_threshold ||
3168
- exec_time_stats.standard_deviation > exec_time_std_dev_warn_threshold)
3171
+ (exec_time_stats.average - max_exp_exec_time) >
3172
+ params_->diagnostics .threshold .controllers .execution_time .mean_error .warn ||
3173
+ exec_time_stats.standard_deviation >
3174
+ params_->diagnostics .threshold .controllers .execution_time .standard_deviation .warn )
3169
3175
{
3170
3176
if (level != diagnostic_msgs::msg::DiagnosticStatus::ERROR)
3171
3177
{
@@ -3294,34 +3300,23 @@ void ControllerManager::controller_manager_diagnostic_callback(
3294
3300
}
3295
3301
}
3296
3302
3297
- const std::string param_prefix = " diagnostics.threshold.controller_manager" ;
3298
- const std::string periodicity_suffix = " .periodicity" ;
3299
- const std::string mean_error_suffix = " .mean_error" ;
3300
- const std::string std_dev_suffix = " .standard_deviation" ;
3301
-
3302
- // Get threshold values from param server
3303
- const double periodicity_mean_warn_threshold =
3304
- this ->get_parameter_or (param_prefix + periodicity_suffix + mean_error_suffix + " .warn" , 5.0 );
3305
- const double periodicity_mean_error_threshold =
3306
- this ->get_parameter_or (param_prefix + periodicity_suffix + mean_error_suffix + " .error" , 10.0 );
3307
- const double periodicity_std_dev_warn_threshold =
3308
- this ->get_parameter_or (param_prefix + periodicity_suffix + std_dev_suffix + " .warn" , 5.0 );
3309
- const double periodicity_std_dev_error_threshold =
3310
- this ->get_parameter_or (param_prefix + periodicity_suffix + std_dev_suffix + " .error" , 10.0 );
3311
-
3312
3303
const double periodicity_error = std::abs (cm_stats.average - get_update_rate ());
3313
3304
const std::string diag_summary =
3314
3305
" Controller Manager has bad periodicity : " + std::to_string (cm_stats.average ) +
3315
3306
" Hz. Expected consistent " + std::to_string (get_update_rate ()) + " Hz" ;
3316
3307
if (
3317
- periodicity_error > periodicity_mean_error_threshold ||
3318
- cm_stats.standard_deviation > periodicity_std_dev_error_threshold)
3308
+ periodicity_error >
3309
+ params_->diagnostics .threshold .controller_manager .periodicity .mean_error .error ||
3310
+ cm_stats.standard_deviation >
3311
+ params_->diagnostics .threshold .controller_manager .periodicity .standard_deviation .error )
3319
3312
{
3320
3313
stat.mergeSummary (diagnostic_msgs::msg::DiagnosticStatus::ERROR, diag_summary);
3321
3314
}
3322
3315
else if (
3323
- periodicity_error > periodicity_mean_warn_threshold ||
3324
- cm_stats.standard_deviation > periodicity_std_dev_warn_threshold)
3316
+ periodicity_error >
3317
+ params_->diagnostics .threshold .controller_manager .periodicity .mean_error .warn ||
3318
+ cm_stats.standard_deviation >
3319
+ params_->diagnostics .threshold .controller_manager .periodicity .standard_deviation .warn )
3325
3320
{
3326
3321
stat.mergeSummary (diagnostic_msgs::msg::DiagnosticStatus::WARN, diag_summary);
3327
3322
}
0 commit comments