app_math.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "app_math.h"
  2. #include "bsp_time.h"
  3. #include "system.h"
  4. #include "hal_ser_imu_mode_manage.h"
  5. #include "math.h"
  6. #include "ble_comm.h"
  7. #include "app_flash.h"
  8. #include "detect_zero_vel.h"
  9. #include "tool.h"
  10. #include "app_switchimu.h"
  11. #include "detect_step_by_mag.h"
  12. #include "pdrStatus.h"
  13. #include "detect_step_by_mag.h"
  14. static int16_t acc_front[20][3];
  15. static int16_t gry_front[20][3];
  16. static int16_t mag6310_front[20][3];
  17. static int16_t mag6310_back[3];
  18. static int32_t timestamp_front[20];
  19. static uint8_t rssi;
  20. static int16_t IMU_STATUS; //记录状态用来重新记录时间戳
  21. static int32_t timestamp;
  22. static int32_t last_timestamp;
  23. void process_imu_data_front(int front_index)
  24. {
  25. if(IMU_STATUS != 1)
  26. {
  27. IMU_STATUS = 1;
  28. last_timestamp = timestamp_front[0];
  29. timestamp = 0;
  30. }
  31. for(int i = 0; i < front_index; i++)
  32. {
  33. int32_t dt = timestamp_front[i] - last_timestamp;
  34. if(dt > 20000 || dt < 0)
  35. {
  36. dt = 10000;
  37. }
  38. timestamp += dt;
  39. last_timestamp = timestamp_front[i];
  40. // SEGGER_RTT_printf(0,"timestamp_front[i] : %d; i = %d\r\n", timestamp_front[i], i);
  41. IMU_Process_motion_queue(mFlash.isHost, timestamp, acc_front[i],
  42. gry_front[i],mag6310_front[i], mag6310_back, rssi);
  43. }
  44. }
  45. void app_math_TimerCounter(void)
  46. {
  47. ser_imu_data_t data;
  48. int16_t group_num = 0;
  49. //游戏模式
  50. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_GAME) != -1){
  51. // CHECK_TIMECONSUMING_START;
  52. rssi = 0-host_get_rssi();
  53. group_num = hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT);
  54. for(int i=0;i<group_num;i++){
  55. hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, i, &data);
  56. gry_front[i][0] = data.gry[0];gry_front[i][1] = data.gry[1];gry_front[i][2] = data.gry[2];
  57. acc_front[i][0] = data.acc[0];acc_front[i][1] = data.acc[1];acc_front[i][2] = data.acc[2];
  58. mag6310_front[i][0] = data.mag[0];mag6310_front[i][1] = data.mag[1];mag6310_front[i][2] = data.mag[2];
  59. timestamp_front[i] = data.fifo_timestamp;
  60. // JS_RTT_Print_06(acc_front[i][0],acc_front[i][1],acc_front[i][2],gry_front[i][0],gry_front[i][1],gry_front[i][2]);
  61. // JS_RTT_Print_06(mag6310_front[i][0],mag6310_front[i][1],mag6310_front[i][2],timestamp_front[i],0,0);
  62. }
  63. if(hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_BACK) >= 1)hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_BACK, 0, &data);
  64. mag6310_back[0] = data.mag[0];mag6310_back[1] = data.mag[1];mag6310_back[2] = data.mag[2];
  65. if(mFlash.isHost){
  66. process_imu_data_front(group_num);
  67. }else if(Slave_Get7_5ms_interval()){
  68. process_imu_data_front(group_num);
  69. }
  70. // CHECK_TIMECONSUMING_END;
  71. }else{
  72. //将状态重设为0
  73. IMU_STATUS = 0;
  74. set_pdr_status();
  75. }
  76. //实时计步模式
  77. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_REALSTEP) != -1){
  78. rssi = 0-host_get_rssi();
  79. group_num = hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT);
  80. for(int i=0;i<group_num;i++){
  81. hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, i, &data);
  82. gry_front[i][0] = data.gry[0];gry_front[i][1] = data.gry[1];gry_front[i][2] = data.gry[2];
  83. acc_front[i][0] = data.acc[0];acc_front[i][1] = data.acc[1];acc_front[i][2] = data.acc[2];
  84. mag6310_front[i][0] = data.mag[0];mag6310_front[i][1] = data.mag[1];mag6310_front[i][2] = data.mag[2];
  85. timestamp_front[i] = data.fifo_timestamp;
  86. // JS_RTT_Print_06(acc_front[i][0],acc_front[i][1],acc_front[i][2],gry_front[i][0],gry_front[i][1],gry_front[i][2]);
  87. // JS_RTT_Print_06(mag6310_front[i][0],mag6310_front[i][1],mag6310_front[i][2],timestamp_front[i],0,0);
  88. }
  89. if(hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_BACK) >= 1)hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_BACK, 0, &data);
  90. mag6310_back[0] = data.mag[0];mag6310_back[1] = data.mag[1];mag6310_back[2] = data.mag[2];
  91. if(RealTimeStep((int16_t*)mag6310_front, (int16_t*)mag6310_back, (int16_t*)acc_front)){
  92. mFlash.mStep.stepCur[0]++;
  93. }
  94. }
  95. }
  96. static void app_math_DailyStep_Process(void)
  97. {
  98. int16_t acc[3];
  99. int16_t mag6310[3];
  100. int16_t group_num = 0;
  101. ser_imu_data_t data;
  102. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_NORMAL) != -1){
  103. group_num = hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT);
  104. for(int i=0; i < group_num; i++)
  105. {
  106. hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, i, &data);
  107. mag6310[0] = data.mag[0];mag6310[1] = data.mag[1];mag6310[2] = data.mag[2];
  108. acc[0] = data.acc[0];acc[1] = data.acc[1];acc[2] = data.acc[2];
  109. //SEGGER_RTT_printf(0,"f_mx=%d\r,f_my=%d\r,f_mz=%d\r\n",mag6310[0],mag6310[1],mag6310[2]);
  110. if(1 == detect_step_by_mag(mag6310,acc[2])){
  111. mFlash.mStep.stepCur[0]++;
  112. SEGGER_RTT_printf(0,"curren step:%d\r\n",mFlash.mStep.stepCur[0]);
  113. break;
  114. }
  115. }
  116. }
  117. }
  118. //static void hal_stepSaveTest_process(void){
  119. // mFlash.mStep.stepCur[0]++;
  120. //// Flash_SaveStep();
  121. // SEGGER_RTT_printf(0,"hal step Save one minute:step %d\r\n",mFlash.mStep.stepCur[0]);
  122. //}
  123. void app_math_Init(void)
  124. {
  125. Process_Start(100,"app_math_DailyStep_Process",app_math_DailyStep_Process);
  126. Process_Start(10,"app_math_TimerCounter",app_math_TimerCounter);
  127. // if(mFlash.isHost)Process_Start(10000,"hal_stepSaveTest",hal_stepSaveTest_process);
  128. }