localization.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __LOCALIZATION_H__
  2. #define __LOCALIZATION_H__
  3. #include <iostream>
  4. #include <cassert>
  5. #include <eigen3/Eigen/Dense>
  6. using namespace std;
  7. //用于标定传感器相当于标准坐标系的正向位置
  8. //当数据为正(+)或者无符号时,表示当投影到标准坐标系中时,位于投影坐标轴的正向空间
  9. //当数据为负(-),表示当投影到标准坐标系中时,位于投影坐标轴的负向空间
  10. //用于标定毫米波雷达(Radar)相对于标准坐标系的正向位置
  11. #define X_Radar 0
  12. #define Y_Radar 465
  13. //用于标定激光雷达(Lidar)相对于标准坐标系的正向位置
  14. #define X_Lidar 0
  15. #define Y_Lidar 0
  16. //用于标定GPS模块相当于标准坐标系的正向位置
  17. #define X_GPS 0
  18. #define Y_GPS 0
  19. //用于标定相机(camera)相当于标准坐标系的正向位置
  20. #define X_Camera 0
  21. #define Y_Camera 188
  22. #define Z_Camera 0
  23. using Eigen::MatrixXd;
  24. class TranslateToStandardLocation
  25. {
  26. public:
  27. static inline MatrixXd translateRadarToStandardLocation(MatrixXd radarLoc)
  28. {
  29. MatrixXd staLoc = radarLoc;
  30. staLoc(1, 0) = staLoc(1, 0) - X_Radar;
  31. staLoc(0, 1) = staLoc(0, 1) - Y_Radar;
  32. return staLoc;
  33. }
  34. static inline MatrixXd translateLidarToStandardLocation(MatrixXd lidarLoc)
  35. {
  36. MatrixXd staLoc = lidarLoc;
  37. staLoc(1, 0) = staLoc(1, 0) - X_Lidar;
  38. staLoc(0, 1) = staLoc(0, 1) - Y_Lidar;
  39. return staLoc;
  40. }
  41. static inline MatrixXd translateGPSToStandardLocation(MatrixXd GPSLoc)
  42. {
  43. MatrixXd staLoc = GPSLoc;
  44. staLoc(1, 0) = staLoc(1, 0) - X_GPS;
  45. staLoc(0, 1) = staLoc(0, 1) - Y_GPS;
  46. return staLoc;
  47. }
  48. static inline MatrixXd translateCameraToStandardLocation(MatrixXd cameraLoc)
  49. {
  50. assert(cameraLoc.rows() == 2);
  51. assert(cameraLoc.cols() == 1);
  52. MatrixXd staLoc(3, 1);
  53. staLoc(0, 0) = cameraLoc(0, 0);
  54. staLoc(1, 0) = cameraLoc(1, 0);
  55. staLoc(2, 0) = 1;
  56. // std::cout << staLoc << std::endl << std::endl;
  57. MatrixXd Mat(3, 3);
  58. Mat <<
  59. -4.5288434998620575e-01, -2.7615788020977561e-01,7.9366326248964913e+02,
  60. -9.4286502898149827e-02,-1.7340325696936468e-01, 1.8919238200384973e+02,
  61. -1.2880669794829137e-04, -3.2569693624068995e-04, 1.;
  62. // -1.82255446e-01, +1.92433308e-03, +1.92772928e+02,
  63. // -3.54541567e-02, -1.35423705e-01, -1.77699852e+01,
  64. // -1.53689475e-04, -1.33359828e-03, +1.00000000e+00;
  65. // std::cout << Mat << std::endl;
  66. //std::cout<< staLoc * Mat << endl;
  67. MatrixXd T(2, 1);
  68. T(0, 0) = X_Camera;
  69. T(1, 0) = Y_Camera;
  70. //T(2, 0) = Z_Camera;
  71. //MatrixXd m2 = Mat * staLoc + T;
  72. MatrixXd m2 = Mat * staLoc;
  73. // std::cout << m2 << std::endl
  74. // << std::endl;
  75. assert(m2(2, 0) != 0);
  76. MatrixXd retMat(2, 1);
  77. retMat(0, 0) = m2(0, 0) / m2(2, 0);
  78. retMat(1, 0) = m2(1, 0) / m2(2, 0);
  79. // std::cout << (retMat + T) << std::endl<<std::endl;
  80. return retMat + T;
  81. }
  82. };
  83. #endif //__LOCALIZATION_H__