add_imu_data_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_imu_data_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 #include "cartographer/sensor/imu_data.h"
00025 #include "cartographer/sensor/internal/dispatchable.h"
00026 #include "google/protobuf/empty.pb.h"
00027 
00028 namespace cartographer {
00029 namespace cloud {
00030 namespace handlers {
00031 
00032 void AddImuDataHandler::OnSensorData(const proto::AddImuDataRequest& request) {
00033   // The 'BlockingQueue' returned by 'sensor_data_queue()' is already
00034   // thread-safe. Therefore it suffices to get an unsynchronized reference to
00035   // the 'MapBuilderContext'.
00036   GetUnsynchronizedContext<MapBuilderContextInterface>()->EnqueueSensorData(
00037       request.sensor_metadata().trajectory_id(),
00038       sensor::MakeDispatchable(request.sensor_metadata().sensor_id(),
00039                                sensor::FromProto(request.imu_data())));
00040 
00041   // The 'BlockingQueue' in 'LocalTrajectoryUploader' is thread-safe.
00042   // Therefore it suffices to get an unsynchronized reference to the
00043   // 'MapBuilderContext'.
00044   if (GetUnsynchronizedContext<MapBuilderContextInterface>()
00045           ->local_trajectory_uploader()) {
00046     auto sensor_data = absl::make_unique<proto::SensorData>();
00047     *sensor_data->mutable_sensor_metadata() = request.sensor_metadata();
00048     *sensor_data->mutable_imu_data() = request.imu_data();
00049     GetUnsynchronizedContext<MapBuilderContextInterface>()
00050         ->local_trajectory_uploader()
00051         ->EnqueueSensorData(std::move(sensor_data));
00052   }
00053 }
00054 
00055 }  // namespace handlers
00056 }  // namespace cloud
00057 }  // namespace cartographer


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