common_data.h 14 KB

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