00001 /* 00002 * Copyright 2017 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_MAP_BUILDER_INTERFACE_H_ 00018 #define CARTOGRAPHER_MAPPING_MAP_BUILDER_INTERFACE_H_ 00019 00020 #include <set> 00021 #include <string> 00022 #include <vector> 00023 00024 #include "Eigen/Geometry" 00025 #include "cartographer/common/lua_parameter_dictionary.h" 00026 #include "cartographer/common/port.h" 00027 #include "cartographer/io/proto_stream_interface.h" 00028 #include "cartographer/mapping/id.h" 00029 #include "cartographer/mapping/pose_graph_interface.h" 00030 #include "cartographer/mapping/proto/submap_visualization.pb.h" 00031 #include "cartographer/mapping/proto/trajectory_builder_options.pb.h" 00032 #include "cartographer/mapping/submaps.h" 00033 #include "cartographer/mapping/trajectory_builder_interface.h" 00034 00035 namespace cartographer { 00036 namespace mapping { 00037 00038 // This interface is used for both library and RPC implementations. 00039 // Implementations wire up the complete SLAM stack. 00040 class MapBuilderInterface { 00041 public: 00042 using LocalSlamResultCallback = 00043 TrajectoryBuilderInterface::LocalSlamResultCallback; 00044 00045 using SensorId = TrajectoryBuilderInterface::SensorId; 00046 00047 MapBuilderInterface() {} 00048 virtual ~MapBuilderInterface() {} 00049 00050 MapBuilderInterface(const MapBuilderInterface&) = delete; 00051 MapBuilderInterface& operator=(const MapBuilderInterface&) = delete; 00052 00053 // Creates a new trajectory builder and returns its index. 00054 virtual int AddTrajectoryBuilder( 00055 const std::set<SensorId>& expected_sensor_ids, 00056 const proto::TrajectoryBuilderOptions& trajectory_options, 00057 LocalSlamResultCallback local_slam_result_callback) = 0; 00058 00059 // Creates a new trajectory and returns its index. Querying the trajectory 00060 // builder for it will return 'nullptr'. 00061 virtual int AddTrajectoryForDeserialization( 00062 const proto::TrajectoryBuilderOptionsWithSensorIds& 00063 options_with_sensor_ids_proto) = 0; 00064 00065 // Returns the 'TrajectoryBuilderInterface' corresponding to the specified 00066 // 'trajectory_id' or 'nullptr' if the trajectory has no corresponding 00067 // builder. 00068 virtual mapping::TrajectoryBuilderInterface* GetTrajectoryBuilder( 00069 int trajectory_id) const = 0; 00070 00071 // Marks the TrajectoryBuilder corresponding to 'trajectory_id' as finished, 00072 // i.e. no further sensor data is expected. 00073 virtual void FinishTrajectory(int trajectory_id) = 0; 00074 00075 // Fills the SubmapQuery::Response corresponding to 'submap_id'. Returns an 00076 // error string on failure, or an empty string on success. 00077 virtual std::string SubmapToProto(const SubmapId& submap_id, 00078 proto::SubmapQuery::Response* response) = 0; 00079 00080 // Serializes the current state to a proto stream. If 00081 // 'include_unfinished_submaps' is set to true, unfinished submaps, i.e. 00082 // submaps that have not yet received all rangefinder data insertions, will 00083 // be included in the serialized state. 00084 virtual void SerializeState(bool include_unfinished_submaps, 00085 io::ProtoStreamWriterInterface* writer) = 0; 00086 00087 // Serializes the current state to a proto stream file on the host system. If 00088 // 'include_unfinished_submaps' is set to true, unfinished submaps, i.e. 00089 // submaps that have not yet received all rangefinder data insertions, will 00090 // be included in the serialized state. 00091 // Returns true if the file was successfully written. 00092 virtual bool SerializeStateToFile(bool include_unfinished_submaps, 00093 const std::string& filename) = 0; 00094 00095 // Loads the SLAM state from a proto stream. Returns the remapping of new 00096 // trajectory_ids. 00097 virtual std::map<int /* trajectory id in proto */, int /* trajectory id */> 00098 LoadState(io::ProtoStreamReaderInterface* reader, bool load_frozen_state) = 0; 00099 00100 // Loads the SLAM state from a pbstream file. Returns the remapping of new 00101 // trajectory_ids. 00102 virtual std::map<int /* trajectory id in proto */, int /* trajectory id */> 00103 LoadStateFromFile(const std::string& filename, bool load_frozen_state) = 0; 00104 00105 virtual int num_trajectory_builders() const = 0; 00106 00107 virtual mapping::PoseGraphInterface* pose_graph() = 0; 00108 00109 virtual const std::vector<proto::TrajectoryBuilderOptionsWithSensorIds>& 00110 GetAllTrajectoryBuilderOptions() const = 0; 00111 }; 00112 00113 } // namespace mapping 00114 } // namespace cartographer 00115 00116 #endif // CARTOGRAPHER_MAPPING_MAP_BUILDER_INTERFACE_H_