tf2 rolling
tf2 maintains the relationship between coordinate frames in a tree structure buffered in time, and lets the user transform points, vectors, etc between any two coordinate frames at any desired point in time.
Loading...
Searching...
No Matches
time_cache.hpp
Go to the documentation of this file.
1// Copyright 2008, Willow Garage, Inc. All rights reserved.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8//
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// * Neither the name of the Willow Garage nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28
33#ifndef TF2__TIME_CACHE_HPP_
34#define TF2__TIME_CACHE_HPP_
35
36#include <chrono>
37#include <memory>
38#include <list>
39#include <sstream>
40#include <string>
41#include <utility>
42
44
46#include "tf2/exceptions.hpp"
47
48namespace tf2
49{
50typedef std::pair<tf2::TimePoint, tf2::CompactFrameID> P_TimeAndFrameID;
51
53{
54public:
56 virtual ~TimeCacheInterface() = default;
57
62 virtual bool getData(
64 std::string * error_str = nullptr, TF2Error * error_code = nullptr) = 0;
65
68 virtual bool insertData(const tf2::TransformStorage & new_data) = 0;
69
72 virtual void clearList() = 0;
73
77 tf2::TimePoint time, std::string * error_str = nullptr, TF2Error * error_code = nullptr) = 0;
78
84
86
88 virtual unsigned int getListLength() = 0;
89
93
97};
98
99using TimeCacheInterfacePtr = std::shared_ptr<TimeCacheInterface>;
100
102constexpr tf2::Duration TIMECACHE_DEFAULT_MAX_STORAGE_TIME = std::chrono::seconds(10);
103
110{
111public:
114
116
120 std::string * error_str = nullptr, TF2Error * error_code = nullptr) override;
124 void clearList() override;
127 tf2::TimePoint time, std::string * error_str = nullptr,
128 TF2Error * error_code = nullptr) override;
131
134 unsigned int getListLength() override;
139
140protected:
141 // (Internal) Return a reference to the internal list of tf2 frames, which
142 // are sorted in timestamp order.
143 // Any items with the same timestamp will be in reverse order of insertion.
145 const std::list<TransformStorage> & getAllItems() const;
146
147private:
148 typedef std::list<TransformStorage> L_TransformStorage;
149 L_TransformStorage storage_;
150
151 tf2::Duration max_storage_time_;
152
153
154 // A helper function for getData
155 // Assumes storage is already locked for it
156 inline uint8_t findClosest(
158 tf2::TimePoint target_time, std::string * error_str = nullptr, TF2Error * error_code = nullptr);
159
160 inline void interpolate(
163
164 void pruneList();
165};
166
168{
169public:
174 std::string * error_str = nullptr, TF2Error * error_code = nullptr) override;
175 // returns false if data unavailable (should be thrown as lookup exception
177 bool insertData(const TransformStorage & new_data) override;
179 void clearList() override;
182 TimePoint time, std::string * error_str = nullptr, TF2Error * error_code = nullptr) override;
185
188 unsigned int getListLength() override;
193
194private:
195 TransformStorage storage_;
196 bool populated_{false};
197};
198} // namespace tf2
199#endif // TF2__TIME_CACHE_HPP_
Definition time_cache.hpp:168
bool getData(TimePoint time, TransformStorage &data_out, std::string *error_str=nullptr, TF2Error *error_code=nullptr) override
Overridden methods.
unsigned int getListLength() override
Debugging information methods.
bool insertData(const TransformStorage &new_data) override
Insert data into the cache.
P_TimeAndFrameID getLatestTimeAndParent() override
Get the latest time stored in this cache, and the parent associated with it. Returns parent = 0 if no...
void clearList() override
Clear the list of stored values.
TimePoint getOldestTimestamp() override
Get the oldest timestamp cached.
CompactFrameID getParent(TimePoint time, std::string *error_str=nullptr, TF2Error *error_code=nullptr) override
Retrieve the parent at a specific time.
TimePoint getLatestTimestamp() override
Get the latest timestamp cached.
Definition time_cache.hpp:53
virtual tf2::TimePoint getOldestTimestamp()=0
Get the oldest timestamp cached.
virtual unsigned int getListLength()=0
Debugging information methods.
virtual void clearList()=0
Clear the list of stored values.
virtual CompactFrameID getParent(tf2::TimePoint time, std::string *error_str=nullptr, TF2Error *error_code=nullptr)=0
Retrieve the parent at a specific time.
virtual bool getData(tf2::TimePoint time, tf2::TransformStorage &data_out, std::string *error_str=nullptr, TF2Error *error_code=nullptr)=0
Access data from the cache returns false if data unavailable (should be thrown as lookup exception)
virtual ~TimeCacheInterface()=default
virtual bool insertData(const tf2::TransformStorage &new_data)=0
Insert data into the cache.
virtual P_TimeAndFrameID getLatestTimeAndParent()=0
Get the latest time stored in this cache, and the parent associated with it. Returns parent = 0 if no...
virtual tf2::TimePoint getLatestTimestamp()=0
Get the latest timestamp cached.
A class to keep a sorted linked list in time (newest first, oldest last). This builds and maintains a...
Definition time_cache.hpp:110
void clearList() override
Clear the list of stored values.
TimePoint getOldestTimestamp() override
Get the oldest timestamp cached.
const std::list< TransformStorage > & getAllItems() const
tf2::CompactFrameID getParent(tf2::TimePoint time, std::string *error_str=nullptr, TF2Error *error_code=nullptr) override
Retrieve the parent at a specific time.
P_TimeAndFrameID getLatestTimeAndParent() override
Get the latest time stored in this cache, and the parent associated with it. Returns parent = 0 if no...
TimePoint getLatestTimestamp() override
Get the latest timestamp cached.
unsigned int getListLength() override
Debugging information methods.
bool getData(tf2::TimePoint time, tf2::TransformStorage &data_out, std::string *error_str=nullptr, TF2Error *error_code=nullptr) override
Overridden methods.
bool insertData(const tf2::TransformStorage &new_data) override
Insert data into the cache.
TimeCache(tf2::Duration max_storage_time=TIMECACHE_DEFAULT_MAX_STORAGE_TIME)
Storage for transforms and their parent.
Definition transform_storage.hpp:48
Author: Tully Foote.
Definition buffer_core.hpp:58
uint32_t CompactFrameID
Definition transform_storage.hpp:44
std::pair< TimePoint, CompactFrameID > P_TimeAndFrameID
Definition buffer_core.hpp:60
B toMsg(const A &a)
Function that converts from one type to a ROS message type. It has to be implemented by each data typ...
TF2Error
Definition exceptions.hpp:46
std::chrono::time_point< std::chrono::system_clock, Duration > TimePoint
Definition time.hpp:41
std::chrono::nanoseconds Duration
Definition time.hpp:40
std::shared_ptr< TimeCacheInterface > TimeCacheInterfacePtr
Definition buffer_core.hpp:64
constexpr tf2::Duration TIMECACHE_DEFAULT_MAX_STORAGE_TIME
default value of 10 seconds storage
Definition time_cache.hpp:102
Author: Tully Foote.
#define TF2_PUBLIC
Definition visibility_control.h:57