common_data.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. #include "../message/message_base.pb.h"
  11. class Common_data
  12. {
  13. public:
  14. //万集雷达扫描周期66ms, (频率15hz), 一般设置大一些
  15. #define WANJI_716_SCAN_CYCLE_MS 75
  16. //vlp16雷达扫描周期100ms, (频率10hz), 一般设置大一些
  17. #define VLP16_SCAN_CYCLE_MS 110
  18. //车位表
  19. #define PARKSPACE_ID_BASE 0
  20. #define PASSAGEWAY_ID_BASE 1100
  21. //唯一码的默认长度 32byte
  22. #define COMMAND_KEY_DEFAULT_LENGTH 32
  23. //整车的测量信息
  24. struct Car_measure_information
  25. {
  26. float car_center_x = 0; //整车的中心点x值, 四轮的中心
  27. float car_center_y = 0; //整车的中心点y值, 四轮的中心
  28. float car_angle = 0; //整车的车身旋转角,
  29. float car_length = 0; //整车的长度, 用于规避碰撞
  30. float car_width = 0; //整车的宽度, 用于规避碰撞
  31. float car_height = 0; //整车的高度, 用于规避碰撞
  32. float car_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  33. float car_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  34. float car_front_theta = 0; //整车的前轮的旋转角
  35. bool correctness = false; //整车的校准标记位
  36. };
  37. //四轮的测量信息
  38. struct Car_wheel_information
  39. {
  40. float car_center_x = 0; //整车的中心点x值, 四轮的中心
  41. float car_center_y = 0; //整车的中心点y值, 四轮的中心
  42. float car_angle = 0; //整车的车身旋转角,
  43. float car_wheel_base = 0; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  44. float car_wheel_width = 0; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  45. float car_front_theta = 0; //整车的前轮的旋转角
  46. bool correctness = false; //整车的校准标记位
  47. public:
  48. Car_wheel_information& operator+=(const Car_wheel_information& other)
  49. {
  50. this->car_center_x += other.car_center_x;
  51. this->car_center_y += other.car_center_y;
  52. this->car_angle += other.car_angle;
  53. this->car_wheel_base += other.car_wheel_base;
  54. this->car_wheel_width += other.car_wheel_width;
  55. this->car_front_theta += other.car_front_theta;
  56. this->correctness &= other.correctness;
  57. return *this;
  58. }
  59. Car_wheel_information& operator-=(const Car_wheel_information& other)
  60. {
  61. this->car_center_x -= other.car_center_x;
  62. this->car_center_y -= other.car_center_y;
  63. this->car_angle -= other.car_angle;
  64. this->car_wheel_base -= other.car_wheel_base;
  65. this->car_wheel_width -= other.car_wheel_width;
  66. this->car_front_theta -= other.car_front_theta;
  67. this->correctness &= other.correctness;
  68. return *this;
  69. }
  70. Car_wheel_information& operator/=(int scalar)
  71. {
  72. if(scalar==0)
  73. return *this;
  74. this->car_center_x /= scalar;
  75. this->car_center_y /= scalar;
  76. this->car_angle /= scalar;
  77. this->car_wheel_base /= scalar;
  78. this->car_wheel_width /= scalar;
  79. this->car_front_theta /= scalar;
  80. return *this;
  81. }
  82. // 定义评分规则,
  83. // wx=1 wy=1 wa=0.5 wb=1 ww=0.5 wft=0.5
  84. float calc_score()
  85. {
  86. float weights[] = {1.0f, 1.0f, 0.5f, 0.1f, 0.05f, 0.05f};
  87. float final_score = 0.0f;
  88. final_score += fabs(weights[0] * this->car_center_x);
  89. final_score += fabs(weights[1] * this->car_center_y);
  90. final_score += fabs(weights[2] * this->car_angle);
  91. final_score += fabs(weights[3] * this->car_wheel_base);
  92. final_score += fabs(weights[4] * this->car_wheel_width);
  93. final_score += fabs(weights[5] * this->car_front_theta);
  94. return final_score;
  95. }
  96. std::string to_string()
  97. {
  98. char buf[512]={0};
  99. sprintf(buf, "%.4f %.4f %.4f %.4f %.4f %.4f\n", car_center_x, car_center_y, car_angle, car_wheel_base, car_wheel_width, car_front_theta);
  100. return std::string(buf);
  101. }
  102. };
  103. // 带时间戳的四轮测量信息
  104. struct Car_wheel_information_stamped
  105. {
  106. Car_wheel_information wheel_data;
  107. std::chrono::system_clock::time_point measure_time;
  108. public:
  109. Car_wheel_information_stamped& operator+=(const Car_wheel_information_stamped& other)
  110. {
  111. this->wheel_data += other.wheel_data;
  112. return *this;
  113. }
  114. Car_wheel_information_stamped& operator-=(const Car_wheel_information_stamped& other)
  115. {
  116. this->wheel_data -= other.wheel_data;
  117. return *this;
  118. }
  119. Car_wheel_information_stamped operator-(const Car_wheel_information_stamped& other)
  120. {
  121. Car_wheel_information_stamped t_info;
  122. t_info = *this;
  123. t_info.wheel_data -= other.wheel_data;
  124. return t_info;
  125. }
  126. Car_wheel_information_stamped& operator/=(int scalar)
  127. {
  128. this->wheel_data /= scalar;
  129. return *this;
  130. }
  131. // 定义评分规则,
  132. // wx=1 wy=1 wa=0.5 wb=1 ww=0.5 wft=0.1
  133. float calc_score()
  134. {
  135. return wheel_data.calc_score();
  136. }
  137. };
  138. struct Car_information
  139. {
  140. std::string license; //车辆凭证号
  141. float car_length=0; //车长
  142. float car_width=0; //车宽
  143. float car_height=0; //车高
  144. float car_wheel_base = 0; //整车的轮距; 前后轮的距离; 用于机器人或agv的抓车
  145. float car_wheel_width = 0; //整车的轮距; 左右轮的距离; 用于机器人或agv的抓车
  146. };
  147. //车位状态枚举
  148. enum Parkspace_status
  149. {
  150. PARKSPACE_STATUS_UNKNOW = 0,
  151. PARKSPACE_EMPTY = 1, //空闲,可分配
  152. PARKSPACE_OCCUPIED = 2, //被占用,不可分配
  153. PARKSPACE_RESERVED = 3, //被预约,预约车辆可分配, 暂时不用
  154. PARKSPACE_LOCKED = 4, //临时锁定,不可分配
  155. PARKSPACE_ERROR = 5, //车位机械结构或硬件故障
  156. };
  157. enum Direction
  158. {
  159. DIRECTION_UNKNOW = 0,
  160. DIRECTION_FORWARD = 1,
  161. DIRECTION_BACKWARD = 2,
  162. };
  163. //车位分配路线(根据中跑车的路线来定)
  164. enum Parkspace_path
  165. {
  166. UNKNOW_PATH = 0,
  167. OPTIMAL_PATH = 1,
  168. LEFT_PATH = 2,
  169. RIGHT_PATH = 3,
  170. TEMPORARY_CACHE_PATH = 4,
  171. };
  172. //车位类型
  173. enum Parkspace_type
  174. {
  175. UNKNOW_PARKSPACE_TYPE = 0,
  176. MIN_PARKINGSPACE = 1,//小车位
  177. MID_PARKINGSPACE = 2,//中车位
  178. BIG_PARKINGSPACE = 3,//大车位
  179. };
  180. //汽车类型
  181. enum Car_type
  182. {
  183. UNKNOW_CAR_TYPE = 0,
  184. MIN_CAR = 1,//小车
  185. MID_CAR = 2,//中车
  186. BIG_CAR = 3,//大车
  187. };
  188. //单个车位基本信息与状态信息,车位信息以及车位上的车辆信息
  189. struct Parkspace_information
  190. {
  191. int parkingspace_index_id=0; //车位编号
  192. Parkspace_type parkingspace_type=UNKNOW_PARKSPACE_TYPE; //车位类型
  193. int parkingspace_unit_id=0; //区块编号
  194. int parkingspace_floor_id=0; //楼层
  195. int parkingspace_room_id=0; //同层编号
  196. Direction parkingspace_direction=DIRECTION_UNKNOW; //前后
  197. float parkingspace_width=0; //车位宽
  198. float parkingspace_height=0; //车位高
  199. Parkspace_status parkingspace_status=PARKSPACE_EMPTY; //车位当前状态
  200. Car_information car_information; //当前车位存入车辆的凭证号
  201. std::string car_entry_time; //入场时间
  202. std::string car_leave_time; //离场时间
  203. Parkspace_path parkspace_path = UNKNOW_PATH; // 车位分配路线
  204. float path_estimate_time = 0; //车位分配路线 time(s)
  205. Parkspace_status parkspace_status_target=PARKSPACE_EMPTY; //车位目标状态
  206. };
  207. static void copy_data(Car_measure_information& car_measure_information_out, const message::Locate_information& locate_information_in);
  208. static void copy_data(message::Locate_information& locate_information_out, const Car_measure_information& car_measure_information_in);
  209. static void copy_data(Car_information& car_information_out, const message::Car_info& car_info_in);
  210. static void copy_data(message::Car_info& car_info_out, const Car_information& car_information_in);
  211. static void copy_data(Parkspace_information& parkspace_information_out, const message::Parkspace_info& parkspace_info_in);
  212. static void copy_data(message::Parkspace_info& parkspace_info_out, const Parkspace_information& parkspace_information_in);
  213. static void transform_data(Car_information& car_information_out, const Car_measure_information& car_measure_information_in);
  214. static void transform_data(Car_measure_information& car_measure_information_out, const Car_information& car_informatio_in);
  215. static void transform_data(Car_wheel_information& car_wheel_information_out, const Car_measure_information& car_measure_information_in);
  216. static void transform_data(Car_measure_information& car_measure_information_out, const Car_wheel_information& car_wheel_information_in);
  217. static void scaling(Car_measure_information& car_measure_information, float rate);
  218. static void scaling(Car_information& car_information, float rate);
  219. static void scaling(Parkspace_information& parkspace_information, float rate);
  220. static bool approximate_rate(float a, float b, float rate);
  221. static bool approximate_difference(float a, float b, float difference);
  222. //调度模块
  223. //调度流程类型
  224. enum Dispatch_process_type
  225. {
  226. DISPATCH_PROCESS_TYPE_UNKNOW = 0, //未知
  227. DISPATCH_PROCESS_STORE = 101, //存车
  228. DISPATCH_PROCESS_PICKUP = 102, //取车
  229. };
  230. //调度动作方向 0=未知,1=存车,2=取车
  231. enum Dispatch_motion_direction
  232. {
  233. DISPATCH_MOTION_DIRECTION_UNKNOWN = 0,
  234. DISPATCH_MOTION_DIRECTION_STORE = 1, //
  235. DISPATCH_MOTION_DIRECTION_PICKUP = 2, //
  236. };
  237. //出入口方向 0=未知,1=入口,2=出口
  238. enum Passageway_direction
  239. {
  240. PASSAGEWAY_DIRECTION_UNKNOWN = 0, //
  241. PASSAGEWAY_DIRECTION_INLET = 1, //
  242. PASSAGEWAY_DIRECTION_OUTLET = 2, //
  243. };
  244. //楼上车位方向 0=未知,1=朝南,2=朝北
  245. enum Parkingspace_direction
  246. {
  247. PARKINGSPACE_DIRECTION_UNKNOWN = 0, //
  248. PARKINGSPACE_DIRECTION_SOUTH = 1, //
  249. PARKINGSPACE_DIRECTION_NORTH = 2, //
  250. };
  251. //防撞雷达标志位 0=未知,1=位置正常,2=位置异常
  252. enum Anticollision_lidar_flag
  253. {
  254. ANTICOLLISION_LIDAR_UNKNOWN = 0, //
  255. ANTICOLLISION_LIDAR_NORMAL = 1, //
  256. ANTICOLLISION_LIDAR_ERROR = 2, //
  257. };
  258. };
  259. #endif //NNXX_TESTS_COMMON_DATA_H