Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
polygon_source.hpp
1 // Copyright (c) 2023 Pixel Robotics GmbH
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__POLYGON_SOURCE_HPP_
16 #define NAV2_COLLISION_MONITOR__POLYGON_SOURCE_HPP_
17 
18 #include <memory>
19 #include <vector>
20 #include <string>
21 
22 #include "geometry_msgs/msg/polygon_instance_stamped.hpp"
23 #include "geometry_msgs/msg/polygon_stamped.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 PolygonSource : public Source
35 {
36 public:
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);
62 
68  bool configure();
69 
77  bool getSourceData(
78  const rclcpp::Time & curr_time,
79  std::vector<Point> & data) override;
80 
87  const geometry_msgs::msg::PolygonStamped & polygon,
88  std::vector<Point> & data) const;
89 
90 protected:
95  void getParameters(std::string & source_topic);
96 
101  void dataCallback(geometry_msgs::msg::PolygonInstanceStamped::ConstSharedPtr msg);
102 
103  // ----- Variables -----
104 
106  nav2::Subscription<geometry_msgs::msg::PolygonInstanceStamped>::SharedPtr data_sub_;
107 
109  std::vector<geometry_msgs::msg::PolygonInstanceStamped> data_;
110 
113 }; // class PolygonSource
114 
115 } // namespace nav2_collision_monitor
116 
117 #endif // NAV2_COLLISION_MONITOR__POLYGON_SOURCE_HPP_
Implementation for polygon source.
void getParameters(std::string &source_topic)
Getting sensor-specific ROS-parameters.
void dataCallback(geometry_msgs::msg::PolygonInstanceStamped::ConstSharedPtr msg)
PolygonSource data callback.
PolygonSource(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)
PolygonSource constructor.
nav2::Subscription< geometry_msgs::msg::PolygonInstanceStamped >::SharedPtr data_sub_
PolygonSource data subscriber.
void convertPolygonStampedToPoints(const geometry_msgs::msg::PolygonStamped &polygon, std::vector< Point > &data) const
Converts a PolygonInstanceStamped to a std::vector<Point>
~PolygonSource()
PolygonSource destructor.
bool configure()
Data source configuration routine. Obtains ROS-parameters and creates subscriber.
bool getSourceData(const rclcpp::Time &curr_time, std::vector< Point > &data) override
Adds latest data from polygon source to the data array.
double sampling_distance_
distance between sampled points on polygon edges
std::vector< geometry_msgs::msg::PolygonInstanceStamped > data_
Latest data obtained.
Basic data source class.
Definition: source.hpp:44