init_scan_matching.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_UTILS_INIT_SCAN_MATCHING_H
2 #define SLAM_CTOR_UTILS_INIT_SCAN_MATCHING_H
3 
4 #include <string>
5 #include <memory>
6 #include <iostream>
7 
8 #include "properties_providers.h"
9 
10 #include "../core/scan_matchers/occupancy_observation_probability.h"
11 
12 #include "../core/scan_matchers/monte_carlo_scan_matcher.h"
13 #include "../core/scan_matchers/hill_climbing_scan_matcher.h"
14 #include "../core/scan_matchers/hcsm_fixed.h"
15 #include "../core/scan_matchers/brute_force_scan_matcher.h"
16 #include "../core/scan_matchers/connect_the_dots_ambiguous_drift_detector.h"
17 #include "../core/scan_matchers/weighted_mean_point_probability_spe.h"
18 
19 static const std::string Slam_SM_NS = "slam/scmtch/";
20 
21 /*============================================================================*/
22 /* Init Occupancy Obeservation Probability Estimator */
23 
24 std::shared_ptr<OccupancyObservationProbabilityEstimator> init_oope(
25  const PropertiesProvider &props) {
26  static const std::string OOPE_NS = Slam_SM_NS + "oope/";
27  auto type = props.get_str(OOPE_NS + "type", "obstacle");
28 
29  if (type == "obstacle") {
30  return std::make_shared<ObstacleBasedOccupancyObservationPE>();
31  } else if (type == "max") {
32  return std::make_shared<MaxOccupancyObservationPE>();
33  } else if (type == "mean") {
34  return std::make_shared<MeanOccupancyObservationPE>();
35  } else if (type == "overlap") {
36  return std::make_shared<OverlapWeightedOccupancyObservationPE>();
37  } else {
38  std::cerr << "Unknown occupancy observation probability estimator type "
39  << "(" << OOPE_NS + "type) " << type << std::endl;
40  std::exit(-1);
41  }
42 }
43 
44 /*============================================================================*/
45 /* Scan Probability Estimator initialization */
46 
47 auto init_swp(const PropertiesProvider &props) {
48  static const std::string SWP_Type = Slam_SM_NS + "spe/wmpp/weighting/type";
49  auto type = props.get_str(SWP_Type, "<undefined>");
50  auto swp = std::shared_ptr<ScanPointWeighting>{};
51 
52  std::cout << "Used SWP: " << type << std::endl;
53  if (type == "even") {
54  swp = std::make_shared<EvenSPW>();
55  } else if (type == "viny") {
56  swp = std::make_shared<VinySlamSPW>();
57  } else if (type == "ahr") {
58  swp = std::make_shared<AngleHistogramReciprocalSPW>();
59  } else {
60  std::cerr << "Unknown Scan Point Weighting type "
61  << "(" << SWP_Type << ") " << type << std::endl;
62  std::exit(-1);
63  }
64  return swp;
65 }
66 
67 auto init_spe(const PropertiesProvider &props,
68  std::shared_ptr<OccupancyObservationProbabilityEstimator> oope) {
69  auto type = props.get_str(Slam_SM_NS + "spe/type", "<undefined>");
70  if (type == "wmpp") {
71  const std::string WMPP_Prefix = Slam_SM_NS + "spe/wmpp";
72  auto skip_rate = props.get_uint(WMPP_Prefix + "/sp_skip_rate", 0);
73  auto max_range = props.get_dbl(WMPP_Prefix + "/sp_max_usable_range", -1);
74  using WmppSpe = WeightedMeanPointProbabilitySPE;
75  return std::make_shared<WmppSpe>(oope, init_swp(props),
76  skip_rate, max_range);
77  } else {
78  std::cerr << "Unknown Scan Probability Estimator type ("
79  << Slam_SM_NS << "spe/type): " << type << std::endl;
80  std::exit(-1);
81  }
82 };
83 
84 auto init_spe(const PropertiesProvider &props) {
85  return init_spe(props, init_oope(props));
86 };
87 
88 /*============================================================================*/
89 /* Init Scan Matcher Algorithm */
90 
92  std::shared_ptr<ScanProbabilityEstimator> spe) {
93  static const std::string SM_NS = Slam_SM_NS + "MC/";
94  static const std::string DISP_NS = SM_NS + "dispersion/";
95 
96  auto transl_dispersion = props.get_dbl(DISP_NS + "translation", 0.2);
97  auto rot_dispersion = props.get_dbl(DISP_NS + "rotation", 0.1);
98  auto failed_attempts_per_dispersion_limit =
99  props.get_uint(DISP_NS + "failed_attempts_limit", 20);
100 
101  auto attempts_limit = props.get_uint(SM_NS + "attempts_limit", 100);
102  auto seed = props.get_int(SM_NS + "seed", std::random_device{}());
103 
104  std::cout << "[INFO] MC Scan Matcher seed: " << seed << std::endl;
105  return std::make_shared<MonteCarloScanMatcher>(
106  spe, seed, transl_dispersion, rot_dispersion,
107  failed_attempts_per_dispersion_limit, attempts_limit);
108 }
109 
111  std::shared_ptr<ScanProbabilityEstimator> spe) {
112  static const std::string SM_NS = Slam_SM_NS + "HC/";
113  static const std::string DIST_NS = SM_NS + "distortion/";
114 
115  auto transl_distorsion = props.get_dbl(DIST_NS + "translation", 0.1);
116  auto rot_distorsion = props.get_dbl(DIST_NS + "rotation", 0.1);
117  auto fal = props.get_uint(DIST_NS + "failed_attempts_limit", 6);
118 
119  return std::make_shared<HillClimbingScanMatcher>(
120  spe, fal, transl_distorsion, rot_distorsion);
121 }
122 
124  std::shared_ptr<ScanProbabilityEstimator> spe) {
125  static const std::string SM_NS = Slam_SM_NS + "BF/";
126 
127  #define INIT_BFSM_RANGE(dim, limit, step) \
128  auto from_##dim = props.get_dbl(SM_NS + #dim + "/from", -(limit)); \
129  auto to_##dim = props.get_dbl(SM_NS + #dim + "/to", limit); \
130  auto step_##dim = props.get_dbl(SM_NS + #dim + "/step", step);
131 
132  INIT_BFSM_RANGE(x, 0.5, 0.1);
133  INIT_BFSM_RANGE(y, 0.5, 0.1);
134  INIT_BFSM_RANGE(t, deg2rad(5), deg2rad(1));
135 
136  #undef INIT_BFSM_RANGE
137 
138  return std::make_shared<BruteForceScanMatcher>(
139  spe, from_x, to_x, step_x, from_y, to_y, step_y, from_t, to_t, step_t);
140 }
141 
143  auto spe = init_spe(props);
144  auto sm = std::shared_ptr<GridScanMatcher>{};
145  auto sm_type = props.get_str(Slam_SM_NS + "type", "<undefined>");
146  std::cout << "Used Scan Matcher: " << sm_type << std::endl;
147  if (sm_type == "MC") { sm = init_monte_carlo_sm(props, spe); }
148  else if (sm_type == "HC") { sm = init_hill_climbing_sm(props, spe); }
149  else if (sm_type == "BF") { sm = init_brute_force_sm(props, spe); }
150  else if (sm_type == "HC_FIXED") {
151  // TODO: params setup
152  sm = std::make_shared<HillClimbingSMFixed>(spe);
153  } else {
154  std::cerr << "Unknown scan matcher type: " << sm_type << std::endl;
155  std::exit(-1);
156  }
157 
158  // TODO: do we need AmbDD to be a wrapper?
159  if (props.get_bool(Slam_SM_NS + "use_amb_drift_detector", false)) {
160  sm = std::make_shared<ConnectTheDotsAmbiguousDriftDetector>(sm);
161  }
162  return sm;
163 }
164 
165 #endif
auto init_brute_force_sm(const PropertiesProvider &props, std::shared_ptr< ScanProbabilityEstimator > spe)
std::shared_ptr< OccupancyObservationProbabilityEstimator > init_oope(const PropertiesProvider &props)
auto init_swp(const PropertiesProvider &props)
virtual str get_str(const std::string &id, const str &dflt) const =0
virtual int get_int(const std::string &id, int dflt) const =0
auto init_spe(const PropertiesProvider &props, std::shared_ptr< OccupancyObservationProbabilityEstimator > oope)
#define INIT_BFSM_RANGE(dim, limit, step)
virtual double get_dbl(const std::string &id, double dflt) const =0
TFSIMD_FORCE_INLINE const tfScalar & y() const
auto init_hill_climbing_sm(const PropertiesProvider &props, std::shared_ptr< ScanProbabilityEstimator > spe)
TFSIMD_FORCE_INLINE const tfScalar & x() const
auto init_scan_matcher(const PropertiesProvider &props)
virtual unsigned get_uint(const std::string &id, unsigned dflt) const =0
constexpr double deg2rad(double angle_deg)
Definition: math_utils.h:56
virtual bool get_bool(const std::string &id, bool dflt) const =0
auto init_monte_carlo_sm(const PropertiesProvider &props, std::shared_ptr< ScanProbabilityEstimator > spe)
static const std::string Slam_SM_NS


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