1 #ifndef SLAM_CTOR_CORE_GRID_MAP_SCAN_ADDERS_H 2 #define SLAM_CTOR_CORE_GRID_MAP_SCAN_ADDERS_H 10 #include "../states/sensor_data.h" 11 #include "../states/world.h" 21 double scan_margin = 0.0)
const {
22 if (scan.
points().empty()) {
return map; }
24 const auto rp = pose.
point();
26 size_t last_pt_i = scan.
points().size() - scan_margin - 1;
27 for (
size_t pt_i = scan_margin; pt_i <= last_pt_i; ++pt_i) {
28 const auto &sp = scan.
points()[pt_i];
41 bool is_occupied)
const {
42 return _occ_est->estimate_occupancy(beam, area_bnds, is_occupied);
49 std::shared_ptr<CellOccupancyEstimator>
_occ_est;
55 #define ADD_SETTER(type, prop_name) \ 59 auto& set_##prop_name(decltype(_##prop_name) prop_name) { \ 60 _##prop_name = prop_name; \ 63 const auto& prop_name() const { return _##prop_name; } 66 ADD_SETTER(std::shared_ptr<CellOccupancyEstimator>, occupancy_estimator);
73 , _max_usable_range{std::numeric_limits<double>::infinity()} {}
76 return std::make_shared<WallDistanceBlurringScanAdder>(*this);
88 , _max_usable_range_sq{std::pow(_props.max_usable_range(), 2)}{}
96 if (_max_usable_range_sq < beam.
length_sq()) {
103 auto obst_dist_sq = robot_pt.
dist_sq(obst_pt);
104 auto hole_dist_sq = std::pow(blur_cell_dist(map, beam, is_occ), 2);
109 auto occ_aoo =
AOO{is_occ, base_occup, beam.
end(), scan_quality};
110 map.
update(pts.back(), occ_aoo);
113 auto empty_aoo =
AOO{
false, {0, 0}, beam.
end(), scan_quality};
114 for (
const auto &pt : pts) {
115 const auto dist_sq = pt.
dist_sq(obst_pt);
117 empty_aoo.is_occupied =
false;
120 if (dist_sq < hole_dist_sq && hole_dist_sq < obst_dist_sq) {
122 empty_aoo.is_occupied =
true;
123 auto prob_scale = 1.0 - dist_sq / hole_dist_sq;
124 empty_aoo.occupancy.prob_occ = base_occup.prob_occ * prob_scale;
126 map.
update(pt, empty_aoo);
138 auto blur_dist = _props.blur_distance() / map.
scale();
142 blur_dist *= -dist_sq;
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
std::shared_ptr< CellOccupancyEstimator > _occ_est
void handle_scan_point(GridMap &map, bool is_occ, double scan_quality, const Segment2D &beam) const override
Coord world_to_cell(const Point2D &pt) const
Rectangle world_cell_bounds(const Coord &coord) const
double dist_sq(const Point2D &pt) const
virtual void handle_scan_point(GridMap &map, bool is_occ, double scan_quality, const Segment2D &beam) const =0
WallDistanceBlurringScanAdder(const ScanAdderProperties &props)
#define ADD_SETTER(type, prop_name)
double dist_sq(const DiscretePoint2D &pt) const
static WallDistanceBlurringScanAdderBuilder builder()
auto estimate_occupancy(const Segment2D &beam, const Rectangle &area_bnds, bool is_occupied) const
const Point2D & end() const
WallDistanceBlurringScanAdderBuilder()
const Points & points() const
std::vector< Coord > world_to_cells(const Segment2D &s) const
double blur_cell_dist(const GridMap &map, const Segment2D &beam, bool is_occ) const
std::shared_ptr< TrigonometryProvider > trig_provider
ScanAdderProperties _props
double _max_usable_range_sq
GridMapScanAdder(std::shared_ptr< CellOccupancyEstimator > e)
const Point2D & beg() const
GridMap & append_scan(GridMap &map, const RobotPose &pose, const LaserScan2D &scan, double scan_quality, double scan_margin=0.0) const
virtual double scale() const