process_result.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "process_result.h"
  2. float gyr[3];
  3. float acc[3];
  4. float mag[3];
  5. int time_stamp = 0;
  6. int16_t accel[3];
  7. int16_t gyro[3];
  8. int16_t magn[3];
  9. uint16_t h_press;
  10. uint16_t s_press;
  11. int32_t s_pos[3];
  12. int16_t s_att[3];
  13. int16_t s_gyro[3];
  14. int16_t s_accl[3];
  15. int16_t s_magn[3];
  16. int32_t h_pos[3];
  17. int16_t h_att[3];
  18. int8_t s_rssi;
  19. int16_t s_zupt;
  20. int16_t h_zupt;
  21. void init_MOTION(void)
  22. {
  23. time_stamp = 0;
  24. }
  25. void process_motion(IMU_DAT_t* p)
  26. {
  27. /*
  28. ½âÎöÊý¾Ý
  29. */
  30. memcpy(accel, p->h.acc, 3 * sizeof(int16_t));
  31. memcpy(gyro , p->h.gyr, 3 * sizeof(int16_t));
  32. memcpy(magn , p->h.mag, 3 * sizeof(int16_t));
  33. gyr[0] = (float)gyro[0] / GYR_LSB;
  34. gyr[1] = (float)gyro[1] / GYR_LSB;
  35. gyr[2] = (float)gyro[2] / GYR_LSB;
  36. acc[0] = (float)accel[0] / ACC_LSB;
  37. acc[1] = (float)accel[1] / ACC_LSB;
  38. acc[2] = (float)accel[2] / ACC_LSB;
  39. mag[0] = (float)magn[0];
  40. mag[1] = (float)magn[1];
  41. mag[2] = (float)magn[2];
  42. if(SH_NUMBER > 18)
  43. {
  44. float mag_temp[3];
  45. memcpy(mag_temp, mag, 3 * sizeof(float));
  46. mag[0] = 0.64278761f * mag[0] - 0.76604444f * mag[1];
  47. mag[1] = 0.76604444f * mag[0] + 0.64278761f * mag[1];
  48. }
  49. mag[0] = (mag[0] - magBias[0]) * magScale[0];
  50. mag[1] = (mag[1] - magBias[1]) * magScale[1];
  51. mag[2] = (mag[2] - magBias[2]) * magScale[2];
  52. float magTmp = mag[0];
  53. mag[0] = mag[1];
  54. mag[1] = magTmp;
  55. mag[2] = -mag[2];
  56. acc[0] = (acc[0] - accBias[0]) * accScale[0];
  57. acc[1] = (acc[1] - accBias[1]) * accScale[1];
  58. acc[2] = (acc[2] - accBias[2]) * accScale[2];
  59. h_press = p->h.press;
  60. s_rssi = p->s.rssi;
  61. time_stamp = time_stamp + 1; //×Ô¶¨Òåʱ¼ä´Á
  62. if(IS_HOST)
  63. {
  64. memcpy(s_pos, p->s.pos, 3 * sizeof(int32_t));
  65. memcpy(s_att, p->s.att, 3 * sizeof(int16_t));
  66. s_press = p->s.press;
  67. s_zupt = p->s.zupt;
  68. if(CAL_MODE)
  69. {
  70. s_gyro[0] = (int16_t)((s_pos[0] & 0xffff0000) >> 16);
  71. s_gyro[1] = (int16_t)((s_pos[0] & 0x0000ffff) >> 0);
  72. s_gyro[2] = (int16_t)((s_pos[1] & 0xffff0000) >> 16);
  73. s_accl[0] = (int16_t)((s_pos[1] & 0x0000ffff) >> 0);
  74. s_accl[1] = (int16_t)((s_pos[2] & 0xffff0000) >> 16);
  75. s_accl[2] = (int16_t)((s_pos[2] & 0x0000ffff) >> 0);
  76. memcpy(s_magn, p->s.att, 3 * sizeof(int16_t));
  77. send_imu_data_to_ble( h_press, gyro, accel, magn, s_press, s_gyro, s_accl, s_magn, s_rssi);
  78. return;
  79. }
  80. host_shoes(time_stamp, gyr, acc, mag, h_press, s_press, h_pos, h_att, s_pos, s_att, h_zupt, s_zupt, s_rssi);
  81. }
  82. else
  83. {
  84. if(!CAL_MODE)
  85. {
  86. slave_shoes( time_stamp, gyr, acc, mag, h_press,
  87. s_pos, s_att, s_zupt);
  88. }
  89. else
  90. {
  91. send_imu_data_to_host( h_press, gyro, accel, magn, 0);
  92. return;
  93. }
  94. }
  95. }