hlds_3dtof_node.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (c) 2018, Hitachi-LG Data Storage, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31  /* Authors: Jeehoon Yang, Wayne Rust */
32  /* maintainer: Jeehoon Yang */
33 
34 #include <ros/ros.h>
36 #include <sensor_msgs/CameraInfo.h>
37 #include <pcl_ros/point_cloud.h>
38 #include "hldstof/tof.h"
39 #include <std_srvs/Empty.h>
40 #include <std_srvs/SetBool.h>
41 #include "hls_lfom_tof_driver/FarSignalCutoff.h"
42 #include "hls_lfom_tof_driver/LowSignalCutoff.h"
43 #include "hls_lfom_tof_driver/DistanceMode.h"
44 
45 using namespace std;
46 using namespace hlds;
47 
50 bool bFarSignalCutoff = false;
51 bool bEdgeSignalCutoff = false;
52 bool bLowSignalCutoff = false;
53 bool bDistanceMode = false;
56 string bDistanceMode_value = "";
57 
58 bool set_far_signal_cutoff(hls_lfom_tof_driver::FarSignalCutoff::Request &req, hls_lfom_tof_driver::FarSignalCutoff::Response &res)
59 {
60  bFarSignalCutoff = true;
61  bFarSignalCutoff_value = req.value;
62  res.result = true;
63 }
64 
65 bool set_low_signal_cutoff(hls_lfom_tof_driver::LowSignalCutoff::Request &req, hls_lfom_tof_driver::LowSignalCutoff::Response &res)
66 {
67  bLowSignalCutoff = true;
68  bLowSignalCutoff_value = req.value;
69  res.result = true;
70 }
71 
72 bool set_edge_signal_cutoff(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
73 {
74  if(req.data == true)
75  {
77  res.success = true;
78  res.message = "Set Edge Signal Cutoff Enable";
79  }
80  if(req.data == false)
81  {
83  res.success = false;
84  res.message = "Set Edge Signal Cutoff Disable";
85  }
86 }
87 
88 bool set_distance_mode(hls_lfom_tof_driver::DistanceMode::Request &req, hls_lfom_tof_driver::DistanceMode::Response &res)
89 {
90  bDistanceMode = true;
91  bDistanceMode_value = req.value;
92  res.result = true;
93 }
94 
95 int main(int argc, char* argv[])
96 {
97  // Initialize ROS
98  ros::init (argc, argv, "hlds_3dtof");
99  std::string frame_id;
100  ros::NodeHandle nh;
101  sensor_msgs::PointCloud2 cloud;
102  sensor_msgs::CameraInfoPtr msgCameraInfo;
103  sensor_msgs::ImagePtr msgDepth;
104  sensor_msgs::ImagePtr msgDepthRaw;
105  sensor_msgs::ImagePtr msgIr;
106  std::string file_name;
107  std::string cloud_topic;
108  ros::Publisher camerainfoPublisher;
109  ros::Publisher cloudPublisher;
110  ros::Publisher depthPublisher;
111  ros::Publisher depthrawPublisher;
112  ros::Publisher irPublisher;
113 
114  ros::ServiceServer set_far_signal_cutoff_service = nh.advertiseService("set_far_signal_cutoff_srv", set_far_signal_cutoff);
115  ros::ServiceServer set_low_signal_cutoff_service = nh.advertiseService("set_low_signal_cutoff_srv", set_low_signal_cutoff);
116  ros::ServiceServer set_edge_signal_cutoff_service = nh.advertiseService("set_edge_signal_cutoff_srv", set_edge_signal_cutoff);
117  ros::ServiceServer set_distance_mode_service = nh.advertiseService("set_distance_mode_srv", set_distance_mode);
118 
119  // Initialize HLDS 3D TOF
120  Result ret = Result::OK;
121  int numoftof = 0;
122  TofManager tm;
123  const TofInfo* ptofinfo = nullptr;
124  FrameDepth frame; //Create instances for reading frames
125  Frame3d frame3d; //Create instances for 3D data after conversion
126  FrameIr frameir; //Create instances for reading IR frames
127 
128  // Open TOF Manager (Read tof.ini file)
129  nh.getParam("ini_path", tm.inifilepath);
130  if ((ret = tm.Open()) != Result::OK) {
131  ROS_ERROR_STREAM("HLDS 3D TOF initialization file \"" << tm.inifilepath <<"tof.ini\" invalid.");
132  return -1;
133  }
134 
135  // Get number of TOF sensor and TOF information list
136  numoftof = tm.GetTofList(&ptofinfo);
137 
138  if (numoftof == 0) {
139  ROS_ERROR_STREAM("No HLDS 3D TOF sensors found.");
140  return -1;
141  }
142 
143  // Create Tof instances for TOF sensors
144  Tof tof;
145 
146  // Open all Tof instances (Set TOF information)
147  string vfpga = "";
148  string vosv = "";
149  string vroot = "";
150  if (tof.Open(ptofinfo[0]) != Result::OK){
151  ROS_ERROR_STREAM("Error connecting to HLDS 3D TOF sensor.");
152  return -1;
153  }
154 
155  if (tof.GetVersion(&vfpga, &vosv, &vroot) == Result::OK) {
156  ROS_INFO_STREAM("HLDS 3D TOF version" << ":" << vfpga.c_str() << ":" << vosv.c_str() << ":" << vroot.c_str() );
157  }
158 
159  if (tof.tofinfo.tofver == TofVersion::TOFv1) {
160  ROS_INFO_STREAM("TOFv1 sensor");
161  } else if(tof.tofinfo.tofver == TofVersion::TOFv2) {
162  ROS_INFO_STREAM("TOFv2 sensor");
163  } else {
164  ROS_INFO_STREAM("Unknown sensor");
165  }
166 
167  // Once Tof instances are started, TofManager is not necessary and closed
168  if (tm.Close() != Result::OK){
169  ROS_ERROR_STREAM("Error closing HLDS 3D TOF manager.");
170  return -1;
171  }
172 
173  //Set TOF sensor parameters
174  bool edge_signal_cutoff;
175  int location_x, location_y, location_z;
176  int angle_x, angle_y, angle_z;
177  int low_signal_cutoff, ir_gain;
178  int pixel_count;
179  double far_signal_cutoff;
180  float temp_depth;
181  std::string camera_pixel, distance_mode, frame_rate, camera_mode;
182 
183  nh.param("frame_id", frame_id, std::string("base_link"));
184  nh.param("cloud_topic", cloud_topic, std::string("cloud"));
185 
186  nh.param("camera_mode", camera_mode, std::string("Depth_Ir"));
187  nh.param("sensor_location_x", location_x, 0);
188  nh.param("sensor_location_y", location_y, 0);
189  nh.param("sensor_location_z", location_z, 0);
190  nh.param("sensor_angle_x", angle_x, 0);
191  nh.param("sensor_angle_y", angle_y, 0);
192  nh.param("sensor_angle_z", angle_z, 0);
193 
194  nh.param("edge_signal_cutoff", edge_signal_cutoff, true);
195  nh.param("low_signal_cutoff", low_signal_cutoff, 20);
196  nh.param("far_signal_cutoff", far_signal_cutoff, 0.0);
197 
198  nh.param("camera_pixel", camera_pixel, std::string("320x240"));
199  nh.param("ir_gain", ir_gain, 8);
200  nh.param("distance_mode", distance_mode, std::string("dm_1_0x"));
201  nh.param("frame_rate", frame_rate, std::string("fr30fps"));
202 
203  //Set camera mode
204  if(camera_mode == "Depth_Ir") {
205  if (tof.SetCameraMode(CameraMode::Depth_Ir) != Result::OK){
206  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Mode Error");
207  return -1;
208  }
209  }
210  else if(camera_mode == "CameraModeDepth") {
211  if (tof.SetCameraMode(CameraMode::CameraModeDepth) != Result::OK){
212  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Mode Error");
213  return -1;
214  }
215  }
216  else if(camera_mode == "CameraModeIr") {
217  if (tof.SetCameraMode(CameraMode::CameraModeIr) != Result::OK){
218  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Mode Error");
219  return -1;
220  }
221  }
222 
223  //Set camera pixel
224  if(camera_pixel == "640x480") {
225  if (tof.SetCameraPixel(CameraPixel::w640h480) != Result::OK){
226  // if (tof.SetCameraPixel(CameraPixel::w160h120) != Result::OK){
227  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
228  return -1;
229  }
230  }
231  else if(camera_pixel == "320x240") {
232  if (tof.SetCameraPixel(CameraPixel::w320h240) != Result::OK){
233  // if (tof.SetCameraPixel(CameraPixel::w160h120) != Result::OK){
234  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
235  return -1;
236  }
237  }
238  else if(camera_pixel == "160x120") {
239  if (tof.SetCameraPixel(CameraPixel::w160h120) != Result::OK){
240  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
241  return -1;
242  }
243  }
244  else if(camera_pixel == "80x60") {
245  if (tof.SetCameraPixel(CameraPixel::w80h60) != Result::OK){
246  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
247  return -1;
248  }
249  }
250  else if(camera_pixel == "64x48") {
251  if (tof.SetCameraPixel(CameraPixel::w64h48) != Result::OK){
252  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
253  return -1;
254  }
255  }
256  else if(camera_pixel == "40x30") {
257  if (tof.SetCameraPixel(CameraPixel::w40h30) != Result::OK){
258  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
259  return -1;
260  }
261  }
262  else if(camera_pixel == "32x24") {
263  if (tof.SetCameraPixel(CameraPixel::w32h24) != Result::OK){
264  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Pixel Error");
265  return -1;
266  }
267  }
268 
269  //Set distance mode
270  if(distance_mode == "dm_2_0x") {
271  if (tof.SetDistanceMode(DistanceMode::dm_2_0x) != Result::OK){
272  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set distance mode Error");
273  return -1;
274  }
275  }
276  else if(distance_mode == "dm_1_5x") {
277  if (tof.SetDistanceMode(DistanceMode::dm_1_5x) != Result::OK){
278  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set distance mode Error");
279  return -1;
280  }
281  }
282  else if(distance_mode == "dm_1_0x") {
283  if (tof.SetDistanceMode(DistanceMode::dm_1_0x) != Result::OK){
284  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set distance mode Error");
285  return -1;
286  }
287  }
288  else if(distance_mode == "dm_0_5x") {
289  if (tof.SetDistanceMode(DistanceMode::dm_0_5x) != Result::OK){
290  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set distance mode Error");
291  return -1;
292  }
293  }
294 
295  //Set frame rate
296  if(frame_rate == "fr30fps") {
297  if (tof.SetFrameRate(FrameRate::fr30fps) != Result::OK){
298  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
299  return -1;
300  }
301  }
302  else if(frame_rate == "fr16fps") {
303  if (tof.SetFrameRate(FrameRate::fr16fps) != Result::OK){
304  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
305  return -1;
306  }
307  }
308  else if(frame_rate == "fr8fps") {
309  if (tof.SetFrameRate(FrameRate::fr8fps) != Result::OK){
310  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
311  return -1;
312  }
313  }
314  else if(frame_rate == "fr4fps") {
315  if (tof.SetFrameRate(FrameRate::fr4fps) != Result::OK){
316  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
317  return -1;
318  }
319  }
320  else if(frame_rate == "fr2fps") {
321  if (tof.SetFrameRate(FrameRate::fr2fps) != Result::OK){
322  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
323  return -1;
324  }
325  }
326  else if(frame_rate == "fr1fps") {
327  if (tof.SetFrameRate(FrameRate::fr1fps) != Result::OK){
328  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set frame rate Error");
329  return -1;
330  }
331  }
332 
333  //Set IR gain
334  if (tof.SetIrGain(ir_gain) != Result::OK){
335  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Ir gain Error");
336  return -1;
337  }
338 
339  //Low signal cutoff
340  if (tof.SetLowSignalCutoff(low_signal_cutoff) != Result::OK){
341  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Low Signal Cutoff Error");
342  return -1;
343  }
344 
345  //Far signal cutoff
346  if (tof.SetFarSignalCutoff(far_signal_cutoff) != Result::OK){
347  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Far Signal Cutoff Error");
348  return -1;
349  }
350 
351  //Edge noise reduction
352  if(edge_signal_cutoff == true){
353  if (tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Enable) != Result::OK){
354  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Edge Signal Cutoff Error");
355  return -1;
356  }
357  }
358  else if(edge_signal_cutoff == false){
359  if (tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Disable) != Result::OK){
360  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Edge Signal Cutoff Error");
361  return -1;
362  }
363  }
364 
365  //Set physical installation position
366  if (tof.SetAttribute(location_x, location_y, location_z, angle_x, angle_y, angle_z) != Result::OK){
367  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Set Camera Position Error");
368  return -1;
369  }
370 
371  //Start
372  if (tof.Run() != Result::OK){
373  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Run Error");
374  return -1;
375  }
376 
377  //Create color table
378  frame.CreateColorTable(0, 65530);
379 
380  // Initialize the ROS publisher
381  camerainfoPublisher = nh.advertise<sensor_msgs::CameraInfo> ("/camera_info", 1);
382  if(camera_mode != "CameraModeIr") {
383  cloudPublisher = nh.advertise<pcl::PointCloud<pcl::PointXYZ> > (cloud_topic, 1);
384  }
385  if((camera_mode == "Depth_Ir")||(camera_mode == "CameraModeIr")) {
386  irPublisher = nh.advertise<sensor_msgs::Image> ("/image_ir", 1);
387  }
388  if(camera_mode != "CameraModeIr") {
389  depthPublisher = nh.advertise<sensor_msgs::Image> ("/image_depth", 1);
390  depthrawPublisher = nh.advertise<sensor_msgs::Image> ("/image_depth_raw", 1);
391  }
392  ROS_INFO_STREAM("Publishing data on topic \"" << nh.resolveName(cloud_topic) << "\" with frame_id \"" << frame_id << "\"");
393 
394  ros::Rate r(40);
395  ros::Time t;
396 
397  //while (nh.ok ())
398  while (ros::ok())
399  {
400  ros::spinOnce();
401 
402  if(bFarSignalCutoff == true)
403  {
404  if(tof.SetFarSignalCutoff(bFarSignalCutoff_value) == Result::OK)
405  ROS_INFO("Far Signal Cutoff : %f", bFarSignalCutoff_value);
406  bFarSignalCutoff = false;
407  }
408 
409  if(bLowSignalCutoff == true)
410  {
411  if(tof.SetLowSignalCutoff(bLowSignalCutoff_value) == Result::OK)
412  ROS_INFO("Low Signal Cutoff : %d", bLowSignalCutoff_value);
413  bLowSignalCutoff = false;
414  }
415 
416  if(bEdgeSignalCutoff_disable == true)
417  {
418  if(tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Disable) == Result::OK)
419  ROS_INFO("Edge Signal Cutoff disabled");
421  }
422 
423  if(bEdgeSignalCutoff_enable == true)
424  {
425  if(tof.SetEdgeSignalCutoff(EdgeSignalCutoff::Enable) == Result::OK)
426  ROS_INFO("Edge Signal Cutoff enabled");
427  bEdgeSignalCutoff_enable = false;
428  }
429 
430  if(bDistanceMode == true)
431  {
432  if(bDistanceMode_value == "dm_2_0x") {
433  if(tof.SetDistanceMode(DistanceMode::dm_2_0x) == Result::OK)
434  ROS_INFO("Distance Mode : dm_2_0x");
435  }
436  if(bDistanceMode_value == "dm_1_5x") {
437  if(tof.SetDistanceMode(DistanceMode::dm_1_5x) == Result::OK)
438  ROS_INFO("Distance Mode : dm_1_5x");
439  }
440  if(bDistanceMode_value == "dm_1_0x") {
441  if(tof.SetDistanceMode(DistanceMode::dm_1_0x) == Result::OK)
442  ROS_INFO("Distance Mode : dm_1_0x");
443  }
444  if(bDistanceMode_value == "dm_0_5x") {
445  if(tof.SetDistanceMode(DistanceMode::dm_0_5x) == Result::OK)
446  ROS_INFO("Distance Mode : dm_0_5x");
447  }
448  bDistanceMode = false;
449  }
450 
451  //Get the latest frame number
452  long frameno;
453  TimeStamp timestamp;
454  tof.GetFrameStatus(&frameno, &timestamp);
455  if (frameno != frame.framenumber) {
456  //Read a new frame only if frame number is changed(Old data is shown if it is not changed.)
457 
458  //Read a frame of depth data
459  ret = Result::OK;
460  if(camera_mode == "Depth_Ir") {
461  ret = tof.ReadFrame(&frame, &frameir);
462  }
463  else if(camera_mode == "CameraModeDepth") {
464  ret = tof.ReadFrame(&frame);
465  }
466  else if(camera_mode == "CameraModeIr") {
467  ret = tof.ReadFrame(&frameir);
468  }
469  if (ret != Result::OK) {
470  ROS_INFO_STREAM("HLDS 3D TOF read frame error");
471  break;
472  }
473  if(camera_mode != "CameraModeIr") {
474  //3D conversion(with lens correction)
475  frame3d.Convert(&frame);
476 
477  //3D rotation(to top view)
478  frame3d.Rotate(angle_x, angle_y, angle_z);
479  }
480 
481  t=ros::Time::now();
482 
483  // Create CameraIno
484  msgCameraInfo = sensor_msgs::CameraInfoPtr(new sensor_msgs::CameraInfo);
485  msgCameraInfo->header.frame_id = frame_id;
486  msgCameraInfo->header.stamp = t;
487  msgCameraInfo->height = frame.height;
488  msgCameraInfo->width = frame.width;
489  msgCameraInfo->K[0] = frame.height;
490  msgCameraInfo->K[1] = 0;
491  msgCameraInfo->K[2] = (frame.width/2)-0.5;
492  msgCameraInfo->K[3] = 0;
493  msgCameraInfo->K[4] = frame.height;
494  msgCameraInfo->K[5] = (frame.width*(3./8.))-0.5;
495  msgCameraInfo->K[6] = 0;
496  msgCameraInfo->K[7] = 0;
497  msgCameraInfo->K[8] = 1;
498  msgCameraInfo->R[0] = 1;
499  msgCameraInfo->R[1] = 0;
500  msgCameraInfo->R[2] = 0;
501  msgCameraInfo->R[3] = 0;
502  msgCameraInfo->R[4] = 1;
503  msgCameraInfo->R[5] = 0;
504  msgCameraInfo->R[6] = 0;
505  msgCameraInfo->R[7] = 0;
506  msgCameraInfo->R[8] = 1;
507  msgCameraInfo->P[0] = frame.height;
508  msgCameraInfo->P[1] = 0;
509  msgCameraInfo->P[2] = (frame.width/2)-0.5;
510  msgCameraInfo->P[3] = 0;
511  msgCameraInfo->P[4] = 0;
512  msgCameraInfo->P[5] = frame.height;
513  msgCameraInfo->P[6] = (frame.width*(3./8.))-0.5;
514  msgCameraInfo->P[7] = 0;
515  msgCameraInfo->P[8] = 0;
516  msgCameraInfo->P[9] = 0;
517  msgCameraInfo->P[10] = 1;
518  msgCameraInfo->P[11] = 0;
519  msgCameraInfo->distortion_model = "plumb_bob";
520  msgCameraInfo->D.resize(5);
521  msgCameraInfo->D[0] = 0;
522  msgCameraInfo->D[1] = 0;
523  msgCameraInfo->D[2] = 0;
524  msgCameraInfo->D[3] = 0;
525  msgCameraInfo->D[4] = 0;
526 
527 
528  // Create the IR image
529  msgIr = sensor_msgs::ImagePtr(new sensor_msgs::Image);
530  msgIr->header.stamp = t;
531  msgIr->header.frame_id = frame_id;
532  msgIr->height = frameir.height;
533  msgIr->width = frameir.width;
534  msgIr->is_bigendian = false;
535  msgIr->encoding = sensor_msgs::image_encodings::MONO8;
536  msgIr->data.resize(frameir.pixel);
537  msgIr->step = frameir.width;
538 
539  // Create the Depth image
540  msgDepth = sensor_msgs::ImagePtr(new sensor_msgs::Image);
541  msgDepth->header.stamp = t;
542  msgDepth->header.frame_id = frame_id;
543  msgDepth->height = frame.height;
544  msgDepth->width = frame.width;
545  msgDepth->is_bigendian = false;
546  msgDepth->encoding = sensor_msgs::image_encodings::RGB8;
547  msgDepth->data.resize(frame.pixel*3);
548  msgDepth->step = frame.width*3;
549 
550  // Create the Depth Raw image
551  msgDepthRaw = sensor_msgs::ImagePtr(new sensor_msgs::Image);
552  msgDepthRaw->header.stamp = t;
553  msgDepthRaw->header.frame_id = frame_id;
554  msgDepthRaw->height = frame.height;
555  msgDepthRaw->width = frame.width;
556  msgDepthRaw->is_bigendian = false;
557  msgDepthRaw->encoding = sensor_msgs::image_encodings::TYPE_32FC1;
558  msgDepthRaw->step = (uint32_t)(sizeof(float) * frame.width);
559  msgDepthRaw->data.resize(sizeof(float)*frame.pixel);
560 
561  // Create the point cloud
562  pcl::PointCloud<pcl::PointXYZ>::Ptr ptCloud(new pcl::PointCloud<pcl::PointXYZ>());
563  ptCloud->header.stamp = pcl_conversions::toPCL(t);
564  ptCloud->header.frame_id = frame_id;
565  ptCloud->width = frame3d.width;
566  ptCloud->height = frame3d.height;
567  ptCloud->is_dense = false;
568  ptCloud->points.resize(sizeof(uint16_t)*frame3d.pixel);
569 
570  float *itD = (float *)&msgDepthRaw->data[0];
571 
572  if(camera_mode != "CameraModeIr"){
573  pixel_count = frame.pixel;
574  } else {
575  pixel_count = frameir.pixel;
576  }
577  for (int i = 0; i < pixel_count; i++, ++itD) {
578  pcl::PointXYZ &point = ptCloud->points[i];
579 
580  temp_depth = (float)(frame.CalculateLength(frame.databuf[i]));
581  if(frame3d.frame3d[i].z == 0) frame3d.frame3d[i].z = std::numeric_limits<float>::quiet_NaN();
582  //Get coordinates after 3D conversion
583  point.x = frame3d.frame3d[i].x/1000.0;
584  point.y = frame3d.frame3d[i].y/1000.0;
585  point.z = frame3d.frame3d[i].z/1000.0;
586 
587  //Get IR frame data
588  msgIr->data[i] = frameir.databuf[i]/256.0;
589 
590  //Get Depth frame data
591  msgDepth->data[3*i] = frame.ColorTable[2][frame.databuf[i]]; //Red
592  msgDepth->data[3*i+1] = frame.ColorTable[1][frame.databuf[i]]; //Green
593  msgDepth->data[3*i+2] = frame.ColorTable[0][frame.databuf[i]]; //Blue
594 
595  //Get Depth Raw frame data
596  *itD = (float)point.z;
597  }
598 
599  // Publish topic
600  camerainfoPublisher.publish(msgCameraInfo);
601  if(camera_mode != "CameraModeIr") {
602  cloudPublisher.publish(*ptCloud);
603  depthPublisher.publish(msgDepth);
604  depthrawPublisher.publish(msgDepthRaw);
605  }
606  if((camera_mode == "Depth_Ir")||(camera_mode == "CameraModeIr")) {
607  irPublisher.publish(msgIr);
608  }
609  }
610  r.sleep();
611  }
612 
613  // Shutdown the sensor
614  if (tof.Stop() != Result::OK || tof.Close() != Result::OK) {
615  ROS_INFO_STREAM("HLDS 3D TOF ID " << tof.tofinfo.tofid << " Stop Error");
616  }
617 
618  return 0;
619 }
bool set_low_signal_cutoff(hls_lfom_tof_driver::LowSignalCutoff::Request &req, hls_lfom_tof_driver::LowSignalCutoff::Response &res)
bool bEdgeSignalCutoff
bool bLowSignalCutoff
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char *argv[])
bool set_edge_signal_cutoff(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
std::string resolveName(const std::string &name, bool remap=true) const
bool bDistanceMode
bool bEdgeSignalCutoff_enable
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool set_distance_mode(hls_lfom_tof_driver::DistanceMode::Request &req, hls_lfom_tof_driver::DistanceMode::Response &res)
int bLowSignalCutoff_value
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
const std::string TYPE_32FC1
bool bFarSignalCutoff
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_INFO_STREAM(args)
string bDistanceMode_value
bool getParam(const std::string &key, std::string &s) const
static Time now()
double bFarSignalCutoff_value
bool set_far_signal_cutoff(hls_lfom_tof_driver::FarSignalCutoff::Request &req, hls_lfom_tof_driver::FarSignalCutoff::Response &res)
#define ROS_ERROR_STREAM(args)
bool bEdgeSignalCutoff_disable
ROSCPP_DECL void spinOnce()
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)


hls-lfom-tof-driver
Author(s): Jeehoon Yang , Wayne Rust
autogenerated on Mon Jun 10 2019 13:33:49