common_data.h 13 KB

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