Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
parameter_handler.hpp
1 // Copyright (c) 2022 Samsung Research America
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 #ifndef OPENNAV_FOLLOWING__PARAMETER_HANDLER_HPP_
16 #define OPENNAV_FOLLOWING__PARAMETER_HANDLER_HPP_
17 
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include <algorithm>
22 #include <mutex>
23 
24 #include "rclcpp/rclcpp.hpp"
25 #include "nav2_util/lifecycle_node.hpp"
26 #include "nav2_util/node_utils.hpp"
27 
28 namespace opennav_following
29 {
30 
31 struct Parameters
32 {
33  // Frequency to run control loops
34  double controller_frequency;
35  // Timeout to detect the object
36  double detection_timeout;
37  // Timeout to detect the object while rotating to it
38  double rotate_to_object_timeout;
39  // Timeout after which a static object is considered as goal reached
40  double static_object_timeout;
41  // Tolerances for arriving at the safe_distance pose
42  double linear_tolerance, angular_tolerance;
43  // Maximum number of times the robot will retry to approach the object
44  int max_retries;
45  // This is the root frame of the robot - typically "base_link"
46  std::string base_frame;
47  // This is our fixed frame for controlling - typically "odom"
48  std::string fixed_frame;
49  // Desired distance to keep from the object
50  double desired_distance;
51  // Skip perception orientation
52  bool skip_orientation;
53  // Should the robot search for the object by rotating or go to last known heading
54  bool search_by_rotating;
55  // Search angle relative to current robot orientation when rotating to find objects
56  double search_angle;
57  // Tolerance for transforming coordinates
58  double transform_tolerance;
59  // Parameters for OdomSmoother
60  std::string odom_topic;
61  double odom_duration;
62  bool use_collision_detection;
63  double filter_coef;
64 };
65 
71 {
72 public:
77  const nav2_util::LifecycleNode::SharedPtr & node,
78  const rclcpp::Logger & logger);
79 
83  ~ParameterHandler() = default;
84 
89  std::mutex & getMutex() {return mutex_;}
90 
95  Parameters * getParams() {return &params_;}
96 
100  void activate();
101 
105  void deactivate();
106 
107 protected:
113  rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(
114  const std::vector<rclcpp::Parameter> & parameters);
115 
116  nav2_util::LifecycleNode::WeakPtr node_;
117  std::mutex mutex_;
118  Parameters params_;
119  rclcpp::Logger logger_;
120  rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
121 };
122 
123 } // namespace opennav_following
124 
125 #endif // OPENNAV_FOLLOWING__PARAMETER_HANDLER_HPP_
Handles parameters and dynamic parameters for Following Server.
Parameters * getParams()
Get a pointer to the internal parameter structure.
void deactivate()
Resets callbacks for dynamic parameter handling.
void activate()
Registers callbacks for dynamic parameter handling.
~ParameterHandler()=default
Destructor for opennav_following::ParameterHandler.
std::mutex & getMutex()
Get the internal mutex used for thread-safe parameter access.
rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Callback executed when a parameter change is detected.
ParameterHandler(const nav2_util::LifecycleNode::SharedPtr &node, const rclcpp::Logger &logger)
Constructor for opennav_following::ParameterHandler.