hcsm_fixed.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_HCSM_FIXED_H_INCLUDED
2 #define SLAM_CTOR_CORE_HCSM_FIXED_H_INCLUDED
3 
4 #include <math.h>
5 #include <limits>
6 
7 #include "grid_scan_matcher.h"
8 #include "../maps/grid_map.h"
9 
10 // FIXME: setup params
12 public:
14  int max_shrinks_nm = 5,
15  double lin_delta = 0.1, double ang_delta = 0.1)
16  : GridScanMatcher(est), _angular_delta(ang_delta), _linear_delta(lin_delta)
17  , _max_step_shrinks(max_shrinks_nm) {}
18 
19  double process_scan(const TransformedLaserScan &raw_scan,
20  const RobotPose &init_pose,
21  const GridMap &map,
22  RobotPoseDelta &pose_delta) override {
23  auto scan = filter_scan(raw_scan.scan, init_pose, map);
24 
25  const double d_t = 0.01;
26  const double d_o = deg2rad(0.5);
27 
28  // TODO: store pose as sampled value
29  RobotPose best_pose = init_pose;
30  double best_pose_prob = scan_probability(scan, best_pose, map);
31  for (unsigned step_shrinks = 0; step_shrinks < _max_step_shrinks;
32  _max_step_shrinks++) {
33  RobotPose current_pose = best_pose;
34 
35  // determine direction
36  size_t next_action = 0;
37  double d_d = 0;
38  double best_diff = 1;
39  for (size_t action = 0; action < DirNm * DimNm; ++action) {
40  RobotPose shifted_pose = shift(current_pose, d_o, d_t, action);
41  double shifted_pose_prob = scan_probability(scan, shifted_pose, map);
42  double prob_diff = best_pose_prob - shifted_pose_prob;
43 
44  if (prob_diff < best_diff) {
45  best_diff = prob_diff;
46  next_action = action;
47  d_d = action % DimNm == Th ? d_o : d_t;
48  }
49  }
50 
51  // determine best value
52  double r = 16 * d_d;
53  while (d_d < r) {
54  auto r_pose = shift(current_pose, r, r, next_action);
55  auto r_prob = scan_probability(scan, r_pose, map);
56  if (best_pose_prob < r_prob) {
57  best_pose_prob = std::move(r_prob);
58  best_pose = r_pose;
59  break;
60  }
61  r /= 2;
62  }
63 
64  if (r == d_d) {
65  if (0 <= best_diff) { break; }
66  best_pose = shift(current_pose, r, r, next_action);
67  best_pose_prob -= best_diff;
68  }
69  }
70  pose_delta = best_pose - init_pose;
71  return best_pose_prob;
72  }
73 
74 private:
75  enum Dim {X = 0, Y, Th, DimNm};
76  enum Dir {Inc = 0, Dec, DirNm};
77  static_assert(DimNm % 2 != DirNm % 2, "");
78 
79  // TODO: return RobotPoseDelta
80  RobotPose shift(const RobotPose &current_pose, double a_step, double l_step,
81  size_t action) {
82  RobotPose shifted = current_pose;
83 
84  double shift_value = action % DirNm ? -1 : 1;
85  switch (action % DimNm) {
86  case X: shifted.x += shift_value * l_step; break;
87  case Y: shifted.y += shift_value * l_step; break;
88  case Th: shifted.theta += shift_value * a_step; break;
89  default: assert(0 && "Missed shift destination");
90  }
91 
92  return shifted;
93  }
94 
95 private:
98 };
99 
100 #endif
HillClimbingSMFixed(SPE est, int max_shrinks_nm=5, double lin_delta=0.1, double ang_delta=0.1)
Definition: hcsm_fixed.h:13
std::shared_ptr< ScanProbabilityEstimator > SPE
double process_scan(const TransformedLaserScan &raw_scan, const RobotPose &init_pose, const GridMap &map, RobotPoseDelta &pose_delta) override
Definition: hcsm_fixed.h:19
double theta
Definition: robot_pose.h:131
RobotPose shift(const RobotPose &current_pose, double a_step, double l_step, size_t action)
Definition: hcsm_fixed.h:80
unsigned _max_step_shrinks
Definition: hcsm_fixed.h:97
LaserScan2D filter_scan(const LaserScan2D &scan, const RobotPose &pose, const GridMap &map)
action
double scan_probability(const LaserScan2D &scan, const RobotPose &pose, const GridMap &map) const
double y
Definition: robot_pose.h:131
constexpr double deg2rad(double angle_deg)
Definition: math_utils.h:56
double x
Definition: robot_pose.h:131


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