range_data_collator.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 <memory>
20 
23 #include "glog/logging.h"
24 
25 namespace cartographer {
26 namespace mapping {
27 
29  const std::string& sensor_id,
30  const sensor::TimedPointCloudData& timed_point_cloud_data) {
31  CHECK_NE(expected_sensor_ids_.count(sensor_id), 0);
32  // TODO(gaschler): These two cases can probably be one.
33  if (id_to_pending_data_.count(sensor_id) != 0) {
35  // When we have two messages of the same sensor, move forward the older of
36  // the two (do not send out current).
37  current_end_ = id_to_pending_data_.at(sensor_id).time;
38  auto result = CropAndMerge();
39  id_to_pending_data_.emplace(sensor_id, timed_point_cloud_data);
40  return result;
41  }
42  id_to_pending_data_.emplace(sensor_id, timed_point_cloud_data);
43  if (expected_sensor_ids_.size() != id_to_pending_data_.size()) {
44  return {};
45  }
47  // We have messages from all sensors, move forward to oldest.
48  common::Time oldest_timestamp = common::Time::max();
49  for (const auto& pair : id_to_pending_data_) {
50  oldest_timestamp = std::min(oldest_timestamp, pair.second.time);
51  }
52  current_end_ = oldest_timestamp;
53  return CropAndMerge();
54 }
55 
58  bool warned_for_dropped_points = false;
59  for (auto it = id_to_pending_data_.begin();
60  it != id_to_pending_data_.end();) {
61  sensor::TimedPointCloudData& data = it->second;
62  sensor::TimedPointCloud& ranges = it->second.ranges;
63 
64  auto overlap_begin = ranges.begin();
65  while (overlap_begin < ranges.end() &&
66  data.time + common::FromSeconds((*overlap_begin)[3]) <
68  ++overlap_begin;
69  }
70  auto overlap_end = overlap_begin;
71  while (overlap_end < ranges.end() &&
72  data.time + common::FromSeconds((*overlap_end)[3]) <= current_end_) {
73  ++overlap_end;
74  }
75  if (ranges.begin() < overlap_begin && !warned_for_dropped_points) {
76  LOG(WARNING) << "Dropped " << std::distance(ranges.begin(), overlap_begin)
77  << " earlier points.";
78  warned_for_dropped_points = true;
79  }
80 
81  // Copy overlapping range.
82  if (overlap_begin < overlap_end) {
83  std::size_t origin_index = result.origins.size();
84  result.origins.push_back(data.origin);
85  double time_correction = common::ToSeconds(data.time - current_end_);
86  for (auto overlap_it = overlap_begin; overlap_it != overlap_end;
87  ++overlap_it) {
89  origin_index};
90  // current_end_ + point_time[3]_after == in_timestamp +
91  // point_time[3]_before
92  point.point_time[3] += time_correction;
93  result.ranges.push_back(point);
94  }
95  }
96 
97  // Drop buffered points until overlap_end.
98  if (overlap_end == ranges.end()) {
99  it = id_to_pending_data_.erase(it);
100  } else if (overlap_end == ranges.begin()) {
101  ++it;
102  } else {
104  data.time, data.origin,
105  sensor::TimedPointCloud(overlap_end, ranges.end())};
106  ++it;
107  }
108  }
109 
110  std::sort(result.ranges.begin(), result.ranges.end(),
113  return a.point_time[3] < b.point_time[3];
114  });
115  return result;
116 }
117 
118 } // namespace mapping
119 } // namespace cartographer
const std::set< std::string > expected_sensor_ids_
std::map< std::string, sensor::TimedPointCloudData > id_to_pending_data_
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
Duration FromSeconds(const double seconds)
Definition: time.cc:24
double ToSeconds(const Duration duration)
Definition: time.cc:29
std::vector< Eigen::Vector4f > TimedPointCloud
Definition: point_cloud.h:39
sensor::TimedPointCloudOriginData CropAndMerge()
sensor::TimedPointCloudOriginData AddRangeData(const std::string &sensor_id, const sensor::TimedPointCloudData &timed_point_cloud_data)


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