/home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/laser_scan.hpp Source File

/home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/laser_scan.hpp Source File#

Beluga ROS: /home/runner/work/beluga/beluga/beluga_ros/include/beluga_ros/laser_scan.hpp Source File
Beluga ROS
laser_scan.hpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
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 BELUGA_ROS_LASER_SCAN_HPP
16 #define BELUGA_ROS_LASER_SCAN_HPP
17 
18 #include <range/v3/view/iota.hpp>
19 
22 #include <beluga_ros/messages.hpp>
23 
24 #include <sophus/se3.hpp>
25 
26 #include <sensor_msgs/msg/laser_scan.hpp>
27 
33 namespace beluga_ros {
34 
36 class LaserScan : public beluga::BaseLaserScan<LaserScan> {
37  public:
39  using Scalar = double;
40 
51  explicit LaserScan(
52  sensor_msgs::msg::LaserScan::ConstSharedPtr scan,
53  Sophus::SE3d origin = Sophus::SE3d(),
54  std::size_t max_beams = std::numeric_limits<std::size_t>::max(),
55  Scalar min_range = std::numeric_limits<Scalar>::min(),
56  Scalar max_range = std::numeric_limits<Scalar>::max())
57  : scan_(std::move(scan)),
58  origin_(std::move(origin)),
59  max_beams_(max_beams),
60  min_range_(std::max(static_cast<Scalar>(scan_->range_min), min_range)),
61  max_range_(std::min(static_cast<Scalar>(scan_->range_max), max_range)) {
62  assert(scan_ != nullptr);
63  }
64 
66  [[nodiscard]] const auto& origin() const { return origin_; }
67 
69  [[nodiscard]] auto angles() const {
70  return ranges::views::iota(0, static_cast<int>(scan_->ranges.size())) | beluga::views::take_evenly(max_beams_) |
71  ranges::views::transform([this](int i) {
72  return static_cast<Scalar>(scan_->angle_min + static_cast<float>(i) * scan_->angle_increment);
73  });
74  }
75 
77  [[nodiscard]] auto ranges() const {
78  return scan_->ranges | beluga::views::take_evenly(max_beams_) |
79  ranges::views::transform([](auto value) { return static_cast<Scalar>(value); });
80  }
81 
83  [[nodiscard]] std::size_t size() const { return scan_->ranges.size(); }
84 
86  [[nodiscard]] auto min_range() const { return min_range_; }
87 
89  [[nodiscard]] auto max_range() const { return max_range_; }
90 
91  private:
92  sensor_msgs::msg::LaserScan::ConstSharedPtr scan_;
93  Sophus::SE3d origin_;
94  std::size_t max_beams_;
95  Scalar min_range_;
96  Scalar max_range_;
97 };
98 
99 } // namespace beluga_ros
100 
101 #endif // BELUGA_ROS_LASER_SCAN_HPP
Thin wrapper type for 2D sensor_msgs/LaserScan messages.
Definition: laser_scan.hpp:36
const auto & origin() const
Get the laser scan frame origin in the filter frame.
Definition: laser_scan.hpp:66
auto min_range() const
Get the minimum range measurement.
Definition: laser_scan.hpp:86
LaserScan(sensor_msgs::msg::LaserScan::ConstSharedPtr scan, Sophus::SE3d origin=Sophus::SE3d(), std::size_t max_beams=std::numeric_limits< std::size_t >::max(), Scalar min_range=std::numeric_limits< Scalar >::min(), Scalar max_range=std::numeric_limits< Scalar >::max())
Definition: laser_scan.hpp:51
auto max_range() const
Get the maximum range measurement.
Definition: laser_scan.hpp:89
double Scalar
Range type.
Definition: laser_scan.hpp:39
std::size_t size() const
Get the number of beams in the scan.
Definition: laser_scan.hpp:83
auto ranges() const
Get laser scan range measurements as a range.
Definition: laser_scan.hpp:77
auto angles() const
Get laser scan measurement angles as a range.
Definition: laser_scan.hpp:69
The main Beluga ROS namespace.
Definition: amcl.hpp:47