read_press_RawData.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. clc
  2. close all;
  3. clear all;
  4. dt = 1;
  5. t=[0];
  6. % m=[0;0;0;0]
  7. m=[0;0;0;0;0;0;0;0;]
  8. p = plot(t,m)
  9. data = [];
  10. buf = [];
  11. x=0;
  12. %legend('左脚气压','右脚气压','r2','r3','b0','b1','b2','b3')
  13. legend('左脚气压','右脚气压')
  14. grid on;
  15. set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.7]);
  16. delete(instrfindall('Type','serial'));%清理串口
  17. object = serial('com3','BaudRate',115200);%配置串口
  18. fopen(object);
  19. state = 0;
  20. Len = 0;
  21. Lenf = 0;
  22. Zarr = [];
  23. Zarr(1) = 0;
  24. Zarr_en = 0;
  25. run = 0;
  26. left = 0;
  27. right = 0;
  28. acc3_b = 0;
  29. acc3_bb = 0;
  30. press_data = [];
  31. press_var = [];
  32. gyr_var = [];
  33. pos_data = [];
  34. imu_data = [];
  35. is_down = 0;
  36. is_up = 0;
  37. is_left = 0;
  38. is_right = 0;
  39. count = 0;
  40. mag_last = [0;0;0];
  41. transfer =[0 -1 0; -1 0 0; 0 0 1];
  42. press = zeros(1,18);
  43. gyr_data = zeros(1, 3);
  44. mag_data = zeros(1, 3);
  45. rotate_matrix = eye(3);
  46. left_acc = [0,0,0];
  47. left_gyr = [0,0,0];
  48. left_front_mag = [0,0,0];
  49. left_back_mag = [0,0,0];
  50. right_acc = [0,0,0];
  51. right_gyr = [0,0,0];
  52. right_front_mag = [0,0,0];
  53. right_back_mag = [0,0,0];
  54. down = 0;
  55. jump = 0;
  56. s_rssi = 0;
  57. rssi_buff =[];
  58. last_rssi = 0;
  59. press_buff = [];
  60. gyr_buff = [];
  61. h_acc_buff = [];
  62. h_acc_norm_buff = [];
  63. s_acc_buff = [];
  64. h_mag_buff = [];
  65. s_mag_buff = [];
  66. time_stamp = 0;
  67. relate_val = 0;
  68. buff_record = [];
  69. mag_norm = 0;
  70. h_mag_norm_buff = [];
  71. s_mag_norm_buff = [];
  72. % for i=1:shuliang
  73. while true
  74. data=fread(object,35);%读取数据
  75. while ~isempty(data)
  76. buf = [buf data(1)];
  77. data(1) = [];
  78. switch state
  79. case 0
  80. if length(buf)>=5
  81. if buf(1)==170
  82. Len = buf(2);
  83. Lenf = 255 - buf(2);
  84. if buf(3) == Lenf
  85. state = 1;
  86. else
  87. buf(1) = [];
  88. end
  89. else
  90. buf(1) = [];
  91. end
  92. end
  93. case 1
  94. if length(buf)>=Len
  95. ver = 0;
  96. for i=1:(Len-1)
  97. ver = ver + buf(i);
  98. end
  99. ver = mod(ver,256);
  100. % disp(ver);
  101. % disp(buf(Len));
  102. if ver==buf(Len) && buf(4) == 123
  103. left_acc(1) = double(bitshift(int16(buf(5)),8)+bitshift(int16(buf(6)),0)) ;
  104. % left_acc(2) = double(bitshift(int16(buf(7)),8)+bitshift(int16(buf(8)),0)) ;
  105. % left_acc(3) = double(bitshift(int16(buf(9)),8)+bitshift(int16(buf(10)),0)) ;
  106. %
  107. %
  108. % left_gyr(1) = double(bitshift(int16(buf(11)),8)+bitshift(int16(buf(12)),0)) ;
  109. % left_gyr(2) = double(bitshift(int16(buf(13)),8)+bitshift(int16(buf(14)),0)) ;
  110. % left_gyr(3) = double(bitshift(int16(buf(15)),8)+bitshift(int16(buf(16)),0)) ;
  111. %
  112. %
  113. % left_front_mag(1) = double(bitshift(int16(buf(17)),8)+bitshift(int16(buf(18)),0));
  114. % left_front_mag(2) = double(bitshift(int16(buf(19)),8)+bitshift(int16(buf(20)),0));
  115. % left_front_mag(3) = double(bitshift(int16(buf(21)),8)+bitshift(int16(buf(22)),0));
  116. %
  117. % left_front_mag_norm = norm(left_front_mag);
  118. %
  119. % left_back_mag(1) = double(bitshift(int16(buf(23)),8)+bitshift(int16(buf(24)),0))
  120. % left_back_mag(2) = double(bitshift(int16(buf(25)),8)+bitshift(int16(buf(26)),0))
  121. % left_back_mag(3) = double(bitshift(int16(buf(27)),8)+bitshift(int16(buf(28)),0))
  122. %
  123. % left_back_mag_norm = norm(left_back_mag);
  124. %
  125. % right_acc(1) = double(bitshift(int16(buf(29)),8)+bitshift(int16(buf(30)),0)) ;
  126. % right_acc(2) = double(bitshift(int16(buf(31)),8)+bitshift(int16(buf(32)),0)) ;
  127. % right_acc(3) = double(bitshift(int16(buf(33)),8)+bitshift(int16(buf(34)),0)) ;
  128. %
  129. %
  130. % right_gyr(1) = double(bitshift(int16(buf(35)),8)+bitshift(int16(buf(36)),0)) ;
  131. % right_gyr(2) = double(bitshift(int16(buf(37)),8)+bitshift(int16(buf(38)),0)) ;
  132. % right_gyr(3) = double(bitshift(int16(buf(39)),8)+bitshift(int16(buf(40)),0)) ;
  133. %
  134. %
  135. % right_front_mag(1) = double(bitshift(int16(buf(41)),8)+bitshift(int16(buf(42)),0));
  136. % right_front_mag(2) = double(bitshift(int16(buf(43)),8)+bitshift(int16(buf(44)),0));
  137. % right_front_mag(3) = double(bitshift(int16(buf(45)),8)+bitshift(int16(buf(46)),0));
  138. %
  139. % right_front_mag_norm = norm(right_front_mag);
  140. %
  141. % right_back_mag(1) = double(bitshift(int16(buf(47)),8)+bitshift(int16(buf(48)),0));
  142. % right_back_mag(2) = double(bitshift(int16(buf(49)),8)+bitshift(int16(buf(50)),0));
  143. % right_back_mag(3) = double(bitshift(int16(buf(51)),8)+bitshift(int16(buf(52)),0));
  144. %
  145. % right_back_mag_norm = norm(right_back_mag);
  146. buff_record = [buff_record;buf(1:Len)];
  147. dt = dt + 1;
  148. t=[t dt];
  149. if dt>250
  150. x=x+1;
  151. end
  152. % if((size(h_acc_norm_buff,2) > 9) && (max(h_acc_norm_buff(end-9:end)) - 1 < 0.1) && (min(h_acc_norm_buff(end-9:end)) - 1 > -0.1))
  153. % acc_zupt = 1;
  154. % else
  155. % acc_zupt = 0;
  156. % end
  157. % %测左右鞋地磁
  158. % m=[m, [ left_front_mag_norm;left_back_mag_norm; right_front_mag_norm ; right_back_mag_norm; 0; 0; 0; 0; ]];
  159. % set(p(1),'XData',t,'YData',m(1,:))
  160. % set(p(2),'XData',t,'YData',m(2,:))
  161. % set(p(3),'XData',t,'YData',m(3,:))
  162. % set(p(4),'XData',t,'YData',m(4,:))
  163. %
  164. % %测左右鞋地磁
  165. % m=[m, [ left_front_mag_norm;left_back_mag_norm; right_front_mag_norm ; right_back_mag_norm; 0; 0; 0; 0; ]];
  166. % set(p(1),'XData',t,'YData',m(1,:))
  167. % set(p(2),'XData',t,'YData',m(2,:))
  168. % set(p(3),'XData',t,'YData',m(3,:))
  169. % set(p(4),'XData',t,'YData',m(4,:))
  170. % %测左鞋前后地磁原始数据
  171. % m=[m, [ left_front_mag(1);left_front_mag(2); left_front_mag(3) ; left_back_mag(1); left_back_mag(2); left_back_mag(3); 0; 0; ]];
  172. % set(p(1),'XData',t,'YData',m(1,:),'Color','red')
  173. % set(p(2),'XData',t,'YData',m(2,:),'Color','green')
  174. % set(p(3),'XData',t,'YData',m(3,:),'Color','blue')
  175. % set(p(4),'XData',t,'YData',m(4,:),'Color','yellow')
  176. % set(p(5),'XData',t,'YData',m(5,:),'Color','black')
  177. % set(p(6),'XData',t,'YData',m(6,:),'Color','cyan')
  178. % %测右鞋前后地磁原始数据
  179. % m=[m, [ right_front_mag(1);right_front_mag(2); right_front_mag(3) ; right_back_mag(1); right_back_mag(2); right_back_mag(3); 0; 0; ]];
  180. % set(p(1),'XData',t,'YData',m(1,:))
  181. % set(p(2),'XData',t,'YData',m(2,:))
  182. % set(p(3),'XData',t,'YData',m(3,:))
  183. % set(p(4),'XData',t,'YData',m(4,:))
  184. % set(p(5),'XData',t,'YData',m(5,:))
  185. % set(p(6),'XData',t,'YData',m(6,:))
  186. %测左鞋六轴
  187. m=[m, [ left_acc(1);0; 0 ; 0; 0; 0; 0; 0; ]];
  188. set(p(1),'XData',t,'YData',m(1,:),'Color','red')
  189. % set(p(2),'XData',t,'YData',m(2,:),'Color','green')
  190. % set(p(3),'XData',t,'YData',m(3,:),'Color','blue')
  191. % set(p(4),'XData',t,'YData',m(4,:),'Color','black')
  192. % set(p(5),'XData',t,'YData',m(5,:),'Color','black')
  193. % set(p(6),'XData',t,'YData',m(6,:),'Color','cyan')
  194. % %测右鞋六轴
  195. % m=[m, [ right_acc(1);right_acc(2); right_acc(3) ; right_gyr(1); right_gyr(2); right_gyr(3); 0; 0; ]];
  196. % set(p(1),'XData',t,'YData',m(1,:))
  197. % set(p(2),'XData',t,'YData',m(2,:))
  198. % set(p(3),'XData',t,'YData',m(3,:))
  199. % set(p(4),'XData',t,'YData',m(4,:))
  200. % set(p(5),'XData',t,'YData',m(5,:))
  201. % set(p(6),'XData',t,'YData',m(6,:))
  202. % set(p(6),'XData',t,'YData', m(6,:))
  203. % set(p(7),'XData',t,'YData',m(7,:))
  204. % set(p(8),'XData',t,'YData',m(8,:))
  205. % set(p(3),'XData',t,'YData',m(7,:))
  206. % set(p(8),'XData',t,'YData',m(8,:))
  207. % set(p(9),'XData',t,'YData',m(9,:))
  208. % set(p(10),'XData',t,'YData',m(10,:))
  209. buf = buf(Len:end);
  210. else
  211. buf(1) = [];
  212. end
  213. state = 0;
  214. end
  215. otherwise
  216. state = 0;
  217. end
  218. end
  219. drawnow limitrate nocallbacks
  220. % axis([x x+300 -0.1 0.1]);
  221. axis([x x+300 0 4000]);
  222. end
  223. fclose(object);
  224. delete(object);
  225. clear object;