interruptible_buffer.h
Go to the documentation of this file.
1 #pragma once
2 
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 
15 #include <geometry_msgs/TransformStamped.h>
16 #include <ros/duration.h>
17 #include <ros/time.h>
18 #include <tf2/buffer_core.h>
19 #include <tf2_ros/buffer.h>
20 
23 
24 namespace cras
25 {
26 
43 {
44 public:
49  explicit InterruptibleTFBuffer(const ::ros::Duration& cacheTime = {::tf2::BufferCore::DEFAULT_CACHE_TIME, 0});
50 
58  explicit InterruptibleTFBuffer(const ::std::shared_ptr<::tf2::BufferCore>& parentBuffer);
59 
63  ~InterruptibleTFBuffer() override;
64 
69  bool ok() const override;
70 
74  virtual void requestStop();
75 
76  bool canTransform(const ::std::string& target_frame, const ::std::string& source_frame,
77  const ::ros::Time& time, ::ros::Duration timeout, ::std::string* errstr) const override;
78 
87  bool canTransform(const ::std::string& target_frame, const ::std::string& source_frame,
88  const ::ros::Time& time, ::ros::Duration timeout) const;
89 
90  bool canTransform(const ::std::string& target_frame, const ::ros::Time& target_time,
91  const ::std::string& source_frame, const ::ros::Time& source_time,
92  const ::std::string& fixed_frame, ::ros::Duration timeout,
93  ::std::string* errstr) const override;
94 
105  bool canTransform(const ::std::string& target_frame, const ::ros::Time& target_time,
106  const ::std::string& source_frame, const ::ros::Time& source_time,
107  const ::std::string& fixed_frame, ::ros::Duration timeout) const;
108 
109  ::geometry_msgs::TransformStamped lookupTransform(
110  const ::std::string& target_frame, const ::std::string& source_frame,
111  const ::ros::Time& time, const ::ros::Duration timeout) const override; // NOLINT
112 
113  ::geometry_msgs::TransformStamped lookupTransform(
114  const ::std::string& target_frame, const ::ros::Time& target_time,
115  const ::std::string& source_frame, const ::ros::Time& source_time,
116  const ::std::string& fixed_frame, const ::ros::Duration timeout) const override; // NOLINT
117 
123  bool setCanTransformPollingScale(double scale);
124 
130  bool setMinPollingDuration(const ::ros::Duration& duration);
131 
137 
142  const ::tf2::BufferCore& getRawBuffer() const;
143 
144  // The transform() functions internally use the overridden lookupTransform(), so it is okay to just call the parent
145  // implementation.
146 
158  template <class T>
159  T& transform(const T& in, T& out, const ::std::string& target_frame, ::ros::Duration timeout = {0, 0}) const
160  {
161  return ::tf2_ros::Buffer::transform(in, out, target_frame, timeout);
162  }
163 
175  template <class T>
176  T transform(const T& in, const ::std::string& target_frame, ::ros::Duration timeout = {0, 0}) const
177  {
178  T out;
179  return ::tf2_ros::Buffer::transform(in, target_frame, timeout);
180  }
181 
199  template <class A, class B>
200  B& transform(const A& in, B& out, const ::std::string& target_frame, ::ros::Duration timeout = {0, 0}) const
201  {
202  return ::tf2_ros::Buffer::transform(in, out, target_frame, timeout);
203  }
204 
220  template <class T>
221  T& transform(const T& in, T& out, const ::std::string& target_frame, const ::ros::Time& target_time,
222  const ::std::string& fixed_frame, ::ros::Duration timeout = {0, 0}) const
223  {
224  return ::tf2_ros::Buffer::transform(in, out, target_frame, target_time, fixed_frame, timeout);
225  }
226 
227 
243  template <class T>
244  T transform(const T& in, const ::std::string& target_frame, const ::ros::Time& target_time,
245  const ::std::string& fixed_frame, ::ros::Duration timeout = {0, 0}) const
246  {
247  return ::tf2_ros::Buffer::transform(in, target_frame, target_time, fixed_frame, timeout);
248  }
249 
271  template <class A, class B>
272  B& transform(const A& in, B& out, const ::std::string& target_frame, const ::ros::Time& target_time,
273  const ::std::string& fixed_frame, ::ros::Duration timeout = {0, 0}) const
274  {
275  return ::tf2_ros::Buffer::transform(in, out, target_frame, target_time, fixed_frame, timeout); // NOLINT
276  }
277 
278  // Methods copied from BufferCore, they do not rely on time.
279 
284 
288  void clear();
289 
298  bool setTransform(const ::geometry_msgs::TransformStamped& transform, const ::std::string& authority,
299  bool is_static = false);
300 
310  ::geometry_msgs::TransformStamped lookupTransform(const ::std::string& target_frame,
311  const ::std::string& source_frame, const ::ros::Time& time) const;
312 
324  ::geometry_msgs::TransformStamped lookupTransform(const ::std::string& target_frame, const ::ros::Time& target_time,
325  const ::std::string& source_frame, const ::ros::Time& source_time, const ::std::string& fixed_frame) const;
326 
335  bool canTransform(const ::std::string& target_frame, const ::std::string& source_frame, const ::ros::Time& time,
336  ::std::string* error_msg = nullptr) const;
337 
348  bool canTransform(const ::std::string& target_frame, const ::ros::Time& target_time,
349  const ::std::string& source_frame, const ::ros::Time& source_time, const ::std::string& fixed_frame,
350  ::std::string* error_msg = nullptr) const;
351 
355  ::std::string allFramesAsYAML(double current_time) const;
356 
360  ::std::string allFramesAsYAML() const;
361 
365  ::std::string allFramesAsString() const;
366 
367 protected:
369  const ::std::shared_ptr<::tf2::BufferCore> parentBuffer {nullptr};
370 
374 
378 
379 private:
381  bool isOk {true};
382 
384  const ::std::shared_ptr<::cras::InterruptibleTFBuffer> interruptibleParentBuffer {nullptr};
385 
389  mutable ::cras::ReverseSemaphore callbackSemaphore;
390 };
391 
392 }
cras::InterruptibleTFBuffer::transform
T & transform(const T &in, T &out, const ::std::string &target_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame. This function is templated and can take as input any valid ...
Definition: interruptible_buffer.h:159
cras::InterruptibleTFBuffer::getCacheLength
::ros::Duration getCacheLength()
Get the duration over which this transformer will cache.
cras::InterruptibleTFBuffer::transform
T transform(const T &in, const ::std::string &target_frame, const ::ros::Time &target_time, const ::std::string &fixed_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame (advanced). This function is templated and can take as input...
Definition: interruptible_buffer.h:244
cras::InterruptibleTFBuffer::minPollingDuration
::ros::Duration minPollingDuration
Minimum duration of a pause between two transform polls. If timeout * canTransformPollingScale would ...
Definition: interruptible_buffer.h:377
cras::InterruptibleTFBuffer
Provides overrides of canTransform() that can be interrupted. Normally, canTransform() waits until tr...
Definition: interruptible_buffer.h:42
cras
Definition: any.hpp:15
cras::InterruptibleTFBuffer::ok
bool ok() const override
Whether it is OK to continue. If false, all pending lookups should stop as soon as possible.
cras::InterruptibleTFBuffer::getRawBuffer
::tf2::BufferCore & getRawBuffer()
Get the raw tf2::BufferCore that actually stores the transforms.
cras::InterruptibleTFBuffer::transform
T transform(const T &in, const ::std::string &target_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame. This function is templated and can take as input any valid ...
Definition: interruptible_buffer.h:176
time.h
interruptible_sleep_interface.h
Object implementing an ok() method that can interrupt pending sleeps when it returns false.
cras::InterruptibleTFBuffer::InterruptibleTFBuffer
InterruptibleTFBuffer(const ::ros::Duration &cacheTime={::tf2::BufferCore::DEFAULT_CACHE_TIME, 0})
Create the buffer.
cras::InterruptibleTFBuffer::transform
B & transform(const A &in, B &out, const ::std::string &target_frame, const ::ros::Time &target_time, const ::std::string &fixed_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame and convert to a specified output type (advanced)....
Definition: interruptible_buffer.h:272
cras::InterruptibleTFBuffer::transform
T & transform(const T &in, T &out, const ::std::string &target_frame, const ::ros::Time &target_time, const ::std::string &fixed_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame (advanced). This function is templated and can take as input...
Definition: interruptible_buffer.h:221
buffer.h
cras::InterruptibleTFBuffer::lookupTransform
::geometry_msgs::TransformStamped lookupTransform(const ::std::string &target_frame, const ::std::string &source_frame, const ::ros::Time &time, const ::ros::Duration timeout) const override
semaphore.hpp
Implementation of a reversed semaphore usable for thread synchronization.
duration.h
cras::InterruptibleTFBuffer::callbackSemaphore
mutable ::cras::ReverseSemaphore callbackSemaphore
Reverse semaphore guarding that the object is not destroyed before all pending callbacks finish....
Definition: interruptible_buffer.h:389
cras::InterruptibleTFBuffer::allFramesAsYAML
::std::string allFramesAsYAML() const
Backwards compatibility for #84.
cras::InterruptibleSleepInterface
Interface to an object whose sleep() calls can be interrupted externally. Multiple sleep() calls can ...
Definition: interruptible_sleep_interface.h:26
tf2_ros::Buffer
buffer_core.h
cras::InterruptibleTFBuffer::setMinPollingDuration
bool setMinPollingDuration(const ::ros::Duration &duration)
Set minimum duration of a pause between two transform polls.
tf2::BufferCore
cras::InterruptibleTFBuffer::transform
B & transform(const A &in, B &out, const ::std::string &target_frame, ::ros::Duration timeout={0, 0}) const
Transform an input into the target frame and convert to a specified output type. It is templated on t...
Definition: interruptible_buffer.h:200
cras::InterruptibleTFBuffer::clear
void clear()
Clear all data.
cras::InterruptibleTFBuffer::~InterruptibleTFBuffer
~InterruptibleTFBuffer() override
Destroys the class. Waits until a running canTransform() call is finished.
tf2::BufferCore::DEFAULT_CACHE_TIME
static const int DEFAULT_CACHE_TIME
cras::InterruptibleTFBuffer::canTransform
bool canTransform(const ::std::string &target_frame, const ::std::string &source_frame, const ::ros::Time &time, ::ros::Duration timeout, ::std::string *errstr) const override
cras::InterruptibleTFBuffer::canTransformPollingScale
double canTransformPollingScale
canTransform() timeout is multiplied by this scale and polling for the transform is done in these tim...
Definition: interruptible_buffer.h:373
cras::InterruptibleTFBuffer::requestStop
virtual void requestStop()
Request all pending lookups to stop. After calling this, ok() should return false.
cras::InterruptibleTFBuffer::setCanTransformPollingScale
bool setCanTransformPollingScale(double scale)
Set the scale by which canTransform() timeout is multiplied to determine the transform polling rate.
cras::InterruptibleTFBuffer::allFramesAsString
::std::string allFramesAsString() const
A way to see what frames have been cached. Useful for debugging.
cras::InterruptibleTFBuffer::interruptibleParentBuffer
const ::std::shared_ptr<::cras::InterruptibleTFBuffer > interruptibleParentBuffer
If parentBuffer is set and it is an InterruptibleTFBuffer, its dynamic cast to this type is stored he...
Definition: interruptible_buffer.h:384
ros::Duration
cras::InterruptibleTFBuffer::parentBuffer
const ::std::shared_ptr<::tf2::BufferCore > parentBuffer
If not null, this class relays all lookups to parentBuffer.
Definition: interruptible_buffer.h:369
cras::InterruptibleTFBuffer::setTransform
bool setTransform(const ::geometry_msgs::TransformStamped &transform, const ::std::string &authority, bool is_static=false)
Add transform information to the tf data structure.
cras::InterruptibleTFBuffer::isOk
bool isOk
True until requestStop() is called.
Definition: interruptible_buffer.h:381


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Mon Jun 17 2024 02:48:56