Fixed issues

This commit is contained in:
Luca Warmenhoven
2024-06-05 14:50:05 +02:00
parent 2b631bd600
commit cca91461f3
2 changed files with 8 additions and 16 deletions

View File

@@ -136,10 +136,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// Acquire paths from the exercise and provide them to the motion processor // Acquire paths from the exercise and provide them to the motion processor
motionProcessor = new InputProcessor(this); motionProcessor = new InputProcessor(this);
motionProcessor.useExercise(exercise); motionProcessor.useExercise(exercise);
/* TODO: Remove if not needed */
motionProcessor.setRecording(true, 10);
motionProcessor.startListening();
}, (n) -> { }, (n) -> {
int randomMessageIndex = (int) Math.floor(Math.random() * EXERCISE_NOT_FOUND_MESSAGES.length); int randomMessageIndex = (int) Math.floor(Math.random() * EXERCISE_NOT_FOUND_MESSAGES.length);
@@ -197,6 +193,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.startCheckingUserMovement(); this.motionProcessor.startCheckingUserMovement();
return true; return true;

View File

@@ -101,21 +101,19 @@ public class InputProcessor {
* This function will start a thread that will check for user movement * This function will start a thread that will check for user movement
* and compare the last rotation vectors to the target rotation vectors. * and compare the last rotation vectors to the target rotation vectors.
*/ */
public void startCheckingUserMovement() public void startCheckingUserMovement() {
{
// Error checking thread. // Error checking thread.
(new Thread(() -> { (new Thread(() -> {
while (this.exercisesRemaining > 0) while (this.exercisesRemaining > 0) {
{
boolean isFaulty = this.isFaultyMovement(); boolean isFaulty = this.isFaultyMovement();
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)
acquireExercise(); acquireExercise();
try { try {
@@ -230,8 +228,7 @@ public class InputProcessor {
* Function for acquiring the next exercise from the database. * Function for acquiring the next exercise from the database.
* Upon successful retrieval, it will call the nextExercise method. * Upon successful retrieval, it will call the nextExercise method.
*/ */
private void acquireExercise() private void acquireExercise() {
{
this.exercisesRemaining--; this.exercisesRemaining--;
this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> { this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> {
@@ -397,8 +394,7 @@ public class InputProcessor {
int i, referenceIndex; int i, referenceIndex;
float distance; float distance;
for ( i = 0; i < selfRotationVectorPaths.length; i++) for (i = 0; i < selfRotationVectorPaths.length; i++) {
{
referenceIndex = (int) (Math.round( referenceIndex = (int) (Math.round(
((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) / ((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) /
(this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length)) (this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length))
@@ -407,8 +403,7 @@ public class InputProcessor {
distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance( distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance(
this.targetRotationVectorPaths[i][referenceIndex]); this.targetRotationVectorPaths[i][referenceIndex]);
if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN) if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN) {
{
Log.i("MotionProcessor", "Faulty movement detected: " + distance + " > " + ExerciseManager.EXERCISE_ERROR_MARGIN); Log.i("MotionProcessor", "Faulty movement detected: " + distance + " > " + ExerciseManager.EXERCISE_ERROR_MARGIN);
return true; return true;
} }