I am creating a custom controller using ros2_control. Going through the source code of existing controllers, I found out that there are 2 ways to initialize parameters(the one defined in controller config .yaml file). I need to know the difference between the two techniques.
The initialization of parameters is done in "on_init()" function.
In the "diff_drive" controller, the "on_init()" is like:
controller_interface::CallbackReturn DiffDriveController::on_init()
{
try
{
// Create the parameter listener and get the parameters
param_listener_ = std::make_shared<ParamListener>(get_node());
params_ = param_listener_->get_params();
}
catch (const std::exception & e)
{
fprintf(stderr, "Exception thrown during init stage with message: %s \n", e.what());
return controller_interface::CallbackReturn::ERROR;
}
return controller_interface::CallbackReturn::SUCCESS;
}
In this the param_listner_ line which is using ParamListner is responsible for initializing the parameters.
But the same "on_init()" for "Example_7" ros2_control_demo available at https://control.ros.org/master/doc/ros2_control_demos/example_7/doc/userdoc.html, is using auto_declare for parameter initialization.
The "on_init()" for "Example 7" is:
controller_interface::CallbackReturn RobotController::on_init()
{
// should have error handling
joint_names_ = auto_declare<std::vector<std::string>>("joints", joint_names_);
command_interface_types_ =
auto_declare<std::vector<std::string>>("command_interfaces", command_interface_types_);
state_interface_types_ =
auto_declare<std::vector<std::string>>("state_interfaces", state_interface_types_);
point_interp_.positions.assign(joint_names_.size(), 0);
point_interp_.velocities.assign(joint_names_.size(), 0);
return CallbackReturn::SUCCESS;
}
What is the difference between the two?