soft_obstacle.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. #include "soft_obstacle.h"
  2. #include "tim.h"
  3. #include "string.h"
  4. #include "math.h"
  5. #include "soft_terrain.h"
  6. #include "soft_uart.h"
  7. #include "common.h"
  8. #include "soft_can.h"
  9. #include "soft_p_2_c.h"
  10. #include "stdlib.h"
  11. #include "soft_flow.h"
  12. #include "common.h"
  13. #include "soft_seed_device.h"
  14. #include "soft_water_device.h"
  15. #include "soft_version.h"
  16. #include "soft_eft.h"
  17. #include "common.h"
  18. uavr_obs uavr11_info = {.get_radar_sensi = 50};
  19. uavr_obs uavr12_info= {.get_radar_sensi = 50};
  20. uavr_obs mimo_f_info = {.signal_qulity = 0};
  21. uavr_obs mimo_b_info = {.signal_qulity = 0};
  22. uavr_obs DM_f_info;
  23. /**
  24. * @file can_recv_enzhao_obstacle
  25. * @brief 恩曌多点避障解析
  26. * @param none
  27. * @details
  28. * @author Zhang Sir
  29. **/
  30. mimo_part_radar F_radar[3];
  31. mimo_part_radar B_radar[3];
  32. uint8_t recv_comF_flag = 0,recv_comB_flag = 0;
  33. void can_recv_enzhao_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len)
  34. {
  35. switch (cellCanID)
  36. {
  37. case CAN_MIMO_FOBS_ID1:
  38. memcpy(&F_radar[0], data, 8);
  39. recv_comF_flag = recv_comF_flag | 1;
  40. Dev.Radar.facid_F = FAC_MIMO_RF;
  41. break;
  42. case CAN_MIMO_FOBS_ID2:
  43. memcpy(&F_radar[1], data, 8);
  44. recv_comF_flag = recv_comF_flag | 2;
  45. break;
  46. case CAN_MIMO_FOBS_ID3:
  47. memcpy(&F_radar[2], data, 8);
  48. recv_comF_flag = recv_comF_flag | 4;
  49. break;
  50. case CAN_MIMO_BOBS_ID1:
  51. memcpy(&B_radar[0], data, 8);
  52. recv_comB_flag = recv_comB_flag | 1;
  53. Dev.Radar.facid_F = FAC_MIMO_RB;
  54. break;
  55. case CAN_MIMO_BOBS_ID2:
  56. memcpy(&B_radar[1], data, 8);
  57. recv_comB_flag = recv_comB_flag | 2;
  58. break;
  59. case CAN_MIMO_BOBS_ID3:
  60. memcpy(&B_radar[2], data, 8);
  61. recv_comB_flag = recv_comB_flag | 4;
  62. break;
  63. default:
  64. break;
  65. }
  66. if(recv_comF_flag == 7)
  67. {
  68. recv_comF_flag = 0;
  69. mimo_buf_sort(&F_radar[0], 3);
  70. for (uint8_t i = 0; i < 3; i++)
  71. {
  72. //X轴小于4M内数据
  73. if (/*(abs(F_radar[i].Distance * 0.05f * 100 * sin(F_radar[i].Amuzith * 0.1f / RAD)) < 400) &&*/ F_radar[i].Distance > 0)
  74. {
  75. mimo_f_info.distance_x = F_radar[i].Distance * 0.05f * 100 * sin(F_radar[i].Amuzith * 0.1f / RAD);
  76. mimo_f_info.distance_y = F_radar[i].Distance * 0.05f * 100 * cos(F_radar[i].Amuzith * 0.1f / RAD);
  77. break;
  78. }
  79. if(i == 2)
  80. {
  81. mimo_f_info.distance_x = 0;
  82. mimo_f_info.distance_y = 0;
  83. }
  84. }
  85. mimo_f_info.Link.connect_status = COMP_NORMAL;
  86. mimo_f_info.Link.recv_time = HAL_GetTick();
  87. }
  88. if(recv_comB_flag == 7)
  89. {
  90. recv_comB_flag = 0;
  91. mimo_buf_sort(&B_radar[0], 3);
  92. for (uint8_t i = 0; i < 3; i++)
  93. {
  94. //X轴小于4M内数据
  95. if (/*(abs(B_radar[i].Distance * 0.05f * 100 * sin(B_radar[i].Amuzith * 0.1f / RAD)) < 400) &&*/ B_radar[i].Distance > 0)
  96. {
  97. mimo_b_info.distance_x = B_radar[i].Distance * 0.05f * 100 * sin(B_radar[i].Amuzith * 0.1f / RAD);
  98. mimo_b_info.distance_y = B_radar[i].Distance * 0.05f * 100 * cos(B_radar[i].Amuzith * 0.1f / RAD);
  99. break;
  100. }
  101. if(i == 2)
  102. {
  103. mimo_b_info.distance_x = 0;
  104. mimo_b_info.distance_y = 0;
  105. }
  106. }
  107. mimo_b_info.Link.recv_time = HAL_GetTick();
  108. mimo_b_info.Link.connect_status = COMP_NORMAL;
  109. }
  110. }
  111. /**
  112. * @file can_recv_enzhao_obstacle
  113. * @brief 恩曌单避障解析
  114. * @param none
  115. * @details
  116. * @author Zhang Sir
  117. **/
  118. void can_recv_mimo_signal_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len)
  119. {
  120. uint16_t frame_header = 0;
  121. memcpy(&frame_header,&data[0],2);
  122. if(frame_header == 0x5AA5 && data[2] == 0x04)
  123. {
  124. switch (cellCanID)
  125. {
  126. case CAN_MIMO_FOBS_SIG:
  127. mimo_f_info.distance_y = data[3] + data[4] * 256;
  128. mimo_f_info.signal_qulity = data[5];
  129. mimo_f_info.Link.recv_time = HAL_GetTick();
  130. mimo_f_info.Link.connect_status = COMP_NORMAL;
  131. Dev.Radar.facid_F = FAC_MIMO_RF;
  132. break;
  133. case CAN_MIMO_BOBS_SIG:
  134. mimo_b_info.distance_y = data[3] + data[4] * 256;
  135. mimo_b_info.signal_qulity = data[5];
  136. mimo_b_info.Link.recv_time = HAL_GetTick();
  137. mimo_b_info.Link.connect_status = COMP_NORMAL;
  138. Dev.Radar.facid_B = FAC_MIMO_RB;
  139. break;
  140. default:
  141. break;
  142. }
  143. }
  144. }
  145. /**
  146. * @file can_recv_mimo_radar_version
  147. * @brief 恩曌设备版本获取
  148. * @param none
  149. * @details
  150. * @author Zhang Sir
  151. **/
  152. void can_recv_mimo_radar_version(uint32_t cellCanID, uint8_t data[], uint8_t len)
  153. {
  154. static uint8_t mimo_version[28] = {0};
  155. static uint8_t frame_num = 0;
  156. static bool frame_head = false;
  157. uint8_t i = 0;
  158. uint32_t checksum = 0;
  159. uint32_t soft_ver = 0;
  160. switch (cellCanID)
  161. {
  162. case 0XFB:
  163. if(data[0] == 0XAA && data[1] == 0X55)
  164. {
  165. if(data[2] == 0X03 && data[3] == 0X61 && data[4] == 0X03 && data[5] == 0X01 && data[6] == 0X65)
  166. {
  167. pmu_set_ack(_MSGID_SET,MSGID_SET_RADAR_FB,0x11,0);
  168. }
  169. else if(data[2] == 0X03 && data[3] == 0X61 && data[4] == 0X03 && data[5] == 0X02 && data[6] == 0X66)
  170. {
  171. pmu_set_ack(_MSGID_SET,MSGID_SET_RADAR_FB,0x12,0);
  172. }
  173. else if(data[2] == 0X03 && data[3] == 0X61 && data[4] == 0X00 && data[5] == 0X03 && data[6] == 0X64)
  174. {
  175. pmu_set_ack(_MSGID_SET,MSGID_SET_RADAR_FB,0x100,0);
  176. }
  177. else
  178. {
  179. frame_num = 0;
  180. memcpy(&mimo_version[frame_num],&data[4],4);
  181. frame_num += 4;
  182. frame_head = true;
  183. }
  184. }
  185. //断料记
  186. else if(data[0] == 0xFB && data[1] == 0x03 && data[2] == 0)
  187. {
  188. //设置距离最大值反馈
  189. if(data[3] == 0xB1 && data[4] == 0xc1 && data[5] == 0)
  190. {
  191. pmu_set_ack(_MSGID_SET,MSGID_SET_LACKLOSS_CAL,mimo_lackloss.cal_distance,mimo_lackloss.strength);
  192. }
  193. }
  194. //流量计
  195. else if(data[0] == 0xFB && data[1] == 0x10) //雷达版本和流量计协议有冲突
  196. {
  197. switch (data[2])
  198. {
  199. case 0:
  200. if(data[4] == 0XD1) //流速K
  201. {
  202. flow_mimo1.flow_k = data[5] * 256 + data[6];
  203. }
  204. else if(data[4] == 0XC1)//设置流速K ack
  205. {
  206. if(data[6] == 0)
  207. {
  208. flow_mimo1.flow_k = flow_mimo1.flow_calk;
  209. if(Dev.Flow_Link1.connect_status == COMP_NORMAL && Dev.Flow_Link2.connect_status != COMP_NORMAL)
  210. {
  211. pmu_set_ack(_MSGID_SET,MSGID_SET_MIMO_FLOW,flow_mimo1.flow_k,0);
  212. }
  213. }
  214. }
  215. else if(data[4] == 0xE2)
  216. {
  217. if(data[6] == 0 && Dev.Flow_Link1.connect_status == COMP_NORMAL && Dev.Flow_Link2.connect_status != COMP_NORMAL)
  218. {
  219. pmu_set_ack(_MSGID_SET,MSGID_SET_FLOW_BACKGROUND,0,0);
  220. }
  221. flow_inf.ch1.clear_background = false;
  222. }
  223. else if (data[4] == 0XEB)//sn 两包 协议冲突 协议有问题
  224. {
  225. for( i= 0;i<2;i++) //内容第一自字节0X0F?先舍弃一字节,
  226. {
  227. flow_mimo1.sn[2*i] = ((data[6 + i] >> 4) & 0xf) + '0';
  228. flow_mimo1.sn[2*i+1] = (data[6 + i] & 0xf )+ '0';
  229. }
  230. frame_num = 21;//流量序列号的标记
  231. }
  232. else if(data[4] == 0XEC)//软件号
  233. {
  234. flow_mimo1.soft_version[0] = data[5] + '0';
  235. flow_mimo1.soft_version[1] = data[6] + '0';
  236. }
  237. break;
  238. case 1:
  239. if(data[4] == 0XD1)
  240. {
  241. flow_mimo2.flow_k = data[5] * 256 + data[6];
  242. }
  243. else if(data[4] == 0XC1)
  244. {
  245. if(data[6] == 0)
  246. {
  247. flow_mimo2.flow_k = flow_mimo2.flow_calk;
  248. if(Dev.Flow_Link1.connect_status == COMP_NORMAL && Dev.Flow_Link2.connect_status == COMP_NORMAL)
  249. {
  250. pmu_set_ack(_MSGID_SET,MSGID_SET_MIMO_FLOW,flow_mimo1.flow_k,flow_mimo2.flow_k);
  251. }
  252. else if(Dev.Flow_Link1.connect_status != COMP_NORMAL && Dev.Flow_Link2.connect_status == COMP_NORMAL)
  253. {
  254. pmu_set_ack(_MSGID_SET,MSGID_SET_MIMO_FLOW,0,flow_mimo2.flow_k);
  255. }
  256. }
  257. }
  258. else if(data[4] == 0xE2)
  259. {
  260. if(data[6] == 0 && Dev.Flow_Link1.connect_status == COMP_NORMAL && Dev.Flow_Link2.connect_status == COMP_NORMAL)
  261. {
  262. pmu_set_ack(_MSGID_SET,MSGID_SET_FLOW_BACKGROUND,0,0);
  263. }
  264. flow_inf.ch1.clear_background = false;
  265. }
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. else
  272. {
  273. if(frame_num == 21)
  274. {
  275. for( i=0;i<5;i++)
  276. {
  277. flow_mimo1.sn[4+2*i] = ((data[i] >> 4) & 0xf) + '0';
  278. flow_mimo1.sn[4+2*i+1] = (data[i] & 0xf )+ '0';
  279. }
  280. //flow_mimo1.sn[1] = 'F';
  281. frame_num = 0;
  282. }
  283. if(frame_num <= 20)
  284. {
  285. if(frame_head == true)
  286. {
  287. memcpy(&mimo_version[frame_num],&data[0],8);
  288. frame_num += 8;
  289. }
  290. if(frame_num == 0x1c) //恩曌SN取中间日期12位,其他有问题
  291. {
  292. checksum = 0x01;
  293. for(uint8_t i = 0; i < 27; i++)
  294. {
  295. checksum += mimo_version[i];
  296. }
  297. if((checksum & 0xFF) == mimo_version[27])
  298. {
  299. memcpy(&soft_ver,&mimo_version[23],4);
  300. switch (mimo_version[18])
  301. {
  302. case 0x00:
  303. mimo_ter_info.version[0] = 'E';
  304. mimo_ter_info.version[1] = 'B';
  305. mimo_ter_info.version[2] = '0';
  306. mimo_ter_info.version[3] = '0';
  307. Int2String(soft_ver,&mimo_ter_info.version[4],6);
  308. memcpy(&mimo_ter_info.hard_version,&mimo_version[19],4);
  309. if(mimo_ter_info.hard_version == 210221)
  310. {
  311. mimo_ter_info.version[3] = 'J';
  312. }
  313. for( i= 0;i<9;i++)
  314. {
  315. mimo_ter_info.sn[2*i] = ((mimo_version[7 + i] >> 4) & 0xf) + '0';
  316. mimo_ter_info.sn[2*i+1] = (mimo_version[7 + i] & 0xf )+ '0';
  317. }
  318. //memcpy(&mimo_ter_info.sn[0],&mimo_version[4],18);
  319. regist_dev_info(&dev_ter,DEVICE_TERRA,false,mimo_ter_info.sn,18,mimo_ter_info.version,10,NULL,0,"mimo",5);
  320. mimo_ter_info.get_radar_ver_flag = true;
  321. mimo_ter_info.Link.boot_flag = false;
  322. break;
  323. case 0x03:
  324. mimo_f_info.version[0] = 'E';
  325. mimo_f_info.version[1] = '1';
  326. mimo_f_info.version[2] = '0';
  327. mimo_f_info.version[3] = '0';
  328. Int2String(soft_ver,&mimo_f_info.version[4],6);
  329. memcpy(&mimo_f_info.hard_version,&mimo_version[19],4);
  330. if(mimo_f_info.hard_version == 190302) //恩曌协议定义
  331. {
  332. mimo_f_info.version[2] = '1'; //极翼
  333. mimo_f_info.version[3] = 'J';
  334. }
  335. else
  336. {
  337. mimo_f_info.version[2] = '0'; //vk
  338. mimo_f_info.version[3] = 'V';
  339. }
  340. for( i= 0;i<9;i++)
  341. {
  342. mimo_f_info.sn[2*i] = ((mimo_version[7 + i] >> 4) & 0xf) + '0';
  343. mimo_f_info.sn[2*i+1] = (mimo_version[7 + i] & 0xf )+ '0';
  344. }
  345. //memcpy(&mimo_f_info.sn[0],&mimo_version[4],12);
  346. regist_dev_info(&dev_obsf,DEVICE_OBSF,false,mimo_f_info.sn,18,mimo_f_info.version,10,mimo_f_info.version,10,"mimo",5);
  347. mimo_f_info.get_radar_ver_flag = true;
  348. mimo_f_info.Link.boot_flag = false;
  349. break;
  350. case 0x04:
  351. mimo_b_info.version[0] = 'E';
  352. mimo_b_info.version[1] = '2';
  353. mimo_b_info.version[2] = '0';
  354. mimo_b_info.version[3] = '0';
  355. Int2String(soft_ver,&mimo_b_info.version[4],6);
  356. memcpy(&mimo_b_info.hard_version,&mimo_version[19],4);
  357. if(mimo_b_info.hard_version == 190302) //恩曌协议定义
  358. {
  359. mimo_b_info.version[2] = '1'; //极翼
  360. mimo_b_info.version[3] = 'J';
  361. }
  362. else
  363. {
  364. mimo_b_info.version[2] = '0'; //vk
  365. mimo_b_info.version[3] = 'V';
  366. }
  367. for( i= 0;i<9;i++)
  368. {
  369. mimo_b_info.sn[2*i] = ((mimo_version[7 + i] >> 4) & 0xf) + '0';
  370. mimo_b_info.sn[2*i+1] = (mimo_version[7 + i] & 0xf )+ '0';
  371. }
  372. //memcpy(&mimo_b_info.sn[0],&mimo_version[4],12);
  373. regist_dev_info(&dev_obsb,DEVICE_OBSB,false,mimo_b_info.sn,18,mimo_b_info.version,10,mimo_b_info.version,10,"mimo",5);
  374. mimo_b_info.get_radar_ver_flag = true;
  375. mimo_b_info.Link.boot_flag = false;
  376. break;
  377. default:
  378. break;
  379. }
  380. frame_num = 0;
  381. frame_head = false;
  382. pmu_send = PMU_SEND_VERSION;
  383. }
  384. }
  385. }
  386. else
  387. {
  388. }
  389. }
  390. // char_to_hex_string(&data[5], 3, &mimo_ter_info.version[4], 6, "00");
  391. // mimo_ter_info.soft_verison = ((data[5] & 0xff) << 16) + ((data[6] & 0xff) << 8) + (data[7] & 0xff);
  392. break;
  393. default:
  394. break;
  395. }
  396. }
  397. /**
  398. * @file can_recv_mocib_F_obstacle
  399. * @brief 莫之比前避障解析
  400. * @param none
  401. * @details
  402. * @author Zhang Sir
  403. **/
  404. bool obs_f_is_link = false;
  405. void can_recv_mocib_F_obstacle(uint8_t *data)
  406. {
  407. uavr11_info.distance_x= (data[0] << 8) + data[1] - 32768;
  408. uavr11_info.distance_y = (data[2] << 8) + data[3];
  409. // if(abs(uavr11_info.distance_x) > 400)
  410. // {
  411. // uavr11_info.distance_y = 0;
  412. // uavr11_info.distance_x = 0;
  413. // }
  414. uavr11_info.Link.connect_status = COMP_NORMAL;
  415. uavr11_info.Link.recv_time = HAL_GetTick();
  416. }
  417. // /**
  418. // * @brief 恩曌360雷达
  419. // */
  420. // #pragma pack(push)
  421. // #pragma pack(1)
  422. // typedef struct
  423. // {
  424. // uint8_t totalSect; //总分区数
  425. // uint8_t validSect; // 有效分区数
  426. // uint8_t cycleCounter;
  427. // uint8_t reserve0;
  428. // uint32_t reserve : 20;
  429. // uint32_t height : 12; // 精度 0.01m
  430. // } FrameHeader1S;
  431. // typedef struct
  432. // {
  433. // uint8_t sectID; //分区 ID
  434. // uint16_t dis; //距离
  435. // int16_t ele;
  436. // uint8_t rcs; //目标雷达截面积
  437. // int16_t reserve1;
  438. // } SectionPackS;
  439. // typedef struct
  440. // {
  441. // uint32_t ID;
  442. // uint8_t data[8];
  443. // } CanMessage_t;
  444. // #pragma pack(pop)
  445. // #define MAX_SECTNUM 180
  446. // typedef struct
  447. // {
  448. // uint32_t totalSect; //总分区个数,数组中对应位置对应目标所在分区
  449. // uint32_t validSect; //总分区个数,数组中对应位置对应目标所在分区
  450. // uint32_t completeQ; // 0 代表无数据 1 代表数据接收到但不全 2 代表全部接收成功
  451. // float height;
  452. // float dis[MAX_SECTNUM]; // 雷达到目标距离,当目标不存在时距离为
  453. // float ele[MAX_SECTNUM]; // 目标的 RCS
  454. // float rcs[MAX_SECTNUM]; // 目标的 RCS
  455. // } TargetInfoS; // 原始目标结构信息
  456. // TargetInfoS Targetbuffer = {0}; // 用于缓存
  457. // TargetInfoS TargetOut = {0};
  458. // static int LastSection = -1;
  459. // int ValidSect = 0;
  460. // comp_status mimo360_link_status = COMP_NOEXIST;
  461. // void can_recv_mocib_360_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len)
  462. // {
  463. // int index;
  464. // CanMessage_t *can_tmp_ptr = NULL;
  465. // CanMessage_t can_tmp;
  466. // FrameHeader1S *frameHead_ptr;
  467. // SectionPackS *pack_ptr;
  468. // can_tmp_ptr = &can_tmp;
  469. // can_tmp_ptr->ID = cellCanID;
  470. // memcpy(&can_tmp_ptr->data[0], data, len);
  471. // mimo360_link_status = COMP_NORMAL;
  472. // if (can_tmp_ptr->ID == 0x301) // 检测到帧头
  473. // {
  474. // if (Targetbuffer.completeQ == 1) // 如果数据未接完
  475. // {
  476. // memcpy(&TargetOut, &Targetbuffer, sizeof(Targetbuffer));
  477. // }
  478. // memset(&Targetbuffer, 0, sizeof(Targetbuffer));
  479. // frameHead_ptr = (FrameHeader1S *)can_tmp_ptr->data;
  480. // Targetbuffer.totalSect = frameHead_ptr->totalSect;
  481. // Targetbuffer.height = frameHead_ptr->height / 100.0F;
  482. // if (frameHead_ptr->validSect == 0) // 如果不存在分区数据
  483. // {
  484. // Targetbuffer.completeQ = 2;
  485. // Targetbuffer.validSect = 0;
  486. // memcpy(&TargetOut, &Targetbuffer, sizeof(Targetbuffer));
  487. // }
  488. // else // 如果存在分区数据
  489. // {
  490. // ValidSect = frameHead_ptr->validSect;
  491. // Targetbuffer.completeQ = 1;
  492. // }
  493. // LastSection = -1;
  494. // }
  495. // else if (can_tmp_ptr->ID == 0x302) // 检测到目标数据
  496. // {
  497. // pack_ptr = (SectionPackS *)can_tmp_ptr->data;
  498. // if (Targetbuffer.completeQ == 1) //如果数据未接收完
  499. // {
  500. // index = pack_ptr->sectID; //获取分区 ID
  501. // if (LastSection == -1)
  502. // {
  503. // Targetbuffer.dis[index] = pack_ptr->dis * 0.01F;
  504. // Targetbuffer.ele[index] = pack_ptr->ele * 0.01F;
  505. // Targetbuffer.rcs[index] = pack_ptr->rcs;
  506. // Targetbuffer.validSect++;
  507. // LastSection = index;
  508. // }
  509. // else if (LastSection < index) //分区数据是按照从小到大输出才是正确的
  510. // {
  511. // Targetbuffer.dis[index] = pack_ptr->dis * 0.01F;
  512. // Targetbuffer.ele[index] = pack_ptr->ele * 0.1F;
  513. // Targetbuffer.rcs[index] = pack_ptr->rcs;
  514. // Targetbuffer.validSect++;
  515. // }
  516. // else // 如果不是则存在丢失包含帧 ID 的多个数据包
  517. // {
  518. // Targetbuffer.completeQ = 0; //数据不保存
  519. // }
  520. // if (Targetbuffer.completeQ == 1)
  521. // {
  522. // if (ValidSect == Targetbuffer.validSect) //有效个数等于实际接收个数
  523. // {
  524. // Targetbuffer.completeQ = 2;
  525. // memcpy(&TargetOut, &Targetbuffer, sizeof(Targetbuffer));
  526. // memset(&Targetbuffer, 0, sizeof(Targetbuffer));
  527. // }
  528. // }
  529. // }
  530. // }
  531. // }
  532. /**
  533. * @file can_recv_mocib_B_obstacle
  534. * @brief 莫之比后避障障解析
  535. * @param none
  536. * @details
  537. * @author Zhang Sir
  538. **/
  539. bool obs_b_is_link = false;
  540. void can_recv_mocib_B_obstacle(uint8_t *data)
  541. {
  542. uavr12_info.distance_x = (data[0] << 8) + data[1] - 32768;
  543. uavr12_info.distance_y = (data[2] << 8) + data[3];
  544. // if(abs(uavr12_info.distance_x) > 400)
  545. // {
  546. // uavr12_info.distance_x = 0;
  547. // uavr12_info.distance_y = 0;
  548. // }
  549. uavr12_info.Link.connect_status = COMP_NORMAL;
  550. uavr12_info.Link.recv_time = HAL_GetTick();
  551. }
  552. uint32_t uavr20_ver_time = 0;
  553. uint32_t uavr20_sensi_time = 0;
  554. char can_get_uavr21_ver_comp = 0;
  555. /**
  556. * @file can_sendmsg_uavr20
  557. * @brief 给墨汁比雷达发送无人机姿态信息
  558. * @param none
  559. * @details
  560. * @author Zhang Sir
  561. **/
  562. uint32_t uavr20_send_time = 0;
  563. void can_sendmsg_uavr20(void)
  564. {
  565. if (uavr12_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.connect_status == COMP_NORMAL ||
  566. uavr56_info.Link.connect_status == COMP_NORMAL)
  567. {
  568. //10hz发送
  569. if ((HAL_GetTick() - uavr20_send_time > 100) && planep.lock_status == 1)
  570. {
  571. uavr20_send_time = HAL_GetTick();
  572. int16_t index = 0;
  573. short tmpShort = 0;
  574. uint8_t send_uavr20_data[16] = {0};
  575. // 开头
  576. send_uavr20_data[index++] = 0XA5;
  577. // 俯仰
  578. tmpShort = planep.pitch_angle;
  579. short2buf(&send_uavr20_data[index], &tmpShort);
  580. index += 2;
  581. // 前后速度
  582. tmpShort = planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  583. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD);
  584. short2buf(&send_uavr20_data[index], &tmpShort);
  585. index += 2;
  586. // 横滚
  587. tmpShort = planep.roll_angle;
  588. short2buf(&send_uavr20_data[index], &tmpShort);
  589. index += 2;
  590. // 左右速度
  591. tmpShort = planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  592. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD);
  593. short2buf(&send_uavr20_data[index], &tmpShort);
  594. index += 2;
  595. // 后边的都没用上
  596. // 上下加速度
  597. tmpShort = planep.alt_vel;
  598. short2buf(&send_uavr20_data[index], &tmpShort);
  599. index += 2;
  600. // 仿地最近距离
  601. tmpShort = uavh30_dist.near;
  602. short2buf(&send_uavr20_data[index], &tmpShort);
  603. index += 2;
  604. // 仿地最远距离
  605. tmpShort = uavh30_dist.far;
  606. short2buf(&send_uavr20_data[index], &tmpShort);
  607. index += 2;
  608. // 结束
  609. send_uavr20_data[index++] = 0X5A;
  610. can_send_msg_normal(send_uavr20_data, sizeof(send_uavr20_data), SEND_UAV20_MSG);
  611. }
  612. //读取前雷达版本
  613. else
  614. {
  615. //读取前雷达灵敏度
  616. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  617. uavr11_info.get_radar_sensi_count < 5)
  618. {
  619. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  620. {
  621. // 开头
  622. uint8_t send_uavr20_sensi[1] = {0};
  623. send_uavr20_sensi[0] = 0x11;
  624. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA);
  625. uavr20_sensi_time = HAL_GetTick();
  626. uavr11_info.get_radar_sensi_count++;
  627. }
  628. }
  629. else
  630. {
  631. //读取后雷达灵敏度
  632. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  633. uavr12_info.get_radar_sensi_count < 5)
  634. {
  635. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  636. {
  637. // 开头
  638. uint8_t send_uavr20_sensi[1] = {0};
  639. send_uavr20_sensi[0] = 0x12;
  640. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA);
  641. uavr20_sensi_time = HAL_GetTick();
  642. uavr12_info.get_radar_sensi_count++;
  643. }
  644. }
  645. else if(uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  646. uavr56_info.get_radar_sensi_count < 5)
  647. {
  648. if (HAL_GetTick() - uavr20_sensi_time > 1000)
  649. {
  650. // 开头
  651. uint8_t send_uavr20_sensi[1] = {0};
  652. send_uavr20_sensi[0] = 0x0B;
  653. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_SENSI_RA);
  654. uavr20_sensi_time = HAL_GetTick();
  655. uavr56_info.get_radar_sensi_count++;
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. bool uavrhup_getr1_ack = false;
  663. short obsfradar_sensitivity = 50;
  664. short obsbradar_sensitivity = 50;
  665. /**
  666. * @file can_set_radar_sensi
  667. * @brief 设置雷达灵敏度
  668. * @param none
  669. * @details
  670. * @author Zhang Sir
  671. **/
  672. void can_set_radar_sensi()
  673. {
  674. static int radar_sensi_ack_time = 0;
  675. // 设置前雷达灵敏度
  676. if (uavr11_info.get_radar_sensi_flag == true &&
  677. uavr11_info.fcu_set_sensi_flag == true && uavr11_info.set_radar_sensi_count < 5 &&
  678. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr11_info.Link.connect_status == COMP_NORMAL)
  679. {
  680. uint8_t send_uavr20_sensi[3] = {0};
  681. uavr11_info.set_radar_sensi_count++;
  682. uavr20_sensi_time = HAL_GetTick();
  683. if (uavrhup_getr1_ack == false)
  684. {
  685. //设置灵敏度先进入boot模式 新版本不进入boot
  686. if(uavr11_info.soft_verison >= RADAR_NER_VERSION )
  687. {
  688. uavrhup_getr1_ack = true;
  689. }
  690. else
  691. {
  692. send_uavr20_sensi[0] = 0x11;
  693. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1);
  694. }
  695. uavr11_info.set_radar_sensi_ack = false;
  696. }
  697. else
  698. {
  699. if (uavr11_info.set_radar_sensi_ack == false)
  700. {
  701. send_uavr20_sensi[0] = 0x11;
  702. //大端方式发送
  703. send_uavr20_sensi[1] = (obsfradar_sensitivity >> 8) & 0xff;
  704. send_uavr20_sensi[2] = (obsfradar_sensitivity)&0xff;
  705. can_send_msg_normal(send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA);
  706. }
  707. else
  708. {
  709. uavr11_info.fcu_set_sensi_flag = false;
  710. uavrhup_getr1_ack = false;
  711. uavr11_info.set_radar_sensi_ack = false;
  712. uavr11_info.set_radar_sensi_count = 0;
  713. }
  714. }
  715. //超过5次失败后恢复
  716. if (uavr11_info.set_radar_sensi_count >= 5)
  717. {
  718. uavr11_info.fcu_set_sensi_flag = false;
  719. uavrhup_getr1_ack = false;
  720. uavr11_info.set_radar_sensi_ack = false;
  721. uavr11_info.set_radar_sensi_count = 0;
  722. }
  723. }
  724. //设置后雷达灵敏度
  725. else if (uavr12_info.get_radar_sensi_flag == true &&
  726. uavr12_info.fcu_set_sensi_flag == true && uavr12_info.set_radar_sensi_count < 5 &&
  727. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr12_info.Link.connect_status == COMP_NORMAL)
  728. {
  729. uint8_t send_uavr20_sensi[3] = {0};
  730. uavr12_info.set_radar_sensi_count++;
  731. uavr20_sensi_time = HAL_GetTick();
  732. if (uavrhup_getr1_ack == false)
  733. {
  734. //设置灵敏度先进入boot模式 新版本不进入boot
  735. if(uavr12_info.soft_verison >= RADAR_NER_VERSION )
  736. {
  737. uavrhup_getr1_ack = true;
  738. }
  739. else
  740. {
  741. //设置灵敏度先进入boot模式
  742. send_uavr20_sensi[0] = 0x12;
  743. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1);
  744. }
  745. uavr12_info.set_radar_sensi_ack = false;
  746. }
  747. else
  748. {
  749. if (uavr12_info.set_radar_sensi_ack == false)
  750. {
  751. send_uavr20_sensi[0] = 0x12;
  752. send_uavr20_sensi[1] = (obsbradar_sensitivity >> 8) & 0xff;
  753. send_uavr20_sensi[2] = (obsbradar_sensitivity)&0xff;
  754. can_send_msg_normal(send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA);
  755. }
  756. else
  757. {
  758. uavr12_info.fcu_set_sensi_flag = false;
  759. uavrhup_getr1_ack = false;
  760. uavr12_info.set_radar_sensi_ack = false;
  761. uavr12_info.set_radar_sensi_count = 0;
  762. }
  763. }
  764. //超过5次失败后恢复
  765. if (uavr12_info.set_radar_sensi_count >= 5)
  766. {
  767. uavr12_info.fcu_set_sensi_flag = false;
  768. uavrhup_getr1_ack = false;
  769. uavr12_info.set_radar_sensi_ack = false;
  770. uavr12_info.set_radar_sensi_count = 0;
  771. }
  772. }
  773. //设置仿地雷达灵敏度
  774. else if (uavr56_info.get_radar_sensi_flag == true &&
  775. uavr56_info.fcu_set_sensi_flag == true && uavr56_info.set_radar_sensi_count < 5 &&
  776. HAL_GetTick() - uavr20_sensi_time > 1000 && uavr56_info.Link.connect_status == COMP_NORMAL)
  777. {
  778. uint8_t send_uavr20_sensi[3] = {0};
  779. uavr56_info.set_radar_sensi_count++;
  780. uavr20_sensi_time = HAL_GetTick();
  781. if (uavrhup_getr1_ack == false)
  782. {
  783. if(uavr56_info.soft_verison >= RADAR_NER_VERSION )
  784. {
  785. uavrhup_getr1_ack = true;
  786. }
  787. else
  788. {
  789. //设置灵敏度先进入boot模式
  790. send_uavr20_sensi[0] = 0x0B;
  791. can_send_msg_normal(send_uavr20_sensi, 1, CAN_UAVRH_UPDATE_S1);
  792. }
  793. uavr56_info.set_radar_sensi_ack = false;
  794. }
  795. else
  796. {
  797. if (uavr56_info.set_radar_sensi_ack == false)
  798. {
  799. send_uavr20_sensi[0] = 0x0B;
  800. send_uavr20_sensi[1] = (uavr56_info.fcu_set_sensi >> 8) & 0xff;
  801. send_uavr20_sensi[2] = (uavr56_info.fcu_set_sensi)&0xff;
  802. can_send_msg_normal(send_uavr20_sensi, sizeof(send_uavr20_sensi), CAN_UAVRH_SENSI_SA);
  803. }
  804. else
  805. {
  806. uavr56_info.fcu_set_sensi_flag = false;
  807. uavrhup_getr1_ack = false;
  808. uavr56_info.set_radar_sensi_ack = false;
  809. uavr56_info.set_radar_sensi_count = 0;
  810. }
  811. }
  812. //超过5次失败后恢复
  813. if (uavr56_info.set_radar_sensi_count >= 5)
  814. {
  815. uavr56_info.fcu_set_sensi_flag = false;
  816. uavrhup_getr1_ack = false;
  817. uavr56_info.set_radar_sensi_ack = false;
  818. uavr56_info.set_radar_sensi_count = 0;
  819. }
  820. }
  821. //设置莫之比避障灵敏度成功后ACK主控
  822. if (uavr11_info.set_radar_sensi_ack == true || uavr12_info.set_radar_sensi_ack == true || uavr56_info.set_radar_sensi_ack == true)
  823. {
  824. //同时设置有个1.5s间隔
  825. if(HAL_GetTick() - radar_sensi_ack_time > 1500)
  826. {
  827. radar_sensi_ack_time = HAL_GetTick();
  828. if (uavr11_info.set_radar_sensi_ack == true)
  829. {
  830. pmu_set_ack(22, 1, uavr11_info.get_radar_sensi,0);
  831. uavr11_info.set_radar_sensi_ack = false;
  832. uavr11_info.fcu_set_sensi_flag = false;
  833. }
  834. else if (uavr12_info.set_radar_sensi_ack == true)
  835. {
  836. pmu_set_ack(22, 2, uavr12_info.get_radar_sensi,0);
  837. uavr12_info.set_radar_sensi_ack = false;
  838. uavr12_info.fcu_set_sensi_flag = false;
  839. }
  840. else if(uavr56_info.set_radar_sensi_ack == true)
  841. {
  842. pmu_set_ack(22, 6, uavr56_info.get_radar_sensi,0);
  843. uavr56_info.set_radar_sensi_ack = false;
  844. uavr56_info.fcu_set_sensi_flag = false;
  845. }
  846. }
  847. }
  848. }
  849. void can_recv_mocib_updata_read_set_hookfunction(uint32_t cellCanID, uint8_t data[])
  850. {
  851. //AG代码 和雷达升级不兼容,优先升级
  852. if (Rupdate.update_flag == true)
  853. {
  854. //避障雷达升级
  855. if (Rupdate.buf_flag == false)
  856. {
  857. memcpy(Rupdate.update_buf, data, 8);
  858. Rupdate.buf_flag = true;
  859. switch (cellCanID)
  860. {
  861. case 0x7E1:
  862. Rupdate.U7E1 = true;
  863. break;
  864. case 0x7E3:
  865. Rupdate.U7E3 = true;
  866. break;
  867. case 0x7E6:
  868. Rupdate.U7E6 = true;
  869. break;
  870. default:
  871. break;
  872. }
  873. }
  874. }
  875. else
  876. {
  877. switch (cellCanID)
  878. {
  879. //莫之比雷达反馈版本信息
  880. case CAN_UAVRH_UPDATE_R1:
  881. uavrhup_getr1_ack = true;
  882. break;
  883. //case CAN_UAVRH_VER_R:
  884. // if (uavr11_info.get_radar_ver_flag == false && can_get_uavr21_ver_comp == 1)
  885. // {
  886. // //char_to_hex_string(data, 4, uavr11_info.version, 10, "11");
  887. // uavr11_info.get_radar_ver_flag = true;
  888. // //升完级发送版本信息
  889. // if(HAL_GetTick() > 10000)
  890. // {
  891. // pmu_send = VERSION;
  892. // }
  893. // }
  894. // else if (uavr12_info.get_radar_ver_flag == false && can_get_uavr21_ver_comp == 2)
  895. // {
  896. // //char_to_hex_string(data, 4, uavr12_info.version, 10, "12");
  897. // uavr12_info.get_radar_ver_flag = true;
  898. // if(HAL_GetTick() > 10000)
  899. // {
  900. // pmu_send = VERSION;
  901. // }
  902. // }
  903. // else if (uavr56_info.get_radar_ver_flag == false && can_get_uavr21_ver_comp == 3)
  904. // {
  905. // //char_to_hex_string(data, 4, uavr56_info.version, 10, "56");
  906. // uavr56_info.get_radar_ver_flag = true;
  907. // if(HAL_GetTick() > 10000)
  908. // {
  909. // pmu_send = VERSION;
  910. // }
  911. // }
  912. // break;
  913. //莫之比雷达设置灵敏度及反馈
  914. case CAN_UAVRH_SENSI_SA:
  915. if (data[0] == 0x11)
  916. {
  917. uavr11_info.set_radar_sensi_ack = true;
  918. //莫之比大端模式
  919. uavr11_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  920. }
  921. else if (data[0] == 0x12)
  922. {
  923. uavr12_info.set_radar_sensi_ack = true;
  924. //莫之比大端模式
  925. uavr12_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  926. }
  927. else if(data[0] == 0x0B)
  928. {
  929. uavr56_info.set_radar_sensi_ack = true;
  930. uavr56_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  931. }
  932. break;
  933. //莫之比雷达读取灵敏度及反馈
  934. case CAN_UAVRH_SENSI_RA:
  935. if (data[0] == 0x11)
  936. {
  937. uavr11_info.get_radar_sensi_flag = true;
  938. //莫之比大端模式
  939. uavr11_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  940. }
  941. else if (data[0] == 0x12)
  942. {
  943. uavr12_info.get_radar_sensi_flag = true; //莫之比大端模式
  944. uavr12_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  945. }
  946. else if(data[0] == 0x0B)
  947. {
  948. uavr56_info.get_radar_sensi_flag = true;
  949. uavr56_info.get_radar_sensi = ((data[1] << 8) & 0xff00) + data[2];
  950. }
  951. default:
  952. break;
  953. }
  954. }
  955. }
  956. /**
  957. * @file can_send_info_to_mimo
  958. * @brief 给恩曌避障发送姿态信息
  959. * @param none
  960. * @details
  961. * @author Zhang Sir
  962. **/
  963. void can_send_info_to_mimo()
  964. {
  965. static int mimo_50HZ = 0;
  966. if (mimo_f_info.Link.connect_status == COMP_NORMAL || mimo_b_info.Link.connect_status == COMP_NORMAL /*||
  967. mimo_360_info.connect_status == COMP_NORMAL*/)
  968. {
  969. if (HAL_GetTick() - mimo_50HZ > 20)
  970. {
  971. mimo_50HZ = HAL_GetTick();
  972. int16_t index = 0;
  973. short tmpShort = 0;
  974. int8_t tmpChar = 0;
  975. uint8_t send_mimo_data[8] = {0};
  976. tmpShort = 1;
  977. short2buf(&send_mimo_data[index], &tmpShort);
  978. index += 2;
  979. // 俯仰
  980. tmpShort = planep.pitch_angle;
  981. short2buf(&send_mimo_data[index], &tmpShort);
  982. index += 2;
  983. // 横滚
  984. tmpShort = planep.roll_angle;
  985. short2buf(&send_mimo_data[index], &tmpShort);
  986. index += 2;
  987. //航向
  988. if(planep.yaw < 0)
  989. tmpShort = planep.yaw + 360;
  990. else
  991. tmpShort = planep.yaw;
  992. short2buf(&send_mimo_data[index], &tmpShort);
  993. index += 2;
  994. can_send_msg_normal(send_mimo_data, sizeof(send_mimo_data), 0x3740403);
  995. index = 0;
  996. // 俯仰
  997. tmpShort = -planep.roll_angle;
  998. short2buf(&send_mimo_data[index], &tmpShort);
  999. index += 2;
  1000. // 横滚
  1001. tmpShort = planep.pitch_angle;
  1002. short2buf(&send_mimo_data[index], &tmpShort);
  1003. index += 2;
  1004. //航向
  1005. if(planep.yaw < 0)
  1006. tmpShort = planep.yaw + 360;
  1007. else
  1008. tmpShort = planep.yaw;
  1009. short2buf(&send_mimo_data[index], &tmpShort);
  1010. index += 2;
  1011. // 前后速度
  1012. tmpChar = (planep.E_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD) +
  1013. planep.N_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  1014. 10; //0.1m/s
  1015. send_mimo_data[index++] = tmpChar;
  1016. //雷达安装俯仰角
  1017. tmpChar = 0;
  1018. send_mimo_data[index] = tmpChar;
  1019. can_send_msg_normal(send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO1);
  1020. index = 0;
  1021. //高度
  1022. tmpShort = planep.alt;
  1023. short2buf(&send_mimo_data[index], &tmpShort);
  1024. index += 2;
  1025. //俯仰角速度
  1026. tmpShort = 0;
  1027. short2buf(&send_mimo_data[index], &tmpShort);
  1028. index += 2;
  1029. //横滚角速度
  1030. tmpShort = 0;
  1031. short2buf(&send_mimo_data[index], &tmpShort);
  1032. index += 2;
  1033. // 左右速度
  1034. tmpChar = (planep.E_vel * cosf(planep.yaw / 100.0f * DEG_TO_RAD) +
  1035. planep.N_vel * sinf(planep.yaw / 100.0f * DEG_TO_RAD)) /
  1036. 10;
  1037. send_mimo_data[index++] = tmpChar;
  1038. //Z速度
  1039. tmpChar = planep.alt_vel / 10; //0.1m/s
  1040. send_mimo_data[index] = tmpChar;
  1041. can_send_msg_normal(send_mimo_data, sizeof(send_mimo_data), CAN_MIMO_ATTI_INFO2);
  1042. }
  1043. }
  1044. }
  1045. /**
  1046. * @file lidar_function
  1047. * @brief 雷达相关函数
  1048. * @param none
  1049. * @details
  1050. * @author Zhang Sir
  1051. **/
  1052. void send_mocib_radar_sensi(void)
  1053. {
  1054. static int radar_sensi_send_time = 0;
  1055. //uint8_t radar_can_buf[8] = {0};
  1056. if(HAL_GetTick() > 7000 && HAL_GetTick() - radar_sensi_send_time > 300)
  1057. {
  1058. //给FMU发送雷达灵敏度
  1059. radar_sensi_send_time = HAL_GetTick();
  1060. //上电后 检测到有雷达连接,向飞控发送雷达灵敏度信息
  1061. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == true &&
  1062. uavr11_info.send_fcu_sensi_count <= 3)
  1063. {
  1064. pmu_set_ack(22, 1, uavr11_info.get_radar_sensi,0);
  1065. uavr11_info.send_fcu_sensi_count++;
  1066. }
  1067. else if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == true &&
  1068. uavr12_info.send_fcu_sensi_count <= 3)
  1069. {
  1070. pmu_set_ack(22, 2, uavr12_info.get_radar_sensi,0);
  1071. uavr12_info.send_fcu_sensi_count++;
  1072. }
  1073. else if (uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == true &&
  1074. uavr56_info.send_fcu_sensi_count <= 3)
  1075. {
  1076. pmu_set_ack(22, 6, uavr56_info.get_radar_sensi,0);
  1077. uavr56_info.send_fcu_sensi_count++;
  1078. }
  1079. }
  1080. }
  1081. void lidar_function(void)
  1082. {
  1083. //莫之比避障雷达升级
  1084. if (radar_update_flag == true && uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true
  1085. && uavr56_info.fcu_set_sensi_flag != true)
  1086. {
  1087. Rupdate.update_flag = true;
  1088. Can_obstacle_update();
  1089. }
  1090. //上电给fcu发送雷达灵敏度
  1091. send_mocib_radar_sensi();
  1092. //设置莫之比避障雷达灵敏度
  1093. can_set_radar_sensi();
  1094. //获取电目雷达盲区、能量、原始数据开关
  1095. get_radar_blindAndPower_function();
  1096. //雷达升级不再给雷达发送信息,莫之比雷达发送姿态信息
  1097. if (radar_update_flag == false)
  1098. {
  1099. can_sendmsg_uavr20();
  1100. }
  1101. //给恩曌雷达发送姿态信息数据
  1102. can_send_info_to_mimo();
  1103. }
  1104. void can_recv_mocib_version_info(uint32_t cellCanID, uint8_t data[], uint8_t len)
  1105. {
  1106. static uint8_t frame_fi = 0,frame_bi = 0,frame_ti = 0;
  1107. switch (cellCanID)
  1108. {
  1109. //SN号
  1110. case CAN_OBSTARCLE11_SN:
  1111. if(frame_fi == 0)
  1112. {
  1113. memcpy(&uavr11_info.sn[0],&data[2],6);//要后六个字节
  1114. frame_fi += 6;
  1115. }
  1116. else if(frame_fi == 6)
  1117. {
  1118. memcpy(&uavr11_info.sn[frame_fi],&data[1],7);//要后7个字节
  1119. frame_fi += 7;
  1120. }
  1121. else if(frame_fi >= 13)
  1122. {
  1123. memcpy(&uavr11_info.sn[frame_fi],&data[1],3);
  1124. frame_fi = 0;
  1125. regist_dev_info(&dev_obsf,DEVICE_OBSF,false,uavr11_info.sn,20,NULL,0,NULL,0,"mocib",6);
  1126. uavr11_info.get_radar_sn_flag = true;
  1127. }
  1128. break;
  1129. case CAN_OBSTARCLE12_SN:
  1130. if(frame_bi == 0)
  1131. {
  1132. memcpy(&uavr12_info.sn[0],&data[2],6);//要后六个字节
  1133. frame_bi += 6;
  1134. }
  1135. else if(frame_bi == 6)
  1136. {
  1137. memcpy(&uavr12_info.sn[frame_bi],&data[1],7);//要后7个字节
  1138. frame_bi += 7;
  1139. }
  1140. else if(frame_bi >= 13)
  1141. {
  1142. memcpy(&uavr12_info.sn[frame_bi],&data[1],3);
  1143. frame_bi = 0;
  1144. regist_dev_info(&dev_obsb,DEVICE_OBSB,false,uavr12_info.sn,20,NULL,0,NULL,0,"mocib",6);
  1145. uavr12_info.get_radar_sn_flag = true;
  1146. }
  1147. break;
  1148. case CAN_OBSTARCLE56_SN:
  1149. if(frame_ti == 0)
  1150. {
  1151. memcpy(&uavr56_info.sn[0],&data[2],6);//要后六个字节
  1152. frame_ti += 6;
  1153. }
  1154. else if(frame_ti == 6)
  1155. {
  1156. memcpy(&uavr56_info.sn[frame_ti],&data[1],7);//要后7个字节
  1157. frame_ti += 7;
  1158. }
  1159. else if(frame_ti >= 13)
  1160. {
  1161. memcpy(&uavr56_info.sn[frame_ti],&data[1],3);
  1162. frame_ti = 0;
  1163. regist_dev_info(&dev_ter,DEVICE_TERRA,false,uavr56_info.sn,20,NULL,0,NULL,0,"mocib",6);
  1164. uavr56_info.get_radar_sn_flag = true;
  1165. }
  1166. break;
  1167. //版本信息
  1168. case 0x00eeff11:
  1169. uavr11_info.version[0] = 'M';
  1170. uavr11_info.version[1] = '1';
  1171. uavr11_info.version[2] = (data[1] + data[2]) + '0';
  1172. uavr11_info.version[3] = (data[3] + data[4]) + '0';
  1173. char_to_hex_string(&data[5], 3, &uavr11_info.version[4], 6, "00");
  1174. uavr11_info.soft_verison = ((data[5] & 0xff) << 16) + ((data[6] & 0xff) << 8) + (data[7] & 0xff);
  1175. uavr11_info.get_radar_ver_flag = true;
  1176. regist_dev_info(&dev_obsf,DEVICE_OBSF,false,NULL,0,uavr11_info.version,10,NULL,0,"mocib",6);
  1177. break;
  1178. case 0x00eeff12:
  1179. uavr12_info.version[0] = 'M';
  1180. uavr12_info.version[1] = '2';
  1181. uavr12_info.version[2] = (data[1] + data[2]) + '0';
  1182. uavr12_info.version[3] = (data[3] + data[4]) + '0';
  1183. char_to_hex_string(&data[5], 3, &uavr12_info.version[4], 6, "00");
  1184. uavr12_info.soft_verison = ((data[5] & 0xff) << 16) + ((data[6] & 0xff) << 8) + (data[7] & 0xff);
  1185. uavr12_info.get_radar_ver_flag = true;
  1186. regist_dev_info(&dev_obsb,DEVICE_OBSB,false,NULL,0,uavr12_info.version,10,NULL,0,"mocib",6);
  1187. break;
  1188. case 0x00eeff0b:
  1189. uavr56_info.version[0] = 'M';
  1190. uavr56_info.version[1] = 'B';
  1191. uavr56_info.version[2] = (data[1] + data[2]) + '0';
  1192. uavr56_info.version[3] = (data[3] + data[4]) + '0';
  1193. char_to_hex_string(&data[5], 3, &uavr56_info.version[4], 6, "00");
  1194. uavr56_info.soft_verison = ((data[5] & 0xff) << 16) + ((data[6] & 0xff) << 8) + (data[7] & 0xff);
  1195. uavr56_info.get_radar_ver_flag = true;
  1196. regist_dev_info(&dev_ter,DEVICE_TERRA,false,NULL,0,uavr56_info.version,10,NULL,0,"mocib",6);
  1197. break;
  1198. default:
  1199. break;
  1200. }
  1201. // if(HAL_GetTick() > 10000)
  1202. // {
  1203. pmu_send = PMU_SEND_VERSION;
  1204. // }
  1205. }
  1206. bool check_radar_update(void)
  1207. {
  1208. if (uavr12_info.Link.connect_status == COMP_NORMAL && uavr12_info.get_radar_sensi_flag == false &&
  1209. uavr12_info.get_radar_sensi_count < 5)
  1210. {
  1211. return false;
  1212. }
  1213. if (uavr11_info.Link.connect_status == COMP_NORMAL && uavr11_info.get_radar_sensi_flag == false &&
  1214. uavr11_info.get_radar_sensi_count < 5)
  1215. {
  1216. return false;
  1217. }
  1218. if (uavr56_info.Link.connect_status == COMP_NORMAL && uavr56_info.get_radar_sensi_flag == false &&
  1219. uavr56_info.get_radar_sensi_count < 5)
  1220. {
  1221. return false;
  1222. }
  1223. if(uavr11_info.fcu_set_sensi_flag == true ||uavr12_info.fcu_set_sensi_flag == true
  1224. || uavr56_info.fcu_set_sensi_flag == true)
  1225. {
  1226. return false;
  1227. }
  1228. return true;
  1229. }
  1230. void get_radar_blindAndPower_function( void )
  1231. {
  1232. uint8_t can_buf[8] = {0};
  1233. uint32_t can_id = 0;
  1234. static uint32_t time_1hz = 0;
  1235. if(!Check_Timer_Ready(&time_1hz,_1_HZ_))
  1236. return;
  1237. if(DM_f_info.Link.connect_status == COMP_NORMAL && DM_f_info.get_radar_blind_flag == false)
  1238. {
  1239. can_id = 0xA81300;
  1240. put_date_to_can(can_buf,0x8,0,0,0,0,0,0,0X7);
  1241. can_send_msg_normal(&can_buf[0], 8, can_id);
  1242. }
  1243. else if(DM_f_info.Link.connect_status == COMP_NORMAL && DM_f_info.get_radar_power_flag == false)
  1244. {
  1245. can_id = 0xA81300;
  1246. put_date_to_can(can_buf,0x9,0,0,0,0,0,0,0X7);
  1247. can_send_msg_normal(&can_buf[0], 8, can_id);
  1248. }
  1249. else if(DM_f_info.Link.connect_status == COMP_NORMAL && DM_f_info.get_radar_rawSwitch_flag == false)
  1250. {
  1251. can_id = 0xA81300;
  1252. put_date_to_can(can_buf,0xB,0,0,0,0,0,0,0X7);
  1253. can_send_msg_normal(&can_buf[0], 8, can_id);
  1254. }
  1255. if(DM_ter_info.Link.connect_status == COMP_NORMAL && DM_ter_info.get_radar_blind_flag == false)
  1256. {
  1257. can_id = 0x981300;
  1258. put_date_to_can(can_buf,0x8,0,0,0,0,0,0,0X7);
  1259. can_send_msg_normal(&can_buf[0], 8, can_id);
  1260. }
  1261. else if(DM_ter_info.Link.connect_status == COMP_NORMAL && DM_ter_info.get_radar_power_flag == false)
  1262. {
  1263. can_id = 0x981300;
  1264. put_date_to_can(can_buf,0x9,0,0,0,0,0,0,0X7);
  1265. can_send_msg_normal(&can_buf[0], 8, can_id);
  1266. }
  1267. else if(DM_ter_info.Link.connect_status == COMP_NORMAL && DM_ter_info.get_radar_rawSwitch_flag == false)
  1268. {
  1269. can_id = 0x981300;
  1270. put_date_to_can(can_buf,0xB,0,0,0,0,0,0,0X7);
  1271. can_send_msg_normal(&can_buf[0], 8, can_id);
  1272. }
  1273. }
  1274. // mimo_360info mimo360_info[MIMO_360_TotalSect];
  1275. // mimo_360status mimo360_status;
  1276. // Connect_check mimo_360_info;
  1277. // void mimo360_sort(mimo_360info *arr,uint16_t length)
  1278. // {
  1279. // if ( length < 2 )
  1280. // {
  1281. // return;
  1282. // }
  1283. // uint16_t num = 0, num1 = 0;
  1284. // mimo_360info tmp;
  1285. // for ( num = length - 1; num >= 1; num-- )
  1286. // {
  1287. // for ( num1 = 0; num1 <= num - 1; num1++ )
  1288. // {
  1289. // if ( ( ( arr + num1 )->dis0 ) > ( ( arr + num1 + 1 )->dis0 ) )
  1290. // {
  1291. // tmp = *( arr + num1 );
  1292. // *( arr + num1 ) = *( arr + num1 + 1 );
  1293. // *( arr + num1 + 1 ) = tmp;
  1294. // }
  1295. // }
  1296. // }
  1297. // }
  1298. // uint16_t test_index = 0;
  1299. // uint16_t compelte = 0;
  1300. // uint8_t radar360_proflag = 0;
  1301. // mimo_360_cont fmu_360info;
  1302. // void can_recv_mocib_new360_obstacle(uint32_t cellCanID, uint8_t data[], uint8_t len)
  1303. // {
  1304. // mimo_360_info.connect_status = COMP_NORMAL;
  1305. // mimo_360_info.recv_time = HAL_GetTick();
  1306. // switch (cellCanID)
  1307. // {
  1308. // case CAN_360MIMO_1ID:
  1309. // memcpy(&mimo360_status,&data[0],8);
  1310. // mimo360_status.index = 0;
  1311. // if(mimo360_status.nTarget == 0)
  1312. // {
  1313. // fmu_360info.total_tar = 0;
  1314. // memset(&fmu_360info.data[0],0,sizeof(mimo_360_data));
  1315. // }
  1316. // break;
  1317. // case CAN_360MIMO_2ID:
  1318. // if(mimo360_status.nTarget <= MIMO_360_TotalSect && mimo360_status.nTarget > 0)
  1319. // {
  1320. // for(uint8_t i = 0;i < 2;i++)
  1321. // {
  1322. // if(i == 0)
  1323. // {
  1324. // memcpy(&mimo360_info[mimo360_status.index].sectId0,&data[0],sizeof(mimo_360info));
  1325. // }
  1326. // else
  1327. // {
  1328. // memcpy(&mimo360_info[mimo360_status.index].sectId0,&data[4],sizeof(mimo_360info));
  1329. // }
  1330. // if(mimo360_status.nTarget - 1 == mimo360_status.index && radar360_proflag == 0)
  1331. // {
  1332. // //mimo360_sort(&mimo360_info[0],mimo360_status.nTarget);
  1333. // fmu_360info.TotalSect = mimo360_status.TotalSect;
  1334. // fmu_360info.total_tar = mimo360_status.nTarget;
  1335. // for(uint8_t j = 0;j < mimo360_status.nTarget;j++)
  1336. // {
  1337. // fmu_360info.data[j].sec_angle = mimo360_info[j].sectId0 * 360 / mimo360_status.TotalSect;
  1338. // fmu_360info.data[j].distance = mimo360_info[j].dis0 * mimo360_status.RangeRes/100; //cm
  1339. // fmu_360info.data[j].rcs0 = mimo360_info[j].rcs0;
  1340. // fmu_360info.data[j].el0 = mimo360_info[j].el0 * 0.5;
  1341. // }
  1342. // }
  1343. // mimo360_status.index++;
  1344. // }
  1345. // }
  1346. // break;
  1347. // default:
  1348. // break;
  1349. // }
  1350. // }