adi_3dtof_adtf31xx.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 "input_sensor.h"
7 #include "module_profile.h"
8 #include "input_sensor_factory.h"
10 #include "adi_3dtof_adtf31xx.h"
11 #include <ros/ros.h>
12 #include <sensor_msgs/Image.h>
13 #include <sensor_msgs/PointCloud2.h>
14 #include <cv_bridge/cv_bridge.h>
18 #include <compressed_depth_image_transport/rvl_codec.h>
19 #include <boost/thread/thread.hpp>
20 
22 
35 {
36  // setting AB threshold and confidence threshold values if they are changed.
37  if (ab_threshold_ != dynamic_reconfigure_config_.ab_threshold)
38  {
40  ROS_INFO("Changed AB threshold value is %d", ab_threshold_);
42  }
43 
44  if (confidence_threshold_ != dynamic_reconfigure_config_.confidence_threshold)
45  {
47  ROS_INFO("Changed Confidence threshold value is %d", confidence_threshold_);
49  }
50 
51  if (jblf_filter_state_ != dynamic_reconfigure_config_.jblf_filter_state)
52  {
54  ROS_INFO("Changed JBLF filter state is %d", jblf_filter_state_);
56  }
57 
58  if (jblf_filter_size_ != dynamic_reconfigure_config_.jblf_filter_size)
59  {
61  ROS_INFO("Changed JBLF filter size is %d", jblf_filter_size_);
63  }
64 
66  {
68  ROS_INFO("Changed Radial filter min threshold is %d", radial_filter_min_threshold_);
70  }
71 
73  {
75  ROS_INFO("Changed Radial filter max threshold is %d", radial_filter_max_threshold_);
77  }
78 }
79 
87 {
89 
91  try
92  {
93  inframe = adtf31xxSensorGetNextFrame();
94  }
95  catch (const std::exception& e)
96  {
97  std::cerr << "Error getting next frame" << e.what() << '\n';
98  return false;
99  }
100 
101  if (inframe == nullptr)
102  {
103  return false;
104  }
105 
107  if (new_output_frame == nullptr)
108  {
109  delete inframe;
110  return false;
111  }
112 
114  depth_frame_ = inframe->getDepthFrame();
115  ab_frame_ = inframe->getABFrame();
116  xyz_frame_ = inframe->getXYZFrame();
117  conf_frame_ = inframe->getConfFrame();
118 
119  if ((depth_frame_ == nullptr) || (ab_frame_ == nullptr) || (xyz_frame_ == nullptr) || (conf_frame_ == nullptr))
120  {
121  delete new_output_frame;
122  return false;
123  }
124  if (new_output_frame != nullptr)
125  {
126  PROFILE_FUNCTION_START(adtf31xx_readNextFrame)
128  {
129  // Compress depth and confidence frame. ab image compression is done in the output thread
130  PROFILE_FUNCTION_START(adtf31xx_depthFrameCompression)
132  new_output_frame->compressed_depth_frame_size_ = rvl.CompressRVL(
133  &depth_frame_[0], &new_output_frame->compressed_depth_frame_[0], image_width_ * image_height_);
134  new_output_frame->compressed_conf_frame_size_ =
135  rvl.CompressRVL(&conf_frame_[0], &new_output_frame->compressed_conf_frame_[0], image_width_ * image_height_);
136  PROFILE_FUNCTION_END(adtf31xx_depthFrameCompression)
137  }
138 
139  new_output_frame->frame_number_ = frame_number_;
140  memcpy(new_output_frame->depth_frame_, depth_frame_, image_width_ * image_height_ * sizeof(depth_frame_[0]));
141  memcpy(new_output_frame->ab_frame_, ab_frame_, image_width_ * image_height_ * sizeof(ab_frame_[0]));
142  memcpy(new_output_frame->conf_frame_, conf_frame_, image_width_ * image_height_ * sizeof(conf_frame_[0]));
143  memcpy(new_output_frame->xyz_frame_, xyz_frame_, 3 * image_width_ * image_height_ * sizeof(xyz_frame_[0]));
144 
145  // Push
146  adtf31xxSensorPushOutputNode(new_output_frame);
147  }
148 
149  delete inframe;
150 
151  frame_number_++;
152  PROFILE_FUNCTION_END(adtf31xx_readNextFrame)
153 
154  return true;
155 }
156 
164 void ADI3DToFADTF31xx::dynamicallyReconfigureVariables(adi_3dtof_adtf31xx::ADTF31xxSensorParamsConfig& config,
165  uint32_t /*level*/)
166 {
168 
169  ROS_INFO(
170  "Configuration variables: ab_threshold: %d, confidence_threshold: %d, jblf_filter_state: %d, jblf_filter_size: "
171  "%d, radial_filter_min_threshold: %d, radial_filter_max_threshold: %d",
174 }
175 
181 {
183  dynamic_reconfigure_config_.confidence_threshold = confidence_threshold_;
188 }
189 
197 int main(int argc, char** argv)
198 {
199  ros::init(argc, argv, "adi_3dtof_adtf31xx");
200 
202 
203  // Create an instance of ADI3DToFADTF31xx
204  ADI3DToFADTF31xx adi_3dtof_adtf31xx;
205 
206  // Spawn the read input thread..
207  boost::thread read_input_thread;
208  bool thread_spawn_status = true;
209  try
210  {
211  read_input_thread = boost::thread(&ADI3DToFADTF31xx::readInput, &adi_3dtof_adtf31xx);
212  }
213  catch (const std::exception& e)
214  {
215  thread_spawn_status = false;
216  std::cerr << "Exception when trying to spawn read_input_thread : " << e.what() << '\n';
217  }
218 
219  // Spawn the process output thread..
220  boost::thread process_output_thread;
221  try
222  {
223  process_output_thread = boost::thread(&ADI3DToFADTF31xx::processOutput, &adi_3dtof_adtf31xx);
224  }
225  catch (const std::exception& e)
226  {
227  thread_spawn_status = false;
228  std::cerr << "Exception when trying to spawn process_output_thread : " << e.what() << '\n';
229  }
230 
231  ros::Rate loop_rate(100);
232  int frame_num = 0;
233 
234  while ((ros::ok()) && (thread_spawn_status))
235  {
236  ROS_INFO_STREAM("Running loop : " << frame_num++);
237 
244  if (!adi_3dtof_adtf31xx.readNextFrame())
245  {
246  break;
247  }
248 
250 
251  loop_rate.sleep();
252 
253  ros::spinOnce();
254  }
255 
256  if (thread_spawn_status)
257  {
258  // Signal thread abort
259  adi_3dtof_adtf31xx.readInputAbort();
260  try
261  {
262  // Wait for the thread to complete
263  read_input_thread.join();
264  }
265  catch (const std::exception& e)
266  {
267  std::cerr << " Exception in read_input_thread.join() : " << e.what() << '\n';
268  }
269  // Signal thread abort
270  adi_3dtof_adtf31xx.processOutputAbort();
271  try
272  {
273  // Wait for the thread to complete
274  process_output_thread.join();
275  }
276  catch (const std::exception& e)
277  {
278  std::cerr << " Exception in process_output_thread.join() : " << e.what() << '\n';
279  }
280  }
281 
283 
284  adi_3dtof_adtf31xx.shutDownAllNodes();
285 
286  return 0;
287 }
ADI3DToFADTF31xxOutputInfo
This is the class for adtf31xx sensor node output information.
Definition: adi_3dtof_adtf31xx_output_info.h:14
sensor_msgs::image_encodings
point_cloud2_iterator.h
ADI3DToFADTF31xx::initSettingsForDynamicReconfigure
void initSettingsForDynamicReconfigure()
Dynamic reconfigure initialization.
Definition: adi_3dtof_adtf31xx.cpp:180
ADI3DToFADTF31xxOutputInfo::compressed_conf_frame_size_
int compressed_conf_frame_size_
Definition: adi_3dtof_adtf31xx_output_info.h:121
ADI3DToFADTF31xx::enable_depth_ab_compression_
bool enable_depth_ab_compression_
Definition: adi_3dtof_adtf31xx.h:245
ADI3DToFADTF31xxFrameInfo::getDepthFrame
unsigned short * getDepthFrame() const
Get the depth image frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:88
distortion_models.h
ADI3DToFADTF31xx::confidence_threshold_
int confidence_threshold_
Definition: adi_3dtof_adtf31xx.h:247
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
pinhole_camera_model.h
ADI3DToFADTF31xx::curr_frame_timestamp_
ros::Time curr_frame_timestamp_
Definition: adi_3dtof_adtf31xx.h:299
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
IInputSensor::setABinvalidationThreshold
virtual void setABinvalidationThreshold(int threshold)=0
module_profile.h
ros.h
compressed_depth_image_transport::RvlCodec::CompressRVL
int CompressRVL(const unsigned short *input, unsigned char *output, int numPixels)
Definition: rvl_codec.cpp:51
ADI3DToFADTF31xx::processOutput
void processOutput()
The output process function, this is running a loop which reads the frame from the putput queue,...
Definition: adi_3dtof_adtf31xx_output_thread.cpp:69
ros::spinOnce
ROSCPP_DECL void spinOnce()
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::radial_filter_max_threshold_
int radial_filter_max_threshold_
Definition: adi_3dtof_adtf31xx.h:251
ADI3DToFADTF31xxOutputInfo::compressed_depth_frame_size_
int compressed_depth_frame_size_
Definition: adi_3dtof_adtf31xx_output_info.h:119
IInputSensor::setRadialFilterMinThreshold
virtual void setRadialFilterMinThreshold(int radial_min_threshold)=0
PROFILE_FUNCTION_END
#define PROFILE_FUNCTION_END(ID)
Definition: module_profile.h:25
ros::ok
ROSCPP_DECL bool ok()
IInputSensor::setConfidenceThreshold
virtual void setConfidenceThreshold(int threshold)=0
ADI3DToFADTF31xx::jblf_filter_state_
bool jblf_filter_state_
Definition: adi_3dtof_adtf31xx.h:248
IInputSensor::setJBLFFilterSize
virtual void setJBLFFilterSize(int jblf_filter_size)=0
ADI3DToFADTF31xx::jblf_filter_size_
int jblf_filter_size_
Definition: adi_3dtof_adtf31xx.h:249
ADI3DToFADTF31xx::input_sensor_
IInputSensor * input_sensor_
Definition: adi_3dtof_adtf31xx.h:239
ADI3DToFADTF31xx::adtf31xxSensorPushOutputNode
void adtf31xxSensorPushOutputNode(ADI3DToFADTF31xxOutputInfo *new_output_node)
This function pushes the debug node to the output queue. If the queue is full, then the last item in ...
Definition: adi_3dtof_adtf31xx_output_thread.cpp:34
ADI3DToFADTF31xxFrameInfo::getXYZFrame
short * getXYZFrame() const
Get point cloud frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:108
input_sensor_factory.h
INIT_FUNCTION_PROFILE
#define INIT_FUNCTION_PROFILE()
Definition: module_profile.h:28
ADI3DToFADTF31xx::updateDynamicReconfigureVariablesInputThread
void updateDynamicReconfigureVariablesInputThread()
updates the parameter of input image based on dynamic reconfigure.
Definition: adi_3dtof_adtf31xx.cpp:34
ADI3DToFADTF31xx::conf_frame_
unsigned short * conf_frame_
Definition: adi_3dtof_adtf31xx.h:260
compressed_depth_image_transport::RvlCodec
Definition: rvl_codec.h:6
input_sensor.h
ADI3DToFADTF31xx::dynamicallyReconfigureVariables
void dynamicallyReconfigureVariables(adi_3dtof_adtf31xx::ADTF31xxSensorParamsConfig &config, uint32_t level)
new values from dynamic reconfigure are copied to a structure variable here, actual update to individ...
Definition: adi_3dtof_adtf31xx.cpp:164
ADI3DToFADTF31xx::dynamic_reconfigure_config_
adi_3dtof_adtf31xx::ADTF31xxSensorParamsConfig dynamic_reconfigure_config_
Definition: adi_3dtof_adtf31xx.h:289
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::frame_number_
int frame_number_
Definition: adi_3dtof_adtf31xx.h:244
ADI3DToFADTF31xx::processOutputAbort
void processOutputAbort()
This function sets the abort flag for the output thread, the function is normally called by the main ...
Definition: adi_3dtof_adtf31xx_output_thread.cpp:22
ADI3DToFADTF31xx::ab_threshold_
int ab_threshold_
Definition: adi_3dtof_adtf31xx.h:246
ADI3DToFADTF31xxFrameInfo::getFrameTimestamp
ros::Time getFrameTimestamp() const
Get Frame Timestamp.
Definition: adi_3dtof_adtf31xx_frame_info.h:158
main
int main(int argc, char **argv)
This is main function.
Definition: adi_3dtof_adtf31xx.cpp:197
ADI3DToFADTF31xx::readNextFrame
bool readNextFrame()
This function is the entry point to the sensor node.
Definition: adi_3dtof_adtf31xx.cpp:86
ADI3DToFADTF31xxOutputInfo::ab_frame_
unsigned short * ab_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:114
ADI3DToFADTF31xx::radial_filter_min_threshold_
int radial_filter_min_threshold_
Definition: adi_3dtof_adtf31xx.h:250
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
FLUSH_FUNCTION_PROFILE
#define FLUSH_FUNCTION_PROFILE()
Definition: module_profile.h:27
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
ros::Rate::sleep
bool sleep()
CLOSE_FUNCTION_PROFILE
#define CLOSE_FUNCTION_PROFILE()
Definition: module_profile.h:29
PROFILE_FUNCTION_START
#define PROFILE_FUNCTION_START(ID)
Definition: module_profile.h:24
ADI3DToFADTF31xx::shutDownAllNodes
void shutDownAllNodes()
This function shuts down all the nodes running in a roscore.
Definition: adi_3dtof_adtf31xx.h:205
ADI3DToFADTF31xxOutputInfo::depth_frame_
unsigned short * depth_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:113
ADI3DToFADTF31xx::image_height_
int image_height_
Definition: adi_3dtof_adtf31xx.h:243
ADI3DToFADTF31xxOutputInfo::conf_frame_
unsigned short * conf_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:115
ADI3DToFADTF31xx
This is main class for this package.
Definition: adi_3dtof_adtf31xx.h:33
cv_bridge.h
ros::Rate
ADI3DToFADTF31xxOutputInfo::xyz_frame_
short * xyz_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:122
ADI3DToFADTF31xxFrameInfo::getConfFrame
unsigned short * getConfFrame() const
Get Confidence frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:118
ADI3DToFADTF31xx::ab_frame_
unsigned short * ab_frame_
Definition: adi_3dtof_adtf31xx.h:258
IInputSensor::setRadialFilterMaxThreshold
virtual void setRadialFilterMaxThreshold(int radial_max_threshold)=0
ADI3DToFADTF31xx::depth_frame_
unsigned short * depth_frame_
Definition: adi_3dtof_adtf31xx.h:257
ADI3DToFADTF31xxOutputInfo::compressed_depth_frame_
unsigned char * compressed_depth_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:116
IInputSensor::setJBLFFilterState
virtual void setJBLFFilterState(bool jblf_filter_state)=0
adi_3dtof_adtf31xx.h
ADI3DToFADTF31xx::xyz_frame_
short * xyz_frame_
Definition: adi_3dtof_adtf31xx.h:259
ROS_INFO
#define ROS_INFO(...)
ADI3DToFADTF31xxFrameInfo::getABFrame
unsigned short * getABFrame() const
Get the AB image frame.
Definition: adi_3dtof_adtf31xx_frame_info.h:98
ADI3DToFADTF31xxOutputInfo::frame_number_
int frame_number_
Definition: adi_3dtof_adtf31xx_output_info.h:112
ADI3DToFADTF31xxOutputInfo::compressed_conf_frame_
unsigned char * compressed_conf_frame_
Definition: adi_3dtof_adtf31xx_output_info.h:118


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