Guest User

Untitled

a guest
Jul 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. package aaGui;
  2.  
  3. public class PatternRecognizer {
  4.  
  5. String Position, Rotation, leftArm, rightArm, posNode1, posNode2, posNode3,
  6. lastPosition = "Error", lastLeftArm = "Error",
  7. lastRightArm = "Error";
  8. String[] nodePositions = {"fadf","fdafafff","hej","LOL"};
  9. int maxLeft = 0, minLeft = 9999, maxRight = 0, minRight = 9999;
  10. long prevTimeLeft = 0, prevTimeLeft2 = 0, prevTimeRight = 0,
  11. prevTimeRight2 = 0, prevPositionTime = 0, prevRotationTime = 0;
  12.  
  13. /**
  14. * This method takes in values from a specific sensor-node and with the values from
  15. * other nodes it calculates the position of the patient, how he/she is rotating the
  16. * upper body and whether the arms are moving or not. This is then saved in an array
  17. * which the GUI then collects and displays.
  18. * @param node_id
  19. * @param acc_x
  20. * @param acc_y
  21. * @param acc_z
  22. * @param mag_x
  23. * @param mag_y
  24. * @param mag_z
  25. * @param gyro_x
  26. * @param gyro_y
  27. * @param gyro_z
  28. */
  29. public void patternRecognition(int node_id, double acc_x, double acc_y,
  30. double acc_z, double mag_x, double mag_y, double mag_z, double gyro_x, double gyro_y,
  31. double gyro_z) {
  32.  
  33.  
  34.  
  35. switch (node_id) {
  36. case 1:
  37. if (acc_z > 8 && acc_z < 12) {
  38. posNode1 = "Ligger";
  39. } else if (acc_z > -2 && acc_z < 2) {
  40. posNode1 = "Står";
  41. }
  42.  
  43. if (gyro_x > 75) {
  44. Rotation = "Vrider vänster";
  45. } else if (gyro_x < -75) {
  46. Rotation = "Vrider höger";
  47. } else {
  48. Rotation = "Stilla";
  49. }
  50. break;
  51. case 2:
  52. if (acc_x > maxLeft) {
  53. maxLeft = (int) acc_x;
  54. prevTimeLeft = System.currentTimeMillis();
  55. }
  56. if (acc_x < minLeft) {
  57. minLeft = (int) acc_x;
  58. prevTimeLeft2 = System.currentTimeMillis();
  59. }
  60. if (acc_z > 8 && acc_z < 12) {
  61. posNode2 = "Ligger";
  62.  
  63. } else if (acc_z > -3 && acc_z < 3) {
  64. if (maxLeft - minLeft > 6) {
  65. posNode2 = "Går";
  66. } else {
  67. posNode2 = "Står";
  68. }
  69. }
  70. if (System.currentTimeMillis() - prevTimeLeft > 1000) {
  71. maxLeft = 0;
  72. }
  73. if (System.currentTimeMillis() - prevTimeLeft2 > 1000) {
  74. minLeft = 9999;
  75. }
  76. break;
  77. case 3:
  78. if (acc_x > maxRight) {
  79. maxRight = (int) acc_x;
  80. prevTimeRight = System.currentTimeMillis();
  81. }
  82. if (acc_x < minRight) {
  83. minRight = (int) acc_x;
  84. prevTimeRight2 = System.currentTimeMillis();
  85. }
  86. if (acc_z > 8 && acc_z < 12) {
  87. posNode3 = "Ligger";
  88.  
  89. } else if (acc_z > -3 && acc_z < 3) {
  90. if (maxRight - minRight > 6) {
  91. posNode3 = "Går";
  92. } else {
  93. posNode3 = "Står";
  94. }
  95. }
  96. if (System.currentTimeMillis() - prevTimeRight > 1000) {
  97. maxRight = 0;
  98. }
  99. if (System.currentTimeMillis() - prevTimeRight2 > 1000) {
  100. minRight = 9999;
  101. }
  102. break;
  103. case 4:
  104. if (acc_x > 8 && acc_x < 12) {
  105. leftArm = "Ner";
  106. } else if (acc_z > 8 && acc_z < 12) {
  107. leftArm = "90 ner";
  108. } else if ((acc_y > 2 && acc_y < 8) && (acc_x < -5 && acc_x > -11)) {
  109. leftArm = "Upp";
  110. } else if (acc_y > 8 && acc_y < 12) {
  111. leftArm = "90 sida";
  112. }
  113. break;
  114. case 5:
  115. if (acc_x > 8 && acc_x < 12) {
  116. rightArm = "Ner";
  117. } else if (acc_z > 8 && acc_z < 12) {
  118. rightArm = "90 ner";
  119. } else if ((acc_y < -3 && acc_y > -9)
  120. && (acc_x < -5 && acc_x > -11)) {
  121. rightArm = "Upp";
  122. } else if (acc_y < -8 && acc_y > -12) {// höger
  123. rightArm = "90 sida";
  124. }
  125. break;
  126.  
  127. }
  128.  
  129. if (posNode1.matches("Står") && posNode2.matches("Står")
  130. && posNode3.matches("Står")) {
  131. Position = "Står";
  132. } else if (posNode3.matches("Ligger") && posNode2.matches("Ligger")
  133. && posNode1.matches("Står")) {
  134. Position = "Sitter";
  135. } else if (posNode3.matches("Ligger") && posNode2.matches("Ligger")
  136. && posNode1.matches("Ligger")) {
  137. Position = "Ligger";
  138. } else if (posNode1.matches("Står") && posNode2.matches("Går")
  139. && posNode2.matches("Går")) {
  140. Position = "Går";
  141. } else {
  142. }
  143.  
  144. if (!lastPosition.matches(Position) && !Position.matches("Error")) {
  145. if (System.currentTimeMillis() - prevPositionTime > 1000) {
  146. nodePositions[0] = Position;
  147. lastPosition = Position;
  148. }
  149. } else {
  150. prevPositionTime = System.currentTimeMillis();
  151. }
  152. if (!lastLeftArm.matches(leftArm) && !leftArm.matches("Error")) {
  153. nodePositions[1] = leftArm;
  154. lastLeftArm = leftArm;
  155. }
  156. if (!lastRightArm.matches(rightArm) && !rightArm.matches("Error")) {
  157. nodePositions[2] = rightArm;
  158. lastRightArm = rightArm;
  159. }
  160. if (System.currentTimeMillis() - prevRotationTime > 1000) {
  161. nodePositions[3] = Rotation;
  162. prevRotationTime = System.currentTimeMillis();
  163. }
  164. for (int i = 0; i < nodePositions.length; i++) {
  165. System.out.println(nodePositions[i]);
  166. }
  167.  
  168. }
  169. /**
  170. * This method is called by the GUI and returns an array containing
  171. * the node-positions of the patient
  172. * @return Nodepositions
  173. */
  174. public String[] getNodePositions() {
  175. return nodePositions;
  176. }
  177.  
  178. }
Add Comment
Please, Sign In to add comment