process_result.c 3.9 KB

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