ivdriver_lidar_rs16.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "ivdriver_lidar_rs16.h"
  2. namespace iv {
  3. ivdriver_lidar_rs16::ivdriver_lidar_rs16()
  4. {
  5. }
  6. int ivdriver_lidar_rs16::processudpData(QByteArray ba, pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud)
  7. {
  8. static double fAngle_Total = 0;
  9. static double fAngle_Last = 0;
  10. int nrtn = 0;
  11. float Ang = 0;
  12. float Range = 0;
  13. int Group = 0;
  14. int pointi = 0;
  15. float wt = 0;
  16. int wt1 = 0;
  17. float V_theta[16] = {-15,-13,-11,-9,-7,-5,-3,-1,15,13,11,9,7,5,3,1};
  18. char * pstr = ba.data();
  19. if(ba.size()<1206)
  20. {
  21. std::cout<<"packet size is small. size is "<<ba.size()<<std::endl;
  22. return -1;
  23. }
  24. wt1 = ((pstr[2 + Group * 100] *256) + pstr[ 3 + Group * 100]) ;
  25. wt = wt1/ 100.0;
  26. double fAngX = wt;
  27. if(fabs(fAngX-fAngle_Last)>300)
  28. {
  29. fAngle_Total = fAngle_Total + fabs(fabs(fAngX-fAngle_Last)-360);
  30. }
  31. else
  32. {
  33. fAngle_Total = fAngle_Total + fabs(fabs(fAngX-fAngle_Last));
  34. }
  35. fAngle_Last = fAngX;
  36. if(fAngle_Total > 360)
  37. {
  38. nrtn = 1;
  39. fAngle_Total = 0;
  40. }
  41. for (Group = 0; Group <= 11; Group++)
  42. {
  43. wt1 = ((pstr[2 + Group * 100] *256) + pstr[ 3 + Group * 100]) ;
  44. wt = wt1/ 100.0;
  45. for (pointi = 0; pointi <16; pointi++)
  46. {
  47. // Ang = (0 - wt - w * T[pointi] - H_BETA[pointi]+213) / 180.0 * Lidar_Pi;
  48. Ang = (0 - wt) / 180.0 * M_PI;
  49. Range = ((pstr[ Group * 100 + 4 + 3 * pointi] << 8) + pstr[Group * 100 + 5 + 3 * pointi]);
  50. unsigned char intensity = pstr[ Group * 100 + 6 + 3 * pointi];
  51. Range=Range* 5.0/1000.0;
  52. if(Range<150)
  53. {
  54. pcl::PointXYZI point;
  55. point.x = Range*cos(V_theta[pointi] / 180 * M_PI)*cos(Ang + mfrollang);
  56. point.y = Range*cos(V_theta[pointi] / 180 * M_PI)*sin(Ang + mfrollang);
  57. point.z = Range*sin(V_theta[pointi] / 180 * M_PI);
  58. if(mbinclix)
  59. {
  60. double y,z;
  61. y = point.y;
  62. z = point.z;
  63. point.y = y*mcos_finclinationang_xaxis +z*msin_finclinationang_xaxis;
  64. point.z = z*mcos_finclinationang_xaxis - y*msin_finclinationang_xaxis;
  65. }
  66. if(mbincliy)
  67. {
  68. double z,x;
  69. z = point.z;
  70. x = point.x;
  71. point.z = z*mcos_finclinationang_yaxis + x*msin_finclinationang_yaxis;
  72. point.x = x*mcos_finclinationang_yaxis - z*msin_finclinationang_yaxis;
  73. }
  74. point.intensity = intensity;
  75. point_cloud->points.push_back(point);
  76. ++point_cloud->width;
  77. }
  78. }
  79. wt = wt + 0.18;
  80. for (pointi = 0; pointi < 16; pointi++)
  81. {
  82. Ang = (0 - wt) / 180.0 * M_PI;
  83. // Ang = Ang+angdiff;
  84. Range = ((pstr[ Group * 100 + 52 + 3 * pointi] << 8) + pstr[Group * 100 + 53 + 3 * pointi]);
  85. unsigned char intensity = pstr[ Group * 100 + 54 + 3 * pointi];
  86. Range=Range* 5.0/1000.0;
  87. if(Range<150)
  88. {
  89. pcl::PointXYZI point;
  90. point.x = Range*cos(V_theta[pointi] / 180 * M_PI)*cos(Ang + mfrollang);
  91. point.y = Range*cos(V_theta[pointi] / 180 * M_PI)*sin(Ang + mfrollang);
  92. point.z = Range*sin(V_theta[pointi] / 180 * M_PI);
  93. if(mbinclix)
  94. {
  95. double y,z;
  96. y = point.y;z = point.z;
  97. point.y = y*mcos_finclinationang_xaxis +z*msin_finclinationang_xaxis;
  98. point.z = z*mcos_finclinationang_xaxis - y*msin_finclinationang_xaxis;
  99. }
  100. if(mbincliy)
  101. {
  102. double z,x;
  103. z = point.z;x = point.x;
  104. point.z = z*mcos_finclinationang_yaxis + x*msin_finclinationang_yaxis;
  105. point.x = x*mcos_finclinationang_yaxis - z*msin_finclinationang_yaxis;
  106. }
  107. point.intensity = intensity;
  108. point_cloud->points.push_back(point);
  109. ++point_cloud->width;
  110. }
  111. }
  112. }
  113. return nrtn;
  114. }
  115. }