0
$\begingroup$

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?

$\endgroup$

1 Answer 1

0
$\begingroup$

ParamListener is needed if the generate_parameter_library is used, the example you have linked just don't use it and the parameters are handled (and declared) manually.

$\endgroup$
4
  • $\begingroup$ Is it necessary to implement odometry and transforms when writing a custom controller or will the robot_state_publisher handle it? I never need to look into odometry as robot_state_publisher publishes odom and transforms automatically but i saw they are implemented explicitly specifically in diff_drive_controller. $\endgroup$
    – Pratham
    Commented May 25 at 1:45
  • $\begingroup$ robot_state_publisher does not calculate any odometry, it only takes joint_states and creates the tf tree with the given robot_description. If you have a mobile robot, you will need to calculate its location in the world frame somehow. $\endgroup$ Commented May 25 at 12:42
  • $\begingroup$ I need to ask multiple such questions regarding ros2_control whose answer is most likely one liner. would it be better to create separate RSE Questions or should I ask them here only? $\endgroup$
    – Pratham
    Commented May 25 at 17:01
  • $\begingroup$ create separate RSE Questions please. And click "Accept this answer" if questions are solved. $\endgroup$ Commented May 25 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.