Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
parameters_handler.cpp
1 // Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
16 
17 namespace mppi
18 {
19 
21  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent)
22 {
23  node_ = parent;
24  auto node = node_.lock();
25  node_name_ = node->get_name();
26  logger_ = node->get_logger();
27 }
28 
30 {
31  auto node = node_.lock();
32  on_set_param_handler_ = node->add_on_set_parameters_callback(
33  std::bind(
35  std::placeholders::_1));
36 
37  auto get_param = getParamGetter(node_name_);
38  get_param(verbose_, "verbose", false);
39 }
40 
41 rcl_interfaces::msg::SetParametersResult
43  std::vector<rclcpp::Parameter> parameters)
44 {
45  rcl_interfaces::msg::SetParametersResult result;
46  std::lock_guard<std::mutex> lock(parameters_change_mutex_);
47 
48  for (auto & pre_cb : pre_callbacks_) {
49  pre_cb();
50  }
51 
52  for (auto & param : parameters) {
53  const std::string & param_name = param.get_name();
54 
55  if (auto callback = get_param_callbacks_.find(param_name);
56  callback != get_param_callbacks_.end())
57  {
58  callback->second(param);
59  } else {
60  RCLCPP_WARN(logger_, "Parameter %s not found", param_name.c_str());
61  }
62  }
63 
64  for (auto & post_cb : post_callbacks_) {
65  post_cb();
66  }
67 
68  result.successful = true;
69  return result;
70 }
71 
72 } // namespace mppi
rcl_interfaces::msg::SetParametersResult dynamicParamsCallback(std::vector< rclcpp::Parameter > parameters)
Dynamic parameter callback.
auto getParamGetter(const std::string &ns)
Get an object to retreive parameters.
void start()
Starts processing dynamic parameter changes.
ParametersHandler()=default
Constructor for mppi::ParametersHandler.