@@ -239,6 +239,7 @@ ControllerManager::ControllerManager(
239239 kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
240240 cm_node_options_(options)
241241{
242+ initialize_parameters ();
242243 init_controller_manager ();
243244}
244245
@@ -247,10 +248,6 @@ ControllerManager::ControllerManager(
247248 bool activate_all_hw_components, const std::string & manager_node_name,
248249 const std::string & node_namespace, const rclcpp::NodeOptions & options)
249250: 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_)),
254251 diagnostics_updater_(this ),
255252 executor_(executor),
256253 loader_(std::make_shared<pluginlib::ClassLoader<controller_interface::ControllerInterface>>(
@@ -260,6 +257,10 @@ ControllerManager::ControllerManager(
260257 kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
261258 cm_node_options_(options)
262259{
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 );
263264 init_controller_manager ();
264265}
265266
@@ -278,18 +279,13 @@ ControllerManager::ControllerManager(
278279 kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
279280 cm_node_options_(options)
280281{
282+ initialize_parameters ();
281283 init_controller_manager ();
282284}
283285
284286void ControllerManager::init_controller_manager ()
285287{
286288 // 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-
293289 if (is_resource_manager_initialized ())
294290 {
295291 init_services ();
@@ -327,6 +323,25 @@ void ControllerManager::init_controller_manager()
327323 &ControllerManager::controller_manager_diagnostic_callback);
328324}
329325
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+
330345void ControllerManager::robot_description_callback (const std_msgs::msg::String & robot_description)
331346{
332347 RCLCPP_INFO (get_logger (), " Received robot description from topic." );
@@ -3072,31 +3087,14 @@ void ControllerManager::controller_activity_diagnostic_callback(
30723087 std::lock_guard<std::recursive_mutex> guard (rt_controllers_wrapper_.controllers_lock_ );
30733088 const std::vector<ControllerSpec> & controllers = rt_controllers_wrapper_.get_updated_list (guard);
30743089 bool all_active = true ;
3075- const std::string param_prefix = " diagnostics.threshold.controllers" ;
30763090 const std::string periodicity_suffix = " .periodicity" ;
30773091 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" ;
30803092 const std::string state_suffix = " .state" ;
30813093
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+ }
31003098
31013099 auto make_stats_string =
31023100 [](const auto & statistics_data, const std::string & measurement_unit) -> std::string
@@ -3138,15 +3136,19 @@ void ControllerManager::controller_activity_diagnostic_callback(
31383136 const double periodicity_error = std::abs (
31393137 periodicity_stats.average - static_cast <double >(controllers[i].c ->get_update_rate ()));
31403138 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 )
31433143 {
31443144 level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
31453145 add_element_to_list (bad_periodicity_async_controllers, controllers[i].info .name );
31463146 }
31473147 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 )
31503152 {
31513153 if (level != diagnostic_msgs::msg::DiagnosticStatus::ERROR)
31523154 {
@@ -3157,15 +3159,19 @@ void ControllerManager::controller_activity_diagnostic_callback(
31573159 }
31583160 const double max_exp_exec_time = is_async ? 1 .e6 / controllers[i].c ->get_update_rate () : 0.0 ;
31593161 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 )
31623166 {
31633167 level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
31643168 high_exec_time_controllers.push_back (controllers[i].info .name );
31653169 }
31663170 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 )
31693175 {
31703176 if (level != diagnostic_msgs::msg::DiagnosticStatus::ERROR)
31713177 {
@@ -3294,34 +3300,23 @@ void ControllerManager::controller_manager_diagnostic_callback(
32943300 }
32953301 }
32963302
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-
33123303 const double periodicity_error = std::abs (cm_stats.average - get_update_rate ());
33133304 const std::string diag_summary =
33143305 " Controller Manager has bad periodicity : " + std::to_string (cm_stats.average ) +
33153306 " Hz. Expected consistent " + std::to_string (get_update_rate ()) + " Hz" ;
33163307 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 )
33193312 {
33203313 stat.mergeSummary (diagnostic_msgs::msg::DiagnosticStatus::ERROR, diag_summary);
33213314 }
33223315 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 )
33253320 {
33263321 stat.mergeSummary (diagnostic_msgs::msg::DiagnosticStatus::WARN, diag_summary);
33273322 }
0 commit comments