algorithm optimization

This commit is contained in:
2024-06-07 14:29:13 +02:00
parent 2ffc391032
commit 5f579f4e50
2 changed files with 22 additions and 21 deletions

View File

@@ -175,7 +175,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// Start checking for user movement once the video has loaded // Start checking for user movement once the video has loaded
this.motionProcessor.startListening(); this.motionProcessor.startListening();
this.motionProcessor.startCheckingUserMovement(); this.motionProcessor.startCheckingUserMovement();
// this.motionProcessor.setRecording(true, 4.f); this.motionProcessor.setRecording(true, 3.f);
return true; return true;
} }

View File

@@ -1,5 +1,6 @@
package com.example.fitbot.util.processing; package com.example.fitbot.util.processing;
import android.app.ActivityManager;
import android.util.Log; import android.util.Log;
import com.example.fitbot.exercise.Exercise; import com.example.fitbot.exercise.Exercise;
@@ -106,32 +107,32 @@ public class InputProcessor {
// Error checking thread. // Error checking thread.
(new Thread(() -> { (new Thread(() -> {
Log.i("InputProcessor", "Movement Checking Thread started"); Log.i("InputProcessor", "Movement Checking Thread started");
while (this.exercisesRemaining > 0) { while (this.exercisesRemaining > 0) {
if ( this.totalChecks == 0 || this.selfRotationVectorPaths == null if ( this.totalChecks == 0 || this.selfRotationVectorPaths == null
|| this.selfRotationVectorPaths.length == 0 || this.selfRotationVectorPaths.length == 0
|| this.selfRotationVectorPaths[0].size() == 0 || this.selfRotationVectorPaths[0].size() == 0
|| this.selfRotationVectorPaths[1].size() == 0) || this.selfRotationVectorPaths[1].size() == 0)
continue; continue;
boolean isFaulty = this.isFaultyMovement(); boolean isFaulty = this.isFaultyMovement();
Log.i("InputProcessor", "Movement checked: " + (isFaulty ? "Faulty" : "Good")); Log.i("InputProcessor", "Movement checked: " + (isFaulty ? "Faulty" : "Good"));
if (isFaulty) { if (isFaulty) {
this.onInadequateRepetition(); this.onInadequateRepetition();
} else this.onAdequateRepetition(); } else this.onAdequateRepetition();
this.checksPerformed++; this.checksPerformed++;
if (this.checksPerformed >= this.totalChecks) if (this.checksPerformed >= this.totalChecks)
{ {
this.checksPerformed = 0; this.checksPerformed = 0;
this.exercisesRemaining--; this.exercisesRemaining--;
acquireExercise(); acquireExercise();
} }
try { try {
Thread.sleep((long) (this.errorCheckInterval_s * 1000)); Thread.sleep((long) (this.errorCheckInterval_s * 1000));
} catch (InterruptedException e) { } catch (InterruptedException e) {
@@ -419,10 +420,10 @@ public class InputProcessor {
* Function for checking whether the last movement was faulty * Function for checking whether the last movement was faulty
*/ */
public boolean isFaultyMovement() { public boolean isFaultyMovement() {
boolean upMovementDetected = false; boolean[] deviceMovementStatus = new boolean[selfRotationVectorPaths.length];
boolean downMovementDetected = false;
for (List<Vector3f> path : selfRotationVectorPaths) { for (int i = 0; i < selfRotationVectorPaths.length; i++) {
List<Vector3f> path = selfRotationVectorPaths[i];
if (path.size() < 2) { if (path.size() < 2) {
continue; // Skip if there are not enough points to compare continue; // Skip if there are not enough points to compare
} }
@@ -433,17 +434,17 @@ public class InputProcessor {
float y1 = firstPoint.y; float y1 = firstPoint.y;
float y2 = lastPoint.y; float y2 = lastPoint.y;
if (y2 > y1) { // Assuming that a good movement is when y2 is greater than y1
upMovementDetected = true; deviceMovementStatus[i] = y2 > y1;
} else if (y2 < y1) { }
downMovementDetected = true;
}
if (upMovementDetected && downMovementDetected) { // Return true for faulty movement if any device has faulty movement
return false; // Return false for faulty movement if both up and down movements are detected for (boolean isGood : deviceMovementStatus) {
if (!isGood) {
return true;
} }
} }
return true; // Return true for faulty movement if only up or down movement is detected return false;
} }
} }