pose_enumeration_scan_matcher.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_POSE_ENUMERATION_SCAN_MATCHER_H
2 #define SLAM_CTOR_CORE_POSE_ENUMERATION_SCAN_MATCHER_H
3 
4 #include <functional>
5 #include <memory>
6 
7 #include "pose_enumerators.h"
8 #include "grid_scan_matcher.h"
9 
10 // TODO: merge the logic with hill climbing scan matcher
11 // create free functions that create scan matchers
12 // TODO: move publish transform to observer
14 public:
15  PoseEnumerationScanMatcher(std::shared_ptr<ScanProbabilityEstimator> spe,
16  std::shared_ptr<PoseEnumerator> pe)
17  : GridScanMatcher{spe}, _pose_enumerator{pe} {}
18 
19  void set_pose_enumerator(std::shared_ptr<PoseEnumerator> pe) {
20  _pose_enumerator = pe;
21  }
22 
23  auto pose_enumerator() const { return _pose_enumerator; }
24 
25  // GridScanMatcher API implementation
26 
27  void reset_state() override {
28  _pose_enumerator->reset();
29  }
30 
31  double process_scan(const TransformedLaserScan &raw_scan,
32  const RobotPose &init_pose,
33  const GridMap &map,
34  RobotPoseDelta &pose_delta) override {
35  do_for_each_observer([&init_pose, &raw_scan, &map](ObsPtr obs) {
36  obs->on_matching_start(init_pose, raw_scan, map);
37  });
38  auto scan = filter_scan(raw_scan.scan, init_pose, map);
39  auto best_pose = init_pose;
40  auto best_pose_prob = scan_probability(scan, best_pose, map);
41 
42  do_for_each_observer([best_pose, scan, best_pose_prob](ObsPtr obs) {
43  obs->on_scan_test(best_pose, scan, best_pose_prob);
44  obs->on_pose_update(best_pose, scan, best_pose_prob);
45  });
46 
47  _pose_enumerator->reset();
48  while (_pose_enumerator->has_next()) {
49  auto sampled_pose = _pose_enumerator->next(best_pose);
50  double sampled_scan_prob = scan_probability(scan, sampled_pose, map);
51  do_for_each_observer([&sampled_pose, &scan,
52  &sampled_scan_prob](ObsPtr obs) {
53  obs->on_scan_test(sampled_pose, scan, sampled_scan_prob);
54  });
55 
56  auto pose_is_acceptable = best_pose_prob < sampled_scan_prob;
57  _pose_enumerator->feedback(pose_is_acceptable);
58  if (!pose_is_acceptable) {
59  continue;
60  }
61 
62  // update pose
63  best_pose_prob = sampled_scan_prob;
64  best_pose = sampled_pose;
65 
66  // notify pose update
67  do_for_each_observer([&best_pose, &scan, &best_pose_prob](ObsPtr obs) {
68  obs->on_pose_update(best_pose, scan, best_pose_prob);
69  });
70  }
71 
72  pose_delta = best_pose - init_pose;
73  do_for_each_observer([&scan, &pose_delta, &best_pose_prob](ObsPtr obs) {
74  obs->on_matching_end(pose_delta, scan, best_pose_prob);
75  });
76  return best_pose_prob;
77  }
78 
79 private:
80  std::shared_ptr<PoseEnumerator> _pose_enumerator;
81 
82 };
83 
84 #endif
PoseEnumerationScanMatcher(std::shared_ptr< ScanProbabilityEstimator > spe, std::shared_ptr< PoseEnumerator > pe)
std::shared_ptr< GridScanMatcherObserver > ObsPtr
double process_scan(const TransformedLaserScan &raw_scan, const RobotPose &init_pose, const GridMap &map, RobotPoseDelta &pose_delta) override
std::shared_ptr< PoseEnumerator > _pose_enumerator
LaserScan2D filter_scan(const LaserScan2D &scan, const RobotPose &pose, const GridMap &map)
double scan_probability(const LaserScan2D &scan, const RobotPose &pose, const GridMap &map) const
void do_for_each_observer(std::function< void(ObsPtr)> op)
void set_pose_enumerator(std::shared_ptr< PoseEnumerator > pe)


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