soft_radar_handle.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. #include "soft_radar_handle.h"
  2. #include "string.h"
  3. #include "main.h"
  4. #include "soft_obstacle.h"
  5. #include "soft_terrain.h"
  6. #include "main_task.h"
  7. #include "usart_data_handle.h"
  8. #include "soft_can.h"
  9. #include "math.h"
  10. #include "soft_update.h"
  11. #include "soft_device.h"
  12. /**
  13. * @file get_radar_info
  14. * @brief 获取雷达信息
  15. * @param Info_Type:避障雷达 X:1 Y:2
  16. * @details
  17. * @author Zhang Sir
  18. **/
  19. short get_radar_info(uint8_t Radar_Type,uint8_t Info_Type)
  20. {
  21. uavr_terrain *Ptr_T = NULL;
  22. uavr_obs *Ptr_O = NULL;
  23. if(Radar_Type == T_RADAR)
  24. {
  25. if(mimo_ter_info.Link.connect_status != COMP_NOEXIST)
  26. Ptr_T = &mimo_ter_info;
  27. else if(uavr56_info.Link.connect_status != COMP_NOEXIST)
  28. Ptr_T = &uavr56_info;
  29. if(Ptr_T->Link.connect_status == COMP_LOST) {return -2;}
  30. else if(Ptr_T == NULL) {return -1;}
  31. else {return Ptr_T->height;}
  32. }
  33. else if(Radar_Type == F_RADAR)
  34. {
  35. if(uavr11_info.Link.connect_status != COMP_NOEXIST)
  36. Ptr_O = &uavr11_info;
  37. else if(mimo_f_info.Link.connect_status != COMP_NOEXIST)
  38. Ptr_O = &mimo_f_info;
  39. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  40. else if(Ptr_O == NULL) {return -1;}
  41. else
  42. {
  43. if(Info_Type == OBS_X)
  44. return Ptr_O->distance_x;
  45. else if((Info_Type == OBS_Y))
  46. return Ptr_O->distance_y;
  47. }
  48. }
  49. else if(Radar_Type == B_RADAR)
  50. {
  51. if(uavr12_info.Link.connect_status != COMP_NOEXIST)
  52. Ptr_O = &uavr12_info;
  53. else if(mimo_b_info.Link.connect_status != COMP_NOEXIST)
  54. Ptr_O = &mimo_b_info;
  55. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  56. else if(Ptr_O == NULL) {return -1;}
  57. else
  58. {
  59. if(Info_Type == OBS_X)
  60. return Ptr_O->distance_x;
  61. else if((Info_Type == OBS_Y))
  62. return Ptr_O->distance_y;
  63. }
  64. }
  65. return 0;
  66. }
  67. /**
  68. * @file radar_version_check
  69. * @brief 更改雷达版本格式
  70. * @param none
  71. * @details
  72. * @author Zhang Sir
  73. **/
  74. char radar_version[3][10] = {0}; //0 前避障 1后避障 2仿地
  75. void radar_version_check(void)
  76. {
  77. //前避障
  78. if(uavr11_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.boot_flag == true)
  79. {
  80. if(uavr11_info.soft_verison == 0 && uavr11_info.get_radar_ver_flag == false)
  81. {
  82. uavr11_info.version[0] = 'M';
  83. uavr11_info.version[1] = '1';
  84. for(uint8_t i = 2;i < 10; i++)
  85. {
  86. uavr11_info.version[i] = '0';
  87. }
  88. }
  89. memcpy(&radar_version[0][0],&uavr11_info.version[0],10);
  90. }
  91. else if (mimo_f_info.Link.connect_status == COMP_NORMAL)
  92. {
  93. if(mimo_f_info.Link.boot_flag == true)
  94. {
  95. memcpy(&mimo_f_info.version,"E100000000",10);
  96. }
  97. memcpy(&radar_version[0][0],&mimo_f_info.version[0],10);
  98. }
  99. //后避障
  100. if(uavr12_info.Link.connect_status == COMP_NORMAL )
  101. {
  102. if(uavr12_info.soft_verison == 0 && uavr12_info.get_radar_ver_flag == false)
  103. {
  104. uavr12_info.version[0] = 'M';
  105. uavr12_info.version[1] = '2';
  106. for(uint8_t i = 2;i < 10; i++)
  107. {
  108. uavr12_info.version[i] = '0';
  109. }
  110. }
  111. memcpy(&radar_version[1][0],&uavr12_info.version[0],10);
  112. }
  113. else if(mimo_b_info.Link.connect_status == COMP_NORMAL)
  114. {
  115. if(mimo_b_info.Link.boot_flag == true)
  116. {
  117. memcpy(&mimo_b_info.version,"E200000000",10);
  118. }
  119. memcpy(&radar_version[1][0],&mimo_b_info.version[0],10);
  120. }
  121. if(uavr56_info.Link.connect_status == COMP_NORMAL )
  122. {
  123. if(uavr56_info.soft_verison == 0 && uavr56_info.get_radar_ver_flag == false)
  124. {
  125. uavr56_info.version[0] = 'M';
  126. uavr56_info.version[1] = 'B';
  127. for(uint8_t i = 2;i < 10; i++)
  128. {
  129. uavr56_info.version[i] = '0';
  130. }
  131. }
  132. memcpy(&radar_version[2][0],&uavr56_info.version[0],10);
  133. }
  134. else if(mimo_ter_info.Link.connect_status == COMP_NORMAL)
  135. {
  136. if(mimo_ter_info.Link.boot_flag == true)
  137. {
  138. memcpy(&mimo_ter_info.version,"EB00000000",10);
  139. }
  140. memcpy(&radar_version[2][0],&mimo_ter_info.version[0],10);
  141. }
  142. }
  143. /**
  144. * @file check_radar_link_status
  145. * @brief 检查雷达连接函数
  146. * @param
  147. * @details
  148. * @author Zhang Sir
  149. **/
  150. void check_radar_link_status(void)
  151. {
  152. Check_dev_link(&mimo_ter_info.Link,3000,(char *)&mimo_ter_info,sizeof(uavr_terrain));
  153. Check_dev_link(&uavr56_info.Link,3000,(char *)&uavr56_info,sizeof(uavr_terrain));
  154. Check_dev_link(&uavr11_info.Link,3000,(char *)&uavr11_info,sizeof(uavr_obs));
  155. Check_dev_link(&uavr12_info.Link,3000,(char *)&uavr12_info,sizeof(uavr_obs));
  156. Check_dev_link(&mimo_f_info.Link,3000,(char *)&mimo_f_info,sizeof(uavr_obs));
  157. Check_dev_link(&mimo_b_info.Link,3000,(char *)&mimo_b_info,sizeof(uavr_obs));
  158. Check_dev_link(&mimo_360_info,3000,NULL,0);
  159. }
  160. /**
  161. * @file lidar_function
  162. * @brief 雷达相关函数
  163. * @param none
  164. * @details
  165. * @author Zhang Sir
  166. **/
  167. void send_mocib_radar_sensi(void)
  168. {
  169. //给FMU发送雷达灵敏度
  170. //上电后 检测到有雷达连接,向飞控发送雷达灵敏度信息
  171. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == true &&
  172. uavr11_info.send_fcu_sensi_count <= 3)
  173. {
  174. pmu_set_ack(22, 1, uavr11_info.get_radar_sensi,0);
  175. uavr11_info.send_fcu_sensi_count++;
  176. }
  177. else if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == true &&
  178. uavr12_info.send_fcu_sensi_count <= 3)
  179. {
  180. pmu_set_ack(22, 2, uavr12_info.get_radar_sensi,0);
  181. uavr12_info.send_fcu_sensi_count++;
  182. }
  183. else if (uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == true &&
  184. uavr56_info.send_fcu_sensi_count <= 3)
  185. {
  186. pmu_set_ack(22, 6, uavr56_info.get_radar_sensi,0);
  187. uavr56_info.send_fcu_sensi_count++;
  188. }
  189. }
  190. /**
  191. * @file can_send_info_to_mimo
  192. * @brief 给恩曌避障发送姿态信息
  193. * @param none
  194. * @details
  195. * @author Zhang Sir
  196. **/
  197. void can_send_info_to_mimo()
  198. {
  199. //static int mimofb_10HZ = 0;
  200. static int mimoatti_50HZ = 0;
  201. static int mimoatti2_50HZ = 0;
  202. int16_t index = 0;
  203. short tmpShort = 0;
  204. int8_t tmpChar = 0;
  205. uint8_t send_mimo_data[8] = {0};
  206. if(update_info.vk_dev_update_flag == true)
  207. return;
  208. if( mimo_f_info.Link.connect_status == COMP_NORMAL || mimo_b_info.Link.connect_status == COMP_NORMAL
  209. || mimo_360_info.connect_status == COMP_NORMAL || (Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && Dev.Part_radarT.facid == FAC_MIMO_RT))
  210. {
  211. if (HAL_GetTick() - mimoatti_50HZ > 19)
  212. {
  213. mimoatti_50HZ = HAL_GetTick();
  214. index = 0;
  215. // 横滚
  216. tmpShort = -planep.roll_angle;
  217. short2buf(&send_mimo_data[index], &tmpShort);
  218. index += 2;
  219. // 俯仰
  220. tmpShort = planep.pitch_angle;
  221. short2buf(&send_mimo_data[index], &tmpShort);
  222. index += 2;
  223. //航向
  224. if(planep.yaw < 0)
  225. tmpShort = planep.yaw + 360;
  226. else
  227. tmpShort = planep.yaw;
  228. short2buf(&send_mimo_data[index], &tmpShort);
  229. index += 2;
  230. // 前后速度
  231. tmpChar = (planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  232. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  233. 10; //0.1m/s
  234. send_mimo_data[index++] = tmpChar;
  235. //雷达安装俯仰角
  236. tmpChar = 0;
  237. send_mimo_data[index++] = tmpChar;
  238. Can_Send_Msg_Func(CANID1, send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO1, CAN_ID_EXT);
  239. }
  240. if(HAL_GetTick() - mimoatti2_50HZ > 21)
  241. {
  242. mimoatti2_50HZ = HAL_GetTick();
  243. index = 0;
  244. //高度
  245. tmpShort = planep.alt;
  246. short2buf(&send_mimo_data[index], &tmpShort);
  247. index += 2;
  248. //俯仰角速度
  249. tmpShort = 0;
  250. short2buf(&send_mimo_data[index], &tmpShort);
  251. index += 2;
  252. //横滚角速度
  253. tmpShort = 0;
  254. short2buf(&send_mimo_data[index], &tmpShort);
  255. index += 2;
  256. // 左右速度
  257. tmpChar = (planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  258. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  259. 10;
  260. send_mimo_data[index++] = tmpChar;
  261. //Z速度
  262. tmpChar = planep.alt_vel / 10; //0.1m/s
  263. send_mimo_data[index++] = tmpChar;
  264. Can_Send_Msg_Func(CANID1, send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO2, CAN_ID_EXT);
  265. }
  266. }
  267. }
  268. /**
  269. * @file can_set_radar_sensi
  270. * @brief 设置雷达灵敏度
  271. * @param none
  272. * @details
  273. * @author Zhang Sir
  274. **/
  275. uint32_t uavr20_sensi_time = 0;
  276. short obsfradar_sensitivity = 50;
  277. short obsbradar_sensitivity = 50;
  278. void can_set_radar_sensi()
  279. {
  280. static int radar_sensi_ack_time = 0;
  281. // 设置前雷达灵敏度
  282. if (uavr11_info.get_radar_sensi_flag == true &&
  283. uavr11_info.fcu_set_sensi_flag == true && uavr11_info.set_radar_sensi_count < 5 &&
  284. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr11_info.Link.connect_status == COMP_NORMAL)
  285. {
  286. uint8_t send_uavr20_sensi[3] = {0};
  287. uavr11_info.set_radar_sensi_count++;
  288. uavr20_sensi_time = HAL_GetTick();
  289. if (uavrhup_getr1_ack == false)
  290. {
  291. //设置灵敏度先进入boot模式 新版本不进入boot
  292. if(uavr11_info.soft_verison >= RADAR_NER_VERSION )
  293. {
  294. uavrhup_getr1_ack = true;
  295. }
  296. else
  297. {
  298. send_uavr20_sensi[0] = 0x11;
  299. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  300. }
  301. uavr11_info.set_radar_sensi_ack = false;
  302. }
  303. else
  304. {
  305. if (uavr11_info.set_radar_sensi_ack == false)
  306. {
  307. send_uavr20_sensi[0] = 0x11;
  308. //大端方式发送
  309. send_uavr20_sensi[1] = (obsfradar_sensitivity >> 8) & 0xff;
  310. send_uavr20_sensi[2] = (obsfradar_sensitivity)&0xff;
  311. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  312. }
  313. else
  314. {
  315. uavr11_info.fcu_set_sensi_flag = false;
  316. uavrhup_getr1_ack = false;
  317. uavr11_info.set_radar_sensi_ack = false;
  318. uavr11_info.set_radar_sensi_count = 0;
  319. }
  320. }
  321. //超过5次失败后恢复
  322. if (uavr11_info.set_radar_sensi_count >= 5)
  323. {
  324. uavr11_info.fcu_set_sensi_flag = false;
  325. uavrhup_getr1_ack = false;
  326. uavr11_info.set_radar_sensi_ack = false;
  327. uavr11_info.set_radar_sensi_count = 0;
  328. }
  329. }
  330. //设置后雷达灵敏度
  331. else if (uavr12_info.get_radar_sensi_flag == true &&
  332. uavr12_info.fcu_set_sensi_flag == true && uavr12_info.set_radar_sensi_count < 5 &&
  333. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr12_info.Link.connect_status == COMP_NORMAL)
  334. {
  335. uint8_t send_uavr20_sensi[3] = {0};
  336. uavr12_info.set_radar_sensi_count++;
  337. uavr20_sensi_time = HAL_GetTick();
  338. if (uavrhup_getr1_ack == false)
  339. {
  340. //设置灵敏度先进入boot模式 新版本不进入boot
  341. if(uavr12_info.soft_verison >= RADAR_NER_VERSION )
  342. {
  343. uavrhup_getr1_ack = true;
  344. }
  345. else
  346. {
  347. //设置灵敏度先进入boot模式
  348. send_uavr20_sensi[0] = 0x12;
  349. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  350. }
  351. uavr12_info.set_radar_sensi_ack = false;
  352. }
  353. else
  354. {
  355. if (uavr12_info.set_radar_sensi_ack == false)
  356. {
  357. send_uavr20_sensi[0] = 0x12;
  358. send_uavr20_sensi[1] = (obsbradar_sensitivity >> 8) & 0xff;
  359. send_uavr20_sensi[2] = (obsbradar_sensitivity)&0xff;
  360. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  361. }
  362. else
  363. {
  364. uavr12_info.fcu_set_sensi_flag = false;
  365. uavrhup_getr1_ack = false;
  366. uavr12_info.set_radar_sensi_ack = false;
  367. uavr12_info.set_radar_sensi_count = 0;
  368. }
  369. }
  370. //超过5次失败后恢复
  371. if (uavr12_info.set_radar_sensi_count >= 5)
  372. {
  373. uavr12_info.fcu_set_sensi_flag = false;
  374. uavrhup_getr1_ack = false;
  375. uavr12_info.set_radar_sensi_ack = false;
  376. uavr12_info.set_radar_sensi_count = 0;
  377. }
  378. }
  379. //设置仿地雷达灵敏度
  380. else if (uavr56_info.get_radar_sensi_flag == true &&
  381. uavr56_info.fcu_set_sensi_flag == true && uavr56_info.set_radar_sensi_count < 5 &&
  382. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr56_info.Link.connect_status == COMP_NORMAL)
  383. {
  384. uint8_t send_uavr20_sensi[3] = {0};
  385. uavr56_info.set_radar_sensi_count++;
  386. uavr20_sensi_time = HAL_GetTick();
  387. if (uavrhup_getr1_ack == false)
  388. {
  389. if(uavr56_info.soft_verison >= RADAR_NER_VERSION )
  390. {
  391. uavrhup_getr1_ack = true;
  392. }
  393. else
  394. {
  395. //设置灵敏度先进入boot模式
  396. send_uavr20_sensi[0] = 0x0B;
  397. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  398. }
  399. uavr56_info.set_radar_sensi_ack = false;
  400. }
  401. else
  402. {
  403. if (uavr56_info.set_radar_sensi_ack == false)
  404. {
  405. send_uavr20_sensi[0] = 0x0B;
  406. send_uavr20_sensi[1] = (uavr56_info.fcu_set_sensi >> 8) & 0xff;
  407. send_uavr20_sensi[2] = (uavr56_info.fcu_set_sensi)&0xff;
  408. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  409. }
  410. else
  411. {
  412. uavr56_info.fcu_set_sensi_flag = false;
  413. uavrhup_getr1_ack = false;
  414. uavr56_info.set_radar_sensi_ack = false;
  415. uavr56_info.set_radar_sensi_count = 0;
  416. }
  417. }
  418. //超过5次失败后恢复
  419. if (uavr56_info.set_radar_sensi_count >= 5)
  420. {
  421. uavr56_info.fcu_set_sensi_flag = false;
  422. uavrhup_getr1_ack = false;
  423. uavr56_info.set_radar_sensi_ack = false;
  424. uavr56_info.set_radar_sensi_count = 0;
  425. }
  426. }
  427. //设置莫之比避障灵敏度成功后ACK主控
  428. if (uavr11_info.set_radar_sensi_ack == true || uavr12_info.set_radar_sensi_ack == true || uavr56_info.set_radar_sensi_ack == true)
  429. {
  430. //同时设置有个1.5s间隔
  431. if(HAL_GetTick() - radar_sensi_ack_time > 1500)
  432. {
  433. radar_sensi_ack_time = HAL_GetTick();
  434. if (uavr11_info.set_radar_sensi_ack == true)
  435. {
  436. pmu_set_ack(22, 1, uavr11_info.get_radar_sensi,0);
  437. uavr11_info.set_radar_sensi_ack = false;
  438. uavr11_info.fcu_set_sensi_flag = false;
  439. }
  440. else if (uavr12_info.set_radar_sensi_ack == true)
  441. {
  442. pmu_set_ack(22, 2, uavr12_info.get_radar_sensi,0);
  443. uavr12_info.set_radar_sensi_ack = false;
  444. uavr12_info.fcu_set_sensi_flag = false;
  445. }
  446. else if(uavr56_info.set_radar_sensi_ack == true)
  447. {
  448. pmu_set_ack(22, 6, uavr56_info.get_radar_sensi,0);
  449. uavr56_info.set_radar_sensi_ack = false;
  450. uavr56_info.fcu_set_sensi_flag = false;
  451. }
  452. }
  453. }
  454. }
  455. /**
  456. * @file can_sendmsg_uavr20
  457. * @brief 给墨汁比雷达发送无人机姿态信息
  458. * @param none
  459. * @details
  460. * @author Zhang Sir
  461. **/
  462. uint32_t uavr20_send_time = 0;
  463. void can_sendmsg_uavr20(void)
  464. {
  465. if (uavr12_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.connect_status == COMP_NORMAL ||
  466. uavr56_info.Link.connect_status == COMP_NORMAL ||(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && Dev.Part_radarT.facid == FAC_MOCIB_RT ))
  467. {
  468. //10hz发送
  469. if ((HAL_GetTick() - uavr20_send_time > 100) && planep.lock_status == 1)
  470. {
  471. uavr20_send_time = HAL_GetTick();
  472. int16_t index = 0;
  473. short tmpShort = 0;
  474. uint8_t send_uavr20_data[16] = {0};
  475. // 开头
  476. send_uavr20_data[index++] = 0XA5;
  477. // 俯仰
  478. tmpShort = planep.pitch_angle;
  479. short2buf(&send_uavr20_data[index], &tmpShort);
  480. index += 2;
  481. // 前后速度
  482. tmpShort = planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  483. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD);
  484. short2buf(&send_uavr20_data[index], &tmpShort);
  485. index += 2;
  486. // 横滚
  487. tmpShort = planep.roll_angle;
  488. short2buf(&send_uavr20_data[index], &tmpShort);
  489. index += 2;
  490. // 左右速度
  491. tmpShort = planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  492. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD);
  493. short2buf(&send_uavr20_data[index], &tmpShort);
  494. index += 2;
  495. // 后边的都没用上
  496. // 上下加速度
  497. tmpShort = planep.alt_vel;
  498. short2buf(&send_uavr20_data[index], &tmpShort);
  499. index += 2;
  500. // 仿地最近距离
  501. tmpShort = 0;
  502. short2buf(&send_uavr20_data[index], &tmpShort);
  503. index += 2;
  504. // 仿地最远距离
  505. tmpShort = 0;
  506. short2buf(&send_uavr20_data[index], &tmpShort);
  507. index += 2;
  508. // 结束
  509. send_uavr20_data[index++] = 0X5A;
  510. Can_Send_Msg_Func(CANID1, send_uavr20_data, sizeof(send_uavr20_data), SEND_UAV20_MSG, CAN_ID_EXT);
  511. }
  512. //读取前雷达版本
  513. else
  514. {
  515. //读取前雷达灵敏度
  516. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  517. uavr11_info.get_radar_sensi_count < 5)
  518. {
  519. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  520. {
  521. // 开头
  522. uint8_t send_uavr20_sensi[1] = {0};
  523. send_uavr20_sensi[0] = 0x11;
  524. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  525. uavr20_sensi_time = HAL_GetTick();
  526. uavr11_info.get_radar_sensi_count++;
  527. }
  528. }
  529. else
  530. {
  531. //读取后雷达灵敏度
  532. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  533. uavr12_info.get_radar_sensi_count < 5)
  534. {
  535. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  536. {
  537. // 开头
  538. uint8_t send_uavr20_sensi[1] = {0};
  539. send_uavr20_sensi[0] = 0x12;
  540. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  541. uavr20_sensi_time = HAL_GetTick();
  542. uavr12_info.get_radar_sensi_count++;
  543. }
  544. }
  545. else if(uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  546. uavr56_info.get_radar_sensi_count < 5)
  547. {
  548. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  549. {
  550. // 开头
  551. uint8_t send_uavr20_sensi[1] = {0};
  552. send_uavr20_sensi[0] = 0x0B;
  553. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  554. uavr20_sensi_time = HAL_GetTick();
  555. uavr56_info.get_radar_sensi_count++;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. /**
  563. * @file check_radar_update
  564. * @brief 雷达升级检测
  565. * @param none
  566. * @details
  567. * @author Zhang Sir
  568. **/
  569. bool check_radar_update(void)
  570. {
  571. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  572. uavr12_info.get_radar_sensi_count < 5)
  573. {
  574. return false;
  575. }
  576. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  577. uavr11_info.get_radar_sensi_count < 5)
  578. {
  579. return false;
  580. }
  581. if (uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  582. uavr56_info.get_radar_sensi_count < 5)
  583. {
  584. return false;
  585. }
  586. if(uavr11_info.fcu_set_sensi_flag == true ||uavr12_info.fcu_set_sensi_flag == true
  587. || uavr56_info.fcu_set_sensi_flag == true)
  588. {
  589. return false;
  590. }
  591. return true;
  592. }
  593. /**
  594. * @file lidar_function
  595. * @brief 设置360雷达分区数
  596. * @param none
  597. * @details
  598. * @author Zhang Sir
  599. **/
  600. void lidar360_set_TotalSect(void)
  601. {
  602. if(mimo_360_info.connect_status == COMP_NORMAL && (mimo360_status.get_TotalSect_flag == true ||
  603. mimo360_status.set_TotalSect_flag == true))
  604. {
  605. uint8_t can_buf[8] = {0};
  606. static uint32_t cur_time = 0;
  607. if(Check_Timer_Ready(&cur_time,_1_HZ_))
  608. {
  609. if(mimo360_status.get_TotalSect_flag == true)
  610. {
  611. put_date_to_can(can_buf,0xAA,0x24,0x03,0x02,0x07,0x00,0x00,(0x24+0x03+0x02+0x07)&0xff);
  612. Can_Send_Msg_Func(CANID1, can_buf, 8, 0xFA, CAN_ID_STD);
  613. }
  614. if(mimo360_status.set_TotalSect_flag == true)
  615. {
  616. //设置12分区
  617. put_date_to_can(can_buf,0xAA,0x24,0x03,0x82,0x07,0xC,0x00,(0x24+0x03+0x82+0x07+0xC)&0xff);
  618. Can_Send_Msg_Func(CANID1, can_buf, 8, 0xFA, CAN_ID_STD);
  619. }
  620. }
  621. }
  622. }
  623. /**
  624. * @file lidar_function
  625. * @brief 雷达
  626. * @param none
  627. * @details
  628. * @author Zhang Sir
  629. **/
  630. void lidar_function(void)
  631. {
  632. //莫之比避障雷达升级
  633. if (radar_update_flag == true && uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true
  634. && uavr56_info.fcu_set_sensi_flag != true)
  635. {
  636. Rupdate.update_flag = true;
  637. Can_obstacle_update();
  638. }
  639. //设置莫之比避障雷达灵敏度
  640. can_set_radar_sensi();
  641. //雷达升级不再给雷达发送信息,莫之比雷达发送姿态信息
  642. if (radar_update_flag == false)
  643. {
  644. can_sendmsg_uavr20();
  645. }
  646. //给恩曌雷达发送姿态信息数据
  647. can_send_info_to_mimo();
  648. //设置360雷达分区数
  649. lidar360_set_TotalSect();
  650. //给恩曌雷达设置灵敏度信息
  651. //can_set_sensi_to_mimo();
  652. }