27 #include "cartographer/cloud/proto/map_builder_service.pb.h" 29 #include "glog/logging.h" 36 constexpr
int kConnectionTimeoutInSecond = 10;
42 server_address, ::grpc::InsecureChannelCredentials())),
44 LOG(INFO) <<
"Connecting to SLAM process at " << server_address;
45 std::chrono::system_clock::time_point deadline(
46 std::chrono::system_clock::now() +
47 std::chrono::seconds(kConnectionTimeoutInSecond));
49 LOG(FATAL) <<
"Failed to connect to " << server_address;
54 const std::set<SensorId>& expected_sensor_ids,
55 const mapping::proto::TrajectoryBuilderOptions& trajectory_options,
57 proto::AddTrajectoryRequest request;
58 *request.mutable_trajectory_builder_options() = trajectory_options;
59 for (
const auto& sensor_id : expected_sensor_ids) {
62 async_grpc::Client<handlers::AddTrajectorySignature> client(
65 CHECK(client.Write(request));
69 std::piecewise_construct,
70 std::forward_as_tuple(client.response().trajectory_id()),
71 std::forward_as_tuple(make_unique<TrajectoryBuilderStub>(
73 local_slam_result_callback)));
74 return client.response().trajectory_id();
78 const mapping::proto::TrajectoryBuilderOptionsWithSensorIds&
79 options_with_sensor_ids_proto) {
80 LOG(FATAL) <<
"Not implemented";
84 int trajectory_id)
const {
89 proto::FinishTrajectoryRequest request;
90 request.set_trajectory_id(trajectory_id);
91 async_grpc::Client<handlers::FinishTrajectorySignature> client(
93 CHECK(client.Write(request));
99 mapping::proto::SubmapQuery::Response* submap_query_response) {
100 proto::GetSubmapRequest request;
101 submap_id.
ToProto(request.mutable_submap_id());
102 async_grpc::Client<handlers::GetSubmapSignature> client(
client_channel_);
103 CHECK(client.Write(request));
104 submap_query_response->CopyFrom(client.response().submap_query_response());
105 return client.response().error_msg();
109 google::protobuf::Empty request;
110 async_grpc::Client<handlers::WriteStateSignature> client(
client_channel_);
111 CHECK(client.Write(request));
112 proto::WriteStateResponse response;
113 while (client.StreamRead(&response)) {
114 switch (response.state_chunk_case()) {
115 case proto::WriteStateResponse::kHeader:
118 case proto::WriteStateResponse::kSerializedData:
119 writer->
WriteProto(response.serialized_data());
122 LOG(FATAL) <<
"Unhandled message type";
128 const bool load_frozen_state) {
129 if (!load_frozen_state) {
130 LOG(FATAL) <<
"Not implemented";
132 async_grpc::Client<handlers::LoadStateSignature> client(
client_channel_);
137 proto::LoadStateRequest request;
138 *request.mutable_pose_graph() = deserializer.
pose_graph();
139 CHECK(client.Write(request));
143 proto::LoadStateRequest request;
144 *request.mutable_all_trajectory_builder_options() =
146 CHECK(client.Write(request));
149 proto::LoadStateRequest request;
152 CHECK(client.Write(request));
155 CHECK(reader->
eof());
156 CHECK(client.StreamWritesDone());
157 CHECK(client.StreamFinish().ok());
168 const std::vector<mapping::proto::TrajectoryBuilderOptionsWithSensorIds>&
170 LOG(FATAL) <<
"Not implemented";
common::Duration FromMilliseconds(const int64 milliseconds)
std::map< int, std::unique_ptr< mapping::TrajectoryBuilderInterface > > trajectory_builder_stubs_
_Unique_if< T >::_Single_object make_unique(Args &&... args)
TrajectoryBuilderInterface::LocalSlamResultCallback LocalSlamResultCallback
std::shared_ptr<::grpc::Channel > client_channel_
const std::vector< mapping::proto::TrajectoryBuilderOptionsWithSensorIds > & GetAllTrajectoryBuilderOptions() const override
void ToProto(proto::SubmapId *proto) const
MapBuilderStub(const std::string &server_address)
bool ReadNextSerializedData(mapping::proto::SerializedData *data)
mapping::TrajectoryBuilderInterface * GetTrajectoryBuilder(int trajectory_id) const override
virtual bool eof() const =0
mapping::proto::PoseGraph & pose_graph()
int AddTrajectoryForDeserialization(const mapping::proto::TrajectoryBuilderOptionsWithSensorIds &options_with_sensor_ids_proto) override
void SerializeState(io::ProtoStreamWriterInterface *writer) override
std::unique_ptr< mapping::PoseGraphInterface > pose_graph_stub_
int AddTrajectoryBuilder(const std::set< SensorId > &expected_sensor_ids, const mapping::proto::TrajectoryBuilderOptions &trajectory_options, LocalSlamResultCallback local_slam_result_callback) override
const mapping::proto::AllTrajectoryBuilderOptions & all_trajectory_builder_options()
void LoadState(io::ProtoStreamReaderInterface *reader, bool load_frozen_state) override
std::string SubmapToProto(const mapping::SubmapId &submap_id, mapping::proto::SubmapQuery::Response *response) override
virtual void WriteProto(const google::protobuf::Message &proto)=0
proto::SensorId ToProto(const mapping::TrajectoryBuilderInterface::SensorId &sensor_id)
std::shared_ptr<::grpc::Channel > client_channel_
void FinishTrajectory(int trajectory_id) override
int num_trajectory_builders() const override
mapping::PoseGraphInterface * pose_graph() override