decoder_rs16_test.cpp 6.0 KB

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