add_trajectory_handler.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/cloud/internal/handlers/add_trajectory_handler.h"
00018 
00019 #include "absl/memory/memory.h"
00020 #include "async_grpc/rpc_handler.h"
00021 #include "cartographer/cloud/internal/map_builder_context_interface.h"
00022 #include "cartographer/cloud/internal/sensor/serialization.h"
00023 #include "cartographer/cloud/proto/map_builder_service.pb.h"
00024 
00025 namespace cartographer {
00026 namespace cloud {
00027 namespace handlers {
00028 
00029 void AddTrajectoryHandler::OnRequest(
00030     const proto::AddTrajectoryRequest& request) {
00031   auto local_slam_result_callback =
00032       GetUnsynchronizedContext<MapBuilderContextInterface>()
00033           ->GetLocalSlamResultCallbackForSubscriptions();
00034   std::set<mapping::TrajectoryBuilderInterface::SensorId> expected_sensor_ids;
00035   for (const auto& sensor_id : request.expected_sensor_ids()) {
00036     expected_sensor_ids.insert(FromProto(sensor_id));
00037   }
00038   const int trajectory_id =
00039       GetContext<MapBuilderContextInterface>()
00040           ->map_builder()
00041           .AddTrajectoryBuilder(expected_sensor_ids,
00042                                 request.trajectory_builder_options(),
00043                                 local_slam_result_callback);
00044   GetContext<MapBuilderContextInterface>()->RegisterClientIdForTrajectory(
00045       request.client_id(), trajectory_id);
00046   if (GetUnsynchronizedContext<MapBuilderContextInterface>()
00047           ->local_trajectory_uploader()) {
00048     auto trajectory_builder_options = request.trajectory_builder_options();
00049 
00050     // Clear the trajectory builder options to convey to the cloud
00051     // Cartographer instance that does not need to instantiate a
00052     // 'LocalTrajectoryBuilder'.
00053     trajectory_builder_options.clear_trajectory_builder_2d_options();
00054     trajectory_builder_options.clear_trajectory_builder_3d_options();
00055 
00056     // Don't instantiate the 'PureLocalizationTrimmer' on the server and don't
00057     // freeze the trajectory on the server.
00058     trajectory_builder_options.clear_pure_localization_trimmer();
00059 
00060     // Ignore initial poses in trajectory_builder_options.
00061     trajectory_builder_options.clear_initial_trajectory_pose();
00062 
00063     auto status =
00064         GetContext<MapBuilderContextInterface>()
00065             ->local_trajectory_uploader()
00066             ->AddTrajectory(request.client_id(), trajectory_id,
00067                             expected_sensor_ids, trajectory_builder_options);
00068     if (!status.ok()) {
00069       LOG(ERROR) << "Failed to create trajectory_id " << trajectory_id
00070                  << " in uplink. Error: " << status.error_message();
00071     }
00072   }
00073 
00074   auto response = absl::make_unique<proto::AddTrajectoryResponse>();
00075   response->set_trajectory_id(trajectory_id);
00076   Send(std::move(response));
00077 }
00078 
00079 }  // namespace handlers
00080 }  // namespace cloud
00081 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35