common_data.h 4.7 KB

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