soft_radar_handle.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. (uavr12_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.connect_status == COMP_NORMAL || uavr56_info.Link.connect_status == COMP_NORMAL))
  211. {
  212. if(radar_update_flag == true)
  213. {
  214. return;
  215. }
  216. if (HAL_GetTick() - mimoatti_50HZ > 19)
  217. {
  218. mimoatti_50HZ = HAL_GetTick();
  219. index = 0;
  220. // 横滚
  221. tmpShort = -planep.roll_angle;
  222. short2buf(&send_mimo_data[index], &tmpShort);
  223. index += 2;
  224. // 俯仰
  225. tmpShort = planep.pitch_angle;
  226. short2buf(&send_mimo_data[index], &tmpShort);
  227. index += 2;
  228. //航向
  229. if(planep.yaw < 0)
  230. tmpShort = planep.yaw + 360;
  231. else
  232. tmpShort = planep.yaw;
  233. short2buf(&send_mimo_data[index], &tmpShort);
  234. index += 2;
  235. // 前后速度
  236. tmpChar = (planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  237. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  238. 10; //0.1m/s
  239. send_mimo_data[index++] = tmpChar;
  240. //雷达安装俯仰角
  241. tmpChar = 0;
  242. send_mimo_data[index++] = tmpChar;
  243. Can_Send_Msg_Func(CANID1, send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO1, CAN_ID_EXT);
  244. }
  245. if(HAL_GetTick() - mimoatti2_50HZ > 21)
  246. {
  247. mimoatti2_50HZ = HAL_GetTick();
  248. index = 0;
  249. //高度
  250. tmpShort = planep.alt;
  251. short2buf(&send_mimo_data[index], &tmpShort);
  252. index += 2;
  253. //俯仰角速度
  254. tmpShort = 0;
  255. short2buf(&send_mimo_data[index], &tmpShort);
  256. index += 2;
  257. //横滚角速度
  258. tmpShort = 0;
  259. short2buf(&send_mimo_data[index], &tmpShort);
  260. index += 2;
  261. // 左右速度
  262. tmpChar = (planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  263. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  264. 10;
  265. send_mimo_data[index++] = tmpChar;
  266. //Z速度
  267. tmpChar = planep.alt_vel / 10; //0.1m/s
  268. send_mimo_data[index++] = tmpChar;
  269. Can_Send_Msg_Func(CANID1, send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO2, CAN_ID_EXT);
  270. }
  271. }
  272. }
  273. /**
  274. * @file can_set_radar_sensi
  275. * @brief 设置雷达灵敏度
  276. * @param none
  277. * @details
  278. * @author Zhang Sir
  279. **/
  280. uint32_t uavr20_sensi_time = 0;
  281. short obsfradar_sensitivity = 50;
  282. short obsbradar_sensitivity = 50;
  283. void can_set_radar_sensi()
  284. {
  285. static int radar_sensi_ack_time = 0;
  286. // 设置前雷达灵敏度
  287. if (uavr11_info.get_radar_sensi_flag == true &&
  288. uavr11_info.fcu_set_sensi_flag == true && uavr11_info.set_radar_sensi_count < 5 &&
  289. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr11_info.Link.connect_status == COMP_NORMAL)
  290. {
  291. uint8_t send_uavr20_sensi[3] = {0};
  292. uavr11_info.set_radar_sensi_count++;
  293. uavr20_sensi_time = HAL_GetTick();
  294. if (uavrhup_getr1_ack == false)
  295. {
  296. //设置灵敏度先进入boot模式 新版本不进入boot
  297. if(uavr11_info.soft_verison >= RADAR_NER_VERSION )
  298. {
  299. uavrhup_getr1_ack = true;
  300. }
  301. else
  302. {
  303. send_uavr20_sensi[0] = 0x11;
  304. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  305. }
  306. uavr11_info.set_radar_sensi_ack = false;
  307. }
  308. else
  309. {
  310. if (uavr11_info.set_radar_sensi_ack == false)
  311. {
  312. send_uavr20_sensi[0] = 0x11;
  313. //大端方式发送
  314. send_uavr20_sensi[1] = (obsfradar_sensitivity >> 8) & 0xff;
  315. send_uavr20_sensi[2] = (obsfradar_sensitivity)&0xff;
  316. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  317. }
  318. else
  319. {
  320. uavr11_info.fcu_set_sensi_flag = false;
  321. uavrhup_getr1_ack = false;
  322. uavr11_info.set_radar_sensi_ack = false;
  323. uavr11_info.set_radar_sensi_count = 0;
  324. }
  325. }
  326. //超过5次失败后恢复
  327. if (uavr11_info.set_radar_sensi_count >= 5)
  328. {
  329. uavr11_info.fcu_set_sensi_flag = false;
  330. uavrhup_getr1_ack = false;
  331. uavr11_info.set_radar_sensi_ack = false;
  332. uavr11_info.set_radar_sensi_count = 0;
  333. }
  334. }
  335. //设置后雷达灵敏度
  336. else if (uavr12_info.get_radar_sensi_flag == true &&
  337. uavr12_info.fcu_set_sensi_flag == true && uavr12_info.set_radar_sensi_count < 5 &&
  338. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr12_info.Link.connect_status == COMP_NORMAL)
  339. {
  340. uint8_t send_uavr20_sensi[3] = {0};
  341. uavr12_info.set_radar_sensi_count++;
  342. uavr20_sensi_time = HAL_GetTick();
  343. if (uavrhup_getr1_ack == false)
  344. {
  345. //设置灵敏度先进入boot模式 新版本不进入boot
  346. if(uavr12_info.soft_verison >= RADAR_NER_VERSION )
  347. {
  348. uavrhup_getr1_ack = true;
  349. }
  350. else
  351. {
  352. //设置灵敏度先进入boot模式
  353. send_uavr20_sensi[0] = 0x12;
  354. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  355. }
  356. uavr12_info.set_radar_sensi_ack = false;
  357. }
  358. else
  359. {
  360. if (uavr12_info.set_radar_sensi_ack == false)
  361. {
  362. send_uavr20_sensi[0] = 0x12;
  363. send_uavr20_sensi[1] = (obsbradar_sensitivity >> 8) & 0xff;
  364. send_uavr20_sensi[2] = (obsbradar_sensitivity)&0xff;
  365. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  366. }
  367. else
  368. {
  369. uavr12_info.fcu_set_sensi_flag = false;
  370. uavrhup_getr1_ack = false;
  371. uavr12_info.set_radar_sensi_ack = false;
  372. uavr12_info.set_radar_sensi_count = 0;
  373. }
  374. }
  375. //超过5次失败后恢复
  376. if (uavr12_info.set_radar_sensi_count >= 5)
  377. {
  378. uavr12_info.fcu_set_sensi_flag = false;
  379. uavrhup_getr1_ack = false;
  380. uavr12_info.set_radar_sensi_ack = false;
  381. uavr12_info.set_radar_sensi_count = 0;
  382. }
  383. }
  384. //设置仿地雷达灵敏度
  385. else if (uavr56_info.get_radar_sensi_flag == true &&
  386. uavr56_info.fcu_set_sensi_flag == true && uavr56_info.set_radar_sensi_count < 5 &&
  387. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr56_info.Link.connect_status == COMP_NORMAL)
  388. {
  389. uint8_t send_uavr20_sensi[3] = {0};
  390. uavr56_info.set_radar_sensi_count++;
  391. uavr20_sensi_time = HAL_GetTick();
  392. if (uavrhup_getr1_ack == false)
  393. {
  394. if(uavr56_info.soft_verison >= RADAR_NER_VERSION )
  395. {
  396. uavrhup_getr1_ack = true;
  397. }
  398. else
  399. {
  400. //设置灵敏度先进入boot模式
  401. send_uavr20_sensi[0] = 0x0B;
  402. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1, CAN_ID_EXT);
  403. }
  404. uavr56_info.set_radar_sensi_ack = false;
  405. }
  406. else
  407. {
  408. if (uavr56_info.set_radar_sensi_ack == false)
  409. {
  410. send_uavr20_sensi[0] = 0x0B;
  411. send_uavr20_sensi[1] = (uavr56_info.fcu_set_sensi >> 8) & 0xff;
  412. send_uavr20_sensi[2] = (uavr56_info.fcu_set_sensi)&0xff;
  413. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA, CAN_ID_EXT);
  414. }
  415. else
  416. {
  417. uavr56_info.fcu_set_sensi_flag = false;
  418. uavrhup_getr1_ack = false;
  419. uavr56_info.set_radar_sensi_ack = false;
  420. uavr56_info.set_radar_sensi_count = 0;
  421. }
  422. }
  423. //超过5次失败后恢复
  424. if (uavr56_info.set_radar_sensi_count >= 5)
  425. {
  426. uavr56_info.fcu_set_sensi_flag = false;
  427. uavrhup_getr1_ack = false;
  428. uavr56_info.set_radar_sensi_ack = false;
  429. uavr56_info.set_radar_sensi_count = 0;
  430. }
  431. }
  432. //设置莫之比避障灵敏度成功后ACK主控
  433. if (uavr11_info.set_radar_sensi_ack == true || uavr12_info.set_radar_sensi_ack == true || uavr56_info.set_radar_sensi_ack == true)
  434. {
  435. //同时设置有个1.5s间隔
  436. if(HAL_GetTick() - radar_sensi_ack_time > 1500)
  437. {
  438. radar_sensi_ack_time = HAL_GetTick();
  439. if (uavr11_info.set_radar_sensi_ack == true)
  440. {
  441. pmu_set_ack(22, 1, uavr11_info.get_radar_sensi,0);
  442. uavr11_info.set_radar_sensi_ack = false;
  443. uavr11_info.fcu_set_sensi_flag = false;
  444. }
  445. else if (uavr12_info.set_radar_sensi_ack == true)
  446. {
  447. pmu_set_ack(22, 2, uavr12_info.get_radar_sensi,0);
  448. uavr12_info.set_radar_sensi_ack = false;
  449. uavr12_info.fcu_set_sensi_flag = false;
  450. }
  451. else if(uavr56_info.set_radar_sensi_ack == true)
  452. {
  453. pmu_set_ack(22, 6, uavr56_info.get_radar_sensi,0);
  454. uavr56_info.set_radar_sensi_ack = false;
  455. uavr56_info.fcu_set_sensi_flag = false;
  456. }
  457. }
  458. }
  459. }
  460. /**
  461. * @file can_sendmsg_uavr20
  462. * @brief 给墨汁比雷达发送无人机姿态信息
  463. * @param none
  464. * @details
  465. * @author Zhang Sir
  466. **/
  467. uint32_t uavr20_send_time = 0;
  468. void can_sendmsg_uavr20(void)
  469. {
  470. if (uavr12_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.connect_status == COMP_NORMAL ||
  471. uavr56_info.Link.connect_status == COMP_NORMAL ||(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && Dev.Part_radarT.facid == FAC_MOCIB_RT ))
  472. {
  473. //10hz发送
  474. if ((HAL_GetTick() - uavr20_send_time > 100) && planep.lock_status == 1)
  475. {
  476. uavr20_send_time = HAL_GetTick();
  477. int16_t index = 0;
  478. short tmpShort = 0;
  479. uint8_t send_uavr20_data[16] = {0};
  480. // 开头
  481. send_uavr20_data[index++] = 0XA5;
  482. // 俯仰
  483. tmpShort = planep.pitch_angle;
  484. short2buf(&send_uavr20_data[index], &tmpShort);
  485. index += 2;
  486. // 前后速度
  487. tmpShort = planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  488. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD);
  489. short2buf(&send_uavr20_data[index], &tmpShort);
  490. index += 2;
  491. // 横滚
  492. tmpShort = planep.roll_angle;
  493. short2buf(&send_uavr20_data[index], &tmpShort);
  494. index += 2;
  495. // 左右速度
  496. tmpShort = planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  497. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD);
  498. short2buf(&send_uavr20_data[index], &tmpShort);
  499. index += 2;
  500. // 后边的都没用上
  501. // 上下加速度
  502. tmpShort = planep.alt_vel;
  503. short2buf(&send_uavr20_data[index], &tmpShort);
  504. index += 2;
  505. // 仿地最近距离
  506. tmpShort = 0;
  507. short2buf(&send_uavr20_data[index], &tmpShort);
  508. index += 2;
  509. // 仿地最远距离
  510. tmpShort = 0;
  511. short2buf(&send_uavr20_data[index], &tmpShort);
  512. index += 2;
  513. // 结束
  514. send_uavr20_data[index++] = 0X5A;
  515. Can_Send_Msg_Func(CANID1, send_uavr20_data, sizeof(send_uavr20_data), SEND_UAV20_MSG, CAN_ID_EXT);
  516. }
  517. //读取前雷达版本
  518. else
  519. {
  520. //读取前雷达灵敏度
  521. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  522. uavr11_info.get_radar_sensi_count < 5)
  523. {
  524. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  525. {
  526. // 开头
  527. uint8_t send_uavr20_sensi[1] = {0};
  528. send_uavr20_sensi[0] = 0x11;
  529. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  530. uavr20_sensi_time = HAL_GetTick();
  531. uavr11_info.get_radar_sensi_count++;
  532. }
  533. }
  534. else
  535. {
  536. //读取后雷达灵敏度
  537. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  538. uavr12_info.get_radar_sensi_count < 5)
  539. {
  540. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  541. {
  542. // 开头
  543. uint8_t send_uavr20_sensi[1] = {0};
  544. send_uavr20_sensi[0] = 0x12;
  545. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  546. uavr20_sensi_time = HAL_GetTick();
  547. uavr12_info.get_radar_sensi_count++;
  548. }
  549. }
  550. else if(uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  551. uavr56_info.get_radar_sensi_count < 5)
  552. {
  553. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  554. {
  555. // 开头
  556. uint8_t send_uavr20_sensi[1] = {0};
  557. send_uavr20_sensi[0] = 0x0B;
  558. Can_Send_Msg_Func(CANID1, send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA, CAN_ID_EXT);
  559. uavr20_sensi_time = HAL_GetTick();
  560. uavr56_info.get_radar_sensi_count++;
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. /**
  568. * @file check_radar_update
  569. * @brief 雷达升级检测
  570. * @param none
  571. * @details
  572. * @author Zhang Sir
  573. **/
  574. bool check_radar_update(void)
  575. {
  576. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  577. uavr12_info.get_radar_sensi_count < 5)
  578. {
  579. return false;
  580. }
  581. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  582. uavr11_info.get_radar_sensi_count < 5)
  583. {
  584. return false;
  585. }
  586. if (uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  587. uavr56_info.get_radar_sensi_count < 5)
  588. {
  589. return false;
  590. }
  591. if(uavr11_info.fcu_set_sensi_flag == true ||uavr12_info.fcu_set_sensi_flag == true
  592. || uavr56_info.fcu_set_sensi_flag == true)
  593. {
  594. return false;
  595. }
  596. return true;
  597. }
  598. /**
  599. * @file lidar_function
  600. * @brief 设置360雷达分区数
  601. * @param none
  602. * @details
  603. * @author Zhang Sir
  604. **/
  605. void lidar360_set_TotalSect(void)
  606. {
  607. if(mimo_360_info.connect_status == COMP_NORMAL && (mimo360_status.get_TotalSect_flag == true ||
  608. mimo360_status.set_TotalSect_flag == true))
  609. {
  610. uint8_t can_buf[8] = {0};
  611. static uint32_t cur_time = 0;
  612. if(Check_Timer_Ready(&cur_time,_1_HZ_))
  613. {
  614. if(mimo360_status.get_TotalSect_flag == true)
  615. {
  616. put_date_to_can(can_buf,0xAA,0x24,0x03,0x02,0x07,0x00,0x00,(0x24+0x03+0x02+0x07)&0xff);
  617. Can_Send_Msg_Func(CANID1, can_buf, 8, 0xFA, CAN_ID_STD);
  618. }
  619. if(mimo360_status.set_TotalSect_flag == true)
  620. {
  621. //设置12分区
  622. put_date_to_can(can_buf,0xAA,0x24,0x03,0x82,0x07,0xC,0x00,(0x24+0x03+0x82+0x07+0xC)&0xff);
  623. Can_Send_Msg_Func(CANID1, can_buf, 8, 0xFA, CAN_ID_STD);
  624. }
  625. }
  626. }
  627. }
  628. /**
  629. * @file lidar_function
  630. * @brief 雷达
  631. * @param none
  632. * @details
  633. * @author Zhang Sir
  634. **/
  635. void lidar_function(void)
  636. {
  637. //莫之比避障雷达升级
  638. if (radar_update_flag == true )/*&& uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true
  639. && uavr56_info.fcu_set_sensi_flag != true)*/
  640. {
  641. Rupdate.update_flag = true;
  642. Can_obstacle_update();
  643. }
  644. //设置莫之比避障雷达灵敏度
  645. can_set_radar_sensi();
  646. //雷达升级不再给雷达发送信息,莫之比雷达发送姿态信息
  647. if (radar_update_flag == false)
  648. {
  649. can_sendmsg_uavr20();
  650. }
  651. //给恩曌雷达发送姿态信息数据
  652. can_send_info_to_mimo();
  653. //设置360雷达分区数
  654. lidar360_set_TotalSect();
  655. //给恩曌雷达设置灵敏度信息
  656. //can_set_sensi_to_mimo();
  657. }