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
69 << "Cannot perform lookup of timestamp " << timestamp;
70
71 // if element is the first in the queue -> cannot interpolate
72 if (poseNextIt == TimeQueue<MessageType>::queue.cbegin())
73 {
74 return *poseNextIt;
75 }
76
77 const auto posePreIt = poseNextIt - 1;
78
79 const auto& posePre = *posePreIt;
80 const auto& poseNext = *poseNextIt;
81
82 // the time fraction [0..1] of the lookup wrt to posePre and poseNext
83 const float t = static_cast<float>(timestamp - posePre.timestamp) /
84 (poseNext.timestamp - posePre.timestamp);
85
86 return interpolate(posePre, poseNext, t);
87 }
88
89 std::size_t
90 size() const noexcept
91 {
92 std::shared_lock g{TimeQueue<MessageType>::mtx};
94 }
95 };
96
97} // namespace armarx::localization_and_mapping::cartographer_adapter
std::string timestamp()
QueueConstIterator findFirstElementAtOrAfter(int64_t timestamp) const
Definition TimeQueue.h:179
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
PoseStamped interpolate(const PoseStamped &posePre, const PoseStamped &poseNext, float t)
#define ARMARX_TRACE
Definition trace.h:75