rgbd_image_buffer
image_buffer.h
Go to the documentation of this file.
1 #ifndef RGBD_IMAGE_BUFFER_IMAGE_BUFFER_H_
2 #define RGBD_IMAGE_BUFFER_IMAGE_BUFFER_H_
3 
4 #include <ros/callback_queue.h>
5 
6 #include <geolib/datatypes.h>
7 
8 #include <rgbd/types.h>
9 
10 #include <tf2_ros/buffer.h>
11 
12 #include <forward_list>
13 #include <memory>
14 #include <mutex>
15 #include <thread>
16 
17 namespace tf2_ros
18 {
19 class TransformListener;
20 }
21 
22 namespace rgbd
23 {
24 class Client;
25 
32 {
33 
34 public:
35 
36  ImageBuffer();
37 
38  ~ImageBuffer();
39 
46  void initialize(const std::string& topic, const std::string& root_frame="map", const float worker_thread_frequency=20);
47 
54  bool nextImage(rgbd::ImageConstPtr& image, geo::Pose3D& sensor_pose);
55 
65  bool waitForRecentImage(rgbd::ImageConstPtr& image, geo::Pose3D& sensor_pose, double timeout_sec, double check_rate);
66 
76  bool waitForRecentImage(rgbd::ImageConstPtr& image, geo::Pose3D& sensor_pose, double timeout_sec, uint timeout_tries = 25u);
77 
78 private:
79 
81 
83 
84  tf2_ros::Buffer tf_buffer_;
86 
91 
92  ros::CallbackQueue cb_queue_;
93 
100  bool shutdown_; // Trigger to kill the worker thread
101 
107  bool getMostRecentImageTF();
108 
113  void workerThreadFunc(const float frequency=20);
114 
115 };
116 
117 } // namespace rgbd
118 
119 #endif // RGBD_IMAGE_BUFFER_IMAGE_BUFFER_H_
datatypes.h
rgbd::ImageBuffer::image_buffer_
std::forward_list< rgbd::ImageConstPtr > image_buffer_
Newer images should be pushed on the front. This will result in the front being the most recent and t...
Definition: image_buffer.h:90
rgbd::ImageBuffer::recent_image_mutex_
std::mutex recent_image_mutex_
For protecting ImageBuffer::recent_image_.
Definition: image_buffer.h:98
rgbd::ImageBuffer::cb_queue_
ros::CallbackQueue cb_queue_
Definition: image_buffer.h:92
std::string
std::shared_ptr
std::pair
rgbd::ImageBuffer::root_frame_
std::string root_frame_
Definition: image_buffer.h:80
geo::Transform3T
rgbd::ImageBuffer::shutdown_
bool shutdown_
Definition: image_buffer.h:100
rgbd::ImageBuffer::recent_image_
std::pair< rgbd::ImageConstPtr, geo::Pose3D > recent_image_
Definition: image_buffer.h:94
rgbd::ImageBuffer::tf_buffer_
tf2_ros::Buffer tf_buffer_
Definition: image_buffer.h:84
rgbd::ImageBuffer
The ImageBuffer class provides a buffer to synchronise rgbd images with sensor positions....
Definition: image_buffer.h:31
rgbd::ImageBuffer::getMostRecentImageTF
bool getMostRecentImageTF()
Iterates over the buffer and tries to get TF for the most recent image. Deletes image and all older i...
Definition: image_buffer.cpp:157
forward_list
rgbd::ImageBuffer::tf_listener_
std::unique_ptr< tf2_ros::TransformListener > tf_listener_
Definition: image_buffer.h:85
thread
tf2_ros
Definition: image_buffer.h:17
rgbd
rgbd::ImageBuffer::workerThreadFunc
void workerThreadFunc(const float frequency=20)
Calls ImageBuffer::getMostRecentImageTF on the specified frequency.
Definition: image_buffer.cpp:250
rgbd::ImageBuffer::rgbd_client_
std::unique_ptr< rgbd::Client > rgbd_client_
Definition: image_buffer.h:82
rgbd::ImageBuffer::ImageBuffer
ImageBuffer()
Definition: image_buffer.cpp:20
memory
rgbd::ImageBuffer::nextImage
bool nextImage(rgbd::ImageConstPtr &image, geo::Pose3D &sensor_pose)
Returns the most recent combination of image and transform, provided it is different from the previou...
Definition: image_buffer.cpp:138
rgbd::ImageBuffer::~ImageBuffer
~ImageBuffer()
Definition: image_buffer.cpp:26
rgbd::ImageBuffer::waitForRecentImage
bool waitForRecentImage(rgbd::ImageConstPtr &image, geo::Pose3D &sensor_pose, double timeout_sec, double check_rate)
Blocks until a new image with transform is found. Returns false if no image or TF could be found with...
Definition: image_buffer.cpp:52
rgbd::ImageBuffer::initialize
void initialize(const std::string &topic, const std::string &root_frame="map", const float worker_thread_frequency=20)
Configure the buffer.
Definition: image_buffer.cpp:35
mutex
types.h
std::unique_ptr< rgbd::Client >
rgbd::ImageBuffer::worker_thread_ptr_
std::unique_ptr< std::thread > worker_thread_ptr_
Definition: image_buffer.h:99