decoder_rs32_test.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include <gtest/gtest.h>
  2. #include <rs_driver/driver/decoder/decoder_RS32.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(TestDecoderRS32, getEchoMode)
  14. {
  15. ASSERT_TRUE(DecoderRS32<PointCloud>::getEchoMode(0) == RSEchoMode::ECHO_DUAL);
  16. ASSERT_TRUE(DecoderRS32<PointCloud>::getEchoMode(1) == RSEchoMode::ECHO_SINGLE);
  17. ASSERT_TRUE(DecoderRS32<PointCloud>::getEchoMode(2) == RSEchoMode::ECHO_SINGLE);
  18. }
  19. TEST(TestDecoderRS32, RS32DifopPkt2Adapter)
  20. {
  21. RSCalibrationAngle v_angle_cali[32] =
  22. {
  23. 0x01, htons(0x2829), // -10.281
  24. 0x00, htons(0x091d) // 2.333
  25. };
  26. RSCalibrationAngle h_angle_cali[32] =
  27. {
  28. 0x00, htons(0x01f4), // 0.5
  29. 0x01, htons(0x01c2) // -0.45
  30. };
  31. RS32DifopPkt src;
  32. src.rpm = 0;
  33. src.fov = {0};
  34. src.return_mode = 0;
  35. memcpy (src.vert_angle_cali, v_angle_cali, 32*sizeof(RSCalibrationAngle));
  36. memcpy (src.horiz_angle_cali, h_angle_cali, 32*sizeof(RSCalibrationAngle));
  37. AdapterDifopPkt dst;
  38. RS32DifopPkt2Adapter(src, dst);
  39. ASSERT_EQ(dst.vert_angle_cali[0].sign, 1);
  40. ASSERT_EQ(ntohs(dst.vert_angle_cali[0].value), 1028);
  41. ASSERT_EQ(dst.vert_angle_cali[1].sign, 0);
  42. ASSERT_EQ(ntohs(dst.vert_angle_cali[1].value), 233);
  43. ASSERT_EQ(dst.horiz_angle_cali[0].sign, 0);
  44. ASSERT_EQ(ntohs(dst.horiz_angle_cali[0].value), 50);
  45. ASSERT_EQ(dst.horiz_angle_cali[1].sign, 1);
  46. ASSERT_EQ(ntohs(dst.horiz_angle_cali[1].value), 45);
  47. }
  48. TEST(TestDecoderRS32, decodeDifopPkt)
  49. {
  50. // const_param
  51. RSDecoderParam param;
  52. DecoderRS32<PointCloud> decoder(param);
  53. decoder.regCallback(errCallback, nullptr);
  54. ASSERT_EQ(decoder.blks_per_frame_, 1801);
  55. ASSERT_EQ(decoder.split_blks_per_frame_, 1801);
  56. // rpm = 600, dual return
  57. RS32DifopPkt pkt;
  58. pkt.rpm = htons(600);
  59. pkt.return_mode = 0;
  60. decoder.decodeDifopPkt((uint8_t*)&pkt, sizeof(pkt));
  61. ASSERT_EQ(decoder.rps_, 10);
  62. ASSERT_EQ(decoder.echo_mode_, RSEchoMode::ECHO_DUAL);
  63. ASSERT_EQ(decoder.blks_per_frame_, 1801);
  64. ASSERT_EQ(decoder.split_blks_per_frame_, 3602);
  65. // rpm = 1200, single return
  66. pkt.rpm = htons(1200);
  67. pkt.return_mode = 1;
  68. decoder.decodeDifopPkt((uint8_t*)&pkt, sizeof(pkt));
  69. ASSERT_EQ(decoder.rps_, 20);
  70. ASSERT_EQ(decoder.echo_mode_, RSEchoMode::ECHO_SINGLE);
  71. ASSERT_EQ(decoder.blks_per_frame_, 900);
  72. ASSERT_EQ(decoder.split_blks_per_frame_, 900);
  73. }
  74. static void splitFrame(uint16_t height, double ts)
  75. {
  76. }
  77. TEST(TestDecoderRS32, decodeMsopPkt)
  78. {
  79. uint8_t pkt[] =
  80. {
  81. //
  82. // header
  83. //
  84. 0x55, 0xAA, 0x05, 0x0A, 0x5A, 0xA5, 0x50, 0xA0, // msop id
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved_1
  86. 0x15, 0x0a, 0x01, 0x01, 0x02, 0x03, 0x11, 0x22, 0x33, 0x44, // ts_YMD
  87. 0x00, // lidar type
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved_2
  89. 0x18, 0x01, // temprature
  90. 0x00, 0x00, // reserved_3
  91. //
  92. // block_01
  93. //
  94. 0xFF, 0xEE, // block id
  95. 0x00, 0x00, // azimuth
  96. 0x03, 0xE8, // chan_00, distance
  97. 0x01, // chan_00, intensity
  98. 0x00, 0x00, // chan_01, distance
  99. 0x00, // chan_01, intensity
  100. 0x00, 0x00, // chan_02, distance
  101. 0x00, // chan_02, intensity
  102. 0x00, 0x00, // chan_03, distance
  103. 0x00, // chan_03, intensity
  104. 0x00, 0x00, // chan_04, distance
  105. 0x00, // chan_04, intensity
  106. 0x00, 0x00, // chan_05, distance
  107. 0x00, // chan_05, intensity
  108. 0x00, 0x00, // chan_06, distance
  109. 0x00, // chan_06, intensity
  110. 0x00, 0x00, // chan_07, distance
  111. 0x00, // chan_07, intensity
  112. 0x00, 0x00, // chan_08, distance
  113. 0x00, // chan_08, intensity
  114. 0x00, 0x00, // chan_09, distance
  115. 0x00, // chan_09, intensity
  116. 0x00, 0x00, // chan_10, distance
  117. 0x00, // chan_10, intensity
  118. 0x00, 0x00, // chan_11, distance
  119. 0x00, // chan_11, intensity
  120. 0x00, 0x00, // chan_12, distance
  121. 0x00, // chan_12, intensity
  122. 0x00, 0x00, // chan_13, distance
  123. 0x00, // chan_13, intensity
  124. 0x00, 0x00, // chan_14, distance
  125. 0x00, // chan_14, intensity
  126. 0x00, 0x00, // chan_15, distance
  127. 0x00, // chan_15, intensity
  128. 0x00, 0x00, // chan_16, distance
  129. 0x00, // chan_16, intensity
  130. 0x00, 0x00, // chan_17, distance
  131. 0x00, // chan_17, intensity
  132. 0x00, 0x00, // chan_18, distance
  133. 0x00, // chan_18, intensity
  134. 0x00, 0x00, // chan_19, distance
  135. 0x00, // chan_19, intensity
  136. 0x00, 0x00, // chan_20, distance
  137. 0x00, // chan_20, intensity
  138. 0x00, 0x00, // chan_21, distance
  139. 0x00, // chan_21, intensity
  140. 0x00, 0x00, // chan_22, distance
  141. 0x00, // chan_22, intensity
  142. 0x00, 0x00, // chan_23, distance
  143. 0x00, // chan_23, intensity
  144. 0x00, 0x00, // chan_24, distance
  145. 0x00, // chan_24, intensity
  146. 0x00, 0x00, // chan_25, distance
  147. 0x00, // chan_25, intensity
  148. 0x00, 0x00, // chan_26, distance
  149. 0x00, // chan_26, intensity
  150. 0x00, 0x00, // chan_27, distance
  151. 0x00, // chan_27, intensity
  152. 0x00, 0x00, // chan_28, distance
  153. 0x00, // chan_28, intensity
  154. 0x00, 0x00, // chan_29, distance
  155. 0x00, // chan_29, intensity
  156. 0x00, 0x00, // chan_30, distance
  157. 0x00, // chan_30, intensity
  158. 0x00, 0x00, // chan_31, distance
  159. 0x00, // chan_31, intensity
  160. //
  161. // block_02
  162. //
  163. 0x00, 0x00, // block id
  164. };
  165. // dense_points = false, use_lidar_clock = true
  166. RSDecoderParam param;
  167. DecoderRS32<PointCloud> decoder(param);
  168. decoder.regCallback(errCallback, splitFrame);
  169. ASSERT_EQ(decoder.chan_angles_.user_chans_.size(), 32);
  170. decoder.chan_angles_.user_chans_[0] = 2;
  171. decoder.chan_angles_.user_chans_[1] = 1;
  172. decoder.param_.dense_points = false;
  173. decoder.param_.use_lidar_clock = true;
  174. decoder.point_cloud_ = std::make_shared<PointCloud>();
  175. decoder.decodeMsopPkt(pkt, sizeof(pkt));
  176. ASSERT_EQ(decoder.getTemperature(), 2.1875);
  177. ASSERT_EQ(decoder.point_cloud_->points.size(), 32);
  178. PointT& point = decoder.point_cloud_->points[0];
  179. ASSERT_EQ(point.intensity, 1);
  180. ASSERT_NE(point.timestamp, 0);
  181. ASSERT_EQ(point.ring, 2);
  182. }