Skip to content

Commit

Permalink
Added individual set functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Jun 17, 2024
1 parent e36ba62 commit d42d840
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rosplane/include/param_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 60 additions & 0 deletions rosplane/src/param_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d42d840

Please sign in to comment.