gmapping_world.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_GMAPPING_WORLD_H
2 #define SLAM_CTOR_GMAPPING_WORLD_H
3 
4 #include <memory>
5 #include <random>
6 #include <cmath>
7 
8 #include "../../core/particle_filter.h"
9 #include "../../core/states/single_state_hypothesis_laser_scan_grid_world.h"
10 #include "../../core/maps/grid_cell.h"
11 #include "../../core/maps/lazy_tiled_grid_map.h"
12 #include "../../core/scan_matchers/hill_climbing_scan_matcher.h"
13 
14 #include "gmapping_grid_cell.h"
15 
17 private:
18  using RandomEngine = std::mt19937;
21 public:
23 
24  GMappingParams(double mean_sample_xy, double sigma_sample_xy,
25  double mean_sample_th, double sigma_sample_th,
26  double min_sm_lim_xy, double max_sm_lim_xy,
27  double min_sm_lim_th, double max_sm_lim_th)
28  : pose_guess_rv{GRV1D{mean_sample_xy, sigma_sample_xy},
29  GRV1D{mean_sample_xy, sigma_sample_xy},
30  GRV1D{mean_sample_th, sigma_sample_th}}
31  , next_sm_delta_rv{URV1D{min_sm_lim_xy, max_sm_lim_xy},
32  URV1D{min_sm_lim_xy, max_sm_lim_xy},
33  URV1D{min_sm_lim_th, max_sm_lim_th}} {}
34 };
35 
37  : public Particle
38  , public SingleStateHypothesisLaserScanGridWorld<UnboundedLazyTiledGridMap> {
39 public:
40  using RandomEngine = std::mt19937;
43 public:
44 
46  const GMappingParams &gparams)
47  // FIXME: [Performance] The adder does extra computations
48  // related to blurring that are not actually used
50  , _raw_odom_pose{0, 0, 0}
51  , _rnd_engine(std::random_device{}())
52  , _pose_guess_rv{gparams.pose_guess_rv}
53  , _next_sm_delta_rv{gparams.next_sm_delta_rv} {
54  reset_scan_matching_delta();
55  }
56 
57  void update_robot_pose(const RobotPoseDelta& delta) override {
58  auto d_th = (pose() - _raw_odom_pose).theta;
59  auto s = std::sin(d_th), c = std::cos(d_th);
60  // rotate delta's translation by d_th
61  auto corrected_delta = RobotPoseDelta{
62  c*delta.x - s*delta.y,
63  s*delta.x + c*delta.y,
64  delta.theta
65  //atan2(std::sin(delta.theta), std::cos(delta.theta)
66  };
67  _raw_odom_pose += delta;
68 
69  _delta_since_last_sm += corrected_delta.abs();
71  }
72 
74  if (_delta_since_last_sm.sq_dist() < _next_sm_delta.sq_dist() &&
75  std::fabs(_delta_since_last_sm.theta) < _next_sm_delta.theta) {
76  return;
77  }
78 
79  // TODO: consider super::handle_observation
80 
81  if (!_scan_is_first) {
82  // add "noise" to guess extra cost function peak
83  auto noise = _pose_guess_rv.sample(_rnd_engine);
85  }
86 
87  RobotPoseDelta pose_delta;
88  double scan_prob = scan_matcher()->process_scan(scan, pose(),
89  map(), pose_delta);
91 
92  // TODO: scan_prob threshold to params
93  if (0.0 < scan_prob || _scan_is_first) {
94  // map update accordig to original gmapping code (ref?)
95  scan_adder()->append_scan(map(), pose(), scan.scan, scan.quality, 0);
96  _scan_is_first = false;
97  }
98 
100  reset_scan_matching_delta();
101  }
102 
103  void mark_master() {
104  _is_master = true;
105  // master is corrected on each step without noise
106  _pose_guess_rv = RobotPoseDeltaRV<RandomEngine>{
107  GRV1D{0, 0}, GRV1D{0, 0}, GRV1D{0, 0}};
108  _next_sm_delta_rv = RobotPoseDeltaRV<RandomEngine>{
109  GRV1D{0, 0}, GRV1D{0, 0}, GRV1D{0, 0}};
110  }
111  bool is_master() { return _is_master; }
112  void sample() override { _is_master = false; }
113 
114 private:
115 
117  _delta_since_last_sm.reset();
118  _next_sm_delta = _next_sm_delta_rv.sample(_rnd_engine);
119  }
120 
121 private:
123  bool _is_master = false;
124  bool _scan_is_first = true;
127  RobotPoseDelta _delta_since_last_sm, _next_sm_delta;
128 };
129 
130 #endif
void sample() override
RobotPose _raw_odom_pose
RandomEngine _rnd_engine
RobotPoseDelta abs() const
Definition: robot_pose.h:44
std::mt19937 RandomEngine
void update_robot_pose(const RobotPoseDelta &delta) override
XmlRpcServer s
void reset_scan_matching_delta()
double theta
Definition: robot_pose.h:51
RobotPoseDeltaRV< RandomEngine > next_sm_delta_rv
GMappingParams(double mean_sample_xy, double sigma_sample_xy, double mean_sample_th, double sigma_sample_th, double min_sm_lim_xy, double max_sm_lim_xy, double min_sm_lim_th, double max_sm_lim_th)
GmappingWorld(const SingleStateHypothesisLSGWProperties &shw_params, const GMappingParams &gparams)
RobotPoseDeltaRV< RandomEngine > _pose_guess_rv
RobotPoseDelta _next_sm_delta
RobotPoseDeltaRV< RandomEngine > pose_guess_rv
void handle_observation(TransformedLaserScan &scan) override
void set_weight(double w)
std::mt19937 RandomEngine
double weight() const
virtual void update_robot_pose(const RobotPoseDelta &delta)
Definition: world.h:75


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