collated_trajectory_builder.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 
20 #include "glog/logging.h"
21 
22 namespace cartographer {
23 namespace mapping {
24 
25 namespace {
26 
27 constexpr double kSensorDataRatesLoggingPeriodSeconds = 15.;
28 
29 } // namespace
30 
32  sensor::CollatorInterface* const sensor_collator, const int trajectory_id,
33  const std::set<SensorId>& expected_sensor_ids,
34  std::unique_ptr<TrajectoryBuilderInterface> wrapped_trajectory_builder)
35  : sensor_collator_(sensor_collator),
36  trajectory_id_(trajectory_id),
37  wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder)),
38  last_logging_time_(std::chrono::steady_clock::now()) {
39  std::unordered_set<std::string> expected_sensor_id_strings;
40  for (const auto& sensor_id : expected_sensor_ids) {
41  expected_sensor_id_strings.insert(sensor_id.id);
42  }
44  trajectory_id, expected_sensor_id_strings,
45  [this](const std::string& sensor_id, std::unique_ptr<sensor::Data> data) {
46  HandleCollatedSensorData(sensor_id, std::move(data));
47  });
48 }
49 
51 
52 void CollatedTrajectoryBuilder::AddData(std::unique_ptr<sensor::Data> data) {
54 }
55 
57  const std::string& sensor_id, std::unique_ptr<sensor::Data> data) {
58  auto it = rate_timers_.find(sensor_id);
59  if (it == rate_timers_.end()) {
60  it = rate_timers_
61  .emplace(
62  std::piecewise_construct, std::forward_as_tuple(sensor_id),
63  std::forward_as_tuple(
64  common::FromSeconds(kSensorDataRatesLoggingPeriodSeconds)))
65  .first;
66  }
67  it->second.Pulse(data->GetTime());
68 
69  if (std::chrono::steady_clock::now() - last_logging_time_ >
70  common::FromSeconds(kSensorDataRatesLoggingPeriodSeconds)) {
71  for (const auto& pair : rate_timers_) {
72  LOG(INFO) << pair.first << " rate: " << pair.second.DebugString();
73  }
74  last_logging_time_ = std::chrono::steady_clock::now();
75  }
76 
77  data->AddToTrajectoryBuilder(wrapped_trajectory_builder_.get());
78 }
79 
80 } // namespace mapping
81 } // namespace cartographer
void AddData(std::unique_ptr< sensor::Data > data)
std::unique_ptr< TrajectoryBuilderInterface > wrapped_trajectory_builder_
void HandleCollatedSensorData(const std::string &sensor_id, std::unique_ptr< sensor::Data > data)
virtual void AddSensorData(int trajectory_id, std::unique_ptr< Data > data)=0
CollatedTrajectoryBuilder(sensor::CollatorInterface *sensor_collator, int trajectory_id, const std::set< SensorId > &expected_sensor_ids, std::unique_ptr< TrajectoryBuilderInterface > wrapped_trajectory_builder)
int trajectory_id_
std::map< std::string, common::RateTimer<> > rate_timers_
virtual void AddTrajectory(int trajectory_id, const std::unordered_set< std::string > &expected_sensor_ids, const Callback &callback)=0
Duration FromSeconds(const double seconds)
Definition: time.cc:24
std::chrono::steady_clock::time_point last_logging_time_


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