Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
pointcloud.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__POINTCLOUD_HPP_
16 #define NAV2_COLLISION_MONITOR__POINTCLOUD_HPP_
17 
18 #include <memory>
19 #include <vector>
20 #include <string>
21 
22 #include "sensor_msgs/msg/point_cloud2.hpp"
23 #include "point_cloud_transport/point_cloud_transport.hpp"
24 
25 #include "nav2_collision_monitor/source.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 
28 namespace nav2_collision_monitor
29 {
30 
34 class PointCloud : public Source
35 {
36 public:
49  PointCloud(
50  const nav2::LifecycleNode::WeakPtr & node,
51  const std::string & source_name,
52  const nav2::TransformBuffer::SharedPtr tf_buffer,
53  const std::string & base_frame_id,
54  const std::string & global_frame_id,
55  const tf2::Duration & transform_tolerance,
56  const rclcpp::Duration & source_timeout,
57  const bool base_shift_correction);
61  ~PointCloud();
62 
68  bool configure();
69 
77  bool getSourceData(
78  const rclcpp::Time & curr_time,
79  std::vector<Point> & data) override;
80 
81 protected:
86  void getParameters(std::string & source_topic);
87 
92  void dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
93 
102  rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(
103  const std::vector<rclcpp::Parameter> & parameters);
104 
111  void updateParametersCallback(const std::vector<rclcpp::Parameter> & parameters);
112 
113  // ----- Variables -----
114 
116  #if RCLCPP_VERSION_GTE(30, 0, 0)
117  std::shared_ptr<point_cloud_transport::PointCloudTransport> pct_;
118  point_cloud_transport::Subscriber data_sub_;
119  #else
120  nav2::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr data_sub_;
121  #endif
122 
123  // Transport type used for PointCloud messages (e.g., raw or compressed)
124  std::string transport_type_;
125 
126  // Minimum and maximum height of PointCloud projected to 2D space
127  double min_height_, max_height_;
128  // Minimum range from sensor origin to filter out close points
129  double min_range_;
134 
136  sensor_msgs::msg::PointCloud2::ConstSharedPtr data_;
137 }; // class PointCloud
138 
139 } // namespace nav2_collision_monitor
140 
141 #endif // NAV2_COLLISION_MONITOR__POINTCLOUD_HPP_
Implementation for pointcloud source.
Definition: pointcloud.hpp:35
bool configure()
Data source configuration routine. Obtains pointcloud related ROS-parameters and creates pointcloud s...
Definition: pointcloud.cpp:65
void getParameters(std::string &source_topic)
Getting sensor-specific ROS-parameters.
Definition: pointcloud.cpp:181
sensor_msgs::msg::PointCloud2::ConstSharedPtr data_
Latest data obtained from pointcloud.
Definition: pointcloud.hpp:136
PointCloud(const nav2::LifecycleNode::WeakPtr &node, const std::string &source_name, const nav2::TransformBuffer::SharedPtr 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)
PointCloud constructor.
Definition: pointcloud.cpp:29
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(const std::vector< rclcpp::Parameter > &parameters)
Validate incoming parameter updates before applying them. This callback is triggered when one or more...
Definition: pointcloud.cpp:204
bool getSourceData(const rclcpp::Time &curr_time, std::vector< Point > &data) override
Adds latest data from pointcloud source to the data array.
Definition: pointcloud.cpp:107
nav2::Subscription< sensor_msgs::msg::PointCloud2 >::SharedPtr data_sub_
PointCloud data subscriber.
Definition: pointcloud.hpp:120
void dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
PointCloud data callback.
Definition: pointcloud.cpp:199
void updateParametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Apply parameter updates after validation This callback is executed when parameters have been successf...
Definition: pointcloud.cpp:228
~PointCloud()
PointCloud destructor.
Definition: pointcloud.cpp:46
Basic data source class.
Definition: source.hpp:44