Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
source.hpp
1 // Copyright (c) 2022 Samsung R&D Institute Russia
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 NAV2_COLLISION_MONITOR__SOURCE_HPP_
16 #define NAV2_COLLISION_MONITOR__SOURCE_HPP_
17 
18 #include <memory>
19 #include <vector>
20 #include <string>
21 
22 #include "rclcpp/rclcpp.hpp"
23 
24 #include "tf2/time.h"
25 #include "tf2_ros/buffer.h"
26 
27 #include "nav2_util/lifecycle_node.hpp"
28 
29 #include "nav2_collision_monitor/types.hpp"
30 
31 namespace nav2_collision_monitor
32 {
33 
37 class Source
38 {
39 public:
52  Source(
53  const nav2_util::LifecycleNode::WeakPtr & node,
54  const std::string & source_name,
55  const std::shared_ptr<tf2_ros::Buffer> tf_buffer,
56  const std::string & base_frame_id,
57  const std::string & global_frame_id,
58  const tf2::Duration & transform_tolerance,
59  const rclcpp::Duration & source_timeout,
60  const bool base_shift_correction);
64  virtual ~Source();
65 
73  virtual void getData(
74  const rclcpp::Time & curr_time,
75  std::vector<Point> & data) const = 0;
76 
81  bool getEnabled() const;
82 
83 protected:
88  bool configure();
89 
94  void getCommonParameters(std::string & source_topic);
95 
102  bool sourceValid(
103  const rclcpp::Time & source_time,
104  const rclcpp::Time & curr_time) const;
105 
110  rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(
111  std::vector<rclcpp::Parameter> parameters);
112 
113  // ----- Variables -----
114 
116  nav2_util::LifecycleNode::WeakPtr node_;
118  rclcpp::Logger logger_{rclcpp::get_logger("collision_monitor")};
120  rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_;
121 
122  // Basic parameters
124  std::string source_name_;
125 
126  // Global variables
128  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
130  std::string base_frame_id_;
132  std::string global_frame_id_;
134  tf2::Duration transform_tolerance_;
136  rclcpp::Duration source_timeout_;
141  bool enabled_;
142 }; // class Source
143 
144 } // namespace nav2_collision_monitor
145 
146 #endif // NAV2_COLLISION_MONITOR__SOURCE_HPP_
Basic data source class.
Definition: source.hpp:38
rclcpp::Logger logger_
Collision monitor node logger stored for further usage.
Definition: source.hpp:118
std::string base_frame_id_
Robot base frame ID.
Definition: source.hpp:130
virtual ~Source()
Source destructor.
Definition: source.cpp:45
bool enabled_
Whether source is enabled.
Definition: source.hpp:141
bool getEnabled() const
Obtains source enabled state.
Definition: source.cpp:96
tf2::Duration transform_tolerance_
Transform tolerance.
Definition: source.hpp:134
void getCommonParameters(std::string &source_topic)
Supporting routine obtaining ROS-parameters common for all data sources.
Definition: source.cpp:60
bool configure()
Source configuration routine.
Definition: source.cpp:49
Source(const nav2_util::LifecycleNode::WeakPtr &node, const std::string &source_name, const std::shared_ptr< tf2_ros::Buffer > tf_buffer, const std::string &base_frame_id, const std::string &global_frame_id, const tf2::Duration &transform_tolerance, const rclcpp::Duration &source_timeout, const bool base_shift_correction)
Source constructor.
Definition: source.cpp:29
std::string global_frame_id_
Global frame ID for correct transform calculation.
Definition: source.hpp:132
std::string source_name_
Name of data source.
Definition: source.hpp:124
rcl_interfaces::msg::SetParametersResult dynamicParametersCallback(std::vector< rclcpp::Parameter > parameters)
Callback executed when a parameter change is detected.
Definition: source.cpp:102
nav2_util::LifecycleNode::WeakPtr node_
Collision Monitor node.
Definition: source.hpp:116
std::shared_ptr< tf2_ros::Buffer > tf_buffer_
TF buffer.
Definition: source.hpp:128
bool sourceValid(const rclcpp::Time &source_time, const rclcpp::Time &curr_time) const
Checks whether the source data might be considered as valid.
Definition: source.cpp:77
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_
Dynamic parameters handler.
Definition: source.hpp:120
bool base_shift_correction_
Whether to correct source data towards to base frame movement, considering the difference between cur...
Definition: source.hpp:139
virtual void getData(const rclcpp::Time &curr_time, std::vector< Point > &data) const =0
Adds latest data from source to the data array. Empty virtual method intended to be used in child imp...
rclcpp::Duration source_timeout_
Maximum time interval in which data is considered valid.
Definition: source.hpp:136