Skip to content

Commit 54f7f4f

Browse files
gaschlerwally-the-cartographer
authored andcommitted
Skip constraint search against unfinished submaps. (#1362)
The uplink server only receives the grid content of a submap after that submap is finished for efficiency. Therefore, constraint searches against that submap need to be skipped. Also add checks to avoid this in the future. FIXES=#1360
1 parent 3f3428e commit 54f7f4f

7 files changed

+17
-4
lines changed

cartographer/mapping/internal/2d/pose_graph_2d.cc

+5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ void PoseGraph2D::ComputeConstraint(const NodeId& node_id,
242242
{
243243
common::MutexLocker locker(&mutex_);
244244
CHECK(data_.submap_data.at(submap_id).state == SubmapState::kFinished);
245+
if (!data_.submap_data.at(submap_id).submap->finished()) {
246+
// Uplink server only receives grids when they are finished, so skip
247+
// constraint search before that.
248+
return;
249+
}
245250

246251
const common::Time node_time = GetLatestNodeTime(node_id, submap_id);
247252
const common::Time last_connection_time =

cartographer/mapping/internal/3d/pose_graph_3d.cc

+5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ void PoseGraph3D::ComputeConstraint(const NodeId& node_id,
256256
{
257257
common::MutexLocker locker(&mutex_);
258258
CHECK(data_.submap_data.at(submap_id).state == SubmapState::kFinished);
259+
if (!data_.submap_data.at(submap_id).submap->finished()) {
260+
// Uplink server only receives grids when they are finished, so skip
261+
// constraint search before that.
262+
return;
263+
}
259264

260265
for (const NodeId& submap_node_id :
261266
data_.submap_data.at(submap_id).node_ids) {

cartographer/mapping/internal/constraints/constraint_builder_2d.cc

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void ConstraintBuilder2D::WhenDone(
158158
const ConstraintBuilder2D::SubmapScanMatcher*
159159
ConstraintBuilder2D::DispatchScanMatcherConstruction(const SubmapId& submap_id,
160160
const Grid2D* const grid) {
161+
CHECK(grid);
161162
if (submap_scan_matchers_.count(submap_id) != 0) {
162163
return &submap_scan_matchers_.at(submap_id);
163164
}
@@ -183,6 +184,7 @@ void ConstraintBuilder2D::ComputeConstraint(
183184
const transform::Rigid2d& initial_relative_pose,
184185
const SubmapScanMatcher& submap_scan_matcher,
185186
std::unique_ptr<ConstraintBuilder2D::Constraint>* constraint) {
187+
CHECK(submap_scan_matcher.fast_correlative_scan_matcher);
186188
const transform::Rigid2d initial_pose =
187189
ComputeSubmapPose(*submap) * initial_relative_pose;
188190

cartographer/mapping/internal/constraints/constraint_builder_2d.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ConstraintBuilder2D {
107107

108108
private:
109109
struct SubmapScanMatcher {
110-
const Grid2D* grid;
110+
const Grid2D* grid = nullptr;
111111
std::unique_ptr<scan_matching::FastCorrelativeScanMatcher2D>
112112
fast_correlative_scan_matcher;
113113
std::weak_ptr<common::Task> creation_task_handle;

cartographer/mapping/internal/constraints/constraint_builder_3d.cc

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void ConstraintBuilder3D::ComputeConstraint(
199199
const transform::Rigid3d& global_submap_pose,
200200
const SubmapScanMatcher& submap_scan_matcher,
201201
std::unique_ptr<Constraint>* constraint) {
202+
CHECK(submap_scan_matcher.fast_correlative_scan_matcher);
202203
// The 'constraint_transform' (submap i <- node j) is computed from:
203204
// - a 'high_resolution_point_cloud' in node j and
204205
// - the initial guess 'initial_pose' (submap i <- node j).

cartographer/mapping/internal/constraints/constraint_builder_3d.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class ConstraintBuilder3D {
116116

117117
private:
118118
struct SubmapScanMatcher {
119-
const HybridGrid* high_resolution_hybrid_grid;
120-
const HybridGrid* low_resolution_hybrid_grid;
119+
const HybridGrid* high_resolution_hybrid_grid = nullptr;
120+
const HybridGrid* low_resolution_hybrid_grid = nullptr;
121121
std::unique_ptr<scan_matching::FastCorrelativeScanMatcher3D>
122122
fast_correlative_scan_matcher;
123123
std::weak_ptr<common::Task> creation_task_handle;

cartographer/mapping/map_builder_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ TEST_P(MapBuilderTestByGridType, LocalizationOnFrozenTrajectory2D) {
443443
++num_cross_trajectory_constraints;
444444
}
445445
}
446-
EXPECT_GT(num_cross_trajectory_constraints, 3);
446+
EXPECT_GE(num_cross_trajectory_constraints, 3);
447447
// TODO(gaschler): Subscribe global slam callback, verify that all nodes are
448448
// optimized.
449449
EXPECT_THAT(constraints, ::testing::Contains(::testing::Field(

0 commit comments

Comments
 (0)