Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aaGui;
- public class PatternRecognizer {
- String Position, Rotation, leftArm, rightArm, posNode1, posNode2, posNode3,
- lastPosition = "Error", lastLeftArm = "Error",
- lastRightArm = "Error";
- String[] nodePositions = {"fadf","fdafafff","hej","LOL"};
- int maxLeft = 0, minLeft = 9999, maxRight = 0, minRight = 9999;
- long prevTimeLeft = 0, prevTimeLeft2 = 0, prevTimeRight = 0,
- prevTimeRight2 = 0, prevPositionTime = 0, prevRotationTime = 0;
- /**
- * This method takes in values from a specific sensor-node and with the values from
- * other nodes it calculates the position of the patient, how he/she is rotating the
- * upper body and whether the arms are moving or not. This is then saved in an array
- * which the GUI then collects and displays.
- * @param node_id
- * @param acc_x
- * @param acc_y
- * @param acc_z
- * @param mag_x
- * @param mag_y
- * @param mag_z
- * @param gyro_x
- * @param gyro_y
- * @param gyro_z
- */
- public void patternRecognition(int node_id, double acc_x, double acc_y,
- double acc_z, double mag_x, double mag_y, double mag_z, double gyro_x, double gyro_y,
- double gyro_z) {
- switch (node_id) {
- case 1:
- if (acc_z > 8 && acc_z < 12) {
- posNode1 = "Ligger";
- } else if (acc_z > -2 && acc_z < 2) {
- posNode1 = "Står";
- }
- if (gyro_x > 75) {
- Rotation = "Vrider vänster";
- } else if (gyro_x < -75) {
- Rotation = "Vrider höger";
- } else {
- Rotation = "Stilla";
- }
- break;
- case 2:
- if (acc_x > maxLeft) {
- maxLeft = (int) acc_x;
- prevTimeLeft = System.currentTimeMillis();
- }
- if (acc_x < minLeft) {
- minLeft = (int) acc_x;
- prevTimeLeft2 = System.currentTimeMillis();
- }
- if (acc_z > 8 && acc_z < 12) {
- posNode2 = "Ligger";
- } else if (acc_z > -3 && acc_z < 3) {
- if (maxLeft - minLeft > 6) {
- posNode2 = "Går";
- } else {
- posNode2 = "Står";
- }
- }
- if (System.currentTimeMillis() - prevTimeLeft > 1000) {
- maxLeft = 0;
- }
- if (System.currentTimeMillis() - prevTimeLeft2 > 1000) {
- minLeft = 9999;
- }
- break;
- case 3:
- if (acc_x > maxRight) {
- maxRight = (int) acc_x;
- prevTimeRight = System.currentTimeMillis();
- }
- if (acc_x < minRight) {
- minRight = (int) acc_x;
- prevTimeRight2 = System.currentTimeMillis();
- }
- if (acc_z > 8 && acc_z < 12) {
- posNode3 = "Ligger";
- } else if (acc_z > -3 && acc_z < 3) {
- if (maxRight - minRight > 6) {
- posNode3 = "Går";
- } else {
- posNode3 = "Står";
- }
- }
- if (System.currentTimeMillis() - prevTimeRight > 1000) {
- maxRight = 0;
- }
- if (System.currentTimeMillis() - prevTimeRight2 > 1000) {
- minRight = 9999;
- }
- break;
- case 4:
- if (acc_x > 8 && acc_x < 12) {
- leftArm = "Ner";
- } else if (acc_z > 8 && acc_z < 12) {
- leftArm = "90 ner";
- } else if ((acc_y > 2 && acc_y < 8) && (acc_x < -5 && acc_x > -11)) {
- leftArm = "Upp";
- } else if (acc_y > 8 && acc_y < 12) {
- leftArm = "90 sida";
- }
- break;
- case 5:
- if (acc_x > 8 && acc_x < 12) {
- rightArm = "Ner";
- } else if (acc_z > 8 && acc_z < 12) {
- rightArm = "90 ner";
- } else if ((acc_y < -3 && acc_y > -9)
- && (acc_x < -5 && acc_x > -11)) {
- rightArm = "Upp";
- } else if (acc_y < -8 && acc_y > -12) {// höger
- rightArm = "90 sida";
- }
- break;
- }
- if (posNode1.matches("Står") && posNode2.matches("Står")
- && posNode3.matches("Står")) {
- Position = "Står";
- } else if (posNode3.matches("Ligger") && posNode2.matches("Ligger")
- && posNode1.matches("Står")) {
- Position = "Sitter";
- } else if (posNode3.matches("Ligger") && posNode2.matches("Ligger")
- && posNode1.matches("Ligger")) {
- Position = "Ligger";
- } else if (posNode1.matches("Står") && posNode2.matches("Går")
- && posNode2.matches("Går")) {
- Position = "Går";
- } else {
- }
- if (!lastPosition.matches(Position) && !Position.matches("Error")) {
- if (System.currentTimeMillis() - prevPositionTime > 1000) {
- nodePositions[0] = Position;
- lastPosition = Position;
- }
- } else {
- prevPositionTime = System.currentTimeMillis();
- }
- if (!lastLeftArm.matches(leftArm) && !leftArm.matches("Error")) {
- nodePositions[1] = leftArm;
- lastLeftArm = leftArm;
- }
- if (!lastRightArm.matches(rightArm) && !rightArm.matches("Error")) {
- nodePositions[2] = rightArm;
- lastRightArm = rightArm;
- }
- if (System.currentTimeMillis() - prevRotationTime > 1000) {
- nodePositions[3] = Rotation;
- prevRotationTime = System.currentTimeMillis();
- }
- for (int i = 0; i < nodePositions.length; i++) {
- System.out.println(nodePositions[i]);
- }
- }
- /**
- * This method is called by the GUI and returns an array containing
- * the node-positions of the patient
- * @return Nodepositions
- */
- public String[] getNodePositions() {
- return nodePositions;
- }
- }
Add Comment
Please, Sign In to add comment