adi_3dtof_adtf31xx_input_thread.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c), 2023 - Analog Devices Inc. All Rights Reserved.
3 This software is PROPRIETARY & CONFIDENTIAL to Analog Devices, Inc.
4 and its licensors.
5 ******************************************************************************/
6 #include "module_profile.h"
8 #include "adi_3dtof_adtf31xx.h"
9 #include <compressed_depth_image_transport/rvl_codec.h>
10 #include <boost/chrono.hpp>
11 #include <boost/thread/thread.hpp>
12 
18 {
20 }
21 
28 {
29  ADI3DToFADTF31xxFrameInfo* inframe = nullptr;
30  input_thread_mtx_.lock();
31  int queue_size = input_frames_queue_.size();
32  input_thread_mtx_.unlock();
33 
34  // We will try till we fill read the buffer, this is just to allow the read thread to fill the queue
35  while ((inframe == nullptr) && ((!error_in_frame_read_) || queue_size > 0))
36  {
37  input_thread_mtx_.lock();
38  queue_size = input_frames_queue_.size();
39  input_thread_mtx_.unlock();
40  if (queue_size > 0)
41  {
42  input_thread_mtx_.lock();
44  input_frames_queue_.pop();
45  input_thread_mtx_.unlock();
46  }
47  if (inframe == nullptr)
48  {
49  // Wait for the buffers to be filled
50  boost::this_thread::sleep_for(boost::chrono::milliseconds(2));
51  }
52  }
53  return inframe;
54 }
55 
64 {
66  {
67  // ROS_INFO("Read loop");
68 
69  // Create a new node
71  if (new_frame != nullptr)
72  {
73  PROFILE_FUNCTION_START(readInput_Thread)
74  bool result = input_sensor_->readNextFrame(new_frame->getDepthFrame(), new_frame->getABFrame(),
75  new_frame->getConfFrame(), new_frame->getXYZFrame());
77  PROFILE_FUNCTION_END(readInput_Thread)
78  if (!result)
79  {
80  // free memory
81  delete new_frame;
82  error_in_frame_read_ = true;
83  continue;
84  }
85  }
86  else
87  {
88  error_in_frame_read_ = true;
90  break;
91  }
92 
93  // Add it to the queue
94  input_thread_mtx_.lock();
95  int queue_size = input_frames_queue_.size();
96  input_thread_mtx_.unlock();
97  if (queue_size <= (max_input_queue_length_ - 1))
98  {
99  input_thread_mtx_.lock();
100  input_frames_queue_.push(new_frame);
101  input_thread_mtx_.unlock();
102  }
103  else
104  {
105  std::cout << "Overwrite buffer" << std::endl;
106  // If the Queue is full, then overwrite the last buffer with the latest frame
107  input_thread_mtx_.lock();
108  [[maybe_unused]] ADI3DToFADTF31xxFrameInfo* last_node = (ADI3DToFADTF31xxFrameInfo*)input_frames_queue_.back();
109  input_thread_mtx_.unlock();
110  last_node = new_frame;
111  delete new_frame;
112  }
113 
114  // sleep
115  boost::this_thread::sleep_for(boost::chrono::milliseconds(2));
116  }
117 
118  // Destroy the queue
119  input_thread_mtx_.lock();
120  int queue_size = input_frames_queue_.size();
121  while (queue_size > 0)
122  {
123  // pop and delete
125  input_frames_queue_.pop();
126  delete new_frame;
127  queue_size = input_frames_queue_.size();
128  }
129  input_thread_mtx_.unlock();
130 }
IInputSensor::getFrameTimestamp
virtual bool getFrameTimestamp(ros::Time *timestamp)=0
ADI3DToFADTF31xxFrameInfo::getDepthFrame
unsigned short * getDepthFrame() const
Get the depth image frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:88
ADI3DToFADTF31xx::readInputAbort
void readInputAbort()
Function to read Abort flag, this function will be called by the main function to exit the thread.
Definition: adi_3dtof_adtf31xx_input_thread.cpp:17
module_profile.h
ADI3DToFADTF31xxFrameInfo::getFrameTimestampPtr
ros::Time * getFrameTimestampPtr()
Get Frame Timestamp Pointer.
Definition: adi_3dtof_adtf31xx_frame_info.h:148
ADI3DToFADTF31xxFrameInfo
This is the class for adtf31xx sensor frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:16
ADI3DToFADTF31xx::image_width_
int image_width_
Definition: adi_3dtof_adtf31xx.h:242
ADI3DToFADTF31xx::read_input_thread_abort_
bool read_input_thread_abort_
Definition: adi_3dtof_adtf31xx.h:272
PROFILE_FUNCTION_END
#define PROFILE_FUNCTION_END(ID)
Definition: module_profile.h:25
ADI3DToFADTF31xx::error_in_frame_read_
bool error_in_frame_read_
Definition: adi_3dtof_adtf31xx.h:277
ADI3DToFADTF31xx::input_sensor_
IInputSensor * input_sensor_
Definition: adi_3dtof_adtf31xx.h:239
ADI3DToFADTF31xxFrameInfo::getXYZFrame
short * getXYZFrame() const
Get point cloud frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:108
ADI3DToFADTF31xx::input_thread_mtx_
boost::mutex input_thread_mtx_
Definition: adi_3dtof_adtf31xx.h:275
adi_3dtof_adtf31xx_frame_info.h
ADI3DToFADTF31xx::adtf31xxSensorGetNextFrame
ADI3DToFADTF31xxFrameInfo * adtf31xxSensorGetNextFrame()
Function to read the next frame from the input Queue.
Definition: adi_3dtof_adtf31xx_input_thread.cpp:27
ADI3DToFADTF31xx::input_frames_queue_
std::queue< ADI3DToFADTF31xxFrameInfo * > input_frames_queue_
Definition: adi_3dtof_adtf31xx.h:280
ADI3DToFADTF31xx::readInput
void readInput()
This function reads the frmae from the sensor. This runs in a loop, reading the frames and adding the...
Definition: adi_3dtof_adtf31xx_input_thread.cpp:63
IInputSensor::readNextFrame
virtual bool readNextFrame(unsigned short *depth_frame, unsigned short *ab_frame, unsigned short *conf_frame, short *xyz_frame)=0
PROFILE_FUNCTION_START
#define PROFILE_FUNCTION_START(ID)
Definition: module_profile.h:24
ADI3DToFADTF31xx::max_input_queue_length_
int max_input_queue_length_
Definition: adi_3dtof_adtf31xx.h:279
ADI3DToFADTF31xx::image_height_
int image_height_
Definition: adi_3dtof_adtf31xx.h:243
ADI3DToFADTF31xxFrameInfo::getConfFrame
unsigned short * getConfFrame() const
Get Confidence frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:118
adi_3dtof_adtf31xx.h
ADI3DToFADTF31xxFrameInfo::getABFrame
unsigned short * getABFrame() const
Get the AB image frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:98


adi_3dtof_adtf31xx
Author(s):
autogenerated on Sat May 17 2025 02:12:30