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)
master
gaschler 2017-11-30 14:41:48 +01:00 committed by GitHub
parent 5147af9763
commit 85bfb888eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 41 deletions

View File

@ -17,24 +17,13 @@
#ifndef CARTOGRAPHER_MAPPING_MAP_BUILDER_H_
#define CARTOGRAPHER_MAPPING_MAP_BUILDER_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "cartographer/mapping/map_builder_interface.h"
#include <memory>
#include <unordered_map>
#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<std::string>& 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_;

View File

@ -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 <string>
#include <unordered_set>
#include <vector>
#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<std::string>& 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_