From 2ffc391032038730164d73d4f7904ed8851ef0e1 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Fri, 7 Jun 2024 12:36:21 +0200 Subject: [PATCH] changes to see how its faulty --- .../util/processing/InputProcessor.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java index 2c64a06..c62aeb8 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java @@ -17,6 +17,7 @@ import com.google.gson.JsonParser; import org.jetbrains.annotations.NotNull; import org.joml.Vector3f; +import org.json.JSONArray; import java.util.ArrayList; import java.util.List; @@ -418,30 +419,31 @@ public class InputProcessor { * Function for checking whether the last movement was faulty */ public boolean isFaultyMovement() { - - // Calculate the index of the reference rotation vector - // This is done by calculating the closest index of the last received vector - // to the current time. - // i = | (t % T) / T * N | - - int i, referenceIndex; - float distance; - - for (i = 0; i < selfRotationVectorPaths.length; i++) { - referenceIndex = (int) (Math.round( - ((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) / - (this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length)) - % this.targetRotationVectorPaths[i].length; - referenceIndex = Math.min(1, Math.max(0, referenceIndex)); - // If distance is greater than the threshold, return true - distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance( - this.targetRotationVectorPaths[i][referenceIndex]); - - if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN) { - Log.i("MotionProcessor", "Faulty movement detected: " + distance + " > " + ExerciseManager.EXERCISE_ERROR_MARGIN); - return true; + boolean upMovementDetected = false; + boolean downMovementDetected = false; + + for (List path : selfRotationVectorPaths) { + if (path.size() < 2) { + continue; // Skip if there are not enough points to compare + } + + Vector3f firstPoint = path.get(0); + Vector3f lastPoint = path.get(path.size() - 1); + + float y1 = firstPoint.y; + float y2 = lastPoint.y; + + if (y2 > y1) { + upMovementDetected = true; + } else if (y2 < y1) { + downMovementDetected = true; + } + + if (upMovementDetected && downMovementDetected) { + return false; // Return false for faulty movement if both up and down movements are detected } } - return false; + + return true; // Return true for faulty movement if only up or down movement is detected } }