From 0a2999afa1143e3f6ca565479ccc1a6ba35e5e3b Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 5 Jun 2024 14:06:57 +0200 Subject: [PATCH 1/3] Added faulty movement checking function --- .../util/processing/InputProcessor.java | 63 +++++++------------ 1 file changed, 21 insertions(+), 42 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 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() { From b5d2e057c3b662b468ad16cac42d016c0e0e5452 Mon Sep 17 00:00:00 2001 From: SebasKoedam Date: Wed, 5 Jun 2024 14:08:17 +0200 Subject: [PATCH 2/3] hoppelijk sloopt dit niks --- code/src/Fitbot/app/build.gradle | 1 + .../fitbot/ui/activities/FitnessActivity.java | 8 ++ .../src/main/res/layout/activity_fitness.xml | 111 ++++++++++-------- .../app/src/main/res/values/strings.xml | 4 +- code/src/Fitbot/gradle.properties | 3 +- 5 files changed, 73 insertions(+), 54 deletions(-) diff --git a/code/src/Fitbot/app/build.gradle b/code/src/Fitbot/app/build.gradle index 1348df8..390414f 100644 --- a/code/src/Fitbot/app/build.gradle +++ b/code/src/Fitbot/app/build.gradle @@ -30,6 +30,7 @@ android { dependencies { + implementation 'com.facebook.shimmer:shimmer:0.5.0' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' implementation 'com.android.support:cardview-v7:28.0.0' diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java index 9fcb10d..30dcb16 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java @@ -34,6 +34,7 @@ import com.example.fitbot.exercise.ExerciseManager; import com.example.fitbot.pepper.Pepper; import com.example.fitbot.util.NavigationManager; import com.example.fitbot.util.processing.InputProcessor; +import com.facebook.shimmer.ShimmerFrameLayout; public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks { @@ -92,6 +93,10 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall progressText = findViewById(R.id.progressText); progressCircle.setMax(maxProgress); + ShimmerFrameLayout shimmerLayout = findViewById(R.id.shimmerFrameLayout); + shimmerLayout.startShimmer(); // Start shimmer animation + + // Set color of loading circle ProgressBar loadingCircle = findViewById(R.id.loadingCircle); loadingCircle.setIndeterminateTintList(ColorStateList.valueOf(Color.RED)); @@ -176,6 +181,9 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall // exerciseDescriptionTextView.setText(exercise.description); exerciseVideoUrl = exercise.videoUrl; + ShimmerFrameLayout shimmerLayout = findViewById(R.id.shimmerFrameLayout); + shimmerLayout.stopShimmer(); // Start shimmer animation + // Play the video playVideo(videoView, this); 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..8b2e257 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 @@ -60,74 +60,81 @@ - - - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - - - - - - - - + android:layout_gravity="center_horizontal" + android:text="@string/exerciseTitle" + android:textAlignment="center" /> - + + + + + + + + + + + + + + + + -