selfcheck.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /*Includes ----------------------------------------------*/
  2. #include "tool.h"
  3. #include "hal_MahonyAHRS.h"
  4. #include "ble_comm.h"
  5. #include "nrf_delay.h"
  6. #include "bsp_pwm.h"
  7. #include "bsp_time.h"
  8. #include "fml_adc.h"
  9. #include "bsp_wdt.h"
  10. #include "exception.h"
  11. #include "selfcheck.h"
  12. #include "system.h"
  13. #include "drv_qma7981.h"
  14. #include "hal_led.h"
  15. #include "hal_battery.h"
  16. #include "bll_imu.h"
  17. #include "app_flash.h"
  18. #include "system.h"
  19. #include "hal_mahonyAHRS.h"
  20. #include "app_detectIsHost.h"
  21. /*Private macro ------------------------------------------------------------------------------------------------------------------------------------*/
  22. #define SELFCHECK_SCAN_DEVICE_RSSI_MIN_THRESHOLD -60 //需要扫描的设备的RSSI最小阈值,-76
  23. #define SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD 80 //充电芯片引脚的最小ADC阈值
  24. #define SELFCHECK_BATTERY_PIN_ADC_MIN_THRESHOLD 3300 //电池分压电阻的最小ADC阈值
  25. #define SELFCHECK_BATTERY_PIN_ADC_MAX_THRESHOLD 4300 //电池分压电阻的最大ADC阈值,拆掉电阻后,原始值为3721,换算为5.49V
  26. #define SELFCHECK_MIDDLE_ACC_PROS_ROLL_MIN_THRESHOLD 0 //中间加速度正向ROLL值最小阈值
  27. #define SELFCHECK_MIDDLE_ACC_PROS_ROLL_MAX_THRESHOLD 35 //中间加速度正向ROLL值最大阈值
  28. #define SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD 160 //中间加速度反向ROLL值最小阈值
  29. #define SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD 180 //中间加速度反向ROLL值最大阈值
  30. #define SELFCHECK_WEAR_INSOLE_MAG_NORM_MIN_THRESHOLD 5000 //穿鞋垫的地磁norm值最小阈值
  31. #define SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD 200 //地磁传感器没焊接电容的最小阈值
  32. #define SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD 200 //自检灯显示周期时间,单位ms
  33. #define SELFCHECK_MIDDLE_ACC_CHECK_MT_MIN_THRESHOLD 5000 //中间加速度检测电机最小阈值
  34. #define SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX 416 //数据监测错误累计最大值
  35. /*STRUCTION ------------------------------------------------------------------------------------------------------------------------------------*/
  36. typedef enum {
  37. SELFCHECK_RESULT_SUCCESS = 0, //自检成功
  38. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS_ID, //自检失败——前脚传感器配置六轴ID
  39. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG_ID, //自检失败——前脚传感器配置地磁ID
  40. SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG_ID, //自检失败——后脚传感器配置地磁ID
  41. SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC, //自检失败——充电芯片引脚ADC
  42. SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC, //自检失败——电池分压电阻ADC
  43. SELFCHECK_RESULT_ERR_RSSI, //自检失败——RSSI
  44. SELFCHECK_RESULT_ERR_MT, //自检失败——震动电机
  45. SELFCHECK_RESULT_ERR_FRONT_IMU_REVERSE, //自检失败——前脚传感器装反
  46. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS, //自检失败——前脚传感器配置六轴
  47. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG, //自检失败——前脚传感器配置地磁
  48. SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA, //自检失败——前脚传感器六轴没数据
  49. SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA, //自检失败——前脚传感器六轴数据异常(数据持续相等)
  50. SELFCHECK_RESULT_ERR_FRONT_MAG_NO_DATA, //自检失败——前脚传感器地磁没数据
  51. SELFCHECK_RESULT_ERR_FRONT_MAG_EXCP_DATA, //自检失败——前脚传感器地磁数据异常(数据持续相等)
  52. SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL, //自检失败——前脚传感器地磁数据过小
  53. SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG, //自检失败——后脚传感器配置
  54. SELFCHECK_RESULT_ERR_BACK_NO_DATA, //自检失败——后脚传感器没数据
  55. SELFCHECK_RESULT_ERR_BACK_EXCP_DATA, //自检失败——后脚传感器数据异常(数据持续相等)
  56. SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL, //自检失败——后脚传感器地磁数据过小
  57. SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG, //自检失败——中间传感器配置
  58. SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA, //自检失败——中间传感器没数据或数据异常
  59. } SELFCHECK_RESULT_e;
  60. typedef struct _selfcheck
  61. {
  62. uint32_t selfcheck_result; //自检结果
  63. uint32_t selfcheck_result_led_color; //自检结果的led灯颜色
  64. uint32_t selfcheck_result_flash_num; //自检结果闪烁次数
  65. int16_t max_rssi; //最大的RSSI值
  66. fml_imu_data_t f_data; //前脚传感器数据
  67. fml_imu_data_t b_data; //后脚传感器数据
  68. qma_data_t m_data; //中间传感器数据
  69. bool f_is_read_data; //前脚传感器是否读到数据标志位
  70. bool b_is_read_data; //后脚传感器是否读到数据标志位
  71. char order; //指令
  72. } SelfCheck_t;
  73. /*Local Variable ------------------------------------------------------------------------------------------------------------------------------------*/
  74. static SelfCheck_t ob_selfcheck;
  75. static const bll_imu_one_way_param_t game_front_param={
  76. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //前脚 - 加速度正常模式
  77. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //前脚 - 陀螺仪正常模式
  78. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //前脚 - 时间戳25US精度
  79. .timestamp_switch = FML_IMU_TIMESTAMP_ON, //前脚 - 时间戳开启
  80. .acc_fs = FML_IMU_ACC_FS_16G, //前脚 - 加速度量程 - 16G
  81. .gry_fs = FML_IMU_GRY_FS_2000DPS, //前脚 - 陀螺仪量程 - 2000DPS
  82. .mag_fs = FML_IMU_MAG_FS_30GS, //前脚 - 地磁计量程 - 30GS
  83. .acc_odr = FML_IMU_ACC_ODR_416HZ, //前脚 - 加速度采样频率 - 104HZ
  84. .gry_odr = FML_IMU_GRY_ODR_416HZ, //前脚 - 陀螺仪采样频率 - 104HZ
  85. .mag_odr = FML_IMU_MAG_ODR_200HZ, //前脚 - 地磁计采样频率 - 200HZ
  86. .fifo_odr = FML_IMU_FIFO_ODR_416HZ,
  87. };
  88. static const bll_imu_one_way_param_t game_back_param={
  89. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //后脚 - 加速度正常模式
  90. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //后脚 - 陀螺仪正常模式
  91. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //后脚 - 时间戳25US精度
  92. .timestamp_switch = FML_IMU_TIMESTAMP_OFF, //后脚 - 时间戳关闭
  93. .acc_fs = FML_IMU_ACC_FS_16G, //后脚 - 加速度量程 - 16G
  94. .gry_fs = FML_IMU_GRY_FS_2000DPS, //后脚 - 陀螺仪量程 - 2000DPS
  95. .mag_fs = FML_IMU_MAG_FS_30GS, //后脚 - 地磁计量程 - 30GS
  96. .acc_odr = FML_IMU_ACC_ODR_OFF, //后脚 - 加速度采样频率 - 关闭
  97. .gry_odr = FML_IMU_GRY_ODR_OFF, //后脚 - 陀螺仪采样频率 - 关闭
  98. .mag_odr = FML_IMU_MAG_ODR_200HZ, //后脚 - 地磁计采样频率 - 200HZ
  99. .fifo_odr = FML_IMU_FIFO_ODR_OFF,
  100. };
  101. static const bll_imu_param_t game_bll_imu_param_t={
  102. .config_param[FML_IMU_DIR_FRONT] = &game_front_param,
  103. .config_param[FML_IMU_DIR_BACK] = &game_back_param,
  104. };
  105. static MahonyAHRS_t Self_Mind_Mahony={0};
  106. static MahonyAHRS_t Self_Front_Mahony={0};
  107. /*Local Functions ------------------------------------------------------------------------------------------------------------------------------------*/
  108. static void monitor_sensor_data(int16_t *f_acc, int16_t *f_gry, int16_t *f_mag, int16_t *b_mag)
  109. {
  110. static int16_t last_f_acc[3]; //上一次的前脚加速度值
  111. static int16_t last_f_gry[3]; //上一次的前脚陀螺仪值
  112. static int16_t last_f_mag[3]; //上一次的前脚地磁计值
  113. static int16_t last_b_mag[3]; //上一次的后脚地磁计值
  114. static int16_t last_f_acc_err_sum; //上一次的前脚加速度值错误累计
  115. static int16_t last_f_gry_err_sum; //上一次的前脚陀螺仪值错误累计
  116. static int16_t last_f_mag_err_sum; //上一次的前脚地磁计值错误累计
  117. static int16_t last_b_mag_err_sum; //上一次的后脚地磁计值错误累计
  118. /*前脚加速度*/
  119. if(f_acc != NULL)
  120. {
  121. if(
  122. last_f_acc[0] == f_acc[0] && \
  123. last_f_acc[1] == f_acc[1] && \
  124. last_f_acc[2] == f_acc[2]
  125. )
  126. {
  127. last_f_acc_err_sum++;
  128. if(last_f_acc_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  129. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA);
  130. }
  131. }else{
  132. last_f_acc_err_sum = 0;
  133. }
  134. last_f_acc[0] = f_acc[0];
  135. last_f_acc[1] = f_acc[1];
  136. last_f_acc[2] = f_acc[2];
  137. }
  138. /*前脚陀螺仪*/
  139. if(f_gry != NULL)
  140. {
  141. if(
  142. last_f_gry[0] == f_gry[0] && \
  143. last_f_gry[1] == f_gry[1] && \
  144. last_f_gry[2] == f_gry[2]
  145. )
  146. {
  147. last_f_gry_err_sum++;
  148. if(last_f_gry_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  149. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA);
  150. }
  151. }else{
  152. last_f_gry_err_sum = 0;
  153. }
  154. last_f_gry[0] = f_gry[0];
  155. last_f_gry[1] = f_gry[1];
  156. last_f_gry[2] = f_gry[2];
  157. }
  158. /*前脚地磁计*/
  159. if(f_mag != NULL)
  160. {
  161. if(
  162. last_f_mag[0] == f_mag[0] && \
  163. last_f_mag[1] == f_mag[1] && \
  164. last_f_mag[2] == f_mag[2]
  165. )
  166. {
  167. last_f_mag_err_sum++;
  168. if(last_f_mag_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  169. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_MAG_EXCP_DATA);
  170. }
  171. }else{
  172. last_f_mag_err_sum = 0;
  173. }
  174. last_f_mag[0] = f_mag[0];
  175. last_f_mag[1] = f_mag[1];
  176. last_f_mag[2] = f_mag[2];
  177. }
  178. /*后脚地磁计*/
  179. if(b_mag != NULL)
  180. {
  181. if(
  182. last_b_mag[0] == b_mag[0] && \
  183. last_b_mag[1] == b_mag[1] && \
  184. last_b_mag[2] == b_mag[2]
  185. )
  186. {
  187. last_b_mag_err_sum++;
  188. if(last_b_mag_err_sum >= (SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX/2)){
  189. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_EXCP_DATA);
  190. }
  191. }else{
  192. last_b_mag_err_sum = 0;
  193. }
  194. last_b_mag[0] = b_mag[0];
  195. last_b_mag[1] = b_mag[1];
  196. last_b_mag[2] = b_mag[2];
  197. }
  198. }
  199. static void fb_data_notify_cb(uint32_t dir_bit)
  200. {
  201. int data_len;
  202. if((dir_bit >> BLL_IMU_DIR_FRONT) & 0x01)
  203. {
  204. memset(&ob_selfcheck.f_data,0,sizeof(ob_selfcheck.f_data));
  205. data_len = bll_imu_get_data_num(BLL_IMU_DIR_FRONT);
  206. for(int i=0; i<data_len;i++)
  207. {
  208. bll_imu_get_data(BLL_IMU_DIR_FRONT, i, &ob_selfcheck.f_data);
  209. }
  210. monitor_sensor_data(ob_selfcheck.f_data.acc, ob_selfcheck.f_data.gry, ob_selfcheck.f_data.mag, NULL);
  211. Mahony_update(&Self_Front_Mahony,0,0,0,ob_selfcheck.f_data.acc[0],ob_selfcheck.f_data.acc[1],ob_selfcheck.f_data.acc[2],0,0,0);
  212. }
  213. if((dir_bit >> BLL_IMU_DIR_BACK) & 0x01)
  214. {
  215. memset(&ob_selfcheck.b_data,0,sizeof(ob_selfcheck.b_data));
  216. data_len = bll_imu_get_data_num(BLL_IMU_DIR_BACK);
  217. for(int i=0; i<data_len;i++)
  218. {
  219. bll_imu_get_data(BLL_IMU_DIR_BACK, i, &ob_selfcheck.b_data);
  220. }
  221. monitor_sensor_data(NULL, NULL, NULL, ob_selfcheck.b_data.mag);
  222. }
  223. if(((dir_bit >> BLL_IMU_DIR_FRONT) & 0x01))
  224. {
  225. ob_selfcheck.f_is_read_data = true;
  226. }
  227. if((dir_bit >> BLL_IMU_DIR_BACK))
  228. {
  229. ob_selfcheck.b_is_read_data = true;
  230. }
  231. }
  232. static void scan_report_cb(ble_gap_evt_adv_report_t const * p_adv_report)
  233. {
  234. ob_selfcheck.max_rssi = (ob_selfcheck.max_rssi > p_adv_report->rssi)?ob_selfcheck.max_rssi:p_adv_report->rssi;
  235. }
  236. static void selfcheck_result_display_process(void)
  237. {
  238. static uint32_t led_display_count = 0;
  239. //根据自检结果显示结果:
  240. //前脚传感器——红色(前脚六轴配置问题闪烁1下,前脚地磁配置问题闪烁2下,前脚六轴数据读取失败或数据异常闪烁3下,前脚地磁数据读取失败或数据异常闪烁4下)
  241. //后脚传感器——红色(后脚地磁配置问题闪烁5下,后脚地磁数据读取失败或数据异常闪烁6下)
  242. //中间传感器——红色(中间加速度配置问题闪烁7下,加速度roll值不在范围内闪烁8下)
  243. //充电芯片和电池分压电阻和蓝牙天线rssi——红色(充电芯片问题闪烁9下,电池分压电阻闪烁10下,蓝牙天线rssi问题闪烁11下)
  244. //中间加速度检测震动电机(待定)
  245. //上述检测通过,蓝色(1秒周期,500ms亮,500ms灭(断电源线)),若检测到鞋垫,则绿色(1秒周期,500ms亮,500ms灭(断电源线))。
  246. //LED电源引脚亮灯拉高,灭灯拉低。(4秒周期,40ms亮,160ms灭(断电源线)一组)
  247. //喂狗
  248. feed_watchdog();
  249. Process_UpdatePeroid(selfcheck_result_display_process,SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD);
  250. led_display_count++;
  251. if(led_display_count % 2 == 0)
  252. {
  253. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  254. }
  255. else
  256. {
  257. WS2812_DisplayDot(ob_selfcheck.selfcheck_result_led_color);WS2812_Pwm_Play();
  258. }
  259. if(led_display_count >= ob_selfcheck.selfcheck_result_flash_num * 2)
  260. {
  261. led_display_count = 0;
  262. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  263. Process_UpdatePeroid(selfcheck_result_display_process,SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD * 3);
  264. }
  265. }
  266. static void selfcheck_mt_process(void)
  267. {
  268. static int16_t max_acc_z = 0;
  269. int16_t acc_z = 0;
  270. static uint8_t flow = 0;
  271. //喂狗
  272. feed_watchdog();
  273. nrf_gpio_pin_write(PIN_MT_EN,1);
  274. switch(flow)
  275. {
  276. case 0:
  277. WS2812_DisplayDot(COLOR_RED);WS2812_Pwm_Play();
  278. flow = 1;
  279. break;
  280. case 1:
  281. WS2812_DisplayDot(COLOR_GREEN);WS2812_Pwm_Play();
  282. flow = 2;
  283. break;
  284. case 2:
  285. WS2812_DisplayDot(COLOR_BLUE);WS2812_Pwm_Play();
  286. flow = 0;
  287. break;
  288. }
  289. //检测震动是否达标
  290. //读取中间传感器数据,计算加速度roll值
  291. if(ob_selfcheck.order == 0x52)
  292. {
  293. memset(&ob_selfcheck.m_data,0,sizeof(ob_selfcheck.m_data));
  294. if(drv_qma_get_acc_data(&ob_selfcheck.m_data) == 0)
  295. {
  296. if(ob_selfcheck.m_data.acc[2] < 0)acc_z = ob_selfcheck.m_data.acc[2]*-1;
  297. else acc_z = ob_selfcheck.m_data.acc[2];
  298. max_acc_z = (max_acc_z > acc_z)?max_acc_z:acc_z;
  299. if(max_acc_z < SELFCHECK_MIDDLE_ACC_CHECK_MT_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MT);
  300. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_MT);
  301. // SEGGER_RTT_printf(0,"middle acc %d,%d,%d acc_z:%d,max:%d\r\n",ob_selfcheck.m_data.acc[0],ob_selfcheck.m_data.acc[1],ob_selfcheck.m_data.acc[2],acc_z,max_acc_z);
  302. }
  303. }
  304. }
  305. #define N 10 //N > 3
  306. int data[N];
  307. int middleFilter(int in_data)
  308. {
  309. int sum = 0;
  310. int temp[N];
  311. int change;
  312. int i,j;
  313. //记录数据
  314. for(i=0; i<(N-1); i++)
  315. {
  316. data[i]=data[i+1];
  317. }
  318. data[N-1] = in_data;
  319. //复制数据
  320. for(i=0; i<N; i++)
  321. temp[i] = data[i];
  322. //冒泡法排序
  323. for(i=1; i<N; i++)
  324. for(j=0; j<N-i; j++)
  325. {
  326. if(temp[i] > temp[i+1])
  327. {
  328. change = temp[i];
  329. temp[i] = temp[i+1];
  330. temp[i+1] = change;
  331. }
  332. }
  333. //求和
  334. for(i=1; i<(N-1); i++)
  335. sum = sum + temp[i];
  336. //返回平均值
  337. return(sum/((N-2)));
  338. }
  339. static void selfcheck_process(void)
  340. {
  341. BLL_IMU_CONFIG_RESULT f_config_result,b_config_result;
  342. int16_t adc_value = 0;
  343. uint16_t front_mag_norm;
  344. uint16_t back_mag_norm;
  345. int16_t roll;
  346. uint8_t buf[256];
  347. uint8_t L=0;
  348. char mac_buf[16];
  349. static uint32_t charge_chip_adc_max = 0;
  350. static int16_t battery_adc_max = 0;
  351. static uint32_t t_count = 0;
  352. static uint32_t battery_adc_t_count = 0;
  353. static uint32_t roll_t_count = 0;
  354. static uint32_t sensor_t_count = 0;
  355. static uint32_t last_tim = 0;
  356. static uint32_t continue_trigger = 0;
  357. t_count++;
  358. //喂狗
  359. feed_watchdog();
  360. //读取中间传感器数据,计算加速度roll值
  361. memset(&ob_selfcheck.m_data,0,sizeof(ob_selfcheck.m_data));
  362. if(drv_qma_get_acc_data(&ob_selfcheck.m_data) != 0)
  363. {
  364. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  365. //重新配置
  366. drv_qma_set_acc_odr(QMA_ACC_ODR_104HZ);
  367. }
  368. Mahony_update(&Self_Mind_Mahony,0,0,0,ob_selfcheck.m_data.acc[0],ob_selfcheck.m_data.acc[1],ob_selfcheck.m_data.acc[2],0,0,0);
  369. //筛选最大的电池分压后的电压
  370. fml_adc_get_value(PIN_ADC_BAT_CHANNEL,&adc_value);
  371. adc_value = ADC_RESULT_IN_MILLI_VOLTS(adc_value) * 5 / 3;
  372. battery_adc_max = middleFilter(adc_value);
  373. //每3秒读取ADC,以5V电压测试电池分压电阻是否焊接,不考虑阻值,设置自检结果。
  374. if(t_count - battery_adc_t_count > (3000/100))
  375. {
  376. if(!(SELFCHECK_BATTERY_PIN_ADC_MIN_THRESHOLD < battery_adc_max && battery_adc_max < SELFCHECK_BATTERY_PIN_ADC_MAX_THRESHOLD))ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC);
  377. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC);
  378. //更新计时
  379. battery_adc_t_count = t_count;
  380. }
  381. //充电芯片检测
  382. fml_adc_get_value(PIN_ADC_CHARGMEASURE_CHANNEL,&adc_value);
  383. if(SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD < adc_value)
  384. {
  385. charge_chip_adc_max++;
  386. }
  387. if(charge_chip_adc_max > 10)
  388. {
  389. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
  390. }
  391. else
  392. {
  393. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
  394. }
  395. //每3秒检测加速度roll值,设置自检结果。
  396. if(t_count - roll_t_count > (3000/100))
  397. {
  398. roll = (int16_t)(Self_Mind_Mahony.roll*100);
  399. if(roll < 0)roll *= -1;
  400. roll = (roll > 0 && roll < 100)?1:roll/100;
  401. if(!( \
  402. (SELFCHECK_MIDDLE_ACC_PROS_ROLL_MIN_THRESHOLD < roll && roll < SELFCHECK_MIDDLE_ACC_PROS_ROLL_MAX_THRESHOLD) || \
  403. (SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD < roll && roll < SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD) \
  404. ))ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  405. else
  406. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  407. //更新计时
  408. roll_t_count = t_count;
  409. }
  410. //每1秒查看前后传感器是否配置且读取成功(至少要1秒才有结果)且值本身是否正常(如地磁没有焊接电容),设置自检结果。
  411. if(t_count - sensor_t_count > (1000/100))
  412. {
  413. //前脚传感器判断
  414. f_config_result = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_FRONT,&game_bll_imu_param_t);
  415. if(f_config_result != BLL_IMU_CONFIG_FINISH)
  416. {
  417. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_SIX_AXIS_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS_ID);
  418. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_MAG_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG_ID);
  419. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_MAG)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG);
  420. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_SIX_AXIS)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS);
  421. }
  422. else
  423. {
  424. //配置没问题
  425. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG);
  426. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS);
  427. if(ob_selfcheck.f_is_read_data != true)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA);
  428. else
  429. {
  430. //数据没问题
  431. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA);
  432. ob_selfcheck.f_is_read_data = false;
  433. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  434. //前脚传感器地磁没焊接电容
  435. if(front_mag_norm < SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL);
  436. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL);
  437. }
  438. }
  439. //后脚传感器判断
  440. b_config_result = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_BACK,&game_bll_imu_param_t);
  441. if(b_config_result != BLL_IMU_CONFIG_FINISH)
  442. {
  443. if(b_config_result == BLL_IMU_CONFIG_FAIL_BACK_MAG_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG_ID);
  444. else ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG);
  445. }
  446. else
  447. {
  448. //配置没问题
  449. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG);
  450. if(ob_selfcheck.b_is_read_data != true)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_NO_DATA);
  451. else
  452. {
  453. //数据没问题
  454. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_NO_DATA);
  455. ob_selfcheck.b_is_read_data = false;
  456. back_mag_norm = sqrt((double)(ob_selfcheck.b_data.mag[0]*ob_selfcheck.b_data.mag[0]) + (double)(ob_selfcheck.b_data.mag[1]*ob_selfcheck.b_data.mag[1]) + (double)(ob_selfcheck.b_data.mag[2]*ob_selfcheck.b_data.mag[2]));
  457. //后脚传感器地磁没焊接电容
  458. if(back_mag_norm < SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL);
  459. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL);
  460. }
  461. }
  462. //任意传感器配置失败,重新配置
  463. if(f_config_result != BLL_IMU_CONFIG_FINISH || b_config_result != BLL_IMU_CONFIG_FINISH || ob_selfcheck.b_is_read_data != true || ob_selfcheck.f_is_read_data != true)
  464. {
  465. bll_imu_Resume_config_param(&game_bll_imu_param_t);
  466. }
  467. //更新计时-
  468. sensor_t_count = t_count;
  469. }
  470. //第3秒获取前脚是否装反
  471. if(t_count == (3000/100) && ob_selfcheck.order == 0x52)
  472. {
  473. roll = (int16_t)(Self_Front_Mahony.roll*100);
  474. if(roll < 0)roll *= -1;
  475. roll = (roll > 0 && roll < 100)?1:roll/100;
  476. if(!(roll >=SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD && roll <= SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD))
  477. {
  478. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_IMU_REVERSE);
  479. }
  480. // SEGGER_RTT_printf(0,"front roll:%d\r\n",roll);
  481. }
  482. //第3秒查看能否读取到任意广播名字,且最小的RSSI是否满足条件,设置自检结果。
  483. if(t_count == (3000/100))
  484. {
  485. if(SELFCHECK_SCAN_DEVICE_RSSI_MIN_THRESHOLD >= ob_selfcheck.max_rssi)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_RSSI);
  486. }
  487. //第3秒关闭100毫秒震动电机自检线程
  488. if(t_count == (3000/100))
  489. {
  490. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  491. nrf_gpio_pin_write(PIN_MT_EN,0);
  492. Process_Stop(selfcheck_mt_process);
  493. }
  494. //第3+SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD秒初始化自检显示结果线程,设置holdon,全功率运行。
  495. if(t_count == ((3000 + SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD)/100))
  496. {
  497. //根据自检结果设置灯
  498. if(ob_selfcheck.selfcheck_result == 0)
  499. {
  500. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  501. if(SELFCHECK_WEAR_INSOLE_MAG_NORM_MIN_THRESHOLD <= front_mag_norm)
  502. {
  503. ob_selfcheck.selfcheck_result_led_color = COLOR_GREEN;
  504. ob_selfcheck.selfcheck_result_flash_num = 1;
  505. }
  506. else
  507. {
  508. ob_selfcheck.selfcheck_result_led_color = COLOR_BLUE;
  509. ob_selfcheck.selfcheck_result_flash_num = 1;
  510. }
  511. }
  512. else
  513. {
  514. ob_selfcheck.selfcheck_result_led_color = COLOR_RED;
  515. for(int i=0;i<sizeof(ob_selfcheck.selfcheck_result)*8;i++)
  516. {
  517. if((ob_selfcheck.selfcheck_result & (1 << i)) != 0)
  518. {
  519. ob_selfcheck.selfcheck_result_flash_num = i;
  520. break;
  521. }
  522. }
  523. }
  524. Process_Start(SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD,"selfcheck_result_display_process",selfcheck_result_display_process);
  525. Process_SetHoldOn(selfcheck_result_display_process,1);
  526. }
  527. //上报中间传感器的加速度值和roll值
  528. L=0;
  529. int16_t rol = (int16_t)(Mahony_M_GetRoll()*100);
  530. int16_t pitch = (int16_t)(Mahony_M_GetPitch()*100);
  531. int16_t yaw = (int16_t)(Mahony_M_GetYaw()*100);
  532. buf[L++] = (uint8_t)(rol>>8);
  533. buf[L++] = (uint8_t)(rol>>0);
  534. buf[L++] = (uint8_t)(pitch>>8);
  535. buf[L++] = (uint8_t)(pitch>>0);
  536. buf[L++] = (uint8_t)(yaw>>8);
  537. buf[L++] = (uint8_t)(yaw>>0);
  538. buf[L++] = 0;
  539. buf[L++] = 0;
  540. buf[L++] = 0;
  541. buf[L++] = 0;
  542. buf[L++] = 0;
  543. buf[L++] = 0;
  544. buf[L++] = 0;
  545. Mahony_send_ANO(0x01,buf,L);
  546. L=0;
  547. int32_t middle_acc_x = ob_selfcheck.m_data.acc[0];
  548. int32_t middle_acc_y = ob_selfcheck.m_data.acc[1];
  549. int16_t middle_acc_z = ob_selfcheck.m_data.acc[2];
  550. middle_acc_x *= 100;
  551. middle_acc_y *= 100;
  552. middle_acc_z *= 10;
  553. buf[L++] = (uint8_t)(middle_acc_x>>24);
  554. buf[L++] = (uint8_t)(middle_acc_x>>16);
  555. buf[L++] = (uint8_t)(middle_acc_x>>8);
  556. buf[L++] = (uint8_t)(middle_acc_x>>0);
  557. buf[L++] = (uint8_t)(middle_acc_y>>24);
  558. buf[L++] = (uint8_t)(middle_acc_y>>16);
  559. buf[L++] = (uint8_t)(middle_acc_y>>8);
  560. buf[L++] = (uint8_t)(middle_acc_y>>0);
  561. buf[L++] = (uint8_t)(middle_acc_z>>8);
  562. buf[L++] = (uint8_t)(middle_acc_z>>0);
  563. Mahony_send_ANO(0x07,buf,L);
  564. //上报前脚传感器的加速度数据、陀螺仪数据、地磁计开平方和数据
  565. //上报后脚传感器的地磁计开平方和数据
  566. //上报扫描到的任意广播的rssi值
  567. if(TIME_GetTicks()-last_tim >= 1000)
  568. {
  569. last_tim = TIME_GetTicks();
  570. ob_selfcheck.max_rssi = -120;
  571. }
  572. L=0;
  573. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[0]>>8);
  574. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[0]>>0);
  575. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[1]>>8);
  576. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[1]>>0);
  577. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[2]>>8);
  578. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[2]>>0);
  579. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[0]>>8);
  580. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[0]>>0);
  581. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[1]>>8);
  582. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[1]>>0);
  583. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[2]>>8);
  584. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[2]>>0);
  585. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  586. back_mag_norm = sqrt((double)(ob_selfcheck.b_data.mag[0]*ob_selfcheck.b_data.mag[0]) + (double)(ob_selfcheck.b_data.mag[1]*ob_selfcheck.b_data.mag[1]) + (double)(ob_selfcheck.b_data.mag[2]*ob_selfcheck.b_data.mag[2]));
  587. buf[L++] = (uint8_t)(front_mag_norm>>8);
  588. buf[L++] = (uint8_t)(front_mag_norm>>0);
  589. buf[L++] = (uint8_t)(back_mag_norm>>8);
  590. buf[L++] = (uint8_t)(back_mag_norm>>0);
  591. buf[L++] = (uint8_t)(ob_selfcheck.max_rssi>> 8);
  592. buf[L++] = (uint8_t)(ob_selfcheck.max_rssi>>0);
  593. Mahony_send_ANO(0x02,buf,L);
  594. fml_adc_get_value(PIN_CHARGING_CHANNEL,&adc_value);
  595. if(adc_value >= 2000)
  596. {
  597. if(continue_trigger <= 50)continue_trigger++;
  598. }
  599. else
  600. {
  601. if(continue_trigger != 0)continue_trigger--;
  602. }
  603. // SEGGER_RTT_printf(0,"continue_trigger:%d,%d\r\n",continue_trigger,adc_value);
  604. // SEGGER_RTT_printf(0,"front mag:%d,%d,%d,%d\r\n",ob_selfcheck.f_data.mag[0],ob_selfcheck.f_data.mag[1],ob_selfcheck.f_data.mag[2],front_mag_norm);
  605. // SEGGER_RTT_printf(0,"back mag:%d,%d,%d,%d\r\n",ob_selfcheck.b_data.mag[0],ob_selfcheck.b_data.mag[1],ob_selfcheck.b_data.mag[2],back_mag_norm);
  606. //第30秒重启
  607. if(t_count >= (30000/100) && !slave_isconnect() && continue_trigger==0)
  608. {
  609. memset(mac_buf, 0, sizeof(mac_buf));
  610. sprintf(mac_buf, "%02X%02X%02X%02X%02X%02X", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2], mFlash.mClient.macAddr[3], mFlash.mClient.macAddr[4], mFlash.mClient.macAddr[5]);
  611. ST_scan_stop();
  612. host_set_scan_name(mac_buf, strlen(mac_buf));
  613. //恢复出厂信息
  614. memset(&mFlash,0xFF,sizeof(mFlash));
  615. memset(&mBackup,0xFF,sizeof(mBackup));
  616. //保存数据到flash
  617. if(Flash_SaveStep() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save step fail");
  618. extern battercb_t battery_record;
  619. // extern void printbatter_cb(battercb_t *c,unsigned char *buff);
  620. memcpy(&mFlash.mbattercb_t,&battery_record,sizeof(battercb_t));
  621. mBackup.RestartCnt =0;
  622. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save backup fail");
  623. if(Flash_SaveInfomation() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save information fail");
  624. NVIC_SystemReset();
  625. }
  626. }
  627. static void adc_callback(uint32_t sample_point, Fml_Adc_All_Channel_Adc_Value_t all_adc_value)
  628. {
  629. //纯粹做覆盖
  630. }
  631. /*API ------------------------------------------------------------------------------------------------------------------------------------*/
  632. /**
  633. @brief 自检触发回调
  634. @param order - [in] 回调触发的指令
  635. @return 无
  636. */
  637. void selfcheck_trigger_callback(char order)
  638. {
  639. int error;
  640. uint32_t last_tim = TIME_GetTicks();
  641. //喂狗
  642. feed_watchdog();
  643. //初始化结构体,自检结果为成功
  644. memset(&ob_selfcheck,0,sizeof(ob_selfcheck));
  645. ob_selfcheck.max_rssi = -120;
  646. ob_selfcheck.selfcheck_result = SELFCHECK_RESULT_SUCCESS;
  647. ob_selfcheck.selfcheck_result_led_color = COLOR_BLACK;
  648. ob_selfcheck.f_is_read_data = false;
  649. ob_selfcheck.b_is_read_data = false;
  650. ob_selfcheck.order = order;
  651. //关闭所有线程,初始化0毫秒自检线程,设置holdon,全功率运行。
  652. Process_All_Stop();
  653. Process_Start(100,"selfcheck_process",selfcheck_process);
  654. Process_SetHoldOn(selfcheck_process,1);
  655. //关闭扫描,设置任意设备扫描回调,开启扫描
  656. while(TIME_GetTicks() - last_tim <= 1000)
  657. {
  658. host_disconnect();
  659. if(host_isconnect() == 0)break;
  660. }
  661. nrf_ble_scan_stop();
  662. host_set_scan_name((char *)"***********",sizeof("***********"));
  663. advdata_report_Evt_Regist(scan_report_cb);
  664. error = ST_scan_start();
  665. if(error != APP_SUCCESS)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_RSSI);
  666. //配置LED电源引脚为输出SOD1
  667. nrf_gpio_cfg(
  668. PIN_LED_ENABLE,
  669. NRF_GPIO_PIN_DIR_OUTPUT,
  670. NRF_GPIO_PIN_INPUT_DISCONNECT,
  671. NRF_GPIO_PIN_NOPULL,
  672. NRF_GPIO_PIN_S0D1,
  673. NRF_GPIO_PIN_NOSENSE);
  674. //配置震动电机引脚为输出SOS1
  675. nrf_gpio_cfg_output(PIN_MT_EN);
  676. nrf_gpio_pin_write(PIN_MT_EN,0);
  677. //配置led灯电源引脚为输出
  678. nrf_gpio_pin_write(PIN_LED_ENABLE,LED_ENABLE);
  679. //重新初始化ADC,配置所有通道。
  680. ADC_SetPinChannel(PIN_ADC_CHARGMEASURE, PIN_ADC_CHARGMEASURE_CHANNEL,NRF_GPIO_PIN_NOPULL);
  681. ADC_SetPinChannel(PIN_ADC_BAT_IN, PIN_ADC_BAT_CHANNEL,NRF_GPIO_PIN_NOPULL);
  682. ADC_SetPinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);
  683. fml_adc_sample_update_notify_register(adc_callback);
  684. //配置前脚传感器、中间传感器、后脚传感器
  685. bll_imu_Init();
  686. bll_imu_register_data_notify_callback(BLL_IMU_DATA_NOTIFY_CB_PRIORITY_1, fb_data_notify_cb);
  687. bll_imu_Resume_config_param(&game_bll_imu_param_t);
  688. error = drv_qma_Init();
  689. if(error == -1)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG);
  690. nrf_delay_ms(20);
  691. error = drv_qma_set_acc_odr(QMA_ACC_ODR_104HZ);
  692. if(error == -1)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG);
  693. //初始化震动电机自检线程
  694. Process_Start(SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD,"selfcheck_mt_process",selfcheck_mt_process);
  695. Process_SetHoldOn(selfcheck_mt_process,1);
  696. //初始化计算roll值算法
  697. Mahony_Init(&Self_Mind_Mahony,104);
  698. Mahony_Init(&Self_Front_Mahony,416);
  699. //喂狗
  700. feed_watchdog();
  701. }