common_data.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Created by huli on 2020/9/8.
  3. //
  4. #ifndef NNXX_TESTS_COMMON_DATA_H
  5. #define NNXX_TESTS_COMMON_DATA_H
  6. #include <chrono>
  7. #include <cmath>
  8. class Common_data
  9. {
  10. public:
  11. //万集雷达扫描周期66ms, (频率15hz), 一般设置大一些
  12. #define WANJI_716_SCAN_CYCLE_MS 70
  13. //整车的测量信息
  14. struct Car_measure_information
  15. {
  16. float center_x = 0; //整车的中心点x值, 四轮的中心
  17. float center_y = 0; //整车的中心点y值, 四轮的中心
  18. float car_angle = 0; //整车的车身旋转角,
  19. float car_length = 0; //整车的长度, 用于规避碰撞
  20. float car_width = 0; //整车的宽度, 用于规避碰撞
  21. float car_height = 0; //整车的高度, 用于规避碰撞
  22. float wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  23. float wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  24. float front_theta = 0; //整车的前轮的旋转角
  25. bool correctness = false; //整车的校准标记位
  26. };
  27. //四轮的测量信息
  28. struct Car_wheel_information
  29. {
  30. float center_x = 0; //整车的中心点x值, 四轮的中心
  31. float center_y = 0; //整车的中心点y值, 四轮的中心
  32. float car_angle = 0; //整车的车身旋转角,
  33. float wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  34. float wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  35. float front_theta = 0; //整车的前轮的旋转角
  36. bool correctness = false; //整车的校准标记位
  37. public:
  38. Car_wheel_information& operator+=(const Car_wheel_information& other)
  39. {
  40. this->center_x += other.center_x;
  41. this->center_y += other.center_y;
  42. this->car_angle += other.car_angle;
  43. this->wheel_base += other.wheel_base;
  44. this->wheel_width += other.wheel_width;
  45. this->front_theta += other.front_theta;
  46. this->correctness &= other.correctness;
  47. return *this;
  48. }
  49. Car_wheel_information& operator-=(const Car_wheel_information& other)
  50. {
  51. this->center_x -= other.center_x;
  52. this->center_y -= other.center_y;
  53. this->car_angle -= other.car_angle;
  54. this->wheel_base -= other.wheel_base;
  55. this->wheel_width -= other.wheel_width;
  56. this->front_theta -= other.front_theta;
  57. this->correctness &= other.correctness;
  58. return *this;
  59. }
  60. Car_wheel_information& operator/=(int scalar)
  61. {
  62. if(scalar==0)
  63. return *this;
  64. this->center_x /= scalar;
  65. this->center_y /= scalar;
  66. this->car_angle /= scalar;
  67. this->wheel_base /= scalar;
  68. this->wheel_width /= scalar;
  69. this->front_theta /= scalar;
  70. return *this;
  71. }
  72. // 定义评分规则,
  73. // wx=1 wy=1 wa=0.5 wb=1 ww=0.5 wft=0.5
  74. float calc_score()
  75. {
  76. float weights[] = {1.0f, 1.0f, 0.5f, 1.0f, 0.5f, 0.5f};
  77. float final_score = 0.0f;
  78. final_score += fabs(weights[0] * this->center_x);
  79. final_score += fabs(weights[1] * this->center_y);
  80. final_score += fabs(weights[2] * this->car_angle);
  81. final_score += fabs(weights[3] * this->wheel_base);
  82. final_score += fabs(weights[4] * this->wheel_width);
  83. final_score += fabs(weights[5] * this->front_theta);
  84. return final_score;
  85. }
  86. };
  87. // 带时间戳的四轮测量信息
  88. struct Car_wheel_information_stamped
  89. {
  90. Car_wheel_information wheel_data;
  91. std::chrono::system_clock::time_point measure_time;
  92. public:
  93. Car_wheel_information_stamped& operator+=(const Car_wheel_information_stamped& other)
  94. {
  95. this->wheel_data += other.wheel_data;
  96. return *this;
  97. }
  98. Car_wheel_information_stamped& operator-=(const Car_wheel_information_stamped& other)
  99. {
  100. this->wheel_data -= other.wheel_data;
  101. return *this;
  102. }
  103. Car_wheel_information_stamped& operator-(const Car_wheel_information_stamped& other)
  104. {
  105. this->wheel_data -= other.wheel_data;
  106. return *this;
  107. }
  108. Car_wheel_information_stamped& operator/=(int scalar)
  109. {
  110. this->wheel_data /= scalar;
  111. return *this;
  112. }
  113. // 定义评分规则,
  114. // wx=1 wy=1 wa=0.5 wb=1 ww=0.5 wft=0.1
  115. float calc_score()
  116. {
  117. return wheel_data.calc_score();
  118. }
  119. };
  120. static void copy_data(Car_measure_information& car_measure_information_in, Car_wheel_information& car_wheel_information_out);
  121. static void copy_data(Car_wheel_information& car_wheel_information_in, Car_measure_information& car_measure_information_out);
  122. };
  123. #endif //NNXX_TESTS_COMMON_DATA_H