Add max_submaps_with_pure_localization parameter (#1141)

Adds a parameter for the currently hard coded `kSubmapsToKeep` in `pure_localization` mode.

The new parameter `max_submaps_with_pure_localization` allows to specify the history size of submaps in `pure_localization` mode.

Closes #1116
master
Alexander Reimann 2018-07-02 20:32:23 +02:00 committed by Wally B. Feed
parent d5ed8a9ded
commit 0981620d8f
7 changed files with 31 additions and 11 deletions

View File

@ -53,7 +53,7 @@ void AddTrajectoryHandler::OnRequest(
// Don't instantiate the 'PureLocalizationTrimmer' on the server and don't // Don't instantiate the 'PureLocalizationTrimmer' on the server and don't
// freeze the trajectory on the server. // freeze the trajectory on the server.
trajectory_builder_options.set_pure_localization(false); trajectory_builder_options.clear_pure_localization_trimmer();
GetContext<MapBuilderContextInterface>() GetContext<MapBuilderContextInterface>()
->local_trajectory_uploader() ->local_trajectory_uploader()

View File

@ -49,7 +49,9 @@ const std::string kMessage = R"(
min_range: 20 min_range: 20
max_range: 30 max_range: 30
} }
pure_localization: true pure_localization_trimmer {
max_submaps_to_keep: 3
}
initial_trajectory_pose { initial_trajectory_pose {
relative_pose { relative_pose {
translation { translation {
@ -122,7 +124,7 @@ TEST_F(AddTrajectoryHandlerTest, WithLocalSlamUploader) {
request.trajectory_builder_options(); request.trajectory_builder_options();
upstream_trajectory_builder_options.clear_trajectory_builder_2d_options(); upstream_trajectory_builder_options.clear_trajectory_builder_2d_options();
upstream_trajectory_builder_options.clear_trajectory_builder_3d_options(); upstream_trajectory_builder_options.clear_trajectory_builder_3d_options();
upstream_trajectory_builder_options.set_pure_localization(false); upstream_trajectory_builder_options.clear_pure_localization_trimmer();
EXPECT_CALL(*mock_local_trajectory_uploader_, EXPECT_CALL(*mock_local_trajectory_uploader_,
AddTrajectory(Eq(13), ParseSensorIds(request), AddTrajectory(Eq(13), ParseSensorIds(request),
Truly(testing::BuildProtoPredicateEquals( Truly(testing::BuildProtoPredicateEquals(

View File

@ -145,10 +145,10 @@ int MapBuilder::AddTrajectoryBuilder(
trimmer_options.min_added_submaps_count())); trimmer_options.min_added_submaps_count()));
} }
} }
if (trajectory_options.pure_localization()) { if (trajectory_options.has_pure_localization_trimmer()) {
constexpr int kSubmapsToKeep = 3;
pose_graph_->AddTrimmer(common::make_unique<PureLocalizationTrimmer>( pose_graph_->AddTrimmer(common::make_unique<PureLocalizationTrimmer>(
trajectory_id, kSubmapsToKeep)); trajectory_id,
trajectory_options.pure_localization_trimmer().max_submaps_to_keep()));
} }
if (trajectory_options.has_initial_trajectory_pose()) { if (trajectory_options.has_initial_trajectory_pose()) {
const auto& initial_trajectory_pose = const auto& initial_trajectory_pose =

View File

@ -24,7 +24,7 @@ namespace mapping {
PureLocalizationTrimmer::PureLocalizationTrimmer(const int trajectory_id, PureLocalizationTrimmer::PureLocalizationTrimmer(const int trajectory_id,
const int num_submaps_to_keep) const int num_submaps_to_keep)
: trajectory_id_(trajectory_id), num_submaps_to_keep_(num_submaps_to_keep) { : trajectory_id_(trajectory_id), num_submaps_to_keep_(num_submaps_to_keep) {
CHECK_GE(num_submaps_to_keep, 3); CHECK_GE(num_submaps_to_keep, 2) << "Cannot trim with less than 2 submaps";
} }
void PureLocalizationTrimmer::Trim(Trimmable* const pose_graph) { void PureLocalizationTrimmer::Trim(Trimmable* const pose_graph) {

View File

@ -29,7 +29,6 @@ message InitialTrajectoryPose {
message TrajectoryBuilderOptions { message TrajectoryBuilderOptions {
LocalTrajectoryBuilderOptions2D trajectory_builder_2d_options = 1; LocalTrajectoryBuilderOptions2D trajectory_builder_2d_options = 1;
LocalTrajectoryBuilderOptions3D trajectory_builder_3d_options = 2; LocalTrajectoryBuilderOptions3D trajectory_builder_3d_options = 2;
bool pure_localization = 3;
InitialTrajectoryPose initial_trajectory_pose = 4; InitialTrajectoryPose initial_trajectory_pose = 4;
message OverlappingSubmapsTrimmerOptions2D { message OverlappingSubmapsTrimmerOptions2D {
@ -38,6 +37,11 @@ message TrajectoryBuilderOptions {
int32 min_added_submaps_count = 3; int32 min_added_submaps_count = 3;
} }
OverlappingSubmapsTrimmerOptions2D overlapping_submaps_trimmer_2d = 5; OverlappingSubmapsTrimmerOptions2D overlapping_submaps_trimmer_2d = 5;
message PureLocalizationTrimmerOptions {
int32 max_submaps_to_keep = 1;
}
PureLocalizationTrimmerOptions pure_localization_trimmer = 6;
} }
message SensorId { message SensorId {

View File

@ -41,6 +41,19 @@ void PopulateOverlappingSubmapsTrimmerOptions2D(
options_dictionary->GetInt("min_added_submaps_count")); options_dictionary->GetInt("min_added_submaps_count"));
} }
void PopulatePureLocalizationTrimmerOptions(
proto::TrajectoryBuilderOptions* const trajectory_builder_options,
common::LuaParameterDictionary* const parameter_dictionary) {
constexpr char kDictionaryKey[] = "pure_localization_trimmer";
if (!parameter_dictionary->HasKey(kDictionaryKey)) return;
auto options_dictionary = parameter_dictionary->GetDictionary(kDictionaryKey);
auto* options =
trajectory_builder_options->mutable_pure_localization_trimmer();
options->set_max_submaps_to_keep(
options_dictionary->GetInt("max_submaps_to_keep"));
}
} // namespace } // namespace
proto::TrajectoryBuilderOptions CreateTrajectoryBuilderOptions( proto::TrajectoryBuilderOptions CreateTrajectoryBuilderOptions(
@ -52,9 +65,8 @@ proto::TrajectoryBuilderOptions CreateTrajectoryBuilderOptions(
*options.mutable_trajectory_builder_3d_options() = *options.mutable_trajectory_builder_3d_options() =
CreateLocalTrajectoryBuilderOptions3D( CreateLocalTrajectoryBuilderOptions3D(
parameter_dictionary->GetDictionary("trajectory_builder_3d").get()); parameter_dictionary->GetDictionary("trajectory_builder_3d").get());
options.set_pure_localization(
parameter_dictionary->GetBool("pure_localization"));
PopulateOverlappingSubmapsTrimmerOptions2D(&options, parameter_dictionary); PopulateOverlappingSubmapsTrimmerOptions2D(&options, parameter_dictionary);
PopulatePureLocalizationTrimmerOptions(&options, parameter_dictionary);
return options; return options;
} }

View File

@ -18,5 +18,7 @@ include "trajectory_builder_3d.lua"
TRAJECTORY_BUILDER = { TRAJECTORY_BUILDER = {
trajectory_builder_2d = TRAJECTORY_BUILDER_2D, trajectory_builder_2d = TRAJECTORY_BUILDER_2D,
trajectory_builder_3d = TRAJECTORY_BUILDER_3D, trajectory_builder_3d = TRAJECTORY_BUILDER_3D,
pure_localization = false, -- pure_localization_trimmer = {
-- max_submaps_to_keep = 3,
-- },
} }