mapping_2d/scan_matching/fast_correlative_scan_matcher.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // This is an implementation of the algorithm described in "Real-Time
18 // Correlative Scan Matching" by Olson.
19 //
20 // It is similar to the RealTimeCorrelativeScanMatcher but has a different
21 // trade-off: Scan matching is faster because more effort is put into the
22 // precomputation done for a given map. However, this map is immutable after
23 // construction.
24 
25 #ifndef CARTOGRAPHER_MAPPING_2D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
26 #define CARTOGRAPHER_MAPPING_2D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
27 
28 #include <memory>
29 #include <vector>
30 
31 #include "Eigen/Core"
35 #include "cartographer/mapping_2d/scan_matching/proto/fast_correlative_scan_matcher_options.pb.h"
37 
38 namespace cartographer {
39 namespace mapping_2d {
40 namespace scan_matching {
41 
42 proto::FastCorrelativeScanMatcherOptions
44  common::LuaParameterDictionary* parameter_dictionary);
45 
46 // A precomputed grid that contains in each cell (x0, y0) the maximum
47 // probability in the width x width area defined by x0 <= x < x0 + width and
48 // y0 <= y < y0.
50  public:
51  PrecomputationGrid(const ProbabilityGrid& probability_grid,
52  const CellLimits& limits, int width,
53  std::vector<float>* reusable_intermediate_grid);
54 
55  // Returns a value between 0 and 255 to represent probabilities between
56  // kMinProbability and kMaxProbability.
57  int GetValue(const Eigen::Array2i& xy_index) const {
58  const Eigen::Array2i local_xy_index = xy_index - offset_;
59  // The static_cast<unsigned> is for performance to check with 2 comparisons
60  // xy_index.x() < offset_.x() || xy_index.y() < offset_.y() ||
61  // local_xy_index.x() >= wide_limits_.num_x_cells ||
62  // local_xy_index.y() >= wide_limits_.num_y_cells
63  // instead of using 4 comparisons.
64  if (static_cast<unsigned>(local_xy_index.x()) >=
65  static_cast<unsigned>(wide_limits_.num_x_cells) ||
66  static_cast<unsigned>(local_xy_index.y()) >=
67  static_cast<unsigned>(wide_limits_.num_y_cells)) {
68  return 0;
69  }
70  const int stride = wide_limits_.num_x_cells;
71  return cells_[local_xy_index.x() + local_xy_index.y() * stride];
72  }
73 
74  // Maps values from [0, 255] to [kMinProbability, kMaxProbability].
75  static float ToProbability(float value) {
77  value *
79  }
80 
81  private:
82  uint8 ComputeCellValue(float probability) const;
83 
84  // Offset of the precomputation grid in relation to the 'probability_grid'
85  // including the additional 'width' - 1 cells.
86  const Eigen::Array2i offset_;
87 
88  // Size of the precomputation grid.
90 
91  // Probabilites mapped to 0 to 255.
92  std::vector<uint8> cells_;
93 };
94 
96 
97 // An implementation of "Real-Time Correlative Scan Matching" by Olson.
99  public:
101  const ProbabilityGrid& probability_grid,
102  const proto::FastCorrelativeScanMatcherOptions& options);
104 
107  delete;
108 
109  // Aligns 'point_cloud' within the 'probability_grid' given an
110  // 'initial_pose_estimate'. If a score above 'min_score' (excluding equality)
111  // is possible, true is returned, and 'score' and 'pose_estimate' are updated
112  // with the result.
113  bool Match(const transform::Rigid2d& initial_pose_estimate,
114  const sensor::PointCloud& point_cloud, float min_score,
115  float* score, transform::Rigid2d* pose_estimate) const;
116 
117  // Aligns 'point_cloud' within the full 'probability_grid', i.e., not
118  // restricted to the configured search window. If a score above 'min_score'
119  // (excluding equality) is possible, true is returned, and 'score' and
120  // 'pose_estimate' are updated with the result.
121  bool MatchFullSubmap(const sensor::PointCloud& point_cloud, float min_score,
122  float* score, transform::Rigid2d* pose_estimate) const;
123 
124  private:
125  // The actual implementation of the scan matcher, called by Match() and
126  // MatchFullSubmap() with appropriate 'initial_pose_estimate' and
127  // 'search_parameters'.
128  bool MatchWithSearchParameters(
129  SearchParameters search_parameters,
130  const transform::Rigid2d& initial_pose_estimate,
131  const sensor::PointCloud& point_cloud, float min_score, float* score,
132  transform::Rigid2d* pose_estimate) const;
133  std::vector<Candidate> ComputeLowestResolutionCandidates(
134  const std::vector<DiscreteScan>& discrete_scans,
135  const SearchParameters& search_parameters) const;
136  std::vector<Candidate> GenerateLowestResolutionCandidates(
137  const SearchParameters& search_parameters) const;
138  void ScoreCandidates(const PrecomputationGrid& precomputation_grid,
139  const std::vector<DiscreteScan>& discrete_scans,
140  const SearchParameters& search_parameters,
141  std::vector<Candidate>* const candidates) const;
142  Candidate BranchAndBound(const std::vector<DiscreteScan>& discrete_scans,
143  const SearchParameters& search_parameters,
144  const std::vector<Candidate>& candidates,
145  int candidate_depth, float min_score) const;
146 
147  const proto::FastCorrelativeScanMatcherOptions options_;
149  std::unique_ptr<PrecomputationGridStack> precomputation_grid_stack_;
150 };
151 
152 } // namespace scan_matching
153 } // namespace mapping_2d
154 } // namespace cartographer
155 
156 #endif // CARTOGRAPHER_MAPPING_2D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
constexpr float kMinProbability
uint8_t uint8
Definition: port.h:32
constexpr float kMaxProbability
PrecomputationGrid(const ProbabilityGrid &probability_grid, const CellLimits &limits, int width, std::vector< float > *reusable_intermediate_grid)
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:30
proto::FastCorrelativeScanMatcherOptions CreateFastCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
float value


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:38