process_result.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. #include "process_result.h"
  2. int time_stamp = 0;
  3. float gyr[3];
  4. float acc[3];
  5. float mag[3];
  6. float magBias[3] = {43.6012f, 154.6074f, -263.2141f};
  7. float magScale[3] = {0.0039f, 0.0037f, 0.0038f};
  8. float accBias[3] = {-0.0641278f, 0.01712f, -0.099816f};
  9. float accScale[3] = {1.0010795f, 0.9971222f, 1.004638f};
  10. int16_t h_pos[3];
  11. int16_t h_att[3];
  12. int16_t h_zupt;
  13. int16_t jump_send_count;
  14. int16_t down_send_count;
  15. int16_t is_jump;
  16. int16_t is_down;
  17. int16_t accel[3];
  18. int16_t gyro[3];
  19. uint16_t h_press;
  20. uint16_t s_press;
  21. int16_t s_pos[3];
  22. int16_t s_att[3];
  23. int8_t s_rssi;
  24. int16_t s_zupt;
  25. int left_press_buff[4];
  26. int32_t left_press = 0;
  27. int32_t right_press = 0;
  28. void sen_data_acc(void)
  29. {
  30. uint8_t buf[256];
  31. uint8_t L=0;
  32. buf[L++] = (uint8_t)(accel[0]>>8);
  33. buf[L++] = (uint8_t)(accel[0]>>0);
  34. buf[L++] = (uint8_t)(accel[1]>>8);
  35. buf[L++] = (uint8_t)(accel[1]>>0);
  36. buf[L++] = (uint8_t)(accel[2]>>8);
  37. buf[L++] = (uint8_t)(accel[2]>>0);
  38. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  39. }
  40. void sen_data_pos(void)
  41. {
  42. uint8_t buf[256];
  43. uint8_t L=0;
  44. static short count = 0;
  45. // buf[L++] = (uint8_t)(h_pos[0]>>8);
  46. // buf[L++] = (uint8_t)(h_pos[0]>>0);
  47. //
  48. // buf[L++] = (uint8_t)(h_pos[1]>>8);
  49. // buf[L++] = (uint8_t)(h_pos[1]>>0);
  50. buf[L++] = (uint8_t)(h_pos[2]>>8);
  51. buf[L++] = (uint8_t)(h_pos[2]>>0);
  52. buf[L++] = (uint8_t)(s_pos[2]>>8);
  53. buf[L++] = (uint8_t)(s_pos[2]>>0);
  54. buf[L++] = (uint8_t)(count>>8);
  55. buf[L++] = (uint8_t)(count>>0);
  56. count ++;
  57. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  58. }
  59. void send_data_press_gyr(void)
  60. {
  61. uint8_t buf[256];
  62. uint8_t L=0;
  63. buf[L++] = (uint8_t)(gyro[0]>>8);
  64. buf[L++] = (uint8_t)(gyro[0]>>0);
  65. buf[L++] = (uint8_t)(gyro[1]>>8);
  66. buf[L++] = (uint8_t)(gyro[1]>>0);
  67. buf[L++] = (uint8_t)(gyro[2]>>8);
  68. buf[L++] = (uint8_t)(gyro[2]>>0);
  69. buf[L++] = (uint8_t)(h_press>>8);
  70. buf[L++] = (uint8_t)(h_press>>0);
  71. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  72. }
  73. //void send_data_pos_angle(void)
  74. //{
  75. // uint8_t buf[256];
  76. // uint8_t L=0;
  77. //
  78. // buf[L++] = (uint8_t)(h_pos[0]>>8);
  79. // buf[L++] = (uint8_t)(h_pos[0]>>0);
  80. //
  81. // buf[L++] = (uint8_t)(h_pos[1]>>8);
  82. // buf[L++] = (uint8_t)(h_pos[1]>>0);
  83. //
  84. // buf[L++] = (uint8_t)(h_pos[2]>>8);
  85. // buf[L++] = (uint8_t)(h_pos[2]>>0);
  86. //
  87. // buf[L++] = (uint8_t)(angle[0]>>8);
  88. // buf[L++] = (uint8_t)(angle[0]>>0);
  89. //
  90. // buf[L++] = (uint8_t)(angle[1]>>8);
  91. // buf[L++] = (uint8_t)(angle[1]>>0);
  92. //
  93. // buf[L++] = (uint8_t)(angle[2]>>8);
  94. // buf[L++] = (uint8_t)(angle[2]>>0);
  95. //
  96. // send_protocol(DEX_NUM,CMD_HEART,buf,L);
  97. //}
  98. void send_data_acc(void)
  99. {
  100. uint8_t buf[256];
  101. uint8_t L=0;
  102. buf[L++] = (uint8_t)(accel[0]>>8);
  103. buf[L++] = (uint8_t)(accel[0]>>0);
  104. buf[L++] = (uint8_t)(accel[1]>>8);
  105. buf[L++] = (uint8_t)(accel[1]>>0);
  106. buf[L++] = (uint8_t)(accel[2]>>8);
  107. buf[L++] = (uint8_t)(accel[2]>>0);
  108. buf[L++] = (uint8_t)(h_press>>8);
  109. buf[L++] = (uint8_t)(h_press>>0);
  110. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  111. }
  112. void sen_data_press(void)
  113. {
  114. uint8_t buf[256];
  115. uint8_t L=0;
  116. buf[L++] = (uint8_t)(h_press>>8);
  117. buf[L++] = (uint8_t)(h_press>>0);
  118. buf[L++] = (uint8_t)(s_press>>8);
  119. buf[L++] = (uint8_t)(s_press>>0);
  120. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  121. }
  122. void sen_data_left_press(void)
  123. {
  124. uint8_t buf[256];
  125. uint8_t L=0;
  126. buf[L++] = (uint8_t)(left_press>>24);
  127. buf[L++] = (uint8_t)(left_press>>16);
  128. buf[L++] = (uint8_t)(left_press>>8);
  129. buf[L++] = (uint8_t)(left_press>>0);
  130. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  131. }
  132. void send_package_data(uint16_t package_num, int16_t right_pos_data[3], int16_t left_pos_data[3], int16_t right_att_data[3], int16_t left_att_data[3],
  133. int16_t s_zupt, int16_t h_zupt,int16_t is_down, int16_t is_jump, int8_t s_rssi, uint8_t time_stamp)
  134. {
  135. uint8_t buf[256];
  136. uint8_t L=0;
  137. buf[L++] = (uint8_t)(right_pos_data[0]>>8);
  138. buf[L++] = (uint8_t)(right_pos_data[0]>>0);
  139. buf[L++] = (uint8_t)(right_pos_data[1]>>8);
  140. buf[L++] = (uint8_t)(right_pos_data[1]>>0);
  141. buf[L++] = (uint8_t)(right_pos_data[2]>>8);
  142. buf[L++] = (uint8_t)(right_pos_data[2]>>0);
  143. buf[L++] = (uint8_t)(left_pos_data[0]>>8);
  144. buf[L++] = (uint8_t)(left_pos_data[0]>>0);
  145. buf[L++] = (uint8_t)(left_pos_data[1]>>8);
  146. buf[L++] = (uint8_t)(left_pos_data[1]>>0);
  147. buf[L++] = (uint8_t)(left_pos_data[2]>>8);
  148. buf[L++] = (uint8_t)(left_pos_data[2]>>0);
  149. buf[L++] = (uint8_t)(right_att_data[0]>>8);
  150. buf[L++] = (uint8_t)(right_att_data[0]>>0);
  151. buf[L++] = (uint8_t)(right_att_data[1]>>8);
  152. buf[L++] = (uint8_t)(right_att_data[1]>>0);
  153. buf[L++] = (uint8_t)(right_att_data[2]>>8);
  154. buf[L++] = (uint8_t)(right_att_data[2]>>0);
  155. buf[L++] = (uint8_t)(left_att_data[0]>>8);
  156. buf[L++] = (uint8_t)(left_att_data[0]>>0);
  157. buf[L++] = (uint8_t)(left_att_data[1]>>8);
  158. buf[L++] = (uint8_t)(left_att_data[1]>>0);
  159. buf[L++] = (uint8_t)(left_att_data[2]>>8);
  160. buf[L++] = (uint8_t)(left_att_data[2]>>0);
  161. buf[L++] = (uint8_t)(s_zupt * 8 + h_zupt * 4 + is_down * 2 + is_jump * 1);
  162. buf[L++] = (uint8_t)(s_rssi >> 0);
  163. buf[L++] = (uint8_t)(time_stamp);
  164. send_protocol(DEX_NUM,package_num,buf,L);
  165. }
  166. void send_dual_foot_data(void)
  167. {
  168. static uint8_t time_stamp = 0;
  169. send_package_data( 0x04, s_pos, h_pos, s_att, h_att ,s_zupt, h_zupt, is_down, is_jump, s_rssi, time_stamp);
  170. time_stamp ++;
  171. }
  172. void send_data_to_pc(void)
  173. {
  174. static uint8_t wait_time = 0;
  175. if(wait_time == 4)
  176. {
  177. send_dual_foot_data();
  178. wait_time = 0;
  179. }
  180. wait_time ++;
  181. }
  182. void process_motion(IMU_DAT_t* p)
  183. {
  184. // int16_t accel[3];
  185. // int16_t gyro[3];
  186. // uint16_t h_press;
  187. // uint16_t s_press;
  188. // int16_t s_pos[3];
  189. // int16_t s_att[3];
  190. // int8_t s_rssi;
  191. // int16_t s_zupt;
  192. memcpy(accel,p->h.acc,sizeof(accel));
  193. memcpy(accel,p->h.gyr,sizeof(gyro));
  194. memcpy(accel,p->s.pos,sizeof(s_pos));
  195. memcpy(accel,p->s.att,sizeof(s_att));
  196. h_press = p->h.press;
  197. s_press = p->s.press;
  198. s_rssi = p->s.rssi;
  199. s_zupt = p->s.zupt;
  200. time_stamp = time_stamp + 1;
  201. left_press = (((int32_t)h_press & 0x0000ffff)<<8);
  202. right_press = (((int32_t)s_press & 0x0000ffff)<<8);
  203. short down_tag = 0;
  204. down_tag = press_down_detect_new(time_stamp, left_press, right_press);
  205. if (down_tag)
  206. {
  207. gpio_mt_run(20);
  208. down_send_count = 20;
  209. }
  210. if(down_send_count > 0)
  211. {
  212. is_down = 1;
  213. down_send_count --;
  214. }
  215. else
  216. {
  217. is_down = 0;
  218. }
  219. short jump_tag = 0;
  220. jump_tag = press_jump_detect(h_pos , s_pos);
  221. if (jump_tag)
  222. {
  223. gpio_mt_run(20);
  224. jump_send_count = 20;
  225. }
  226. //连续发20次蹲,终端再处理
  227. if(jump_send_count > 0)
  228. {
  229. is_jump = 1;
  230. jump_send_count --;
  231. }
  232. else
  233. {
  234. is_jump = 0;
  235. }
  236. gyr[0] = (float)mMPU9250.gyro_x / GYR_LSB;
  237. gyr[1] = (float)mMPU9250.gyro_y / GYR_LSB;
  238. gyr[2] = (float)mMPU9250.gyro_z / GYR_LSB;
  239. acc[0] = (float)mMPU9250.acc_x / ACC_LSB;
  240. acc[1] = (float)mMPU9250.acc_y / ACC_LSB;
  241. acc[2] = (float)mMPU9250.acc_z / ACC_LSB;
  242. mag[0] = (float)mMPU9250.mag_x;
  243. mag[1] = (float)mMPU9250.mag_y;
  244. mag[2] = (float)mMPU9250.mag_z;
  245. mag[0] = (mag[0] - magBias[0]) * magScale[0];
  246. mag[1] = (mag[1] - magBias[1]) * magScale[1];
  247. mag[2] = (mag[2] - magBias[2]) * magScale[2];
  248. acc[0] = (acc[0] - accBias[0]) * accScale[0];
  249. acc[1] = (acc[1] - accBias[1]) * accScale[1];
  250. acc[2] = (acc[2] - accBias[2]) * accScale[2];
  251. // acc[0] = (acc[0] + 0.004700898f) / 0.99823547f;
  252. // acc[1] = (acc[1] - 0.0037821f) / 0.9982976f;
  253. // acc[2] = (acc[2] + 0.03741163f) / 1.0116903f;
  254. //
  255. unsigned char left_tag = footPDR(time_stamp, gyr, acc, mag, left_press, h_pos, h_att, &h_zupt);
  256. //
  257. // if(h_pos[1] < -20)
  258. // {
  259. // gpio_mt_run(30);
  260. // }
  261. // if (h_zupt > 1 || h_zupt < 0)
  262. // {
  263. //// send_motion_to_phone(MOTION_LEFT, time_stamp);
  264. // gpio_mt_run(20);
  265. // }
  266. // memcpy(pos_n_offset, s_gyro, 3*sizeof(short));
  267. send_data_to_pc();
  268. }