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 dc46191..cd81be9 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 @@ -112,6 +112,7 @@ public class InputProcessor { ExerciseManager.TOTAL_REPETITIONS_REQUIRED += ExerciseManager.DEFAULT_EXERCISE_REPETITIONS; ExerciseManager.TOTAL_EXERCISES_PREFORMED++; + this.selfRotationVectorPaths = new ArrayList[2]; this.selfRotationVectorPaths[0] = new ArrayList<>(); this.selfRotationVectorPaths[1] = new ArrayList<>(); @@ -130,14 +131,14 @@ public class InputProcessor { */ public void onAdequateRepetition() { ExerciseManager.TOTAL_REPETITIONS_PERFORMED++; - new FitnessActivity().incrementProgress(); + this.parentActivity.incrementProgress(); } /** * Method that is called whenever the user performs a bad repetition. */ public void onInadequateRepetition() { - new FitnessActivity().triggerColorBurst(false); + this.parentActivity.triggerColorBurst(false); } /** @@ -352,55 +353,33 @@ public class InputProcessor { }*/ /** - * Function for getting the error offsets of the user's path compared to the - * target path at a given point in time. * - * @param sensorId The sensor ID to get the error offsets from. - * @param time The time to get the error offsets from. - * This value must be >= 0 && <= exerciseTime, otherwise - * the error will be 0 by default. - * @return A list of error offsets of the motion data compared to the reference path. */ - public double getError(int sensorId, float time) { + public boolean isFaultyMovement(int sensorId, float time) { // Ensure the sensor ID is within the bounds of the array if (sensorId < 0 || sensorId >= selfRotationVectorPaths.length) - return 0.0d; + return false; - // Calculate the index of the rotational vector where we're currently at - int targetRotationIdx = + // 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; - // Index of the current rotation vector - int targetIndex = (int) ((this.exerciseDurationInSeconds / this.targetRotationVectorPaths[sensorId].length) * time); - int selfIndex = (int) (this.selfRotationVectorPaths[sensorId].length / this.sampleRate * time); - - // Ensure the indexes are within the bounds of the array - if ( - targetIndex >= 0 && targetIndex <= this.targetRotationVectorPaths[sensorId].length - 1 && - selfIndex >= 0 && selfIndex <= this.selfRotationVectorPaths[sensorId].length - 1 && - this.selfRotationVectorPaths[sensorId][selfIndex] != null && - this.targetRotationVectorPaths[sensorId][targetIndex] != null - ) { - return this.selfRotationVectorPaths[sensorId][selfIndex].distance(this.targetRotationVectorPaths[sensorId][targetIndex]); - }*/ - return 0.0d; - } - - /** - * Method for getting the average error of the motion data - * compared to the reference path. - * - * @param sensorId The sensor ID to get the error offsets from. - * @return The average error of the motion data compared to the reference path. - */ - public double getAverageError(int sensorId) { - double error = 0; - for (int i = 0; i < this.exerciseRepetitionDurationInSeconds; i++) { - error += getError(sensorId, i); + for ( i = 0; i < selfRotationVectorPaths.length; i++) + { + referenceIndex = (int) (Math.round( + ((time % this.exerciseRepetitionDurationInSeconds) / + (this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length)) + % this.targetRotationVectorPaths[i].length; + // If distance is greater than the threshold, return true + if (this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance( + this.targetRotationVectorPaths[i][referenceIndex]) > ExerciseManager.EXERCISE_ERROR_MARGIN) + return true; } - return error / this.exerciseRepetitionDurationInSeconds; + return false; } public float secondsPassed() { diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml index 641d8d9..261cb35 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml @@ -97,7 +97,6 @@ android:textAlignment="center" /> - Title - Exercise description Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. + Description + + Exercise description Exercise title \ No newline at end of file diff --git a/code/src/Fitbot/gradle.properties b/code/src/Fitbot/gradle.properties index c5abf2b..2ab3bb7 100644 --- a/code/src/Fitbot/gradle.properties +++ b/code/src/Fitbot/gradle.properties @@ -15,4 +15,3 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true -#android.enableJetifier=true \ No newline at end of file