process_result.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "process_result.h"
  2. #include "hal_mt.h"
  3. #include "hal_flash.h"
  4. #include "detect_zero_vel.h"
  5. extern uint8_t isGameMode;
  6. float gyr[3];
  7. float acc[3];
  8. float mag[3];
  9. uint32_t time_stamp = 0;
  10. int16_t accel[3];
  11. int16_t gyro[3];
  12. int16_t magn[3];
  13. int32_t pos[3];
  14. int16_t att[3];
  15. int zupt;
  16. int zupt_res;
  17. uint16_t laser_distance;
  18. uint8_t slave_rssi;
  19. uint8_t foot_data_buf[64];
  20. uint8_t foot_data_len;
  21. int16_t front_zero;
  22. int16_t back_zero;
  23. int16_t acc_zero;
  24. void init_MOTION(void)
  25. {
  26. time_stamp = 0;
  27. }
  28. void foot_data_to_package()
  29. {
  30. static uint16_t package_time = 0;
  31. foot_data_len = 0;
  32. foot_data_buf[foot_data_len++] = (uint8_t)(laser_distance>>8);
  33. foot_data_buf[foot_data_len++] = (uint8_t)(laser_distance>>0);
  34. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>24);
  35. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>16);
  36. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>8);
  37. foot_data_buf[foot_data_len++] = (uint8_t)(pos[0]>>0);
  38. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>24);
  39. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>16);
  40. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>8);
  41. foot_data_buf[foot_data_len++] = (uint8_t)(pos[1]>>0);
  42. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>24);
  43. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>16);
  44. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>8);
  45. foot_data_buf[foot_data_len++] = (uint8_t)(pos[2]>>0);
  46. foot_data_buf[foot_data_len++] = (uint8_t)(att[0]>>8);
  47. foot_data_buf[foot_data_len++] = (uint8_t)(att[0]>>0);
  48. foot_data_buf[foot_data_len++] = (uint8_t)(att[1]>>8);
  49. foot_data_buf[foot_data_len++] = (uint8_t)(att[1]>>0);
  50. foot_data_buf[foot_data_len++] = (uint8_t)(att[2]>>8);
  51. foot_data_buf[foot_data_len++] = (uint8_t)(att[2]>>0);
  52. foot_data_buf[foot_data_len++] = (uint8_t)(zupt>>0);
  53. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>8);
  54. foot_data_buf[foot_data_len++] = (uint8_t)(accel[0]>>0);
  55. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>8);
  56. foot_data_buf[foot_data_len++] = (uint8_t)(accel[1]>>0);
  57. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>8);
  58. foot_data_buf[foot_data_len++] = (uint8_t)(accel[2]>>0);
  59. foot_data_buf[foot_data_len++] = (uint8_t) slave_rssi;
  60. foot_data_buf[foot_data_len++] = (uint8_t)(package_time>>8);
  61. foot_data_buf[foot_data_len++] = (uint8_t)(package_time>>0);
  62. foot_data_buf[foot_data_len++] = (uint8_t)(magn[0]>>8);
  63. foot_data_buf[foot_data_len++] = (uint8_t)(magn[0]>>0);
  64. foot_data_buf[foot_data_len++] = (uint8_t)(magn[1]>>8);
  65. foot_data_buf[foot_data_len++] = (uint8_t)(magn[1]>>0);
  66. package_time ++;
  67. }
  68. void get_foot_data(uint8_t *buf, uint8_t *buff_len)
  69. {
  70. memcpy(buf, foot_data_buf, foot_data_len);
  71. * buff_len = foot_data_len;
  72. }
  73. void process_motion(int16_t _acc[3], int16_t _gry[3], int16_t _mag[3], uint16_t _laser_distance, uint8_t _rssi)
  74. {
  75. /*
  76. ½âÎöÊý¾Ý
  77. */
  78. memcpy(accel, _acc, 3 * sizeof(int16_t));
  79. accel[2] = -accel[2];
  80. memcpy(gyro , _gry, 3 * sizeof(int16_t));
  81. memcpy(magn , _mag, 3 * sizeof(int16_t));
  82. gyr[0] = (float)gyro[0] / GYR_LSB;
  83. gyr[1] = (float)gyro[1] / GYR_LSB;
  84. gyr[2] = (float)gyro[2] / GYR_LSB;
  85. acc[0] = (float)accel[0] / ACC_LSB;
  86. acc[1] = (float)accel[1] / ACC_LSB;
  87. acc[2] = (float)accel[2] / ACC_LSB;
  88. // acc[0] += 0.03f;
  89. // acc[1] += 0.1f;
  90. laser_distance = _laser_distance;
  91. //
  92. slave_rssi = _rssi - 20;
  93. //
  94. //
  95. // if(acc_x_status == 1 || acc_y_status == 1 || acc_z_status == 1)
  96. // {
  97. // zupt = 1;
  98. // }
  99. // else
  100. // {
  101. // zupt = 0;
  102. // }
  103. //
  104. static int acc_x_status;
  105. static int acc_y_status;
  106. static int acc_z_status;
  107. step_detect_by_acc_gyr(acc, gyr, &acc_x_status, &acc_y_status, &acc_z_status, &zupt);
  108. if(acc_x_status == 1 || acc_y_status == 1 || acc_z_status == 1)
  109. {
  110. zupt = 1;
  111. }
  112. else
  113. {
  114. zupt = 0;
  115. }
  116. //zupt_res = cor_zupt_function(zupt);
  117. //detect_zero_vel(magn[0], magn[1], accel, &front_zero, &back_zero, &acc_zero);
  118. // if(front_zero > 0 || back_zero > 0 )
  119. // {
  120. // zupt = 1;
  121. // }
  122. // else
  123. // {
  124. // zupt = 0;
  125. // }
  126. acc[2] = -acc[2];
  127. footPDR(time_stamp, gyr, acc, mag, 0, pos, att, acc_x_status, acc_y_status, zupt_res);
  128. // att[1] = -att[1];
  129. // att[2] = mFlash.mStep.stepCur[0];
  130. // att[0] = acc_x_status;
  131. // att[1] = acc_y_status;
  132. // att[2] = zupt;
  133. // detect_step_by_acc(accel, &zupt);
  134. // att[2] = zupt;
  135. // att[0] = mFlash.mStep.stepCur[0];
  136. foot_data_to_package();
  137. time_stamp ++;
  138. }