common_data.h 4.6 KB

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