common_data.h 14 KB

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