-
Notifications
You must be signed in to change notification settings - Fork 421
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
Programmatically loading parameters from yaml files into nodes dynamically #1029
Comments
For what it is worth, it should be possible to do this pretty easily right now. You'd just need a small program that opened up a YAML file (maybe using yaml-cpp), formatted that YAML into a https://github.com/ros2/rcl_interfaces/blob/master/rcl_interfaces/srv/SetParameters.srv (one per node), and then called the I guess we could potentially make this easier with an API on rclcpp, but I'm not sure. |
Actually there is a So consider the parsing problem is solved, and it just need to overwrite or create a new parameter from the parsed |
Were the multiple |
@CursedRock17 i think we already can do this with, (really easy)
we can even do this with remote node. but there is no such method in CC: @clalancette what do you think? |
@fujitatomoya Thank you very much for the hints, here is how I got it working for reference : #include <ament_index_cpp/get_package_share_directory.hpp>
// Read yaml parameter file
const std::string yaml_filepath = ament_index_cpp::get_package_share_directory("package_name") + "/config/params.yaml";
RCLCPP_INFO_STREAM(node_->get_logger(), "Reading yaml parameter files located at" << yaml_filename << std::endl);
auto parameters_client = std::make_shared<rclcpp::AsyncParametersClient>(node_, "package_name");
parameters_client->load_parameters(yaml_filepath); |
If this something the rclcpp maintainers fine with adding, we could review a PR @RobinBaruffa. |
i believe that having @clalancette @wjwwood @sloretz @alsora @mjcarroll what do you think? Note:
|
Sorry I haven't time to read everything here or comment before now, but we discussed this a bit today in our triage meeting and I summarized our thoughts here: #2406 (review) In short, this seems like a good feature, but we would like to avoid expanding the methods on the |
Hm, I don't get the purpose of the MR for multiple reasons
I agree to this statement. But I would like to point out the primary reason on why my colleagues and I think so. |
When writing a Gazebo plugin that was connected to ROS, I had to load a yaml directly from the c++ code as the gazebo_ros package acts as the node handler and therefore I couldn't pass parameter through it (at least not to my knowledge). In addition, gazebo plugins are instantiated by Gazebo and are not always ran using a roslaunch file so in this case I believe it makes sense to load a yaml directly from the code.
I don't think so, if |
You get passed a sdf::ElementPtr _sdf in the Load function of your plugin. Within the _sdf the parameters for your plugin are contained. You are supposed to put them into the SDF together with 'adding' of the plugin of your robot. So no use case here...
The proposal does not state the export of the loaded parameters. The suggested implementation seems to do this, even though it is not mentioned in the description of the function. |
Feature request
Programmatically loading parameters from yaml files into nodes dynamically
Feature description
A simple c++ function (possibly put into rclcpp::Node?) for loading parameters from yaml files after the node has been started. (ie. not via supplying a yaml file in the
ros2 run
command)There were several ros1 repos using this functionality of loading nodes dynamically and supplying yaml file. However, the spec on parameters changed with ros2.
Implementation considerations
Not sure if the function should be under rclcpp::Node.
Some upcoming repos that could use this functionality:
ros2_controls controller_manager loading controllers at runtime
ros2 version gazebo_ros_controls (blocked)
Reference code doing the same thing as this request that you could use:
https://github.com/ros-controls/ros2_control/pull/64/files
A good use case would be the following yaml file contains parameters for two nodes:
As far as I know it follows the spec given on the ROS2 tutorials
The text was updated successfully, but these errors were encountered: