Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to declare parameter that are only known at runtime #2367

Closed
saikishor opened this issue Nov 10, 2023 · 2 comments
Closed

Unable to declare parameter that are only known at runtime #2367

saikishor opened this issue Nov 10, 2023 · 2 comments

Comments

@saikishor
Copy link

saikishor commented Nov 10, 2023

Hello!

I'm currently facing an issue with the ros2 parameters. I'm not sure how to approach this, from Iron on ros2_controller creates a node without the node options allow_undeclared_parameters and automatically_declare_parameters_from_overrides. I would like to define a block of parameters for my controller, however, their namespace is only known at the runtime. This is making it hard for me to load the parameters using the spawner.

A simple case would be something like below:

joints: ["joint_1", "joint_2"]
parameters:
  joint_1:
    type: rotary
    frame: joint_1_link
  joint_2:
    type: rotary
    frame: joint_2_link

To parse such a block, we need to know the joints parameter already at the time of declaration, and this is currently not possible. So, at the time of declaration, as this is not known, I'm not able to declare the parameter block and hence unable to set any of the respective parameters.

std::vector<JointParams> joint_params;
auto joint_names = node->declare_parameter<std::vector<std::string>>("joints", std::vector<std::string>());
for (auto joint : joint_names)
{
  RCLCPP_INFO(logger, "Adding Joint: %s", joint.c_str());
  JointParams params;
  params.name = name;
  params.type = node->declare_parameter<std::string>("parameters." + name + ".type", std::string());
  params.frame = node->declare_parameter<std::string>("parameters." + name + ".frame", std::string());
  params.param_name = node->declare_parameter<std::string>(name + ".param_name", std::string());
  joint_params.push_back(params);
}

Moreover, in the existing parameter callbacks(add_pre_set_parameters_callback , add_on_set_parameters_callback , and add_post_set_parameters_callback), we cannot declare or set any parameters, so I would like to know if there is a way to declare some parameters at runtime. If not, I propose to have a new callback method that helps to declare the parameters at runtime or a way to specify to allow undeclared parameters to a specific namespace.

Is there a better way to approach this problem?

@saikishor saikishor changed the title Ability to declare parameter that are only known at runtime Unable to declare parameter that are only known at runtime Nov 14, 2023
@saikishor
Copy link
Author

Hello!

Can someone help me with this?. I would like to know how to handle this, so I can fix it at different places of ros2_control. Any help is appreciated.

Thank you,

@saikishor
Copy link
Author

This solves the issue by setting the arguments in the NodeOptions. Please refer to ros-controls/ros2_control#1293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant