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 }
bool setMinPollingDuration(const ::ros::Duration &duration)
Set minimum duration of a pause between two transform polls.
void clear()
Clear all data.
double canTransformPollingScale
canTransform() timeout is multiplied by this scale and polling for the transform is done in these tim...
Provides overrides of canTransform() that can be interrupted. Normally, canTransform() waits until tr...
mutable ::cras::ReverseSemaphore callbackSemaphore
Reverse semaphore guarding that the object is not destroyed before all pending callbacks finish...
bool setCanTransformPollingScale(double scale)
Set the scale by which canTransform() timeout is multiplied to determine the transform polling rate...
const ::std::shared_ptr<::tf2::BufferCore > parentBuffer
If not null, this class relays all lookups to parentBuffer.
bool isOk
True until requestStop() is called.
Implementation of a reversed semaphore usable for thread synchronization.
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). It is templated on two types: the type of the input object and the type of the transformed output. For example, the template type could be a Transform, Pose, Vector, or Quaternion message type (as defined in geometry_msgs). The function will calculate the transformation and then convert the result into the specified output type. Compilation will fail if a known conversion does not exist bewteen the two template parameters. This function follows the advanced API, which allows transforming between different time points, and specifying a fixed frame that does not varying in time.
::ros::Duration getCacheLength()
Get the duration over which this transformer will cache.
::geometry_msgs::TransformStamped lookupTransform(const ::std::string &target_frame, const ::std::string &source_frame, const ::ros::Time &time, const ::ros::Duration timeout) const override
::std::string allFramesAsString() const
A way to see what frames have been cached. Useful for debugging.
bool ok() const override
Whether it is OK to continue. If false, all pending lookups should stop as soon as possible...
~InterruptibleTFBuffer() override
Destroys the class. Waits until a running canTransform() call is finished.
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...
Object implementing an ok() method that can interrupt pending sleeps when it returns false...
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...
bool canTransform(const ::std::string &target_frame, const ::std::string &source_frame, const ::ros::Time &time, ::ros::Duration timeout, ::std::string *errstr) const override
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 ...
static const int DEFAULT_CACHE_TIME
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 ...
::tf2::BufferCore & getRawBuffer()
Get the raw tf2::BufferCore that actually stores the transforms.
InterruptibleTFBuffer(const ::ros::Duration &cacheTime={::tf2::BufferCore::DEFAULT_CACHE_TIME, 0})
Create the buffer.
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: any.hpp:15
::std::string allFramesAsYAML() const
Backwards compatibility for #84.
virtual void requestStop()
Request all pending lookups to stop. After calling this, ok() should return false.
bool setTransform(const ::geometry_msgs::TransformStamped &transform, const ::std::string &authority, bool is_static=false)
Add transform information to the tf data structure.
Interface to an object whose sleep() calls can be interrupted externally. Multiple sleep() calls can ...
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...
::ros::Duration minPollingDuration
Minimum duration of a pause between two transform polls. If timeout * canTransformPollingScale would ...


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53