add_trajectory_handler.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "async_grpc/rpc_handler.h"
22 #include "cartographer/cloud/proto/map_builder_service.pb.h"
24 
25 namespace cartographer {
26 namespace cloud {
27 namespace handlers {
28 
29 void AddTrajectoryHandler::OnRequest(
30  const proto::AddTrajectoryRequest& request) {
31  auto local_slam_result_callback =
32  GetUnsynchronizedContext<MapBuilderContextInterface>()
33  ->GetLocalSlamResultCallbackForSubscriptions();
34  std::set<mapping::TrajectoryBuilderInterface::SensorId> expected_sensor_ids;
35  for (const auto& sensor_id : request.expected_sensor_ids()) {
36  expected_sensor_ids.insert(FromProto(sensor_id));
37  }
38  const int trajectory_id =
39  GetContext<MapBuilderContextInterface>()
40  ->map_builder()
41  .AddTrajectoryBuilder(expected_sensor_ids,
42  request.trajectory_builder_options(),
43  local_slam_result_callback);
44  if (GetUnsynchronizedContext<MapBuilderContextInterface>()
45  ->local_trajectory_uploader()) {
46  auto trajectory_builder_options = request.trajectory_builder_options();
47 
48  // Clear the trajectory builder options to convey to the cloud
49  // Cartographer instance that does not need to instantiate a
50  // 'LocalTrajectoryBuilder'.
51  trajectory_builder_options.clear_trajectory_builder_2d_options();
52  trajectory_builder_options.clear_trajectory_builder_3d_options();
53 
54  // Don't instantiate the 'PureLocalizationTrimmer' on the server and don't
55  // freeze the trajectory on the server.
56  trajectory_builder_options.set_pure_localization(false);
57 
58  GetContext<MapBuilderContextInterface>()
59  ->local_trajectory_uploader()
60  ->AddTrajectory(trajectory_id, expected_sensor_ids,
61  trajectory_builder_options);
62  }
63 
64  auto response = common::make_unique<proto::AddTrajectoryResponse>();
65  response->set_trajectory_id(trajectory_id);
66  Send(std::move(response));
67 }
68 
69 } // namespace handlers
70 } // namespace cloud
71 } // namespace cartographer
mapping::TrajectoryBuilderInterface::SensorId FromProto(const proto::SensorId &proto)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58