vinyx_world.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_SLAM_VINYX_WORLD_H
2 #define SLAM_CTOR_SLAM_VINYX_WORLD_H
3 
4 /*
5  * vinySLAM+ world.
6  * FIXME: add a brief description
7  * Each hypothesis is tracked by single-hypothesis vinySLAM.
8  *
9  * author: hatless.fox
10  */
11 
12 #include <vector>
13 #include <memory>
14 #include "../../core/states/single_state_hypothesis_laser_scan_grid_world.h"
15 
16 #include "../viny/viny_grid_cell.h"
17 
18 #include "../../core/scan_matchers/m3rsm_engine.h"
19 #include "../../core/maps/rescalable_caching_grid_map.h"
20 #include "../../core/maps/lazy_tiled_grid_map.h"
21 
22 class VinyXDSCell : public VinyDSCell {
23 public:
24  std::unique_ptr<GridCell> clone() const override {
25  return std::make_unique<VinyXDSCell>(*this);
26  }
27 
28  double discrepancy(const AreaOccupancyObservation &aoo) const override {
29  // TODO: consider normalized discrepancy usage in plain vinySLAM
30  // FIXME:
31  return 0;
32  }
33 };
34 
35 // FIXME: rm from the global namespace
37 
38 class VinyXWorld : public World<TransformedLaserScan,
39  VinyXMapT> {
40 public:
43 public: // methods
44  VinyXWorld(const Properties &props)
45  : _props{props} {
46  _hypotheses.push_back(WorldT{props});
47  }
48 
50  update_robot_pose(scan.pose_delta);
51  handle_observation(scan);
52  notify_with_pose(pose());
53  notify_with_map(map());
54  }
55 
56  void update_robot_pose(const RobotPoseDelta& delta) override {
57  for (auto &h : _hypotheses) {
58  h.update_robot_pose(delta);
59  }
60  }
61 
62  const WorldT& world() const override {
63  // TODO: return a max peak?
64  return _hypotheses[0];
65  }
66 
67  const RobotPose& pose() const override { return world().pose(); }
68  const VinyXMapT& map() const override { return world().map(); }
69 
71  //detect_peaks(obs);
72  for (auto &h : _hypotheses) {
73  // FIXME: use peaks info in order to just update world state
74  h.handle_observation(obs);
75  }
76  }
77 
78 private:
79 
80  void detect_peaks(const TransformedLaserScan &raw_scan) {
81  //std::cout << "=== Detect Peaks ===" << std::endl;
82  M3RSMEngine engine;
83  engine.set_translation_lookup_range(0.4, 0.4);
84  engine.set_rotation_lookup_range(0.2, 0.05);
85  SafeRescalableMap rescalable_map{map()};
86  // FIXME: use custom SPE, not necessary GridWorldOne
87  auto spe = _props.gsm->scan_probability_estimator();
88  engine.add_scan_matching_request(spe, pose(),
89  raw_scan.scan, rescalable_map, true);
90  double max_prob = -1;
91  unsigned peaks_nm = 0;
92  while (1) {
93  auto best_match = engine.next_best_match(0.4);
94  if (!best_match.is_valid()) {
95  break;
96  }
97  if (best_match.is_finest()) {
98  double p = best_match.prob_upper_bound;
99  if (max_prob == -1) { max_prob = p; }
100  //std::cout << "next prob: " << p << std::endl;
101  if (p < max_prob * 0.97 || p < 0.5) {
102  break;
103  }
104  peaks_nm++;
105  continue;
106  }
107  auto drift_center = best_match.translation_drift.center();
108  engine.add_match(Match{M3RSMEngine::Rect{drift_center}, best_match});
109  }
110  if (1 < peaks_nm) { std::cout << "PEAKS NM: " << peaks_nm << std::endl; }
111  }
112 
113 private: // fields
115  std::vector<WorldT> _hypotheses;
116 };
117 
118 #endif
VinyXWorld(const Properties &props)
Definition: vinyx_world.h:44
void set_translation_lookup_range(double max_x_error, double max_y_error)
Definition: m3rsm_engine.h:150
void handle_observation(TransformedLaserScan &obs) override
Definition: vinyx_world.h:70
std::vector< WorldT > _hypotheses
Definition: vinyx_world.h:115
std::unique_ptr< GridCell > clone() const override
Definition: vinyx_world.h:24
Definition: world.h:69
void set_rotation_lookup_range(double sector, double step)
Definition: m3rsm_engine.h:155
Match next_best_match(double translation_step)
Definition: m3rsm_engine.h:198
void update_robot_pose(const RobotPoseDelta &delta) override
Definition: vinyx_world.h:56
Properties _props
Definition: vinyx_world.h:114
double prob_upper_bound
Definition: m3rsm_engine.h:22
const WorldT & world() const override
Definition: vinyx_world.h:62
const RobotPose & pose() const override
Definition: vinyx_world.h:67
void add_match(Match &&match)
Definition: m3rsm_engine.h:160
void handle_sensor_data(TransformedLaserScan &scan) override
Definition: vinyx_world.h:49
RobotPoseDelta pose_delta
Definition: sensor_data.h:177
decltype(SPEParams{}.sp_analysis_area) Rect
Definition: m3rsm_engine.h:137
void add_scan_matching_request(std::shared_ptr< ScanProbabilityEstimator > spe, const RobotPose &pose, const LaserScan2D &raw_scan, GridMap &map, bool prerotate_scan=false)
Definition: m3rsm_engine.h:171
const GridMap & map(unsigned scale_id) const
const VinyXMapT & map() const override
Definition: vinyx_world.h:68
void detect_peaks(const TransformedLaserScan &raw_scan)
Definition: vinyx_world.h:80
double discrepancy(const AreaOccupancyObservation &aoo) const override
Definition: vinyx_world.h:28


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25