lidar_rs_helios.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "lidar_rs_helios.h"
  2. bool LidarMessageRsHelios::packet(void *data, int size) {
  3. unsigned char *cloud = (unsigned char *) data;
  4. // security checks
  5. if (cloud == nullptr || size < 0) {
  6. printf("---Debug error %s %d\n", __func__, __LINE__);
  7. return false;
  8. }
  9. // clear m_data_
  10. if (m_data_ != nullptr) {
  11. free(m_data_);
  12. m_data_ = nullptr;
  13. }
  14. // pack data
  15. bool ret = false;
  16. ret = packHelios16P(cloud, size);
  17. return true;
  18. }
  19. bool LidarMessageRsHelios::checkFrameHeader(unsigned char *data) {
  20. // header ID
  21. if (!(data[0] == 0X55 && data[1] == 0XAA && data[2] == 0X05 && data[3] == 0X5A)) {
  22. printf("---Debug error %s %d\n", __func__, __LINE__);
  23. printf("---Debug Head: %#X %#X %#X %#X \n", data[0], data[1], data[2], data[3]);
  24. return false;
  25. }
  26. // 协议版本号
  27. if (!(data[4] == 0X00 && data[5] == 0X01)) {
  28. printf("---Debug error %s %d\n", __func__, __LINE__);
  29. return false;
  30. }
  31. // Lidar Type && Lidar Model
  32. if (!(data[31] == 0X06 && data[32] > 0X00 && data[32] < 0X05)) {
  33. printf("---Debug error %s %d\n", __func__, __LINE__);
  34. return false;
  35. }
  36. // Tail
  37. if (!(data[1246] == 0X00 && data[1247] == 0XFF)) {
  38. printf("---Debug error %s %d\n", __func__, __LINE__);
  39. return false;
  40. }
  41. return true;
  42. }
  43. bool LidarMessageRsHelios::packHelios16P(unsigned char *data, int size) {
  44. m_length_ = size + ZX::PACKET_HEAD_SIZE + ZX::PACKET_END_SIZE;
  45. m_data_ = (unsigned char *) malloc(m_length_);
  46. memset(m_data_, 0, m_length_);
  47. packInfo(ZX::LIDAR_RS_HELIOS_16P, size / 7, 0X01);
  48. for (int i = 0; i < size; i++) {
  49. m_data_[ZX::PACKET_HEAD_SIZE + i] = data[i];
  50. }
  51. return true;
  52. }
  53. void LidarMessageRsHelios::parseDualDataBlock(unsigned char *data) {
  54. }
  55. void LidarMessageRsHelios::parseSingleDataBlock(unsigned char *data) {
  56. unsigned short distance, roll = 0, yaw = 0, yaw_delta = 0;
  57. int coor_data = 42, coor_m_data = ZX::PACKET_HEAD_SIZE;
  58. for (int i = 0; i < 11; i++) {
  59. unsigned int angle_a = (data[44 + 100 * i] << 8 | data[45 + 100 * i]);
  60. unsigned int angle_b = (data[144 + 100 * i] << 8 | data[145 + 100 * i]);
  61. // printf("---Debug %d %#X \n", i, angle_a);
  62. if (angle_b < angle_a) {
  63. angle_b += 36000;
  64. }
  65. yaw_delta += (angle_b - angle_a);
  66. }
  67. yaw_delta = yaw_delta / 22;
  68. for (int i = 0; i < 12; i++) {
  69. // get yaw
  70. yaw = data[coor_data + 2] << 8 | data[coor_data + 3];
  71. coor_data += 4;
  72. for (int j = 0; j < 32; j++) {
  73. // prase distance
  74. m_data_[coor_m_data + 0] = data[coor_data + 0];
  75. m_data_[coor_m_data + 1] = data[coor_data + 1];
  76. // prase roll
  77. m_data_[coor_m_data + 2] = roll_angle[j % 16] >> 8;
  78. m_data_[coor_m_data + 3] = roll_angle[j % 16];
  79. // prase yaw
  80. if (j > 15) {
  81. m_data_[coor_m_data + 4] = (yaw + yaw_delta) >> 8;
  82. m_data_[coor_m_data + 5] = (yaw + yaw_delta);
  83. } else {
  84. m_data_[coor_m_data + 4] = (yaw) >> 8;
  85. m_data_[coor_m_data + 5] = (yaw);
  86. }
  87. // prase i
  88. m_data_[coor_m_data + 6] = data[coor_data + 2];
  89. coor_m_data += 7;
  90. coor_data += 3;
  91. }
  92. }
  93. }