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 
43  struct PoseStamped
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
armarx::localization_and_mapping::cartographer_adapter::PoseStamped::timestamp
int64_t timestamp
Definition: InterpolatingTimeQueue.h:46
armarx::localization_and_mapping::cartographer_adapter::TimeQueue::findFirstElementAtOrAfter
QueueConstIterator findFirstElementAtOrAfter(int64_t timestamp) const
Definition: TimeQueue.h:179
armarx::localization_and_mapping::cartographer_adapter::PoseStamped
Definition: InterpolatingTimeQueue.h:43
armarx::localization_and_mapping::cartographer_adapter::InterpolatingTimeQueue
Definition: InterpolatingTimeQueue.h:52
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
TimeQueue.h
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::localization_and_mapping::cartographer_adapter
This file is part of ArmarX.
Definition: ApproximateTimeQueue.cpp:15
ExpressionException.h
armarx::localization_and_mapping::cartographer_adapter::PoseStamped::pose
Eigen::Isometry3f pose
Definition: InterpolatingTimeQueue.h:45
armarx::localization_and_mapping::cartographer_adapter::TimeQueue::size
std::size_t size() const noexcept
Definition: TimeQueue.h:165
armarx::localization_and_mapping::cartographer_adapter::InterpolatingTimeQueue::InterpolatingTimeQueue
InterpolatingTimeQueue(const std::size_t maxQueueSize=100)
Definition: InterpolatingTimeQueue.h:55
armarx::localization_and_mapping::cartographer_adapter::TimeQueue
Definition: TimeQueue.h:50
armarx::localization_and_mapping::cartographer_adapter::InterpolatingTimeQueue::size
std::size_t size() const noexcept
Definition: InterpolatingTimeQueue.h:88
Logging.h
armarx::localization_and_mapping::cartographer_adapter::interpolate
PoseStamped interpolate(const PoseStamped &posePre, const PoseStamped &poseNext, float t)
Definition: InterpolatingTimeQueue.cpp:32
armarx::localization_and_mapping::cartographer_adapter::InterpolatingTimeQueue::lookupInterpolate
MessageType lookupInterpolate(int64_t timestamp) const
Definition: InterpolatingTimeQueue.h:61