common_data.h 11 KB

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