Nav2 Navigation Stack - jazzy  jazzy
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  if (on_set_param_handler_ && node) {
33  node->remove_on_set_parameters_callback(on_set_param_handler_.get());
34  }
35  on_set_param_handler_.reset();
36 }
37 
39 {
40  auto node = node_.lock();
41  on_set_param_handler_ = node->add_on_set_parameters_callback(
42  std::bind(
44  std::placeholders::_1));
45 
46  auto get_param = getParamGetter(node_name_);
47  get_param(verbose_, "verbose", false);
48 }
49 
50 rcl_interfaces::msg::SetParametersResult
52  std::vector<rclcpp::Parameter> parameters)
53 {
54  rcl_interfaces::msg::SetParametersResult result;
55  std::lock_guard<std::mutex> lock(parameters_change_mutex_);
56 
57  for (auto & pre_cb : pre_callbacks_) {
58  pre_cb();
59  }
60 
61  for (auto & param : parameters) {
62  const std::string & param_name = param.get_name();
63 
64  if (auto callback = get_param_callbacks_.find(param_name);
65  callback != get_param_callbacks_.end())
66  {
67  callback->second(param);
68  } else {
69  RCLCPP_WARN(logger_, "Parameter %s not found", param_name.c_str());
70  }
71  }
72 
73  for (auto & post_cb : post_callbacks_) {
74  post_cb();
75  }
76 
77  result.successful = true;
78  return result;
79 }
80 
81 } // 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.
~ParametersHandler()
Destructor for mppi::ParametersHandler.