Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CARTOGRAPHER_MAPPING_INTERNAL_CONSTRAINTS_CONSTRAINT_BUILDER_2D_H_
00018 #define CARTOGRAPHER_MAPPING_INTERNAL_CONSTRAINTS_CONSTRAINT_BUILDER_2D_H_
00019
00020 #include <array>
00021 #include <deque>
00022 #include <functional>
00023 #include <limits>
00024 #include <vector>
00025
00026 #include "Eigen/Core"
00027 #include "Eigen/Geometry"
00028 #include "absl/synchronization/mutex.h"
00029 #include "cartographer/common/fixed_ratio_sampler.h"
00030 #include "cartographer/common/histogram.h"
00031 #include "cartographer/common/math.h"
00032 #include "cartographer/common/task.h"
00033 #include "cartographer/common/thread_pool.h"
00034 #include "cartographer/mapping/2d/submap_2d.h"
00035 #include "cartographer/mapping/internal/2d/scan_matching/ceres_scan_matcher_2d.h"
00036 #include "cartographer/mapping/internal/2d/scan_matching/fast_correlative_scan_matcher_2d.h"
00037 #include "cartographer/mapping/pose_graph_interface.h"
00038 #include "cartographer/mapping/proto/pose_graph/constraint_builder_options.pb.h"
00039 #include "cartographer/metrics/family_factory.h"
00040 #include "cartographer/sensor/internal/voxel_filter.h"
00041 #include "cartographer/sensor/point_cloud.h"
00042
00043 namespace cartographer {
00044 namespace mapping {
00045 namespace constraints {
00046
00047
00048
00049 transform::Rigid2d ComputeSubmapPose(const Submap2D& submap);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 class ConstraintBuilder2D {
00060 public:
00061 using Constraint = PoseGraphInterface::Constraint;
00062 using Result = std::vector<Constraint>;
00063
00064 ConstraintBuilder2D(const proto::ConstraintBuilderOptions& options,
00065 common::ThreadPoolInterface* thread_pool);
00066 ~ConstraintBuilder2D();
00067
00068 ConstraintBuilder2D(const ConstraintBuilder2D&) = delete;
00069 ConstraintBuilder2D& operator=(const ConstraintBuilder2D&) = delete;
00070
00071
00072
00073
00074
00075
00076
00077 void MaybeAddConstraint(const SubmapId& submap_id, const Submap2D* submap,
00078 const NodeId& node_id,
00079 const TrajectoryNode::Data* const constant_data,
00080 const transform::Rigid2d& initial_relative_pose);
00081
00082
00083
00084
00085
00086
00087
00088 void MaybeAddGlobalConstraint(
00089 const SubmapId& submap_id, const Submap2D* submap, const NodeId& node_id,
00090 const TrajectoryNode::Data* const constant_data);
00091
00092
00093 void NotifyEndOfNode();
00094
00095
00096
00097
00098 void WhenDone(const std::function<void(const Result&)>& callback);
00099
00100
00101 int GetNumFinishedNodes();
00102
00103
00104 void DeleteScanMatcher(const SubmapId& submap_id);
00105
00106 static void RegisterMetrics(metrics::FamilyFactory* family_factory);
00107
00108 private:
00109 struct SubmapScanMatcher {
00110 const Grid2D* grid = nullptr;
00111 std::unique_ptr<scan_matching::FastCorrelativeScanMatcher2D>
00112 fast_correlative_scan_matcher;
00113 std::weak_ptr<common::Task> creation_task_handle;
00114 };
00115
00116
00117
00118 const SubmapScanMatcher* DispatchScanMatcherConstruction(
00119 const SubmapId& submap_id, const Grid2D* grid)
00120 EXCLUSIVE_LOCKS_REQUIRED(mutex_);
00121
00122
00123
00124
00125 void ComputeConstraint(const SubmapId& submap_id, const Submap2D* submap,
00126 const NodeId& node_id, bool match_full_submap,
00127 const TrajectoryNode::Data* const constant_data,
00128 const transform::Rigid2d& initial_relative_pose,
00129 const SubmapScanMatcher& submap_scan_matcher,
00130 std::unique_ptr<Constraint>* constraint)
00131 LOCKS_EXCLUDED(mutex_);
00132
00133 void RunWhenDoneCallback() LOCKS_EXCLUDED(mutex_);
00134
00135 const constraints::proto::ConstraintBuilderOptions options_;
00136 common::ThreadPoolInterface* thread_pool_;
00137 absl::Mutex mutex_;
00138
00139
00140 std::unique_ptr<std::function<void(const Result&)>> when_done_
00141 GUARDED_BY(mutex_);
00142
00143
00144
00145
00146
00147 int num_started_nodes_ GUARDED_BY(mutex_) = 0;
00148
00149 int num_finished_nodes_ GUARDED_BY(mutex_) = 0;
00150
00151 std::unique_ptr<common::Task> finish_node_task_ GUARDED_BY(mutex_);
00152
00153 std::unique_ptr<common::Task> when_done_task_ GUARDED_BY(mutex_);
00154
00155
00156
00157
00158 std::deque<std::unique_ptr<Constraint>> constraints_ GUARDED_BY(mutex_);
00159
00160
00161 std::map<SubmapId, SubmapScanMatcher> submap_scan_matchers_
00162 GUARDED_BY(mutex_);
00163
00164 common::FixedRatioSampler sampler_;
00165 scan_matching::CeresScanMatcher2D ceres_scan_matcher_;
00166
00167
00168 common::Histogram score_histogram_ GUARDED_BY(mutex_);
00169 };
00170
00171 }
00172 }
00173 }
00174
00175 #endif // CARTOGRAPHER_MAPPING_INTERNAL_CONSTRAINTS_CONSTRAINT_BUILDER_2D_H_