tiny_world.h
Go to the documentation of this file.
1 #ifndef __TINY_WORLD_H
2 #define __TINY_WORLD_H
3 
4 #include <iostream>
5 #include <cmath>
6 #include <memory>
7 
8 #include "../core/state_data.h"
9 #include "../core/sensor_data.h"
10 #include "../core/laser_scan_grid_world.h"
11 #include "../core/maps/grid_cell_strategy.h"
12 
13 #include "tiny_grid_cells.h"
14 #include "tiny_scan_matcher.h"
15 
22  const double SIG_XY;
23  const double SIG_TH;
24  const unsigned BAD_LMT;
25  const unsigned TOT_LMT;
26  const double HOLE_WIDTH;
27 
28  TinyWorldParams(double sig_XY, double sig_T, unsigned lim_bad,
29  unsigned lim_totl, double hole_width) :
30  SIG_XY(sig_XY), SIG_TH(sig_T), BAD_LMT(lim_bad), TOT_LMT(lim_totl),
31  HOLE_WIDTH(hole_width) {}
32 };
33 
40 class TinyWorld : public LaserScanGridWorld {
41 public:
43 public:
44 
50  TinyWorld(std::shared_ptr<GridCellStrategy> gcs,
51  const TinyWorldParams &params,
52  const GridMapParams &init_map_params) :
53  LaserScanGridWorld(gcs, init_map_params), _gcs(gcs), _params(params),
54  _scan_matcher(new TinyScanMatcher(_gcs->cost_est(),
55  params.BAD_LMT, params.TOT_LMT,
56  params.SIG_XY, params.SIG_TH)) {}
57 
64  virtual void handle_observation(TransformedLaserScan &scan) override {
65  RobotState pose_delta;
66  _scan_matcher->reset_state();
67  _scan_matcher->process_scan(pose(), scan, map(), pose_delta);
68  update_robot_pose(pose_delta.x, pose_delta.y, pose_delta.theta);
69 
70  bool pose_was_fixed = pose_delta.x || pose_delta.y || pose_delta.theta;
71  auto factory = _gcs->cell_factory();
72  scan.quality = pose_was_fixed ? _params.localized_scan_quality :
73  _params.raw_scan_quality;
75  }
76 
88  virtual void handle_scan_point(GridMap &map,
89  double laser_x, double laser_y,
90  double beam_end_x, double beam_end_y,
91  bool is_occ, double quality) override {
92  Beam beam{laser_x, laser_y, beam_end_x, beam_end_y};
93  Point robot_pt = map.world_to_cell(laser_x, laser_y);
94  Point obst_pt = map.world_to_cell(beam_end_x, beam_end_y);
95 
96  double obst_dist_sq = robot_pt.dist_sq(obst_pt);
97  std::vector<Point> pts = DiscreteLine2D(robot_pt, obst_pt).points();
98  double hole_dist_sq = std::pow(_params.HOLE_WIDTH / map.cell_scale(), 2);
99 
100  auto occ_est = _gcs->occupancy_est();
101  Occupancy beam_end_occ = occ_est->estimate_occupancy(beam,
102  map.world_cell_bounds(pts.back()), is_occ);
103  map.update_cell(pts.back(), beam_end_occ, quality);
104  pts.pop_back();
105 
106  for (const auto &pt : pts) {
107  Occupancy empty_cell_value = occ_est->estimate_occupancy(beam,
108  map.world_cell_bounds(pts.back()), false);
109  // wall blur
110  double dist_sq = pt.dist_sq(obst_pt);
111  if (dist_sq < hole_dist_sq && hole_dist_sq < obst_dist_sq && is_occ) {
112  empty_cell_value.prob_occ +=
113  (1.0 - dist_sq / hole_dist_sq) * beam_end_occ.prob_occ;
114  }
115 
116  map.update_cell(pt, empty_cell_value, quality);
117  }
118  }
119 
123  std::shared_ptr<GridScanMatcher> scan_matcher() {
124  return _scan_matcher;
125  }
126 private:
127  std::shared_ptr<GridCellStrategy> _gcs;
129  std::shared_ptr<TinyScanMatcher> _scan_matcher;
130 };
131 
132 #endif
double x
Definition: state_data.h:38
Tracks a robots perception of an environment. The environment is represented by a GridMap; A laser sc...
std::shared_ptr< GridCellStrategy > _gcs
Definition: tiny_world.h:127
Definition of classes file:   BaseTinyCell, AvgTinyCell (are inherited from GidCell),   TinyBaseCellFactory, TinyAvgCellFactory (from GridCellFactory)
Rectangle world_cell_bounds(const DiscretePoint2D &cell_coord)
Definition: grid_map.h:117
double localized_scan_quality
Definition: tiny_world.h:21
An occupancy grid implementation.
Definition: grid_map.h:22
virtual void handle_scan_point(GridMap &map, double laser_x, double laser_y, double beam_end_x, double beam_end_y, bool is_occ, double quality) override
Definition: tiny_world.h:88
void update_cell(const DiscretePoint2D &cell_coord, const Occupancy &new_value, double quality=1.0)
Definition: grid_map.h:76
const TinyWorldParams _params
Definition: tiny_world.h:128
double dist_sq(const DiscretePoint2D &pt) const
A container for the following tinySLAM parameters: TODO: params description.
Definition: tiny_world.h:20
double theta
The position of robot.
Definition: state_data.h:38
double y
Definition: state_data.h:38
virtual void handle_observation(TransformedLaserScan &scan) override
Definition: tiny_world.h:64
double cell_scale() const
Returnes the scale.
Definition: grid_map.h:110
Defines a robot position in cartesian coordinates and an angle of rotation.
Definition: state_data.h:14
TinyWorld(std::shared_ptr< GridCellStrategy > gcs, const TinyWorldParams &params, const GridMapParams &init_map_params)
Definition: tiny_world.h:50
const unsigned TOT_LMT
Definition: tiny_world.h:25
const std::vector< Point > & points() const
Returns the line&#39;s component points.
The class implements the tinySLAM-specific map update logic.
Definition: tiny_world.h:40
double raw_scan_quality
Definition: tiny_world.h:21
The scan matcher based on the Monte Carlo simulation.
const unsigned BAD_LMT
Definition: tiny_world.h:24
const double SIG_XY
Definition: tiny_world.h:22
DiscretePoint2D world_to_cell(double x, double y) const
Definition: grid_map.h:101
TinyWorldParams(double sig_XY, double sig_T, unsigned lim_bad, unsigned lim_totl, double hole_width)
Definition: tiny_world.h:28
double quality
The quality of scan. 0 - low, 1 - fine.
Definition: sensor_data.h:37
Defines a line segment on a plane.
const double SIG_TH
Definition: tiny_world.h:23
const double HOLE_WIDTH
Definition: tiny_world.h:26
Defines a point with integer coordinates on a plane.
Framework internal representation of a laser scan.
Definition: sensor_data.h:33
std::shared_ptr< TinyScanMatcher > _scan_matcher
Definition: tiny_world.h:129
virtual void handle_observation(TransformedLaserScan &scan)
std::shared_ptr< GridScanMatcher > scan_matcher()
Definition: tiny_world.h:123


tiny_slam
Author(s):
autogenerated on Mon Jun 10 2019 15:30:57