InterpolatingTimeQueue.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <algorithm>
25#include <deque>
26#include <iterator>
27#include <shared_mutex>
28#include <vector>
29
30#include <Eigen/Core>
31#include <Eigen/Geometry>
32
33#include <SimoxUtility/math/pose/interpolate.h>
34
37
38#include "TimeQueue.h"
39
41{
42
44 {
45 Eigen::Isometry3f pose;
46 int64_t timestamp;
47 };
48
49 PoseStamped interpolate(const PoseStamped& posePre, const PoseStamped& poseNext, float t);
50
51 template <typename MessageType>
52 class InterpolatingTimeQueue : public TimeQueue<MessageType>
53 {
54 public:
55 InterpolatingTimeQueue(const std::size_t maxQueueSize = 100) :
56 TimeQueue<MessageType>(maxQueueSize)
57 {
58 }
59
60 MessageType
62 {
64 std::shared_lock g{TimeQueue<MessageType>::mtx};
65 // ARMARX_CHECK(this->_has(timestamp));
66
68
69 // if element is the first in the queue -> cannot interpolate
70 if (poseNextIt == TimeQueue<MessageType>::queue.cbegin())
71 {
72 return *poseNextIt;
73 }
74
75 const auto posePreIt = poseNextIt - 1;
76
77 const auto& posePre = *posePreIt;
78 const auto& poseNext = *poseNextIt;
79
80 // the time fraction [0..1] of the lookup wrt to posePre and poseNext
81 const float t = static_cast<float>(timestamp - posePre.timestamp) /
82 (poseNext.timestamp - posePre.timestamp);
83
84 return interpolate(posePre, poseNext, t);
85 }
86
87 std::size_t
88 size() const noexcept
89 {
90 std::shared_lock g{TimeQueue<MessageType>::mtx};
92 }
93 };
94
95} // namespace armarx::localization_and_mapping::cartographer_adapter
std::string timestamp()
QueueConstIterator findFirstElementAtOrAfter(int64_t timestamp) const
Definition TimeQueue.h:179
PoseStamped interpolate(const PoseStamped &posePre, const PoseStamped &poseNext, float t)
#define ARMARX_TRACE
Definition trace.h:77