transform_interpolation_buffer.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 
19 #include <algorithm>
20 
21 #include "Eigen/Core"
22 #include "Eigen/Geometry"
24 #include "glog/logging.h"
25 
26 namespace cartographer {
27 namespace transform {
28 
30  const mapping::proto::Trajectory& trajectory) {
31  for (const mapping::proto::Trajectory::Node& node : trajectory.node()) {
32  Push(common::FromUniversal(node.timestamp()),
33  transform::ToRigid3(node.pose()));
34  }
35 }
36 
38  const transform::Rigid3d& transform) {
39  if (!timestamped_transforms_.empty()) {
40  CHECK_GE(time, latest_time()) << "New transform is older than latest.";
41  }
42  timestamped_transforms_.push_back(TimestampedTransform{time, transform});
43 }
44 
46  if (timestamped_transforms_.empty()) {
47  return false;
48  }
49  return earliest_time() <= time && time <= latest_time();
50 }
51 
53  const common::Time time) const {
54  CHECK(Has(time)) << "Missing transform for: " << time;
55  const auto end = std::lower_bound(
57  [](const TimestampedTransform& timestamped_transform,
58  const common::Time time) {
59  return timestamped_transform.time < time;
60  });
61  if (end->time == time) {
62  return end->transform;
63  }
64  const auto start = std::prev(end);
65  return Interpolate(*start, *end, time).transform;
66 }
67 
69  CHECK(!empty()) << "Empty buffer.";
70  return timestamped_transforms_.front().time;
71 }
72 
74  CHECK(!empty()) << "Empty buffer.";
75  return timestamped_transforms_.back().time;
76 }
77 
79  return timestamped_transforms_.empty();
80 }
81 
82 } // namespace transform
83 } // namespace cartographer
void Push(common::Time time, const transform::Rigid3d &transform)
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
transform::Rigid3d ToRigid3(const proto::Rigid3d &rigid)
Definition: transform.cc:71
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
static time_point time
TimestampedTransform Interpolate(const TimestampedTransform &start, const TimestampedTransform &end, const common::Time time)


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