diff --git a/rosplane/include/param_manager.hpp b/rosplane/include/param_manager.hpp index c57f0df..27d4279 100644 --- a/rosplane/include/param_manager.hpp +++ b/rosplane/include/param_manager.hpp @@ -49,7 +49,16 @@ class param_manager */ // TODO: Check to make sure that setting a parameter before declaring it won't give an error. // Hypothesis is that it will break, but is that not desired behavior? - void set_parameters(); + void set_parameters(); + + /** + * This function sets a previously declared parameter to a new value in both the parameter object + * and the ROS system. + */ + void set_parameter(std::string param_name, double value); + void set_parameter(std::string param_name, bool value); + void set_int(std::string param_name, int64_t value); + void set_parameter(std::string param_name, std::string value); /** * This function should be called in the parametersCallback function in a containing ROS node. diff --git a/rosplane/src/param_manager.cpp b/rosplane/src/param_manager.cpp index 6f8dc1d..2b7ac29 100644 --- a/rosplane/src/param_manager.cpp +++ b/rosplane/src/param_manager.cpp @@ -37,6 +37,66 @@ void param_manager::declare_string(std::string param_name, std::string value) container_node_->declare_parameter(param_name, value); } +void param_manager::set_parameter(std::string param_name, double value) +{ + // Check that the parameter is in the parameter struct + if (params_.find(param_name) == params_.end()) + { + RCLCPP_ERROR_STREAM(container_node_->get_logger(), "Parameter not found in parameter struct: " + param_name); + return; + } + + // Set the parameter in the parameter struct + params_[param_name] = value; + // Set the parameter in the ROS2 param system + container_node_->set_parameter(rclcpp::Parameter(param_name, value)); +} + +void param_manager::set_parameter(std::string param_name, bool value) +{ + // Check that the parameter is in the parameter struct + if (params_.find(param_name) == params_.end()) + { + RCLCPP_ERROR_STREAM(container_node_->get_logger(), "Parameter not found in parameter struct: " + param_name); + return; + } + + // Set the parameter in the parameter struct + params_[param_name] = value; + // Set the parameter in the ROS2 param system + container_node_->set_parameter(rclcpp::Parameter(param_name, value)); +} + +void param_manager::set_int(std::string param_name, int64_t value) +{ + // Check that the parameter is in the parameter struct + if (params_.find(param_name) == params_.end()) + { + RCLCPP_ERROR_STREAM(container_node_->get_logger(), "Parameter not found in parameter struct: " + param_name); + return; + } + + // Set the parameter in the parameter struct + params_[param_name] = value; + // Set the parameter in the ROS2 param system + container_node_->set_parameter(rclcpp::Parameter(param_name, value)); +} + +void param_manager::set_parameter(std::string param_name, std::string value) +{ + // Check that the parameter is in the parameter struct + if (params_.find(param_name) == params_.end()) + { + RCLCPP_ERROR_STREAM(container_node_->get_logger(), "Parameter not found in parameter struct: " + param_name); + return; + } + + // Set the parameter in the parameter struct + params_[param_name] = value; + // Set the parameter in the ROS2 param system + container_node_->set_parameter(rclcpp::Parameter(param_name, value)); +} + double param_manager::get_double(std::string param_name) { try