func_count5.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function [step,up_flag] = func_count5(front,back,up_flag,acc)
  2. global front_flag2;
  3. global back_flag2;
  4. global FrontLiftPoint2;
  5. global BackLiftPoint2;
  6. global FrontDownPoint2;
  7. global BackDownPoint2;
  8. global SD2;
  9. global accl2;
  10. global counter2;
  11. k = length(front);
  12. queue_front(2) = front(k);
  13. queue_front(1) = front(k-1);
  14. queue_back(2) = back(k);
  15. queue_back(1) = back(k-1);
  16. if queue_front(2)-queue_front(1)>=0
  17. FrontDownPoint2 = queue_front(2);
  18. else
  19. FrontLiftPoint2 = queue_front(2);
  20. end
  21. if queue_back(2)-queue_back(1)>=0
  22. BackDownPoint2 = queue_back(2);
  23. else
  24. BackLiftPoint2 = queue_back(2);
  25. end
  26. acc_flag = 0;
  27. for i=1:1:2
  28. if abs(acc(i)-2048)>200
  29. acc_flag = acc_flag+1;
  30. end
  31. end
  32. %¼ÆËã¼ÓËٶȷ½²î
  33. MV = (acc(1)+acc(2))/2;
  34. D = 0;
  35. for i=1:1:2
  36. D = D + (acc(i) - MV)^2;
  37. end
  38. D = D/2;
  39. SD2 = sqrt(D);
  40. %%%%%%%%%%%%%%%%%
  41. if (queue_front(2)-FrontLiftPoint2>2500)
  42. front_flag2 = 1;
  43. end
  44. if (queue_front(2)-FrontDownPoint2<-1000)
  45. front_flag2 = 0;
  46. end
  47. if (queue_back(2)-BackLiftPoint2>2500)
  48. back_flag2 = 1;
  49. end
  50. if queue_back(2)-BackDownPoint2<-1000
  51. back_flag2 = 0;
  52. end
  53. if up_flag == 0
  54. if (front_flag2==1||back_flag2==1)
  55. step=1;
  56. up_flag = 1;
  57. accl2 = 100000;
  58. counter2 = 0;
  59. else
  60. step = 0;
  61. up_flag = 0;
  62. end
  63. else
  64. step = 0;
  65. counter2 = counter2+1;
  66. if (abs(acc(3)-2000)<350)
  67. accl2 = acc(3);
  68. end
  69. if counter2>2
  70. if (acc(3)-accl2>1000)&&(accl2~=100000)
  71. up_flag = 0;
  72. else
  73. up_flag = 1;
  74. end
  75. end
  76. end
  77. end