From 85bfb888ebdcdb7837934c5bece31c8c8f7f1b5b Mon Sep 17 00:00:00 2001 From: gaschler Date: Thu, 30 Nov 2017 14:41:48 +0100 Subject: [PATCH] Interface for MapBuilder (#715) Defines an interface for MapBuilder that can be used to implement a gRPC stub. [RFC=0002](https://github.com/googlecartographer/rfcs/blob/master/text/0002-cloud-based-mapping-1.md) --- cartographer/mapping/map_builder.h | 57 ++++--------- cartographer/mapping/map_builder_interface.h | 89 ++++++++++++++++++++ 2 files changed, 105 insertions(+), 41 deletions(-) create mode 100644 cartographer/mapping/map_builder_interface.h diff --git a/cartographer/mapping/map_builder.h b/cartographer/mapping/map_builder.h index 4bd874d..1b16b9e 100644 --- a/cartographer/mapping/map_builder.h +++ b/cartographer/mapping/map_builder.h @@ -17,24 +17,13 @@ #ifndef CARTOGRAPHER_MAPPING_MAP_BUILDER_H_ #define CARTOGRAPHER_MAPPING_MAP_BUILDER_H_ -#include -#include -#include -#include -#include +#include "cartographer/mapping/map_builder_interface.h" + +#include +#include -#include "Eigen/Geometry" -#include "cartographer/common/lua_parameter_dictionary.h" -#include "cartographer/common/port.h" #include "cartographer/common/thread_pool.h" -#include "cartographer/io/proto_stream.h" -#include "cartographer/mapping/id.h" -#include "cartographer/mapping/pose_graph.h" #include "cartographer/mapping/proto/map_builder_options.pb.h" -#include "cartographer/mapping/proto/submap_visualization.pb.h" -#include "cartographer/mapping/proto/trajectory_builder_options.pb.h" -#include "cartographer/mapping/submaps.h" -#include "cartographer/mapping/trajectory_builder.h" #include "cartographer/mapping_2d/pose_graph.h" #include "cartographer/mapping_3d/pose_graph.h" #include "cartographer/sensor/collator.h" @@ -47,50 +36,36 @@ proto::MapBuilderOptions CreateMapBuilderOptions( // Wires up the complete SLAM stack with TrajectoryBuilders (for local submaps) // and a PoseGraph for loop closure. -class MapBuilder { +class MapBuilder : public MapBuilderInterface { public: - using LocalSlamResultCallback = - GlobalTrajectoryBuilderInterface::LocalSlamResultCallback; - MapBuilder(const proto::MapBuilderOptions& options, const LocalSlamResultCallback& local_slam_result_callback); - ~MapBuilder(); + ~MapBuilder() override; MapBuilder(const MapBuilder&) = delete; MapBuilder& operator=(const MapBuilder&) = delete; - // Creates a new trajectory builder and returns its index. int AddTrajectoryBuilder( const std::unordered_set& expected_sensor_ids, - const proto::TrajectoryBuilderOptions& trajectory_options); + const proto::TrajectoryBuilderOptions& trajectory_options) override; - // Creates a new trajectory and returns its index. Querying the trajectory - // builder for it will return 'nullptr'. - int AddTrajectoryForDeserialization(); + int AddTrajectoryForDeserialization() override; - // Returns the TrajectoryBuilder corresponding to the specified - // 'trajectory_id' or 'nullptr' if the trajectory has no corresponding - // builder. - mapping::TrajectoryBuilder* GetTrajectoryBuilder(int trajectory_id) const; + mapping::TrajectoryBuilder* GetTrajectoryBuilder( + int trajectory_id) const override; - // Marks the TrajectoryBuilder corresponding to 'trajectory_id' as finished, - // i.e. no further sensor data is expected. - void FinishTrajectory(int trajectory_id); + void FinishTrajectory(int trajectory_id) override; - // Fills the SubmapQuery::Response corresponding to 'submap_id'. Returns an - // error string on failure, or an empty string on success. std::string SubmapToProto(const SubmapId& submap_id, - proto::SubmapQuery::Response* response); + proto::SubmapQuery::Response* response) override; - // Serializes the current state to a proto stream. - void SerializeState(io::ProtoStreamWriter* writer); + void SerializeState(io::ProtoStreamWriter* writer) override; - // Loads submaps from a proto stream into a new frozen trajectory. - void LoadMap(io::ProtoStreamReader* reader); + void LoadMap(io::ProtoStreamReader* reader) override; - int num_trajectory_builders() const; + int num_trajectory_builders() const override; - mapping::PoseGraph* pose_graph(); + mapping::PoseGraph* pose_graph() override; private: const proto::MapBuilderOptions options_; diff --git a/cartographer/mapping/map_builder_interface.h b/cartographer/mapping/map_builder_interface.h new file mode 100644 index 0000000..473adf7 --- /dev/null +++ b/cartographer/mapping/map_builder_interface.h @@ -0,0 +1,89 @@ +/* + * Copyright 2017 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CARTOGRAPHER_MAPPING_MAP_BUILDER_INTERFACE_H_ +#define CARTOGRAPHER_MAPPING_MAP_BUILDER_INTERFACE_H_ + +#include +#include +#include + +#include "Eigen/Geometry" +#include "cartographer/common/lua_parameter_dictionary.h" +#include "cartographer/common/port.h" +#include "cartographer/io/proto_stream.h" +#include "cartographer/mapping/id.h" +#include "cartographer/mapping/pose_graph.h" +#include "cartographer/mapping/proto/submap_visualization.pb.h" +#include "cartographer/mapping/proto/trajectory_builder_options.pb.h" +#include "cartographer/mapping/submaps.h" +#include "cartographer/mapping/trajectory_builder.h" + +namespace cartographer { +namespace mapping { + +// This interface is used for both library and RPC implementations. +// Implementations wire up the complete SLAM stack. +class MapBuilderInterface { + public: + using LocalSlamResultCallback = + GlobalTrajectoryBuilderInterface::LocalSlamResultCallback; + + MapBuilderInterface(){}; + virtual ~MapBuilderInterface(){}; + + MapBuilderInterface(const MapBuilderInterface&) = delete; + MapBuilderInterface& operator=(const MapBuilderInterface&) = delete; + + // Creates a new trajectory builder and returns its index. + virtual int AddTrajectoryBuilder( + const std::unordered_set& expected_sensor_ids, + const proto::TrajectoryBuilderOptions& trajectory_options) = 0; + + // Creates a new trajectory and returns its index. Querying the trajectory + // builder for it will return 'nullptr'. + virtual int AddTrajectoryForDeserialization() = 0; + + // Returns the TrajectoryBuilder corresponding to the specified + // 'trajectory_id' or 'nullptr' if the trajectory has no corresponding + // builder. + virtual mapping::TrajectoryBuilder* GetTrajectoryBuilder( + int trajectory_id) const = 0; + + // Marks the TrajectoryBuilder corresponding to 'trajectory_id' as finished, + // i.e. no further sensor data is expected. + virtual void FinishTrajectory(int trajectory_id) = 0; + + // Fills the SubmapQuery::Response corresponding to 'submap_id'. Returns an + // error string on failure, or an empty string on success. + virtual std::string SubmapToProto(const SubmapId& submap_id, + proto::SubmapQuery::Response* response) = 0; + + // Serializes the current state to a proto stream. + virtual void SerializeState(io::ProtoStreamWriter* writer) = 0; + + // Loads submaps from a proto stream into a new frozen trajectory. + virtual void LoadMap(io::ProtoStreamReader* reader) = 0; + + virtual int num_trajectory_builders() const = 0; + + virtual mapping::PoseGraph* pose_graph() = 0; +}; + +} // namespace mapping +} // namespace cartographer + +#endif // CARTOGRAPHER_MAPPING_MAP_BUILDER_INTERFACE_H_