app_math.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "app_math.h"
  2. #include "bsp_time.h"
  3. #include "system.h"
  4. #include "math.h"
  5. #include "ble_comm.h"
  6. #include "app_flash.h"
  7. #include "detect_zero_vel.h"
  8. #include "tool.h"
  9. #include "app_switchimu.h"
  10. #include "detect_step_by_mag.h"
  11. #include "pdrStatus.h"
  12. #include "detect_step_by_mag.h"
  13. #include "app_client_step.h"
  14. #include "hal_mt.h"
  15. #include "hal_led.h"
  16. #include "bll_imu.h"
  17. #include "app_game.h"
  18. static uint32_t timeCNT = 0;
  19. static uint8_t FlagFix_process = 0;
  20. //叫硫珂쇌
  21. void app_math_calit_time(uint8_t appminute){
  22. timeCNT = (appminute)*60*32768;
  23. }
  24. //寧鬼珂셕珂
  25. static void app_math_Hour_process(void){
  26. static uint8_t Halfhour_cnt =0;
  27. uint32_t sec = 0;
  28. static uint32_t cnt_b=0;
  29. uint32_t cnt = NRF_RTC0->COUNTER;
  30. if(cnt<cnt_b) cnt += 16777216;
  31. timeCNT += cnt - cnt_b;
  32. sec = (timeCNT)/32768;
  33. if(cnt >16777216)cnt_b = cnt - 16777216;
  34. else cnt_b = cnt;
  35. if(sec >=1800){//곕鬼珂
  36. if(1 != Halfhour_cnt){
  37. Halfhour_cnt =1;
  38. FlagFix_process =1;
  39. }
  40. }
  41. if(sec >= 3600){//寧鬼珂
  42. timeCNT =0;
  43. app_client_step_SetIsScan();
  44. FlagFix_process =1;
  45. Halfhour_cnt =0;
  46. DEBUG_LOG("timeCNT(%d)(%d)\n",timeCNT,sec);
  47. }
  48. }
  49. //炬랬叫硫친駕
  50. static const bll_imu_one_way_param_t calibration_front_param={
  51. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //품신 - 속醵똑攣끽친駕
  52. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //품신 - 顧쭁老攣끽친駕
  53. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //품신 - 珂쇌늑25US쑹똑
  54. .timestamp_switch = FML_IMU_TIMESTAMP_ON, //품신 - 珂쇌늑역폘
  55. .acc_fs = FML_IMU_ACC_FS_16G, //품신 - 속醵똑좆넋 - 16G
  56. .gry_fs = FML_IMU_GRY_FS_2000DPS, //품신 - 顧쭁老좆넋 - 2000DPS
  57. .mag_fs = FML_IMU_MAG_FS_30GS, //품신 - 뒈늚셕좆넋 - 30GS
  58. .acc_odr = FML_IMU_ACC_ODR_104HZ, //품신 - 속醵똑꽃湳틉쪽 - 104HZ
  59. .gry_odr = FML_IMU_GRY_ODR_104HZ, //품신 - 顧쭁老꽃湳틉쪽 - 104HZ
  60. .mag_odr = FML_IMU_MAG_ODR_200HZ, //품신 - 뒈늚셕꽃湳틉쪽 - 200HZ
  61. .fifo_odr = FML_IMU_FIFO_ODR_104HZ,
  62. };
  63. static const bll_imu_one_way_param_t calibration_back_param={
  64. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //빈신 - 속醵똑攣끽친駕
  65. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //빈신 - 顧쭁老攣끽친駕
  66. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //빈신 - 珂쇌늑25US쑹똑
  67. .timestamp_switch = FML_IMU_TIMESTAMP_OFF, //빈신 - 珂쇌늑밑균
  68. .acc_fs = FML_IMU_ACC_FS_16G, //빈신 - 속醵똑좆넋 - 16G
  69. .gry_fs = FML_IMU_GRY_FS_2000DPS, //빈신 - 顧쭁老좆넋 - 2000DPS
  70. .mag_fs = FML_IMU_MAG_FS_30GS, //빈신 - 뒈늚셕좆넋 - 30GS
  71. .acc_odr = FML_IMU_ACC_ODR_OFF, //빈신 - 속醵똑꽃湳틉쪽 - 밑균
  72. .gry_odr = FML_IMU_GRY_ODR_OFF, //빈신 - 顧쭁老꽃湳틉쪽 - 밑균
  73. .mag_odr = FML_IMU_MAG_ODR_200HZ, //빈신 - 뒈늚셕꽃湳틉쪽 - 200HZ
  74. .fifo_odr = FML_IMU_FIFO_ODR_OFF,
  75. };
  76. static const bll_imu_param_t calibration_bll_imu_param_t={
  77. .config_param[BLL_IMU_DIR_FRONT] = &calibration_front_param,
  78. .config_param[BLL_IMU_DIR_BACK] = &calibration_back_param,
  79. };
  80. static void app_gyro_Fix_process(void){//顧쭁老쥐튤시攣
  81. static uint8_t state =0;
  82. static int16_t sample_count =0;
  83. static uint32_t tim =0;
  84. static uint8_t Setimu_config =0;
  85. bll_imu_data_t data= {0};
  86. uint8_t front_CS =0,back_CS =0;
  87. switch(state){
  88. case 0:
  89. if(!app_game_GetGameMode() && 1 == FlagFix_process){
  90. Process_SetHoldOn(app_gyro_Fix_process,1);
  91. bll_imu_Resume_config_param(&calibration_bll_imu_param_t);
  92. state =1;
  93. FlagFix_process =0;
  94. tim = TIME_GetTicks();
  95. Setimu_config =0;
  96. DEBUG_LOG("====>>>>HAL_SER_IMU_MODE_MANAGE_CALIBRATION,tim:%d s\r\n",TIME_GetTicks()/1000);
  97. }
  98. break;
  99. case 1:
  100. front_CS = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_FRONT,&calibration_bll_imu_param_t);
  101. back_CS = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_BACK,&calibration_bll_imu_param_t);
  102. if(BLL_IMU_CONFIG_FINISH == front_CS && BLL_IMU_CONFIG_FINISH == back_CS){
  103. state =2;
  104. Process_UpdatePeroid(app_gyro_Fix_process,10);
  105. sample_count =0;
  106. tim = TIME_GetTicks();
  107. // MT_Run(500);
  108. // DEBUG_LOG("====INTO HAL_SER_IMU_MODE_MANAGE_CALIBRATION\r\n");
  109. }
  110. else if(BLL_IMU_CONFIG_DOING != front_CS || BLL_IMU_CONFIG_DOING != back_CS){
  111. bll_imu_Resume_config_param(&calibration_bll_imu_param_t);
  112. if(++Setimu_config >= 20){Setimu_config =0;
  113. bll_imu_Resume_unregister_config_param(&calibration_bll_imu_param_t);
  114. state =3;
  115. Except_TxError(EXCEPT_GAME,"shoes into CALIBRATION mode fail");
  116. }
  117. }
  118. if(app_game_GetGameMode())state =3;//踏狗친駕苟藁놔
  119. break;
  120. case 2:
  121. //뗍혤ACC令6
  122. if(bll_imu_get_data_num(BLL_IMU_DIR_FRONT) >= 1){
  123. bll_imu_get_data(BLL_IMU_DIR_FRONT, 0, &data);
  124. estimate_gyr_bias_interface(data.gry,sample_count);
  125. // DEBUG_LOG("====>>>>gry:%d,%d,%d,tim:%d\r\n",data.gry[0],data.gry[1],data.gry[2],sample_count);
  126. sample_count++;
  127. }
  128. if(TIME_GetTicks()-tim>=10000){ //텝供10취藁놔
  129. state =3;
  130. // DEBUG_LOG("====>>>>HAL_SER_IMU_MODE_MANAGE_CALIBRATION\r\n");
  131. }
  132. if(app_game_GetGameMode())state =3;//踏狗친駕苟藁놔
  133. break;
  134. case 3:
  135. Process_UpdatePeroid(app_gyro_Fix_process,1000);
  136. bll_imu_Resume_unregister_config_param(&calibration_bll_imu_param_t);
  137. Process_SetHoldOn(app_gyro_Fix_process,0);
  138. state =0;
  139. Setimu_config =0;
  140. // DEBUG_LOG("====OUT app_gyro_Fix_process\r\n");
  141. break;
  142. default:state =0;Setimu_config =0;break;
  143. }
  144. }
  145. void app_math_Init(void)
  146. {
  147. // Process_Start(500,"app_gyro_Fix_process",app_gyro_Fix_process);
  148. Process_Start(1000,"app_math_Hour",app_math_Hour_process);
  149. }