app_math.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "app_math.h"
  2. #include "bsp_time.h"
  3. #include "system.h"
  4. #include "hal_imu.h"
  5. #include "math.h"
  6. #include "ble_comm.h"
  7. #include "hal_flash.h"
  8. #include "detect_zero_vel.h"
  9. #include "tool.h"
  10. #include "app_switchimu.h"
  11. #include "pdrStatus.h"
  12. static int16_t acc_front[IMU_BUFF_SIZE][3];
  13. static int16_t gry_front[IMU_BUFF_SIZE][3];
  14. static int16_t mag6310_front[IMU_BUFF_SIZE][3];
  15. static int16_t mag6310_back[3];
  16. static int32_t timestamp_front[IMU_BUFF_SIZE];
  17. static uint8_t rssi;
  18. static int16_t IMU_STATUS; //记录状态用来重新记录时间戳
  19. static int32_t timestamp;
  20. static int32_t last_timestamp;
  21. void process_imu_data_front(int front_index)
  22. {
  23. if(IMU_STATUS != 1)
  24. {
  25. IMU_STATUS = 1;
  26. last_timestamp = timestamp_front[0];
  27. timestamp = 0;
  28. }
  29. for(int i = 0; i < front_index; i++)
  30. {
  31. int32_t dt = timestamp_front[i] - last_timestamp;
  32. if(dt > 20000 || dt < 0)
  33. {
  34. dt = 10000;
  35. }
  36. timestamp += dt;
  37. last_timestamp = timestamp_front[i];
  38. SEGGER_RTT_printf(0,"timestamp_front[i] : %d; i = %d\r\n", timestamp_front[i], i);
  39. IMU_Process_motion_queue(mFlash.isHost, timestamp, acc_front[i],
  40. gry_front[i],mag6310_front[i], mag6310_back, rssi);
  41. }
  42. }
  43. void app_math_TimerCounter(void)
  44. {
  45. int16_t group_num = 0;
  46. int16_t front_index = 0;
  47. if(1 == time_10ms_flag){
  48. //游戏模式
  49. if(IMU_GetSensorEnable() > 0 && IMU_GetGameMode()>0 && IMU_GetCurrentMode() == STATE_FULL_POWER_MODE){
  50. // CHECK_TIMECONSUMING_START;
  51. rssi = IMU_Get_Rssi();
  52. group_num = IMU_Get_Front_Update_Data_GroupNum();
  53. group_num = group_num >= IMU_BUFF_SIZE?IMU_BUFF_SIZE:group_num;
  54. front_index = IMU_Get_Front_Full_Power_Data((int16_t*)gry_front, (int16_t*)acc_front, (int16_t*)mag6310_front, timestamp_front, group_num);
  55. IMU_Get_Back_Mag(mag6310_back);
  56. if(mFlash.isHost){
  57. process_imu_data_front(front_index);
  58. }else if(Slave_Get7_5ms_interval()){
  59. process_imu_data_front(front_index);
  60. }
  61. // CHECK_TIMECONSUMING_END;
  62. }
  63. else
  64. {
  65. //将状态重设为0
  66. IMU_STATUS = 0;
  67. set_pdr_status();
  68. }
  69. //实时计步模式
  70. if(IMU_GetSensorEnable() > 0 && IMU_GetRealTimeStepMode()>0 && IMU_GetCurrentMode() == STATE_FULL_POWER_MODE){
  71. rssi = 0-host_get_rssi();
  72. group_num = IMU_Get_Front_Update_Data_GroupNum();
  73. group_num = group_num >= IMU_BUFF_SIZE?IMU_BUFF_SIZE:group_num;
  74. front_index = IMU_Get_Front_Full_Power_Data((int16_t*)gry_front, (int16_t*)acc_front, (int16_t*)mag6310_front, timestamp_front, group_num);
  75. IMU_Get_Back_Mag(mag6310_back);
  76. start_cal_step(mag6310_front[0], mag6310_back, acc_front[0]);
  77. }
  78. }
  79. }
  80. static void app_math_DailyStep_Process(void)
  81. {
  82. int16_t group_num = 0;
  83. int16_t front_index = 0;
  84. if(IMU_GetCurrentMode() == STATE_LOW_POWER_MODE){
  85. group_num = IMU_Get_Front_Update_Data_GroupNum();
  86. group_num = group_num >= IMU_BUFF_SIZE?IMU_BUFF_SIZE:group_num;
  87. front_index = IMU_Get_Front_Low_Power_Data((int16_t*)acc_front, (int16_t*)mag6310_front, timestamp_front, group_num);
  88. for(int i=0; i < front_index; i++)
  89. {
  90. SEGGER_RTT_printf(0,"f_mx=%d\r,f_my=%d\r,f_mz=%d\r\n",mag6310_front[i][0],mag6310_front[i][1],mag6310_front[i][2]);
  91. }
  92. }
  93. }
  94. void app_math_Init(void)
  95. {
  96. Process_Start(100,"app_math_DailyStep_Process",app_math_DailyStep_Process);
  97. Process_Start(10,"app_math_TimerCounter",app_math_TimerCounter);
  98. }