Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
scan.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__SCAN_HPP_
16 #define NAV2_COLLISION_MONITOR__SCAN_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "sensor_msgs/msg/laser_scan.hpp"
23 
24 #include "nav2_collision_monitor/source.hpp"
25 
26 namespace nav2_collision_monitor
27 {
28 
32 class Scan : public Source
33 {
34 public:
47  Scan(
48  const nav2::LifecycleNode::WeakPtr & node,
49  const std::string & source_name,
50  const std::shared_ptr<tf2_ros::Buffer> tf_buffer,
51  const std::string & base_frame_id,
52  const std::string & global_frame_id,
53  const tf2::Duration & transform_tolerance,
54  const rclcpp::Duration & source_timeout,
55  const bool base_shift_correction);
59  ~Scan();
60 
65  void configure();
66 
74  bool getData(
75  const rclcpp::Time & curr_time,
76  std::vector<Point> & data);
77 
78 protected:
83  void dataCallback(sensor_msgs::msg::LaserScan::ConstSharedPtr msg);
84 
85  // ----- Variables -----
86 
88  nav2::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr data_sub_;
89 
91  sensor_msgs::msg::LaserScan::ConstSharedPtr data_;
92 }; // class Scan
93 
94 } // namespace nav2_collision_monitor
95 
96 #endif // NAV2_COLLISION_MONITOR__SCAN_HPP_
Implementation for laser scanner source.
Definition: scan.hpp:33
bool getData(const rclcpp::Time &curr_time, std::vector< Point > &data)
Adds latest data from laser scanner to the data array.
Definition: scan.cpp:69
nav2::Subscription< sensor_msgs::msg::LaserScan >::SharedPtr data_sub_
Laser scanner data subscriber.
Definition: scan.hpp:88
void dataCallback(sensor_msgs::msg::LaserScan::ConstSharedPtr msg)
Laser scanner data callback.
Definition: scan.cpp:106
sensor_msgs::msg::LaserScan::ConstSharedPtr data_
Latest data obtained from laser scanner.
Definition: scan.hpp:91
~Scan()
Scan destructor.
Definition: scan.cpp:44
void configure()
Data source configuration routine. Obtains ROS-parameters and creates laser scanner subscriber.
Definition: scan.cpp:50
Scan(const nav2::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)
Scan constructor.
Definition: scan.cpp:27
Basic data source class.
Definition: source.hpp:38