LivoxHorizon.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "LivoxHorizon.h"
  2. RegisterLaser(Horizon)
  3. CHorizonLaser::CHorizonLaser(int id, Laser_proto::laser_parameter laser_param)
  4. :CLivoxLaser(id, laser_param)
  5. {
  6. //设备livox扫描最大帧数
  7. m_frame_maxnum = laser_param.frame_num();
  8. //判断参数类型,
  9. if(laser_param.type()=="Horizon")
  10. {
  11. //填充雷达设备的广播码
  12. g_sn_laser.insert(std::make_pair(laser_param.sn(), this));
  13. //初始化livox
  14. InitLivox();
  15. }
  16. }
  17. CHorizonLaser::~CHorizonLaser()
  18. {
  19. }
  20. //雷达的启动接口函数, 让雷达进行扫描,一般需要子类重载,不同的雷达开始方式不同。
  21. Error_manager CHorizonLaser::start_scan()
  22. {
  23. //LOG(INFO) << " Horizon start :"<<this;
  24. return CLivoxLaser::start_scan();
  25. }
  26. //将二进制消息转化为三维点云的功能函数,每次只转化一个CBinaryData,
  27. // 纯虚函数,必须由子类重载,
  28. Buf_type CHorizonLaser::transform_buf_to_points(Binary_buf* p_binary_buf, std::vector<CPoint3D>& point3D_cloud)
  29. {
  30. static int count=0;
  31. if ( p_binary_buf ==NULL )
  32. {
  33. return BUF_UNKNOW;
  34. }
  35. else
  36. {
  37. //livox的二进制数据格式就是三维点坐标。直接强行转化指针类型即可
  38. LivoxExtendRawPoint *tp_Livox_data = (LivoxExtendRawPoint *)p_binary_buf->get_buf();
  39. //计算这一帧数据有多少个三维点。
  40. int t_count = p_binary_buf->get_length() / (sizeof(LivoxExtendRawPoint));
  41. if (t_count <= 0)
  42. {
  43. return BUF_UNKNOW;
  44. }
  45. else
  46. {
  47. //转变三维点格式,并存入vector。
  48. for (int i = 0; i < t_count; ++i)
  49. {
  50. //LivoxExtendRawPoint 转为 CPoint3D
  51. //int32_t 转 double。不要信号强度
  52. LivoxExtendRawPoint t_livox_point = tp_Livox_data[i];
  53. CPoint3D t_point3D;
  54. t_point3D.x = t_livox_point.x/1000.0;
  55. t_point3D.y = t_livox_point.y/1000.0;
  56. t_point3D.z = t_livox_point.z/1000.0;
  57. point3D_cloud.push_back(t_point3D);
  58. // std::cout << "huli points:" << t_point3D.x << " : " << t_point3D.y << " : " << t_point3D.z<< std::endl;
  59. }
  60. return BUF_DATA;
  61. }
  62. }
  63. }