2018-01-11 17:19:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2018 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.
|
|
|
|
*/
|
|
|
|
|
2018-01-15 22:31:33 +08:00
|
|
|
#ifndef CARTOGRAPHER_GRPC_LOCAL_TRAJECTORY_UPLOADER_H
|
|
|
|
#define CARTOGRAPHER_GRPC_LOCAL_TRAJECTORY_UPLOADER_H
|
2018-01-11 17:19:37 +08:00
|
|
|
|
2018-01-13 06:16:29 +08:00
|
|
|
#include <map>
|
2018-01-17 19:01:29 +08:00
|
|
|
#include <memory>
|
2018-01-26 22:07:49 +08:00
|
|
|
#include <set>
|
2018-01-11 17:19:37 +08:00
|
|
|
#include <string>
|
2018-01-17 19:01:29 +08:00
|
|
|
#include <thread>
|
2018-01-13 06:16:29 +08:00
|
|
|
|
2018-01-15 22:31:33 +08:00
|
|
|
#include "cartographer/common/blocking_queue.h"
|
2018-01-13 06:16:29 +08:00
|
|
|
#include "cartographer/mapping/proto/trajectory_builder_options.pb.h"
|
2018-01-26 22:07:49 +08:00
|
|
|
#include "cartographer/mapping/trajectory_builder_interface.h"
|
2018-02-02 00:19:15 +08:00
|
|
|
#include "cartographer_grpc/framework/client.h"
|
|
|
|
#include "cartographer_grpc/handlers/add_fixed_frame_pose_data_handler.h"
|
|
|
|
#include "cartographer_grpc/handlers/add_imu_data_handler.h"
|
|
|
|
#include "cartographer_grpc/handlers/add_landmark_data_handler.h"
|
|
|
|
#include "cartographer_grpc/handlers/add_local_slam_result_data_handler.h"
|
|
|
|
#include "cartographer_grpc/handlers/add_odometry_data_handler.h"
|
|
|
|
#include "cartographer_grpc/proto/map_builder_service.pb.h"
|
2018-01-13 06:16:29 +08:00
|
|
|
#include "grpc++/grpc++.h"
|
2018-01-11 17:19:37 +08:00
|
|
|
|
|
|
|
namespace cartographer_grpc {
|
|
|
|
|
2018-02-01 20:05:08 +08:00
|
|
|
class LocalTrajectoryUploaderInterface {
|
2018-01-11 17:19:37 +08:00
|
|
|
public:
|
2018-01-26 22:07:49 +08:00
|
|
|
using SensorId = cartographer::mapping::TrajectoryBuilderInterface::SensorId;
|
|
|
|
|
2018-02-01 20:05:08 +08:00
|
|
|
virtual ~LocalTrajectoryUploaderInterface() = default;
|
|
|
|
|
|
|
|
// Enqueue an Add*DataRequest message to be uploaded.
|
|
|
|
virtual void EnqueueDataRequest(
|
|
|
|
std::unique_ptr<google::protobuf::Message> data_request) = 0;
|
|
|
|
virtual void AddTrajectory(
|
|
|
|
int local_trajectory_id, const std::set<SensorId>& expected_sensor_ids,
|
|
|
|
const cartographer::mapping::proto::TrajectoryBuilderOptions&
|
|
|
|
trajectory_options) = 0;
|
|
|
|
virtual void FinishTrajectory(int local_trajectory_id) = 0;
|
|
|
|
|
|
|
|
virtual SensorId GetLocalSlamResultSensorId(
|
|
|
|
int local_trajectory_id) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface {
|
|
|
|
public:
|
2018-01-17 19:01:29 +08:00
|
|
|
LocalTrajectoryUploader(const std::string& uplink_server_address);
|
|
|
|
~LocalTrajectoryUploader();
|
|
|
|
|
|
|
|
// Starts the upload thread.
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
// Shuts down the upload thread. This method blocks until the shutdown is
|
|
|
|
// complete.
|
|
|
|
void Shutdown();
|
|
|
|
|
2018-01-13 06:16:29 +08:00
|
|
|
void AddTrajectory(
|
2018-01-26 22:07:49 +08:00
|
|
|
int local_trajectory_id, const std::set<SensorId>& expected_sensor_ids,
|
2018-01-13 06:16:29 +08:00
|
|
|
const cartographer::mapping::proto::TrajectoryBuilderOptions&
|
2018-02-01 20:05:08 +08:00
|
|
|
trajectory_options) override;
|
|
|
|
void FinishTrajectory(int local_trajectory_id) override;
|
2018-01-15 22:31:33 +08:00
|
|
|
void EnqueueDataRequest(
|
2018-02-01 20:05:08 +08:00
|
|
|
std::unique_ptr<google::protobuf::Message> data_request) override;
|
2018-01-13 06:16:29 +08:00
|
|
|
|
2018-02-01 20:05:08 +08:00
|
|
|
SensorId GetLocalSlamResultSensorId(int local_trajectory_id) const override {
|
2018-01-29 21:02:33 +08:00
|
|
|
return SensorId{SensorId::SensorType::LOCAL_SLAM_RESULT,
|
|
|
|
"local_slam_result_" + std::to_string(local_trajectory_id)};
|
|
|
|
}
|
|
|
|
|
2018-01-13 06:16:29 +08:00
|
|
|
private:
|
2018-01-17 19:01:29 +08:00
|
|
|
void ProcessSendQueue();
|
2018-01-29 21:02:33 +08:00
|
|
|
void TranslateTrajectoryId(proto::SensorMetadata* sensor_metadata);
|
2018-01-17 19:01:29 +08:00
|
|
|
void ProcessFixedFramePoseDataMessage(
|
2018-01-29 21:02:33 +08:00
|
|
|
proto::AddFixedFramePoseDataRequest* data_request);
|
|
|
|
void ProcessImuDataMessage(proto::AddImuDataRequest* data_request);
|
|
|
|
void ProcessLocalSlamResultDataMessage(
|
|
|
|
proto::AddLocalSlamResultDataRequest* data_request);
|
|
|
|
void ProcessOdometryDataMessage(proto::AddOdometryDataRequest* data_request);
|
2018-02-02 00:19:15 +08:00
|
|
|
void ProcessLandmarkDataMessage(proto::AddLandmarkDataRequest* data_request);
|
2018-01-17 19:01:29 +08:00
|
|
|
|
2018-01-13 06:16:29 +08:00
|
|
|
std::shared_ptr<grpc::Channel> client_channel_;
|
|
|
|
std::map<int, int> local_to_cloud_trajectory_id_map_;
|
2018-01-15 22:31:33 +08:00
|
|
|
cartographer::common::BlockingQueue<
|
|
|
|
std::unique_ptr<google::protobuf::Message>>
|
|
|
|
send_queue_;
|
2018-01-17 19:01:29 +08:00
|
|
|
bool shutting_down_ = false;
|
|
|
|
std::unique_ptr<std::thread> upload_thread_;
|
2018-02-02 00:19:15 +08:00
|
|
|
std::unique_ptr<framework::Client<handlers::AddFixedFramePoseDataHandler>>
|
|
|
|
add_fixed_frame_pose_client_;
|
|
|
|
std::unique_ptr<framework::Client<handlers::AddImuDataHandler>>
|
|
|
|
add_imu_client_;
|
|
|
|
std::unique_ptr<framework::Client<handlers::AddLocalSlamResultDataHandler>>
|
|
|
|
add_local_slam_result_client_;
|
|
|
|
std::unique_ptr<framework::Client<handlers::AddOdometryDataHandler>>
|
|
|
|
add_odometry_client_;
|
|
|
|
std::unique_ptr<framework::Client<handlers::AddLandmarkDataHandler>>
|
|
|
|
add_landmark_client_;
|
2018-01-11 17:19:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cartographer_grpc
|
|
|
|
|
2018-01-15 22:31:33 +08:00
|
|
|
#endif // CARTOGRAPHER_GRPC_LOCAL_TRAJECTORY_UPLOADER_H
|