process_result.c 6.0 KB

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