common_data.h 13 KB

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