params.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. #include "params.h"
  2. #include "control_throttle.h"
  3. #include "my_math.h"
  4. #include "soft_flash.h"
  5. #include "soft_imu.h"
  6. enum
  7. {
  8. PARAM_READ = 0,
  9. PARAM_WRITE = 1
  10. };
  11. /* 参数存储表 */
  12. /* static int16_t param_list_buff[128]; */
  13. /*----------------------- duplicating --------------------*/
  14. struct FEI_CAN_DATA conf_par;
  15. struct VER_DATA ver_par;
  16. // 参数分两套data记录,是因为数据上传转换为float后再下传会有精度损失
  17. struct data_pid pidinf; // 参数配置
  18. struct data_ver verinf; // 版本信息
  19. struct data_conf confinf; // 机型参数配置
  20. struct data_cam caminf; // 拍照参数配置
  21. struct data_par parinf; // 备用参数
  22. /*--------------------------------------------------------*/
  23. /**
  24. * @brief
  25. * @param uint16_t num 设置项序号
  26. * @param int16_t value 设置的值
  27. * @param uint8_t wr 读取还是写入,0 为读取,1 为写入
  28. */
  29. static int16_t _params_read_wirte(ParamsEnumType num, int16_t value, uint8_t wr)
  30. {
  31. int16_t retval = 0;
  32. switch (num)
  33. {
  34. // 机型参数
  35. case ParamNum_APType:
  36. if (wr)
  37. {
  38. retval = value;
  39. if (thr_lock_status == LOCKED)
  40. {
  41. confinf._jixing = value;
  42. write_conf_information = true;
  43. }
  44. }
  45. else
  46. {
  47. retval = confinf._jixing;
  48. }
  49. break;
  50. // 电台失联时间
  51. case ParamNum_RadioLinkLostTimeS:
  52. if (wr)
  53. {
  54. retval = value;
  55. confinf._lostlink_time = value;
  56. write_conf_information = true;
  57. }
  58. else
  59. {
  60. retval = confinf._lostlink_time;
  61. }
  62. break;
  63. // 低电压动作
  64. case ParamNum_LowVoltAction1:
  65. if (wr)
  66. {
  67. retval = value;
  68. confinf._lowvolt_flag = value;
  69. write_conf_information = true;
  70. }
  71. else
  72. {
  73. retval = confinf._lowvolt_flag;
  74. }
  75. break;
  76. // 低电压阈值
  77. case ParamNum_LowVoltValue1:
  78. if (wr)
  79. {
  80. retval = value;
  81. confinf._lowvolt_value = value;
  82. write_conf_information = true;
  83. }
  84. else
  85. {
  86. retval = confinf._lowvolt_value;
  87. }
  88. break;
  89. // 盘旋半径
  90. case ParamNum_APCircleRadiusM:
  91. if (wr)
  92. {
  93. retval = value;
  94. confinf._circle_radius = value;
  95. write_conf_information = true;
  96. }
  97. else
  98. {
  99. retval = confinf._circle_radius;
  100. }
  101. break;
  102. // 返航高度
  103. case ParamNum_APRthAltM:
  104. if (wr)
  105. {
  106. retval = value;
  107. confinf._rth_alt = value;
  108. write_conf_information = true;
  109. }
  110. else
  111. {
  112. retval = confinf._rth_alt;
  113. }
  114. break;
  115. // 起飞高度
  116. case ParamNum_APTakeoffAltM:
  117. if (wr)
  118. {
  119. retval = value;
  120. confinf._takeoff_alt = value;
  121. write_conf_information = true;
  122. }
  123. else
  124. {
  125. retval = confinf._takeoff_alt;
  126. }
  127. break;
  128. // 磁偏角
  129. case ParamNum_MagDeclinationDeg:
  130. if (wr)
  131. {
  132. retval = value;
  133. confinf._mag_offset = value;
  134. write_conf_information = true;
  135. }
  136. else
  137. {
  138. retval = confinf._mag_offset;
  139. }
  140. break;
  141. // 雷达灵敏度
  142. case ParamNum_LidarObavoidAction:
  143. if (wr)
  144. {
  145. retval = value;
  146. confinf._enable_infrared = value;
  147. write_conf_information = true;
  148. }
  149. else
  150. {
  151. retval = confinf._enable_infrared;
  152. }
  153. break;
  154. // imu 滤波参数
  155. case ParamNum_ImuFilterLever:
  156. if (wr)
  157. {
  158. retval = value;
  159. if (thr_lock_status == LOCKED)
  160. {
  161. uint8_t calib_value[3] = {0, 0, 0};
  162. calib_value[0] = value;
  163. send_calibration_msg_to_imu(FILTER_PARAM_CALIB, calib_value, 1);
  164. }
  165. }
  166. else
  167. {
  168. retval = ins.imu_conf.filter_param;
  169. }
  170. break;
  171. // 安装方向
  172. case ParamNum_ImuAssembleDirection:
  173. if (wr)
  174. {
  175. retval = value;
  176. if (thr_lock_status == LOCKED)
  177. {
  178. uint8_t calib_value[3] = {value, 0, 0};
  179. send_calibration_msg_to_imu(ASSEMBLE_CALIB, calib_value, 1);
  180. }
  181. }
  182. else
  183. {
  184. retval = ins.imu_conf.assemble_direction_param;
  185. }
  186. break;
  187. // 怠速等级
  188. case ParamNum_APIdleSpeed:
  189. if (wr)
  190. {
  191. retval = value;
  192. if (thr_lock_status == LOCKED)
  193. {
  194. if (value >= 1050 && value <= 1300)
  195. {
  196. confinf._idle_speed_level = (value - 1050) / 50 + 1;
  197. write_conf_information = true;
  198. }
  199. }
  200. }
  201. else
  202. {
  203. retval = (confinf._idle_speed_level - 1) * 50 + 1050;
  204. }
  205. break;
  206. // 安装 x 补偿
  207. case ParamNum_Gps1PosCalibX:
  208. if (wr)
  209. {
  210. retval = value;
  211. if (thr_lock_status == LOCKED)
  212. {
  213. int8_t gps_pos_param[6];
  214. for (uint8_t i = 0; i < 6; ++i)
  215. {
  216. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  217. }
  218. gps_pos_param[0] = value;
  219. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  220. }
  221. }
  222. else
  223. {
  224. retval = ins.imu_conf.gps_pos_param[0];
  225. }
  226. break;
  227. // 安装 y 补偿
  228. case ParamNum_Gps1PosCalibY:
  229. if (wr)
  230. {
  231. retval = value;
  232. if (thr_lock_status == LOCKED)
  233. {
  234. int8_t gps_pos_param[6];
  235. for (uint8_t i = 0; i < 6; ++i)
  236. {
  237. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  238. }
  239. gps_pos_param[1] = value;
  240. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  241. }
  242. }
  243. else
  244. {
  245. retval = ins.imu_conf.gps_pos_param[1];
  246. }
  247. break;
  248. // 安装 z 补偿
  249. case ParamNum_Gps1PosCalibZ:
  250. if (wr)
  251. {
  252. retval = value;
  253. if (thr_lock_status == LOCKED)
  254. {
  255. int8_t gps_pos_param[6];
  256. for (uint8_t i = 0; i < 6; ++i)
  257. {
  258. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  259. }
  260. gps_pos_param[2] = value;
  261. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  262. }
  263. }
  264. else
  265. {
  266. retval = ins.imu_conf.gps_pos_param[2];
  267. }
  268. break;
  269. // 串口 4 功能复用
  270. case ParamNum_Port4Multiplexing:
  271. if (wr)
  272. {
  273. retval = value;
  274. if (thr_lock_status == LOCKED)
  275. {
  276. confinf._port4_af_function = value;
  277. write_conf_information = true;
  278. }
  279. }
  280. else
  281. {
  282. retval = confinf._port4_af_function;
  283. }
  284. break;
  285. // 差分双天线安装方向
  286. case ParamNum_DgpsAssembleDirection:
  287. if (wr)
  288. {
  289. retval = value;
  290. if (thr_lock_status == LOCKED)
  291. {
  292. uint8_t calib_value[3] = {value, 0, 0};
  293. send_calibration_msg_to_imu(DGPS_DIRECTION_CALIB,
  294. calib_value,
  295. 1);
  296. }
  297. }
  298. else
  299. {
  300. retval = ins.imu_conf.dgps_direction_param;
  301. }
  302. break;
  303. // 最大倾斜角度
  304. case ParamNum_APMaxTilteAngleDeg:
  305. if (wr)
  306. {
  307. retval = value;
  308. parinf._par_maxangle = value;
  309. write_par_information = true;
  310. }
  311. else
  312. {
  313. retval = parinf._par_maxangle;
  314. }
  315. break;
  316. // gps 模式推干最大目标水平速度
  317. case ParamNum_APMaxHorizonalSpeedGpsModeDms:
  318. if (wr)
  319. {
  320. retval = value;
  321. parinf._par_maxhspeed = value;
  322. write_par_information = true;
  323. }
  324. else
  325. {
  326. retval = parinf._par_maxhspeed;
  327. }
  328. break;
  329. // GPS 模式推干最大目标上升速度
  330. case ParamNum_APMaxClimbSpeedGpsModeDms:
  331. if (wr)
  332. {
  333. retval = value;
  334. parinf._par_maxupspeed = value;
  335. write_par_information = true;
  336. }
  337. else
  338. {
  339. retval = parinf._par_maxupspeed;
  340. }
  341. break;
  342. // GPS 模式推干最大目标下降速度
  343. case ParamNum_APMaxDeclineSpeedGpsModeDms:
  344. if (wr)
  345. {
  346. retval = value;
  347. parinf._par_maxdownspeed = value;
  348. write_par_information = true;
  349. }
  350. else
  351. {
  352. retval = parinf._par_maxdownspeed;
  353. }
  354. break;
  355. // 悬停油门
  356. case ParamNum_APHoverThrottle:
  357. if (wr)
  358. {
  359. retval = value;
  360. parinf._par_hover_throttle = value;
  361. write_par_information = true;
  362. }
  363. else
  364. {
  365. retval = parinf._par_hover_throttle;
  366. }
  367. break;
  368. // 一级高度限制
  369. case ParamNum_AltRestrictionA:
  370. if (wr)
  371. {
  372. retval = value;
  373. parinf._par_alt_fs_rth = value;
  374. write_par_information = true;
  375. }
  376. else
  377. {
  378. retval = parinf._par_alt_fs_rth;
  379. }
  380. break;
  381. // 二级高度限制
  382. case ParamNum_AltRestrictionB:
  383. if (wr)
  384. {
  385. retval = value;
  386. parinf._par_alt_fs_land = value;
  387. write_par_information = true;
  388. }
  389. else
  390. {
  391. retval = parinf._par_alt_fs_land;
  392. }
  393. break;
  394. // 最大航向锁尾角速度
  395. case ParamNum_APMaxYawRate:
  396. if (wr)
  397. {
  398. retval = value;
  399. parinf._par_maxyawrate = value;
  400. write_par_information = true;
  401. }
  402. else
  403. {
  404. retval = parinf._par_maxyawrate;
  405. }
  406. break;
  407. // 电压比例校准系数0
  408. case ParamNum_VoltCalibKp0:
  409. if (wr)
  410. {
  411. retval = value;
  412. parinf._par_volt_kp[0] = value;
  413. write_par_information = true;
  414. }
  415. else
  416. {
  417. retval = parinf._par_volt_kp[0];
  418. }
  419. break;
  420. // 电压比例校准系数1
  421. case ParamNum_VoltCalibKp1:
  422. if (wr)
  423. {
  424. retval = value;
  425. parinf._par_volt_kp[1] = value;
  426. write_par_information = true;
  427. }
  428. else
  429. {
  430. retval = parinf._par_volt_kp[1];
  431. }
  432. break;
  433. // 电压比例校准系数2
  434. case ParamNum_VoltCalibKp2:
  435. if (wr)
  436. {
  437. retval = value;
  438. parinf._par_volt_kp[2] = value;
  439. write_par_information = true;
  440. }
  441. else
  442. {
  443. retval = parinf._par_volt_kp[2];
  444. }
  445. break;
  446. // 电压校准偏移系数 0
  447. case ParamNum_VoltCalibOffset0:
  448. if (wr)
  449. {
  450. retval = value;
  451. parinf._par_volt_offset[0] = value;
  452. write_par_information = true;
  453. }
  454. else
  455. {
  456. retval = parinf._par_volt_offset[0];
  457. }
  458. break;
  459. // 电压校准偏移系数 1
  460. case ParamNum_VoltCalibOffset1:
  461. if (wr)
  462. {
  463. retval = value;
  464. parinf._par_volt_offset[1] = value;
  465. write_par_information = true;
  466. }
  467. else
  468. {
  469. retval = parinf._par_volt_offset[1];
  470. }
  471. break;
  472. // 电压校准偏移系数 2
  473. case ParamNum_VoltCalibOffset2:
  474. if (wr)
  475. {
  476. retval = value;
  477. parinf._par_volt_offset[2] = value;
  478. write_par_information = true;
  479. }
  480. else
  481. {
  482. retval = parinf._par_volt_offset[2];
  483. }
  484. break;
  485. // 跟随距离
  486. case ParamNum_FollowDistM:
  487. if (wr)
  488. {
  489. retval = value;
  490. parinf._fllow_dist = value;
  491. write_par_information = true;
  492. }
  493. else
  494. {
  495. retval = parinf._fllow_dist;
  496. }
  497. break;
  498. // 自动模式最大爬升速度
  499. case ParamNum_APMaxClimbSpeedAutoModeDms:
  500. if (wr)
  501. {
  502. retval = value;
  503. parinf._par_max_climb_rate_automode = value;
  504. write_par_information = true;
  505. }
  506. else
  507. {
  508. retval = parinf._par_max_climb_rate_automode;
  509. }
  510. break;
  511. // 自动模式最大下降速度
  512. case ParamNum_APMaxDeclineSpeedAutoModeDms:
  513. if (wr)
  514. {
  515. retval = value;
  516. parinf._par_max_approach_rate_automode = value;
  517. write_par_information = true;
  518. }
  519. else
  520. {
  521. retval = parinf._par_max_approach_rate_automode;
  522. }
  523. break;
  524. // 自动模式最小降落速度
  525. case ParamNum_APMinLandingRateAutoModeDms:
  526. if (wr)
  527. {
  528. retval = value;
  529. parinf._par_min_landing_rate_automode = value;
  530. write_par_information = true;
  531. }
  532. else
  533. {
  534. retval = parinf._par_min_landing_rate_automode;
  535. }
  536. break;
  537. // 飞机最远水平距离
  538. case ParamNum_MaxHorizonalDistanceM:
  539. if (wr)
  540. {
  541. retval = value;
  542. parinf._max_horizonal_distance = value;
  543. write_par_information = true;
  544. }
  545. else
  546. {
  547. retval = parinf._max_horizonal_distance;
  548. }
  549. break;
  550. // 拍照信号类型
  551. case ParamNum_CameraSignalType:
  552. if (wr)
  553. {
  554. retval = value;
  555. caminf._signal_type = value;
  556. write_cam_information = true;
  557. }
  558. else
  559. {
  560. retval = caminf._signal_type;
  561. }
  562. break;
  563. // 拍照信号持续时间
  564. case ParamNum_CameraSignalInterval:
  565. if (wr)
  566. {
  567. retval = value;
  568. caminf._signal_interval = value;
  569. write_cam_information = true;
  570. }
  571. else
  572. {
  573. retval = caminf._signal_interval;
  574. }
  575. break;
  576. // 拍照信号pwm on
  577. case ParamNum_CameraSignalPwmOn:
  578. if (wr)
  579. {
  580. retval = value;
  581. caminf._signal_pwm_takephoto_on = value;
  582. write_cam_information = true;
  583. }
  584. else
  585. {
  586. retval = caminf._signal_pwm_takephoto_on;
  587. }
  588. break;
  589. // 拍照信号 pwm off
  590. case ParamNum_CameraSignalPwmOff:
  591. if (wr)
  592. {
  593. retval = value;
  594. caminf._signal_pwm_takephoto_off = value;
  595. write_cam_information = true;
  596. }
  597. else
  598. {
  599. retval = caminf._signal_pwm_takephoto_off;
  600. }
  601. break;
  602. // 横滚姿态感度
  603. case ParamNum_RollAngleKp:
  604. if (wr)
  605. {
  606. retval = value;
  607. pidinf._Roll_Angle_P = value;
  608. write_pid_information = true;
  609. }
  610. else
  611. {
  612. retval = pidinf._Roll_Angle_P;
  613. }
  614. break;
  615. // 横滚基础感度
  616. case ParamNum_RollGyroKp:
  617. if (wr)
  618. {
  619. retval = value;
  620. pidinf._Roll_Gyro_P = value;
  621. write_pid_information = true;
  622. }
  623. else
  624. {
  625. retval = pidinf._Roll_Gyro_P;
  626. }
  627. break;
  628. // 横滚姿态增稳系数
  629. case ParamNum_RollGyroKd:
  630. if (wr)
  631. {
  632. retval = value;
  633. pidinf._Roll_Gyro_D = value;
  634. write_pid_information = true;
  635. }
  636. else
  637. {
  638. retval = pidinf._Roll_Gyro_D;
  639. }
  640. break;
  641. // 俯仰姿态感度
  642. case ParamNum_PitchAngleKp:
  643. if (wr)
  644. {
  645. retval = value;
  646. pidinf._Pitch_Angle_P = value;
  647. write_pid_information = true;
  648. }
  649. else
  650. {
  651. retval = pidinf._Pitch_Angle_P;
  652. }
  653. break;
  654. // 俯仰基础感度
  655. case ParamNum_PitchGyroKp:
  656. if (wr)
  657. {
  658. retval = value;
  659. pidinf._Pitch_Gyro_P = value;
  660. write_pid_information = true;
  661. }
  662. else
  663. {
  664. retval = pidinf._Pitch_Gyro_P;
  665. }
  666. break;
  667. // 俯仰姿态增稳系数
  668. case ParamNum_PitchGyroKd:
  669. if (wr)
  670. {
  671. retval = value;
  672. pidinf._Pitch_Gyro_D = value;
  673. write_pid_information = true;
  674. }
  675. else
  676. {
  677. retval = pidinf._Pitch_Gyro_D;
  678. }
  679. break;
  680. // 航向姿态感度
  681. case ParamNum_YawAngleKp:
  682. if (wr)
  683. {
  684. retval = value;
  685. pidinf._Yaw_Angle_P = value;
  686. write_pid_information = true;
  687. }
  688. else
  689. {
  690. retval = pidinf._Yaw_Angle_P;
  691. }
  692. break;
  693. // 航向基础感度
  694. case ParamNum_YawGyroKp:
  695. if (wr)
  696. {
  697. retval = value;
  698. pidinf._Yaw_Gyro_P = value;
  699. write_pid_information = true;
  700. }
  701. else
  702. {
  703. retval = pidinf._Yaw_Gyro_P;
  704. }
  705. break;
  706. // 航向姿态增稳系数
  707. case ParamNum_YawGyroKd:
  708. if (wr)
  709. {
  710. retval = value;
  711. pidinf._Yaw_Gyro_D = value;
  712. write_pid_information = true;
  713. }
  714. else
  715. {
  716. retval = pidinf._Yaw_Gyro_D;
  717. }
  718. break;
  719. // 定高位置系数
  720. case ParamNum_AltholdDistKp:
  721. if (wr)
  722. {
  723. retval = value;
  724. pidinf._AltHold_Dist_P = value;
  725. write_pid_information = true;
  726. }
  727. else
  728. {
  729. retval = pidinf._AltHold_Dist_P;
  730. }
  731. break;
  732. // 定高速度系数
  733. case ParamNum_AltholdSpeedKp:
  734. if (wr)
  735. {
  736. retval = value;
  737. pidinf._AltHold_Speed_P = value;
  738. write_pid_information = true;
  739. }
  740. else
  741. {
  742. retval = pidinf._AltHold_Speed_P;
  743. }
  744. break;
  745. // 定高加速度系数
  746. case ParamNum_AltholdAccKp:
  747. if (wr)
  748. {
  749. retval = value;
  750. pidinf._AltHold_Acc_P = value;
  751. write_pid_information = true;
  752. }
  753. else
  754. {
  755. retval = pidinf._AltHold_Acc_P;
  756. }
  757. break;
  758. // 定高积分补偿系数
  759. case ParamNum_AltholdAccKi:
  760. if (wr)
  761. {
  762. retval = value;
  763. pidinf._AltHold_Acc_I = value;
  764. write_pid_information = true;
  765. }
  766. else
  767. {
  768. retval = pidinf._AltHold_Acc_I;
  769. }
  770. break;
  771. // 水平位置系数
  772. case ParamNum_LoiterDistKp:
  773. if (wr)
  774. {
  775. retval = value;
  776. pidinf._Loiter_Dist_P = value;
  777. write_pid_information = true;
  778. }
  779. else
  780. {
  781. retval = pidinf._Loiter_Dist_P;
  782. }
  783. break;
  784. // 水平速度系数
  785. case ParamNum_LoiterSpeedKp:
  786. if (wr)
  787. {
  788. retval = value;
  789. pidinf._Loiter_Speed_P = value;
  790. write_pid_information = true;
  791. }
  792. else
  793. {
  794. retval = pidinf._Loiter_Speed_P;
  795. }
  796. break;
  797. // 水平加速度系数
  798. case ParamNum_LoiterAccKp:
  799. if (wr)
  800. {
  801. retval = value;
  802. pidinf._Loiter_Acc_P = value;
  803. write_pid_information = true;
  804. }
  805. else
  806. {
  807. retval = pidinf._Loiter_Acc_P;
  808. }
  809. break;
  810. // 水平积分补偿系数
  811. case ParamNum_LoiterAccKi:
  812. if (wr)
  813. {
  814. retval = value;
  815. pidinf._Loiter_Acc_I = value;
  816. write_pid_information = true;
  817. }
  818. else
  819. {
  820. retval = pidinf._Loiter_Acc_I;
  821. }
  822. break;
  823. // 最大巡航水平速度
  824. case ParamNum_APRthSpeedDms:
  825. if (wr)
  826. {
  827. retval = value;
  828. parinf._par_max_rth_horizontal_speed = value;
  829. write_par_information = true;
  830. }
  831. else
  832. {
  833. retval = parinf._par_max_rth_horizontal_speed;
  834. }
  835. break;
  836. // 陀螺刹车系数
  837. case ParamNum_GyroBrakeRatio:
  838. if (wr)
  839. {
  840. retval = value;
  841. pidinf._Loiter_Brake_Gyro = retval;
  842. write_pid_information = true;
  843. }
  844. else
  845. {
  846. retval = pidinf._Loiter_Brake_Gyro;
  847. }
  848. break;
  849. /* 2 级低电压动作 */
  850. case ParamNum_LowVoltAction2:
  851. if (wr)
  852. {
  853. retval = value;
  854. confinf._lowvolt_flag2 = value;
  855. write_conf_information = true;
  856. }
  857. else
  858. {
  859. retval = confinf._lowvolt_flag2;
  860. }
  861. break;
  862. /* 2 级低电压阈值 */
  863. case ParamNum_LowVoltValue2:
  864. if (wr)
  865. {
  866. retval = value;
  867. confinf._lowvolt_value2 = value;
  868. write_conf_information = true;
  869. }
  870. else
  871. {
  872. retval = confinf._lowvolt_value2;
  873. }
  874. break;
  875. /* 遥控器失控悬停等待时间 */
  876. case ParamNum_RcFailLoiterTimeS:
  877. if (wr)
  878. {
  879. retval = value;
  880. confinf._rc_fail_loiter_time = value;
  881. write_conf_information = true;
  882. }
  883. else
  884. {
  885. retval = confinf._rc_fail_loiter_time;
  886. }
  887. break;
  888. /* Gps 2 安装 X 补偿 */
  889. case ParamNum_Gps2PosCalibX:
  890. if (wr)
  891. {
  892. retval = value;
  893. if (thr_lock_status == LOCKED)
  894. {
  895. int8_t gps_pos_param[6];
  896. for (uint8_t i = 0; i < 6; ++i)
  897. {
  898. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  899. }
  900. gps_pos_param[3] = value;
  901. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  902. }
  903. }
  904. else
  905. {
  906. retval = ins.imu_conf.gps_pos_param[3];
  907. }
  908. break;
  909. /* Gps 2 安装 Y 补偿 */
  910. case ParamNum_Gps2PosCalibY:
  911. if (wr)
  912. {
  913. retval = value;
  914. if (thr_lock_status == LOCKED)
  915. {
  916. int8_t gps_pos_param[6];
  917. for (uint8_t i = 0; i < 6; ++i)
  918. {
  919. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  920. }
  921. gps_pos_param[4] = value;
  922. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  923. }
  924. }
  925. else
  926. {
  927. retval = ins.imu_conf.gps_pos_param[4];
  928. }
  929. break;
  930. /* Gps 2 安装 Z 补偿 */
  931. case ParamNum_Gps2PosCalibZ:
  932. if (wr)
  933. {
  934. retval = value;
  935. if (thr_lock_status == LOCKED)
  936. {
  937. int8_t gps_pos_param[6];
  938. for (uint8_t i = 0; i < 6; ++i)
  939. {
  940. gps_pos_param[i] = ins.imu_conf.gps_pos_param[i];
  941. }
  942. gps_pos_param[5] = value;
  943. send_calibration_msg_to_imu(GPS_POS_CALIB, (uint8_t *)gps_pos_param, 6);
  944. }
  945. }
  946. else
  947. {
  948. retval = ins.imu_conf.gps_pos_param[5];
  949. }
  950. break;
  951. /* 跟随前向距离 */
  952. case ParamNum_VehicleFollowForwardDistDM:
  953. if (wr)
  954. {
  955. retval = value;
  956. parinf._vehicle_forward_dist_dm = value;
  957. write_par_information = true;
  958. }
  959. else
  960. {
  961. retval = parinf._vehicle_forward_dist_dm;
  962. }
  963. break;
  964. /* 跟随右向距离 */
  965. case ParamNum_VehicleFollowRightDistDM:
  966. if (wr)
  967. {
  968. retval = value;
  969. parinf._vehicle_right_dist_dm = value;
  970. write_par_information = true;
  971. }
  972. else
  973. {
  974. retval = parinf._vehicle_right_dist_dm;
  975. }
  976. break;
  977. /* 跟随机头夹角 */
  978. case ParamNum_VehicleFollowIncYawAngleDeg:
  979. if (wr)
  980. {
  981. retval = value;
  982. parinf._vehicle_yaw_included_angle =
  983. constrain_int16(value, -180, 180);
  984. write_par_information = true;
  985. }
  986. else
  987. {
  988. retval = parinf._vehicle_yaw_included_angle;
  989. }
  990. break;
  991. /* 跟随天向距离 */
  992. case ParamNum_VehicleFollowUpDistDM:
  993. if (wr)
  994. {
  995. retval = value;
  996. parinf._vehicle_up_dist = value;
  997. write_par_information = true;
  998. }
  999. else
  1000. {
  1001. retval = parinf._vehicle_up_dist;
  1002. }
  1003. break;
  1004. /* 基站磁偏角 */
  1005. case ParamNum_BaseDgpsYawDeclination:
  1006. if (wr)
  1007. {
  1008. if (thr_lock_status == LOCKED)
  1009. {
  1010. retval = value;
  1011. parinf._vehicle_base_dgps_yaw_dec =
  1012. constrain_int16(value, -90 * 10, 90 * 10);
  1013. write_par_information = true;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. retval = parinf._vehicle_base_dgps_yaw_dec;
  1019. }
  1020. break;
  1021. case ParamNum_ImitatingFlightSensibility:
  1022. if (wr)
  1023. {
  1024. retval = value;
  1025. confinf._imitate_sensibility = constrain_int16(value, 0, 100);
  1026. write_conf_information = true;
  1027. }
  1028. else
  1029. {
  1030. retval = constrain_int16(confinf._imitate_sensibility, 0, 100);
  1031. }
  1032. break;
  1033. case ParamNum_ObstacleHoldDistCm:
  1034. if (wr)
  1035. {
  1036. retval = value;
  1037. parinf._obstacle_dist_cm = constrain_int16(value, 200, 800);
  1038. write_par_information = true;
  1039. }
  1040. else
  1041. {
  1042. retval = constrain_int16(parinf._obstacle_dist_cm, 200, 800);
  1043. }
  1044. break;
  1045. case ParamNum_SbusOAfCofig:
  1046. if (wr)
  1047. {
  1048. retval = value;
  1049. parinf._sbuso_af_config = value;
  1050. write_par_information = true;
  1051. }
  1052. else
  1053. {
  1054. retval = parinf._sbuso_af_config;
  1055. }
  1056. break;
  1057. case ParamNum_LinklostAction:
  1058. if (wr)
  1059. {
  1060. retval = value;
  1061. if (value <= 1)
  1062. {
  1063. parinf._linklost_action = value;
  1064. write_par_information = true;
  1065. }
  1066. }
  1067. else
  1068. {
  1069. retval = parinf._linklost_action;
  1070. }
  1071. break;
  1072. case ParamNum_MaxHorJet:
  1073. if (wr)
  1074. {
  1075. retval = value;
  1076. if (value >= 4 && value <= 50)
  1077. {
  1078. parinf._max_hor_jet = value;
  1079. write_par_information = true;
  1080. }
  1081. }
  1082. else
  1083. {
  1084. if (parinf._max_hor_jet < 4 || parinf._max_hor_jet > 50)
  1085. {
  1086. retval = 50;
  1087. }
  1088. else
  1089. {
  1090. retval = parinf._max_hor_jet;
  1091. }
  1092. }
  1093. break;
  1094. case ParamNum_BmsLowCapcityPercentage:
  1095. if (wr)
  1096. {
  1097. retval = value;
  1098. if (value >= 0 && value <= 80)
  1099. {
  1100. parinf._bms_low_capacity_percentage = value;
  1101. write_par_information = true;
  1102. }
  1103. }
  1104. else
  1105. {
  1106. if (parinf._max_hor_jet < 0 || parinf._max_hor_jet > 80)
  1107. {
  1108. retval = 20;
  1109. }
  1110. else
  1111. {
  1112. retval = parinf._bms_low_capacity_percentage;
  1113. }
  1114. }
  1115. break;
  1116. case ParamNUm_TPAFCONF:
  1117. if (wr)
  1118. {
  1119. retval = value;
  1120. if (value <= 1)
  1121. {
  1122. parinf._tp_afconfig = value;
  1123. write_par_information = true;
  1124. }
  1125. }
  1126. else
  1127. {
  1128. if (parinf._tp_afconfig > 1)
  1129. {
  1130. retval = 0;
  1131. }
  1132. else
  1133. {
  1134. retval = parinf._tp_afconfig;
  1135. }
  1136. }
  1137. break;
  1138. case ParamNum_ServoFailsafe:
  1139. if (wr)
  1140. {
  1141. retval = value;
  1142. if (value <= 2)
  1143. {
  1144. parinf._motor_failsafe_action = value;
  1145. write_par_information = true;
  1146. }
  1147. }
  1148. else
  1149. {
  1150. if (parinf._motor_failsafe_action > 2)
  1151. {
  1152. retval = 0;
  1153. }
  1154. else
  1155. {
  1156. retval = parinf._motor_failsafe_action;
  1157. }
  1158. }
  1159. break;
  1160. case ParamNum_BmsLowCapcityPercentage2:
  1161. if (wr)
  1162. {
  1163. retval = value;
  1164. if (value >= 0 && value <= 80)
  1165. {
  1166. parinf._bms_low_capacity_percentage2 = value;
  1167. write_par_information = true;
  1168. }
  1169. }
  1170. else
  1171. {
  1172. if (parinf._max_hor_jet < 0 || parinf._max_hor_jet > 80)
  1173. {
  1174. retval = 20;
  1175. }
  1176. else
  1177. {
  1178. retval = parinf._bms_low_capacity_percentage2;
  1179. }
  1180. }
  1181. break;
  1182. default:
  1183. break;
  1184. }
  1185. return retval;
  1186. }
  1187. void params_set_value(uint16_t param_num, int16_t param_value)
  1188. {
  1189. _params_read_wirte((ParamsEnumType)param_num, param_value, PARAM_WRITE);
  1190. }
  1191. int16_t params_get_value(uint16_t param_num)
  1192. {
  1193. int16_t retval =
  1194. _params_read_wirte((ParamsEnumType)param_num, 0, PARAM_READ);
  1195. return retval;
  1196. }