common_data.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //
  2. // Created by huli on 2020/9/8.
  3. //
  4. #include "common_data.h"
  5. void Common_data::copy_data(Car_measure_information& car_measure_information_out, const message::Locate_information& locate_information_in)
  6. {
  7. if ( locate_information_in.has_locate_x() )
  8. {
  9. car_measure_information_out.car_center_x = locate_information_in.locate_x();
  10. }
  11. else
  12. {
  13. car_measure_information_out.car_center_x = 0;
  14. }
  15. if ( locate_information_in.has_locate_y() )
  16. {
  17. car_measure_information_out.car_center_y = locate_information_in.locate_y();
  18. }
  19. else
  20. {
  21. car_measure_information_out.car_center_y = 0;
  22. }
  23. if ( locate_information_in.has_locate_angle() )
  24. {
  25. car_measure_information_out.car_angle = locate_information_in.locate_angle();
  26. }
  27. else
  28. {
  29. car_measure_information_out.car_angle = 0;
  30. }
  31. if ( locate_information_in.has_locate_length() )
  32. {
  33. car_measure_information_out.car_length = locate_information_in.locate_length();
  34. }
  35. else
  36. {
  37. car_measure_information_out.car_length = 0;
  38. }
  39. if ( locate_information_in.has_locate_width() )
  40. {
  41. car_measure_information_out.car_width = locate_information_in.locate_width();
  42. }
  43. else
  44. {
  45. car_measure_information_out.car_width = 0;
  46. }
  47. if ( locate_information_in.has_locate_height() )
  48. {
  49. car_measure_information_out.car_height = locate_information_in.locate_height();
  50. }
  51. else
  52. {
  53. car_measure_information_out.car_height = 0;
  54. }
  55. if ( locate_information_in.has_locate_wheel_base() )
  56. {
  57. car_measure_information_out.car_wheel_base = locate_information_in.locate_wheel_base();
  58. }
  59. else
  60. {
  61. car_measure_information_out.car_wheel_base = 0;
  62. }
  63. if ( locate_information_in.has_locate_wheel_width() )
  64. {
  65. car_measure_information_out.car_wheel_width = locate_information_in.locate_wheel_width();
  66. }
  67. else
  68. {
  69. car_measure_information_out.car_wheel_width = 0;
  70. }
  71. if ( locate_information_in.has_locate_front_theta() )
  72. {
  73. car_measure_information_out.car_front_theta = locate_information_in.locate_front_theta();
  74. }
  75. else
  76. {
  77. car_measure_information_out.car_front_theta = 0;
  78. }
  79. if ( locate_information_in.has_locate_correct() )
  80. {
  81. car_measure_information_out.correctness = locate_information_in.locate_correct();
  82. }
  83. else
  84. {
  85. car_measure_information_out.correctness = false;
  86. }
  87. }
  88. void Common_data::copy_data(message::Locate_information& locate_information_out, const Car_measure_information& car_measure_information_in)
  89. {
  90. locate_information_out.set_locate_x(car_measure_information_in.car_center_x);
  91. locate_information_out.set_locate_y(car_measure_information_in.car_center_y);
  92. locate_information_out.set_locate_angle(car_measure_information_in.car_angle);
  93. locate_information_out.set_locate_length(car_measure_information_in.car_length);
  94. locate_information_out.set_locate_width(car_measure_information_in.car_width);
  95. locate_information_out.set_locate_height(car_measure_information_in.car_height);
  96. locate_information_out.set_locate_wheel_base(car_measure_information_in.car_wheel_base);
  97. locate_information_out.set_locate_wheel_width(car_measure_information_in.car_wheel_width);
  98. locate_information_out.set_locate_front_theta(car_measure_information_in.car_front_theta);
  99. locate_information_out.set_locate_correct(car_measure_information_in.correctness);
  100. }
  101. void Common_data::copy_data(Car_information& car_information_out, const message::Car_info& car_info_in)
  102. {
  103. if ( car_info_in.has_license() )
  104. {
  105. car_information_out.license = car_info_in.license();
  106. }
  107. else
  108. {
  109. car_information_out.license.clear();
  110. }
  111. if ( car_info_in.has_car_length() )
  112. {
  113. car_information_out.car_length = car_info_in.car_length();
  114. }
  115. else
  116. {
  117. car_information_out.car_length = 0;
  118. }
  119. if ( car_info_in.has_car_width() )
  120. {
  121. car_information_out.car_width = car_info_in.car_width();
  122. }
  123. else
  124. {
  125. car_information_out.car_width = 0;
  126. }
  127. if ( car_info_in.has_car_height() )
  128. {
  129. car_information_out.car_height = car_info_in.car_height();
  130. }
  131. else
  132. {
  133. car_information_out.car_height = 0;
  134. }
  135. if ( car_info_in.has_car_wheel_base() )
  136. {
  137. car_information_out.car_wheel_base = car_info_in.car_wheel_base();
  138. }
  139. else
  140. {
  141. car_information_out.car_wheel_base = 0;
  142. }
  143. if ( car_info_in.has_car_wheel_width() )
  144. {
  145. car_information_out.car_wheel_width = car_info_in.car_wheel_width();
  146. }
  147. else
  148. {
  149. car_information_out.car_wheel_width = 0;
  150. }
  151. }
  152. void Common_data::copy_data(message::Car_info& car_info_out, const Car_information& car_information_in)
  153. {
  154. car_info_out.set_license(car_information_in.license);
  155. car_info_out.set_car_length(car_information_in.car_length);
  156. car_info_out.set_car_width(car_information_in.car_width);
  157. car_info_out.set_car_height(car_information_in.car_height);
  158. car_info_out.set_car_wheel_base(car_information_in.car_wheel_base);
  159. car_info_out.set_car_wheel_width(car_information_in.car_wheel_width);
  160. }
  161. void Common_data::copy_data(Parkspace_information& parkspace_information_out, const message::Parkspace_info& parkspace_info_in)
  162. {
  163. parkspace_information_out.parkingspace_index_id = parkspace_info_in.parkingspace_index_id();
  164. parkspace_information_out.parkingspace_type = (Common_data::Parkspace_type)parkspace_info_in.parkingspace_type();
  165. parkspace_information_out.parkingspace_unit_id = parkspace_info_in.parkingspace_unit_id();
  166. parkspace_information_out.parkingspace_floor_id = parkspace_info_in.parkingspace_floor_id();
  167. parkspace_information_out.parkingspace_room_id = parkspace_info_in.parkingspace_room_id();
  168. parkspace_information_out.parkingspace_direction = (Common_data::Direction)parkspace_info_in.parkingspace_direction();
  169. parkspace_information_out.parkingspace_width = parkspace_info_in.parkingspace_width();
  170. parkspace_information_out.parkingspace_height = parkspace_info_in.parkingspace_height();
  171. parkspace_information_out.parkingspace_status = (Common_data::Parkspace_status)parkspace_info_in.parkingspace_status();
  172. copy_data(parkspace_information_out.car_information, (message::Car_info&) parkspace_info_in.car_info());
  173. parkspace_information_out.car_entry_time = parkspace_info_in.entry_time();
  174. parkspace_information_out.car_leave_time = parkspace_info_in.leave_time();
  175. parkspace_information_out.parkspace_path = (Common_data::Parkspace_path)parkspace_info_in.parkspace_path();
  176. parkspace_information_out.path_estimate_time = parkspace_info_in.path_estimate_time();
  177. parkspace_information_out.parkspace_status_target = (Common_data::Parkspace_status)parkspace_info_in.parkspace_status_target();
  178. }
  179. void Common_data::copy_data(message::Parkspace_info& parkspace_info_out, const Parkspace_information& parkspace_information_in)
  180. {
  181. parkspace_info_out.set_parkingspace_index_id(parkspace_information_in.parkingspace_index_id);
  182. parkspace_info_out.set_parkingspace_type((message::Parkspace_type)parkspace_information_in.parkingspace_type);
  183. parkspace_info_out.set_parkingspace_unit_id(parkspace_information_in.parkingspace_unit_id);
  184. parkspace_info_out.set_parkingspace_room_id(parkspace_information_in.parkingspace_room_id);
  185. parkspace_info_out.set_parkingspace_direction((message::Direction)parkspace_information_in.parkingspace_direction);
  186. parkspace_info_out.set_parkingspace_floor_id(parkspace_information_in.parkingspace_floor_id);
  187. parkspace_info_out.set_parkingspace_width(parkspace_information_in.parkingspace_width);
  188. parkspace_info_out.set_parkingspace_height(parkspace_information_in.parkingspace_height);
  189. parkspace_info_out.set_parkingspace_status((message::Parkspace_status)parkspace_information_in.parkingspace_status);
  190. copy_data(*parkspace_info_out.mutable_car_info(), parkspace_information_in.car_information);
  191. parkspace_info_out.set_entry_time(parkspace_information_in.car_entry_time);
  192. parkspace_info_out.set_leave_time(parkspace_information_in.car_leave_time);
  193. parkspace_info_out.set_parkspace_path((message::Parkspace_path)parkspace_information_in.parkspace_path);
  194. parkspace_info_out.set_path_estimate_time(parkspace_information_in.path_estimate_time);
  195. parkspace_info_out.set_parkspace_status_target((message::Parkspace_status)parkspace_information_in.parkspace_status_target);
  196. }
  197. void Common_data::transform_data(Car_information& car_information_out, const Car_measure_information& car_measure_information_in)
  198. {
  199. car_information_out.license.clear();
  200. car_information_out.car_length = car_measure_information_in.car_length;
  201. car_information_out.car_width = car_measure_information_in.car_width;
  202. car_information_out.car_height = car_measure_information_in.car_height;
  203. car_information_out.car_wheel_base = car_measure_information_in.car_wheel_base;
  204. car_information_out.car_wheel_width = car_measure_information_in.car_wheel_width;
  205. }
  206. void Common_data::transform_data(Car_measure_information& car_measure_information_out, const Car_information& car_informatio_in)
  207. {
  208. car_measure_information_out.car_center_x = 0;
  209. car_measure_information_out.car_center_y = 0;
  210. car_measure_information_out.car_angle = 0;
  211. car_measure_information_out.car_length = car_informatio_in.car_length;
  212. car_measure_information_out.car_width = car_informatio_in.car_width;
  213. car_measure_information_out.car_height = car_informatio_in.car_height;
  214. car_measure_information_out.car_wheel_base = car_informatio_in.car_wheel_base;
  215. car_measure_information_out.car_wheel_width = car_informatio_in.car_wheel_width;
  216. car_measure_information_out.car_front_theta = 0;
  217. car_measure_information_out.correctness = false;
  218. }
  219. void Common_data::transform_data(Car_wheel_information& car_wheel_information_out, const Car_measure_information& car_measure_information_in)
  220. {
  221. car_wheel_information_out.car_center_x = car_measure_information_in.car_center_x;
  222. car_wheel_information_out.car_center_y = car_measure_information_in.car_center_y;
  223. car_wheel_information_out.car_angle = car_measure_information_in.car_angle;
  224. car_wheel_information_out.car_wheel_base = car_measure_information_in.car_wheel_base;
  225. car_wheel_information_out.car_wheel_width = car_measure_information_in.car_wheel_width;
  226. car_wheel_information_out.car_front_theta = car_measure_information_in.car_front_theta;
  227. car_wheel_information_out.correctness = car_measure_information_in.correctness;
  228. }
  229. void Common_data::transform_data(Car_measure_information& car_measure_information_out, const Car_wheel_information& car_wheel_information_in)
  230. {
  231. car_measure_information_out.car_center_x = car_wheel_information_in.car_center_x;
  232. car_measure_information_out.car_center_y = car_wheel_information_in.car_center_y;
  233. car_measure_information_out.car_angle = car_wheel_information_in.car_angle;
  234. car_measure_information_out.car_length = 0;
  235. car_measure_information_out.car_width = 0;
  236. car_measure_information_out.car_height = 0;
  237. car_measure_information_out.car_wheel_base = car_wheel_information_in.car_wheel_base;
  238. car_measure_information_out.car_wheel_width = car_wheel_information_in.car_wheel_width;
  239. car_measure_information_out.car_front_theta = car_wheel_information_in.car_front_theta;
  240. car_measure_information_out.correctness = car_wheel_information_in.correctness;
  241. }
  242. void Common_data::scaling(Car_measure_information& car_measure_information, float rate)
  243. {
  244. car_measure_information.car_center_x *= rate;
  245. car_measure_information.car_center_y *= rate;
  246. car_measure_information.car_length *= rate;
  247. car_measure_information.car_width *= rate;
  248. car_measure_information.car_height *= rate;
  249. car_measure_information.car_wheel_base *= rate;
  250. car_measure_information.car_wheel_width *= rate;
  251. }
  252. void Common_data::scaling(Car_information& car_information, float rate)
  253. {
  254. car_information.car_length *= rate;
  255. car_information.car_width *= rate;
  256. car_information.car_height *= rate;
  257. car_information.car_wheel_base *= rate;
  258. car_information.car_wheel_width *= rate;
  259. }
  260. void Common_data::scaling(Parkspace_information& parkspace_information, float rate)
  261. {
  262. parkspace_information.parkingspace_width *= rate;
  263. parkspace_information.parkingspace_height *= rate;
  264. scaling(parkspace_information.car_information, rate);
  265. }
  266. bool Common_data::approximate_rate(float a, float b, float rate)
  267. {
  268. if ( a >= b*(1-rate) && a< b*(1+rate))
  269. {
  270. return true;
  271. }
  272. else
  273. {
  274. return false;
  275. }
  276. }
  277. bool Common_data::approximate_difference(float a, float b, float difference)
  278. {
  279. if ( a >= (b-difference) && a< (b+difference) )
  280. {
  281. return true;
  282. }
  283. else
  284. {
  285. return false;
  286. }
  287. }