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 = 0, TF2Error * error_code = 0) = 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 = 0, TF2Error * error_code = 0) = 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
118 virtual bool getData(
120 std::string * error_str = 0, TF2Error * error_code = 0);
124 virtual void clearList();
127 tf2::TimePoint time, std::string * error_str = 0, TF2Error * error_code = 0);
130
133 virtual unsigned int getListLength();
138
139protected:
140 // (Internal) Return a reference to the internal list of tf2 frames, which
141 // are sorted in timestamp order.
142 // Any items with the same timestamp will be in reverse order of insertion.
144 const std::list<TransformStorage> & getAllItems() const;
145
146private:
147 typedef std::list<TransformStorage> L_TransformStorage;
148 L_TransformStorage storage_;
149
150 tf2::Duration max_storage_time_;
151
152
153 // A helper function for getData
154 // Assumes storage is already locked for it
155 inline uint8_t findClosest(
157 tf2::TimePoint target_time, std::string * error_str = 0, TF2Error * error_code = 0);
158
159 inline void interpolate(
162
163 void pruneList();
164};
165
167{
168public:
171 virtual bool getData(
173 std::string * error_str = 0, TF2Error * error_code = 0);
174 // returns false if data unavailable (should be thrown as lookup exception
176 virtual bool insertData(const TransformStorage & new_data);
178 virtual void clearList();
181 TimePoint time, std::string * error_str = 0, TF2Error * error_code = 0);
184
187 virtual unsigned int getListLength();
192
193private:
194 TransformStorage storage_;
195};
196} // namespace tf2
197#endif // TF2__TIME_CACHE_HPP_
Definition time_cache.hpp:167
virtual TimePoint getOldestTimestamp()
Get the oldest timestamp cached.
virtual TimePoint getLatestTimestamp()
Get the latest timestamp cached.
virtual bool insertData(const TransformStorage &new_data)
Insert data into the cache.
virtual unsigned int getListLength()
Debugging information methods.
virtual CompactFrameID getParent(TimePoint time, std::string *error_str=0, TF2Error *error_code=0)
Retrieve the parent at a specific time.
virtual P_TimeAndFrameID getLatestTimeAndParent()
Get the latest time stored in this cache, and the parent associated with it. Returns parent = 0 if no...
virtual bool getData(TimePoint time, TransformStorage &data_out, std::string *error_str=0, TF2Error *error_code=0)
Virtual methods.
virtual void clearList()
Clear the list of stored values.
Definition time_cache.hpp:53
virtual bool getData(tf2::TimePoint time, tf2::TransformStorage &data_out, std::string *error_str=0, TF2Error *error_code=0)=0
Access data from the cache returns false if data unavailable (should be thrown as lookup exception)
virtual CompactFrameID getParent(tf2::TimePoint time, std::string *error_str=0, TF2Error *error_code=0)=0
Retrieve the parent at a specific time.
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 ~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
virtual TimePoint getOldestTimestamp()
Get the oldest timestamp cached.
const std::list< TransformStorage > & getAllItems() const
virtual P_TimeAndFrameID getLatestTimeAndParent()
Get the latest time stored in this cache, and the parent associated with it. Returns parent = 0 if no...
virtual bool insertData(const tf2::TransformStorage &new_data)
Insert data into the cache.
virtual unsigned int getListLength()
Debugging information methods.
virtual bool getData(tf2::TimePoint time, tf2::TransformStorage &data_out, std::string *error_str=0, TF2Error *error_code=0)
Virtual methods.
virtual void clearList()
Clear the list of stored values.
TimeCache(tf2::Duration max_storage_time=TIMECACHE_DEFAULT_MAX_STORAGE_TIME)
virtual tf2::CompactFrameID getParent(tf2::TimePoint time, std::string *error_str=0, TF2Error *error_code=0)
Retrieve the parent at a specific time.
virtual TimePoint getLatestTimestamp()
Get the latest timestamp cached.
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