decoder_rsbp_test.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include <gtest/gtest.h>
  2. #include <rs_driver/driver/decoder/decoder_RSBP.hpp>
  3. #include <rs_driver/msg/point_cloud_msg.hpp>
  4. #include <rs_driver/utility/dbg.hpp>
  5. using namespace robosense::lidar;
  6. typedef PointXYZIRT PointT;
  7. typedef PointCloudT<PointT> PointCloud;
  8. static ErrCode errCode = ERRCODE_SUCCESS;
  9. static void errCallback(const Error& err)
  10. {
  11. errCode = err.error_code;
  12. }
  13. TEST(TestDecoderRSBP, getEchoMode)
  14. {
  15. ASSERT_TRUE(DecoderRSBP<PointCloud>::getEchoMode(0) == RSEchoMode::ECHO_DUAL);
  16. ASSERT_TRUE(DecoderRSBP<PointCloud>::getEchoMode(1) == RSEchoMode::ECHO_SINGLE);
  17. ASSERT_TRUE(DecoderRSBP<PointCloud>::getEchoMode(2) == RSEchoMode::ECHO_SINGLE);
  18. }
  19. TEST(TestDecoderRSBP, decodeDifopPkt)
  20. {
  21. // const_param
  22. RSDecoderParam param;
  23. DecoderRSBP<PointCloud> decoder(param);
  24. decoder.regCallback(errCallback, nullptr);
  25. ASSERT_EQ(decoder.blks_per_frame_, 1801);
  26. ASSERT_EQ(decoder.split_blks_per_frame_, 1801);
  27. // rpm = 600, dual return
  28. RSBPDifopPkt pkt;
  29. pkt.rpm = htons(600);
  30. pkt.return_mode = 0;
  31. decoder.decodeDifopPkt((uint8_t*)&pkt, sizeof(pkt));
  32. ASSERT_EQ(decoder.rps_, 10);
  33. ASSERT_EQ(decoder.echo_mode_, RSEchoMode::ECHO_DUAL);
  34. ASSERT_EQ(decoder.blks_per_frame_, 1801);
  35. ASSERT_EQ(decoder.split_blks_per_frame_, 3602);
  36. // rpm = 1200, single return
  37. pkt.rpm = htons(1200);
  38. pkt.return_mode = 1;
  39. decoder.decodeDifopPkt((uint8_t*)&pkt, sizeof(pkt));
  40. ASSERT_EQ(decoder.rps_, 20);
  41. ASSERT_EQ(decoder.echo_mode_, RSEchoMode::ECHO_SINGLE);
  42. ASSERT_EQ(decoder.blks_per_frame_, 900);
  43. ASSERT_EQ(decoder.split_blks_per_frame_, 900);
  44. }
  45. static void splitFrame(uint16_t height, double ts)
  46. {
  47. }
  48. TEST(TestDecoderRSBP, decodeMsopPkt)
  49. {
  50. uint8_t pkt[] =
  51. {
  52. //
  53. // header
  54. //
  55. 0x55, 0xAA, 0x05, 0x0A, 0x5A, 0xA5, 0x50, 0xA0, // msop id
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved_1
  57. 0x15, 0x0a, 0x01, 0x01, 0x02, 0x03, 0x11, 0x22, 0x33, 0x44, // ts_YMD
  58. 0x00, // lidar type
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved_2
  60. 0x18, 0x01, // temprature
  61. 0x00, 0x00, // reserved_3
  62. //
  63. // block_01
  64. //
  65. 0xFF, 0xEE, // block id
  66. 0x00, 0x00, // azimuth
  67. 0x03, 0xE8, // chan_00, distance
  68. 0x01, // chan_00, intensity
  69. 0x00, 0x00, // chan_01, distance
  70. 0x00, // chan_01, intensity
  71. 0x00, 0x00, // chan_02, distance
  72. 0x00, // chan_02, intensity
  73. 0x00, 0x00, // chan_03, distance
  74. 0x00, // chan_03, intensity
  75. 0x00, 0x00, // chan_04, distance
  76. 0x00, // chan_04, intensity
  77. 0x00, 0x00, // chan_05, distance
  78. 0x00, // chan_05, intensity
  79. 0x00, 0x00, // chan_06, distance
  80. 0x00, // chan_06, intensity
  81. 0x00, 0x00, // chan_07, distance
  82. 0x00, // chan_07, intensity
  83. 0x00, 0x00, // chan_08, distance
  84. 0x00, // chan_08, intensity
  85. 0x00, 0x00, // chan_09, distance
  86. 0x00, // chan_09, intensity
  87. 0x00, 0x00, // chan_10, distance
  88. 0x00, // chan_10, intensity
  89. 0x00, 0x00, // chan_11, distance
  90. 0x00, // chan_11, intensity
  91. 0x00, 0x00, // chan_12, distance
  92. 0x00, // chan_12, intensity
  93. 0x00, 0x00, // chan_13, distance
  94. 0x00, // chan_13, intensity
  95. 0x00, 0x00, // chan_14, distance
  96. 0x00, // chan_14, intensity
  97. 0x00, 0x00, // chan_15, distance
  98. 0x00, // chan_15, intensity
  99. 0x00, 0x00, // chan_16, distance
  100. 0x00, // chan_16, intensity
  101. 0x00, 0x00, // chan_17, distance
  102. 0x00, // chan_17, intensity
  103. 0x00, 0x00, // chan_18, distance
  104. 0x00, // chan_18, intensity
  105. 0x00, 0x00, // chan_19, distance
  106. 0x00, // chan_19, intensity
  107. 0x00, 0x00, // chan_20, distance
  108. 0x00, // chan_20, intensity
  109. 0x00, 0x00, // chan_21, distance
  110. 0x00, // chan_21, intensity
  111. 0x00, 0x00, // chan_22, distance
  112. 0x00, // chan_22, intensity
  113. 0x00, 0x00, // chan_23, distance
  114. 0x00, // chan_23, intensity
  115. 0x00, 0x00, // chan_24, distance
  116. 0x00, // chan_24, intensity
  117. 0x00, 0x00, // chan_25, distance
  118. 0x00, // chan_25, intensity
  119. 0x00, 0x00, // chan_26, distance
  120. 0x00, // chan_26, intensity
  121. 0x00, 0x00, // chan_27, distance
  122. 0x00, // chan_27, intensity
  123. 0x00, 0x00, // chan_28, distance
  124. 0x00, // chan_28, intensity
  125. 0x00, 0x00, // chan_29, distance
  126. 0x00, // chan_29, intensity
  127. 0x00, 0x00, // chan_30, distance
  128. 0x00, // chan_30, intensity
  129. 0x00, 0x00, // chan_31, distance
  130. 0x00, // chan_31, intensity
  131. //
  132. // block_02
  133. //
  134. 0x00, 0x00, // block id
  135. };
  136. // dense_points = false, use_lidar_clock = true
  137. RSDecoderParam param;
  138. DecoderRSBP<PointCloud> decoder(param);
  139. decoder.regCallback(errCallback, splitFrame);
  140. ASSERT_EQ(decoder.chan_angles_.user_chans_.size(), 32);
  141. decoder.chan_angles_.user_chans_[0] = 2;
  142. decoder.chan_angles_.user_chans_[1] = 1;
  143. decoder.param_.dense_points = false;
  144. decoder.param_.use_lidar_clock = true;
  145. decoder.point_cloud_ = std::make_shared<PointCloud>();
  146. decoder.decodeMsopPkt(pkt, sizeof(pkt));
  147. ASSERT_EQ(decoder.getTemperature(), 2.1875);
  148. ASSERT_EQ(decoder.point_cloud_->points.size(), 32);
  149. PointT& point = decoder.point_cloud_->points[0];
  150. ASSERT_EQ(point.intensity, 1);
  151. ASSERT_NE(point.timestamp, 0);
  152. ASSERT_EQ(point.ring, 2);
  153. }