process_result.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #include "process_result.h"
  2. #include "hal_mt.h"
  3. #include "app_flash.h"
  4. #include "app_switchimu.h"
  5. #include "system.h"
  6. #include "math.h"
  7. #define CHECK_TIMECONSUMING_START uint32_t cnt1 = 0, cnt2 = 0; \
  8. static char string[100]; \
  9. cnt1 = NRF_RTC0->COUNTER
  10. #define CHECK_TIMECONSUMING_END cnt2 = NRF_RTC0->COUNTER; \
  11. sprintf(string,"=====>time consuming:%02f us\r\n",(cnt2-cnt1)/32.768 * 1000); \
  12. DEBUG_LOG("%s",string)
  13. float gyr[3];
  14. float acc[3];
  15. float mag[3];
  16. int16_t accel[3];
  17. int16_t gyro[3];
  18. int16_t front_magn[3];
  19. int16_t back_magn[3];
  20. int32_t pos[3];
  21. int16_t att[3];
  22. int16_t zupt;
  23. int8_t slave_rssi;
  24. uint8_t foot_data_buf[64];
  25. uint8_t foot_data_len;
  26. int16_t front_zero;
  27. int16_t back_zero;
  28. int16_t acc_zero;
  29. uint16_t front_mag_norm;
  30. uint16_t back_mag_norm;
  31. int32_t step_count;
  32. float gyr[3];
  33. float acc[3];
  34. float mag[3];
  35. int low_power_dectect;
  36. int low_power_step;
  37. uint16_t low_power_mag;
  38. int zupt_wait_time;
  39. int nan_flag = 0;
  40. //left
  41. //float acc_bias[3] = {0.091139f, 0.101830f, -0.048524f};
  42. //float acc_scale[3] = {0.980197f, 1.003513f, 0.987654f};
  43. //right
  44. float acc_bias[3] = {0.0001f, -0.0041f, 0.0283f};
  45. float acc_scale[3] = {0.9929f, 0.9950f, 1.0018f};
  46. void foot_data_to_package()
  47. {
  48. static uint16_t package_time = 0;
  49. foot_data_len = 0;
  50. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>24);
  51. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>16);
  52. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>8);
  53. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>0);
  54. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>24);
  55. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>16);
  56. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>8);
  57. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>0);
  58. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>24);
  59. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>16);
  60. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>8);
  61. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>0);
  62. foot_data_buf[foot_data_len++] = (uint8_t)(att[0]>>8);
  63. foot_data_buf[foot_data_len++] = (uint8_t)(att[0]>>0);
  64. foot_data_buf[foot_data_len++] = (uint8_t)(att[1]>>8);
  65. foot_data_buf[foot_data_len++] = (uint8_t)(att[1]>>0);
  66. foot_data_buf[foot_data_len++] = (uint8_t)(att[2]>>8);
  67. foot_data_buf[foot_data_len++] = (uint8_t)(att[2]>>0);
  68. foot_data_buf[foot_data_len++] = (uint8_t)(front_mag_norm>>8);
  69. foot_data_buf[foot_data_len++] = (uint8_t)(front_mag_norm>>0);
  70. foot_data_buf[foot_data_len++] = (uint8_t)(back_mag_norm>>8);
  71. foot_data_buf[foot_data_len++] = (uint8_t)(back_mag_norm>>0);
  72. foot_data_buf[foot_data_len++] = (uint8_t)(zupt>>0);
  73. foot_data_buf[foot_data_len++] = (uint8_t) slave_rssi;
  74. foot_data_buf[foot_data_len++] = (uint8_t)(package_time>>8);
  75. foot_data_buf[foot_data_len++] = (uint8_t)(package_time>>0);
  76. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>8);
  77. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>0);
  78. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>8);
  79. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>0);
  80. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>8);
  81. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>0);
  82. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[0]>>8);
  83. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[0]>>0);
  84. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[1]>>8);
  85. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[1]>>0);
  86. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[2]>>8);
  87. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[2]>>0);
  88. // DEBUG_LOG("test footPDR \n");
  89. package_time ++;
  90. }
  91. void imu_data_to_package()
  92. {
  93. static uint16_t package_time = 0;
  94. foot_data_len = 0;
  95. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>8);
  96. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>0);
  97. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>8);
  98. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>0);
  99. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>8);
  100. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>0);
  101. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[0]>>8);
  102. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[0]>>0);
  103. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[1]>>8);
  104. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[1]>>0);
  105. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[2]>>8);
  106. foot_data_buf[foot_data_len++] = (uint8_t)(gyro[2]>>0);
  107. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[0]>>8);
  108. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[0]>>0);
  109. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[1]>>8);
  110. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[1]>>0);
  111. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[2]>>8);
  112. foot_data_buf[foot_data_len++] = (uint8_t)(front_magn[2]>>0);
  113. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[0]>>8);
  114. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[0]>>0);
  115. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[1]>>8);
  116. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[1]>>0);
  117. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[2]>>8);
  118. foot_data_buf[foot_data_len++] = (uint8_t)(back_magn[2]>>0);
  119. package_time ++;
  120. }
  121. void get_foot_data(uint8_t *buf, uint8_t *buff_len)
  122. {
  123. memcpy(buf, foot_data_buf, foot_data_len);
  124. *buff_len = foot_data_len;
  125. }
  126. void process_motion(uint32_t time_stamp, int16_t _acc[3], int16_t _gry[3], int16_t front_mag[3], int16_t back_mag[3], uint8_t _rssi)
  127. {
  128. /*
  129. 解析数据
  130. */
  131. memcpy(accel, _acc, 3 * sizeof(int16_t));
  132. memcpy(gyro , _gry, 3 * sizeof(int16_t));
  133. memcpy(front_magn , front_mag, 3 * sizeof(int16_t));
  134. memcpy(back_magn, back_mag, 3 * sizeof(int16_t));
  135. slave_rssi = _rssi;
  136. if(slave_rssi < 0)
  137. {
  138. slave_rssi = 0;
  139. }
  140. for(int i = 0; i < 3; i++)
  141. {
  142. gyr[i] = gyro[i] / GYR_LSB;
  143. }
  144. for(int i = 0; i < 3; i++)
  145. {
  146. acc[i] = accel[i] / ACC_LSB;
  147. }
  148. front_mag_norm = (uint16_t)(abs(front_magn[2]));
  149. back_mag_norm = (uint16_t)(abs(back_magn[2]));
  150. //检测零速
  151. detect_zero_vel(front_magn, back_magn, accel, &front_zero, &back_zero, &acc_zero);
  152. //轨迹计算
  153. if(front_zero > 0 || back_zero > 0 )
  154. {
  155. zupt = 1;
  156. }
  157. else
  158. {
  159. zupt = 0;
  160. }
  161. footPDR(time_stamp, gyr, acc, front_mag_norm , zupt, acc_zero, pos, att);
  162. int32_t pos_tmp[3];
  163. memcpy(pos_tmp, pos, 3 * sizeof(int32_t));
  164. pos[0] = -pos_tmp[1];
  165. pos[1] = pos_tmp[0];
  166. accel[2] = -accel[2];
  167. foot_data_to_package();
  168. }