Add MappingServer skeleton. (#730)

master
Christoph Schütte 2017-12-05 14:46:25 +01:00 committed by GitHub
parent 49d55d97c1
commit 697be9a77b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 264 additions and 3 deletions

View File

@ -87,6 +87,14 @@ void Server::Start() {
}
}
void Server::WaitForShutdown() {
if (!server_) {
return;
}
server_->Wait();
}
void Server::Shutdown() {
LOG(INFO) << "Shutting down server.";

View File

@ -85,6 +85,11 @@ class Server {
// Starts a server starts serving the registered services.
void Start();
// Waits for the server to shut down. Note: The server must be either shutting
// down or some other thread must call 'Shutdown()' for this function to ever
// return.
void WaitForShutdown();
// Shuts down the server and all of its services.
void Shutdown();

View File

@ -0,0 +1,70 @@
/*
* 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.
*/
#include "cartographer_grpc/map_builder_server.h"
#include "cartographer_grpc/proto/map_builder_service.grpc.pb.h"
#include "glog/logging.h"
namespace cartographer_grpc {
MapBuilderServer::MapBuilderServer(
const proto::MapBuilderServerOptions& map_builder_server_options)
: map_builder_(map_builder_server_options.map_builder_options()) {
framework::Server::Builder server_builder;
server_builder.SetServerAddress(map_builder_server_options.server_address());
server_builder.SetNumberOfThreads(
map_builder_server_options.num_grpc_threads());
grpc_server_ = server_builder.Build();
grpc_server_->SetExecutionContext(
cartographer::common::make_unique<MapBuilderContext>(&map_builder_));
}
void MapBuilderServer::Start() {
shutting_down_ = false;
StartSlamThread();
grpc_server_->Start();
}
void MapBuilderServer::WaitForShutdown() {
grpc_server_->WaitForShutdown();
if (slam_thread_) {
slam_thread_->join();
}
}
void MapBuilderServer::Shutdown() {
shutting_down_ = true;
grpc_server_->Shutdown();
if (slam_thread_) {
slam_thread_->join();
}
}
void MapBuilderServer::ProcessSensorDataQueue() {
while (!shutting_down_) {
// TODO(cschuet): Implement this.
}
}
void MapBuilderServer::StartSlamThread() {
CHECK(!slam_thread_);
// Start the SLAM processing thread.
slam_thread_ = cartographer::common::make_unique<std::thread>(
[this]() { this->ProcessSensorDataQueue(); });
}
} // namespace cartographer_grpc

View File

@ -0,0 +1,67 @@
/*
* 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_GRPC_MAP_BUILDER_SERVER_H
#define CARTOGRAPHER_GRPC_MAP_BUILDER_SERVER_H
#include "cartographer/common/blocking_queue.h"
#include "cartographer/mapping/map_builder.h"
#include "cartographer/sensor/data.h"
#include "cartographer_grpc/framework/execution_context.h"
#include "cartographer_grpc/framework/server.h"
#include "cartographer_grpc/proto/map_builder_server_options.pb.h"
namespace cartographer_grpc {
class MapBuilderServer {
public:
class MapBuilderContext : public framework::ExecutionContext {
public:
MapBuilderContext(cartographer::mapping::MapBuilder* map_builder)
: map_builder_(map_builder) {}
cartographer::mapping::MapBuilder& map_builder() { return *map_builder_; }
private:
cartographer::mapping::MapBuilder* map_builder_;
};
MapBuilderServer(
const proto::MapBuilderServerOptions& map_builder_server_options);
// Starts the gRPC server and the SLAM thread.
void Start();
// Waits for the 'MapBuilderServer' to shut down. Note: The server must be
// either shutting down or some other thread must call 'Shutdown()' for this
// function to ever return.
void WaitForShutdown();
// Shuts down the gRPC server and the SLAM thread.
void Shutdown();
private:
void ProcessSensorDataQueue();
void StartSlamThread();
bool shutting_down_ = false;
std::unique_ptr<std::thread> slam_thread_;
std::unique_ptr<framework::Server> grpc_server_;
cartographer::mapping::MapBuilder map_builder_;
};
} // namespace cartographer_grpc
#endif // CARTOGRAPHER_GRPC_MAP_BUILDER_SERVER_H

View File

@ -0,0 +1,50 @@
/*
* 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.
*/
#include "cartographer_grpc/map_builder_server_options.h"
#include "cartographer/common/configuration_file_resolver.h"
#include "cartographer/common/make_unique.h"
#include "cartographer/mapping/map_builder.h"
namespace cartographer_grpc {
proto::MapBuilderServerOptions CreateMapBuilderServerOptions(
::cartographer::common::LuaParameterDictionary* lua_parameter_dictionary) {
proto::MapBuilderServerOptions map_builder_server_options;
map_builder_server_options.set_server_address(
lua_parameter_dictionary->GetString("server_address"));
map_builder_server_options.set_num_grpc_threads(
lua_parameter_dictionary->GetInt("num_grpc_threads"));
*map_builder_server_options.mutable_map_builder_options() =
cartographer::mapping::CreateMapBuilderOptions(lua_parameter_dictionary);
return map_builder_server_options;
}
proto::MapBuilderServerOptions LoadMapBuilderServerOptions(
const std::string& configuration_directory,
const std::string& configuration_basename) {
auto file_resolver = cartographer::common::make_unique<
cartographer::common::ConfigurationFileResolver>(
std::vector<std::string>{configuration_directory});
const std::string code =
file_resolver->GetFileContentOrDie(configuration_basename);
cartographer::common::LuaParameterDictionary lua_parameter_dictionary(
code, std::move(file_resolver));
return CreateMapBuilderServerOptions(&lua_parameter_dictionary);
}
} // namespace cartographer_grpc

View File

@ -0,0 +1,36 @@
/*
* 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_GRPC_MAP_BUILDER_SERVER_OPTIONS_H
#define CARTOGRAPHER_GRPC_MAP_BUILDER_SERVER_OPTIONS_H
#include <string>
#include "cartographer/common/lua_parameter_dictionary.h"
#include "cartographer_grpc/proto/map_builder_server_options.pb.h"
namespace cartographer_grpc {
proto::MapBuilderServerOptions CreateMapBuilderServerOptions(
::cartographer::common::LuaParameterDictionary* lua_parameter_dictionary);
proto::MapBuilderServerOptions LoadMapBuilderServerOptions(
const std::string& configuration_directory,
const std::string& configuration_basename);
} // namespace cartographer_grpc
#endif // CARTOGRAPHER_GRPC_MAP_BUILDER_SERVER_OPTIONS_H

View File

@ -0,0 +1,25 @@
// 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.
syntax = "proto3";
import "cartographer/mapping/proto/map_builder_options.proto";
package cartographer_grpc.proto;
message MapBuilderServerOptions {
string server_address = 1;
int32 num_grpc_threads = 2;
cartographer.mapping.proto.MapBuilderOptions map_builder_options = 3;
}

View File

@ -21,8 +21,9 @@ import "google/protobuf/empty.proto";
package cartographer_grpc.proto;
message AddTrajectoryRequest {
repeated string expected_sensor_ids = 1;
cartographer.mapping.proto.TrajectoryBuilderOptions
trajectory_builder_options = 1;
trajectory_builder_options = 2;
}
message SensorMetadata {
@ -53,7 +54,7 @@ message FinishTrajectoryRequest {
int32 trajectory_id = 1;
}
service Cartographer {
service MapBuilderService {
// Starts a new trajectory and returns its index.
rpc AddTrajectory(AddTrajectoryRequest) returns (AddTrajectoryResponse);
@ -75,4 +76,3 @@ service Cartographer {
// i.e. no further sensor data is expected.
rpc FinishTrajectory(FinishTrajectoryRequest) returns (google.protobuf.Empty);
}