ivdriver_lidar_rs32.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "ivdriver_lidar_rs32.h"
  2. namespace iv {
  3. ivdriver_lidar_rs32::ivdriver_lidar_rs32()
  4. {
  5. }
  6. int ivdriver_lidar_rs32::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 w = 0.0036;
  12. float Ang = 0;
  13. float Range = 0;
  14. int Group = 0;
  15. int pointi = 0;
  16. float wt = 0;
  17. int wt1 = 0;
  18. // int dx;
  19. // int dy;
  20. // float lidar_32_xdistance = 0.3; //32线激光雷达X轴补偿
  21. // float lidar_32_ydistance = -2.3; //32线激光雷达Y轴补偿
  22. float H_BETA[32] = {
  23. -8,-8,-8,-8,-8,-2.672,2.672,8,
  24. -8,-2.672,2.672,8,-8,-2.672,2.672,8,
  25. 8,8,8,-8,8,-8,8,-8,
  26. -8,-2.672,2.672,8,-8,-2.672,2.672,8
  27. };
  28. // float V_theta[16] = {-15,-13,-11,-9,-7,-5,-3,-1,15,13,11,9,7,5,3,1};
  29. float V_theta[32] = {-25,-14.638,-7.91,-5.407,-3.667,-4,-4.333,-4.667,-2.333,-2.667,-3,-3.333,-1,-1.333,-1.667,-2,
  30. -10.281,-6.424,2.333,3.333,4.667,7,10.333,15,0.333,0,-0.333,-0.667,1.667,1.333,1.0,0.667};
  31. if(ba.size()<1206)
  32. {
  33. std::cout<<"packet size is small. size is "<<ba.size()<<std::endl;
  34. return -1;
  35. }
  36. char * pstr = (char * )ba.data();
  37. wt1 = ((pstr[2 + Group * 100] *256) + pstr[ 3 + Group * 100]) ;
  38. wt = wt1/ 100.0;
  39. double fAngX = wt;
  40. if(fabs(fAngX-fAngle_Last)>300)
  41. {
  42. fAngle_Total = fAngle_Total + fabs(fabs(fAngX-fAngle_Last)-360);
  43. }
  44. else
  45. {
  46. fAngle_Total = fAngle_Total + fabs(fabs(fAngX-fAngle_Last));
  47. }
  48. fAngle_Last = fAngX;
  49. if(fAngle_Total > 360)
  50. {
  51. nrtn = 1;
  52. fAngle_Total = 0;
  53. }
  54. for (Group = 0; Group <= 11; Group++)
  55. {
  56. wt1 = ((pstr[2 + Group * 100] *256) + pstr[ 3 + Group * 100]) ;
  57. wt = wt1/ 100.0;
  58. for (pointi = 0; pointi <32; pointi++)
  59. {
  60. // Ang = (0 - wt - w * T[pointi] - H_BETA[pointi]+213) / 180.0 * Lidar_Pi;
  61. Ang = (0 - wt-H_BETA[pointi]) / 180.0 * M_PI;
  62. Range = ((pstr[ Group * 100 + 4 + 3 * pointi] << 8) + pstr[Group * 100 + 5 + 3 * pointi]);
  63. unsigned char intensity = pstr[ Group * 100 + 6 + 3 * pointi];
  64. Range=Range* 5.0/1000.0;
  65. if(Range<150)
  66. {
  67. pcl::PointXYZI point;
  68. point.x = Range*cos(V_theta[pointi] / 180 * M_PI)*cos(Ang + mfrollang);
  69. point.y = Range*cos(V_theta[pointi] / 180 * M_PI)*sin(Ang + mfrollang);
  70. point.z = Range*sin(V_theta[pointi] / 180 * M_PI);
  71. if(mbinclix)
  72. {
  73. double y,z;
  74. y = point.y;
  75. z = point.z;
  76. point.y = y*mcos_finclinationang_xaxis +z*msin_finclinationang_xaxis;
  77. point.z = z*mcos_finclinationang_xaxis - y*msin_finclinationang_xaxis;
  78. }
  79. if(mbincliy)
  80. {
  81. double z,x;
  82. z = point.z;
  83. x = point.x;
  84. point.z = z*mcos_finclinationang_yaxis + x*msin_finclinationang_yaxis;
  85. point.x = x*mcos_finclinationang_yaxis - z*msin_finclinationang_yaxis;
  86. }
  87. point.intensity = intensity;
  88. point_cloud->points.push_back(point);
  89. ++point_cloud->width;
  90. }
  91. }
  92. }
  93. return nrtn;
  94. }
  95. }