Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
observation_buffer.hpp
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, 2013, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Eitan Marder-Eppstein
36  *********************************************************************/
37 #ifndef NAV2_COSTMAP_2D__OBSERVATION_BUFFER_HPP_
38 #define NAV2_COSTMAP_2D__OBSERVATION_BUFFER_HPP_
39 
40 #include <vector>
41 #include <list>
42 #include <string>
43 
44 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
45 #include "rclcpp/time.hpp"
46 #include "nav2_ros_common/tf2_factories.hpp"
47 #include "tf2_sensor_msgs/tf2_sensor_msgs.hpp"
48 #include "sensor_msgs/msg/point_cloud2.hpp"
49 #include "nav2_costmap_2d/observation.hpp"
50 #include "nav2_ros_common/lifecycle_node.hpp"
51 
52 
53 namespace nav2_costmap_2d
54 {
60 {
61 public:
79  const nav2::LifecycleNode::WeakPtr & parent,
80  std::string topic_name,
81  double observation_keep_time,
82  double expected_update_rate,
83  double min_obstacle_height, double max_obstacle_height, double obstacle_max_range,
84  double obstacle_min_range,
85  double raytrace_max_range, double raytrace_min_range, nav2::TransformBuffer & tf2_buffer,
86  std::string global_frame,
87  std::string sensor_frame,
88  tf2::Duration tf_tolerance);
89 
95  void bufferCloud(const sensor_msgs::msg::PointCloud2 & cloud);
96 
101  void getObservations(std::vector<Observation::ConstSharedPtr> & observations);
102 
107  bool isCurrent() const;
108 
112  inline void lock()
113  {
114  lock_.lock();
115  }
116 
120  inline void unlock()
121  {
122  lock_.unlock();
123  }
124 
128  void resetLastUpdated();
129 
130 private:
134  void purgeStaleObservations();
135 
136  rclcpp::Clock::SharedPtr clock_;
137  rclcpp::Logger logger_{rclcpp::get_logger("nav2_costmap_2d")};
138  nav2::TransformBuffer & tf2_buffer_;
139  const rclcpp::Duration observation_keep_time_;
140  const rclcpp::Duration expected_update_rate_;
141  rclcpp::Time last_updated_;
142  std::string global_frame_;
143  std::string sensor_frame_;
144  std::list<Observation::ConstSharedPtr> observation_list_;
145  std::string topic_name_;
146  double min_obstacle_height_, max_obstacle_height_;
147  std::recursive_mutex lock_;
148  double obstacle_max_range_, obstacle_min_range_, raytrace_max_range_, raytrace_min_range_;
149  tf2::Duration tf_tolerance_;
150 };
151 } // namespace nav2_costmap_2d
152 #endif // NAV2_COSTMAP_2D__OBSERVATION_BUFFER_HPP_
Takes in point clouds from sensors, transforms them to the desired frame, and stores them.
void unlock()
Lock the observation buffer.
void lock()
Lock the observation buffer.
bool isCurrent() const
Check if the observation buffer is being update at its expected rate.
void getObservations(std::vector< Observation::ConstSharedPtr > &observations)
Pushes copies of all current observations onto the end of the vector passed in.
void bufferCloud(const sensor_msgs::msg::PointCloud2 &cloud)
Transforms a PointCloud to the global frame and buffers it Note: The burden is on the user to make su...
void resetLastUpdated()
Reset last updated timestamp.
ObservationBuffer(const nav2::LifecycleNode::WeakPtr &parent, std::string topic_name, double observation_keep_time, double expected_update_rate, double min_obstacle_height, double max_obstacle_height, double obstacle_max_range, double obstacle_min_range, double raytrace_max_range, double raytrace_min_range, nav2::TransformBuffer &tf2_buffer, std::string global_frame, std::string sensor_frame, tf2::Duration tf_tolerance)
Constructs an observation buffer.