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 #ifndef CARTOGRAPHER_MAPPING_2D_SUBMAP_2D_H_ 00018 #define CARTOGRAPHER_MAPPING_2D_SUBMAP_2D_H_ 00019 00020 #include <memory> 00021 #include <vector> 00022 00023 #include "Eigen/Core" 00024 #include "cartographer/common/lua_parameter_dictionary.h" 00025 #include "cartographer/mapping/2d/grid_2d.h" 00026 #include "cartographer/mapping/2d/map_limits.h" 00027 #include "cartographer/mapping/proto/2d/submaps_options_2d.pb.h" 00028 #include "cartographer/mapping/proto/serialization.pb.h" 00029 #include "cartographer/mapping/proto/submap_visualization.pb.h" 00030 #include "cartographer/mapping/range_data_inserter_interface.h" 00031 #include "cartographer/mapping/submaps.h" 00032 #include "cartographer/mapping/trajectory_node.h" 00033 #include "cartographer/mapping/value_conversion_tables.h" 00034 #include "cartographer/sensor/range_data.h" 00035 #include "cartographer/transform/rigid_transform.h" 00036 00037 namespace cartographer { 00038 namespace mapping { 00039 00040 proto::SubmapsOptions2D CreateSubmapsOptions2D( 00041 common::LuaParameterDictionary* parameter_dictionary); 00042 00043 class Submap2D : public Submap { 00044 public: 00045 Submap2D(const Eigen::Vector2f& origin, std::unique_ptr<Grid2D> grid, 00046 ValueConversionTables* conversion_tables); 00047 explicit Submap2D(const proto::Submap2D& proto, 00048 ValueConversionTables* conversion_tables); 00049 00050 proto::Submap ToProto(bool include_grid_data) const override; 00051 void UpdateFromProto(const proto::Submap& proto) override; 00052 00053 void ToResponseProto(const transform::Rigid3d& global_submap_pose, 00054 proto::SubmapQuery::Response* response) const override; 00055 00056 const Grid2D* grid() const { return grid_.get(); } 00057 00058 // Insert 'range_data' into this submap using 'range_data_inserter'. The 00059 // submap must not be finished yet. 00060 void InsertRangeData(const sensor::RangeData& range_data, 00061 const RangeDataInserterInterface* range_data_inserter); 00062 void Finish(); 00063 00064 private: 00065 std::unique_ptr<Grid2D> grid_; 00066 ValueConversionTables* conversion_tables_; 00067 }; 00068 00069 // The first active submap will be created on the insertion of the first range 00070 // data. Except during this initialization when no or only one single submap 00071 // exists, there are always two submaps into which range data is inserted: an 00072 // old submap that is used for matching, and a new one, which will be used for 00073 // matching next, that is being initialized. 00074 // 00075 // Once a certain number of range data have been inserted, the new submap is 00076 // considered initialized: the old submap is no longer changed, the "new" submap 00077 // is now the "old" submap and is used for scan-to-map matching. Moreover, a 00078 // "new" submap gets created. The "old" submap is forgotten by this object. 00079 class ActiveSubmaps2D { 00080 public: 00081 explicit ActiveSubmaps2D(const proto::SubmapsOptions2D& options); 00082 00083 ActiveSubmaps2D(const ActiveSubmaps2D&) = delete; 00084 ActiveSubmaps2D& operator=(const ActiveSubmaps2D&) = delete; 00085 00086 // Inserts 'range_data' into the Submap collection. 00087 std::vector<std::shared_ptr<const Submap2D>> InsertRangeData( 00088 const sensor::RangeData& range_data); 00089 00090 std::vector<std::shared_ptr<const Submap2D>> submaps() const; 00091 00092 private: 00093 std::unique_ptr<RangeDataInserterInterface> CreateRangeDataInserter(); 00094 std::unique_ptr<GridInterface> CreateGrid(const Eigen::Vector2f& origin); 00095 void FinishSubmap(); 00096 void AddSubmap(const Eigen::Vector2f& origin); 00097 00098 const proto::SubmapsOptions2D options_; 00099 std::vector<std::shared_ptr<Submap2D>> submaps_; 00100 std::unique_ptr<RangeDataInserterInterface> range_data_inserter_; 00101 ValueConversionTables conversion_tables_; 00102 }; 00103 00104 } // namespace mapping 00105 } // namespace cartographer 00106 00107 #endif // CARTOGRAPHER_MAPPING_2D_SUBMAP_2D_H_