trajectory_builder_interface.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/mapping/trajectory_builder_interface.h"
00018 
00019 #include "cartographer/mapping/internal/2d/local_trajectory_builder_options_2d.h"
00020 #include "cartographer/mapping/internal/3d/local_trajectory_builder_options_3d.h"
00021 #include "cartographer/mapping/local_slam_result_data.h"
00022 
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace {
00026 
00027 void PopulatePureLocalizationTrimmerOptions(
00028     proto::TrajectoryBuilderOptions* const trajectory_builder_options,
00029     common::LuaParameterDictionary* const parameter_dictionary) {
00030   constexpr char kDictionaryKey[] = "pure_localization_trimmer";
00031   if (!parameter_dictionary->HasKey(kDictionaryKey)) return;
00032 
00033   auto options_dictionary = parameter_dictionary->GetDictionary(kDictionaryKey);
00034   auto* options =
00035       trajectory_builder_options->mutable_pure_localization_trimmer();
00036   options->set_max_submaps_to_keep(
00037       options_dictionary->GetInt("max_submaps_to_keep"));
00038 }
00039 
00040 }  // namespace
00041 
00042 proto::TrajectoryBuilderOptions CreateTrajectoryBuilderOptions(
00043     common::LuaParameterDictionary* const parameter_dictionary) {
00044   proto::TrajectoryBuilderOptions options;
00045   *options.mutable_trajectory_builder_2d_options() =
00046       CreateLocalTrajectoryBuilderOptions2D(
00047           parameter_dictionary->GetDictionary("trajectory_builder_2d").get());
00048   *options.mutable_trajectory_builder_3d_options() =
00049       CreateLocalTrajectoryBuilderOptions3D(
00050           parameter_dictionary->GetDictionary("trajectory_builder_3d").get());
00051   options.set_collate_fixed_frame(
00052       parameter_dictionary->GetBool("collate_fixed_frame"));
00053   options.set_collate_landmarks(
00054       parameter_dictionary->GetBool("collate_landmarks"));
00055   PopulatePureLocalizationTrimmerOptions(&options, parameter_dictionary);
00056   return options;
00057 }
00058 
00059 proto::SensorId ToProto(const TrajectoryBuilderInterface::SensorId& sensor_id) {
00060   proto::SensorId sensor_id_proto;
00061   switch (sensor_id.type) {
00062     case TrajectoryBuilderInterface::SensorId::SensorType::RANGE:
00063       sensor_id_proto.set_type(proto::SensorId::RANGE);
00064       break;
00065     case TrajectoryBuilderInterface::SensorId::SensorType::IMU:
00066       sensor_id_proto.set_type(proto::SensorId::IMU);
00067       break;
00068     case TrajectoryBuilderInterface::SensorId::SensorType::ODOMETRY:
00069       sensor_id_proto.set_type(proto::SensorId::ODOMETRY);
00070       break;
00071     case TrajectoryBuilderInterface::SensorId::SensorType::FIXED_FRAME_POSE:
00072       sensor_id_proto.set_type(proto::SensorId::FIXED_FRAME_POSE);
00073       break;
00074     case TrajectoryBuilderInterface::SensorId::SensorType::LANDMARK:
00075       sensor_id_proto.set_type(proto::SensorId::LANDMARK);
00076       break;
00077     case TrajectoryBuilderInterface::SensorId::SensorType::LOCAL_SLAM_RESULT:
00078       sensor_id_proto.set_type(proto::SensorId::LOCAL_SLAM_RESULT);
00079       break;
00080     default:
00081       LOG(FATAL) << "Unsupported sensor type.";
00082   }
00083   sensor_id_proto.set_id(sensor_id.id);
00084   return sensor_id_proto;
00085 }
00086 
00087 TrajectoryBuilderInterface::SensorId FromProto(
00088     const proto::SensorId& sensor_id_proto) {
00089   TrajectoryBuilderInterface::SensorId sensor_id;
00090   switch (sensor_id_proto.type()) {
00091     case proto::SensorId::RANGE:
00092       sensor_id.type = TrajectoryBuilderInterface::SensorId::SensorType::RANGE;
00093       break;
00094     case proto::SensorId::IMU:
00095       sensor_id.type = TrajectoryBuilderInterface::SensorId::SensorType::IMU;
00096       break;
00097     case proto::SensorId::ODOMETRY:
00098       sensor_id.type =
00099           TrajectoryBuilderInterface::SensorId::SensorType::ODOMETRY;
00100       break;
00101     case proto::SensorId::FIXED_FRAME_POSE:
00102       sensor_id.type =
00103           TrajectoryBuilderInterface::SensorId::SensorType::FIXED_FRAME_POSE;
00104       break;
00105     case proto::SensorId::LANDMARK:
00106       sensor_id.type =
00107           TrajectoryBuilderInterface::SensorId::SensorType::LANDMARK;
00108       break;
00109     case proto::SensorId::LOCAL_SLAM_RESULT:
00110       sensor_id.type =
00111           TrajectoryBuilderInterface::SensorId::SensorType::LOCAL_SLAM_RESULT;
00112       break;
00113     default:
00114       LOG(FATAL) << "Unsupported sensor type.";
00115   }
00116   sensor_id.id = sensor_id_proto.id();
00117   return sensor_id;
00118 }
00119 
00120 }  // namespace mapping
00121 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:36