Added error checking

This commit is contained in:
Luca Warmenhoven
2024-06-05 14:32:06 +02:00
parent e0bb86d0e9
commit f4cbf50821
2 changed files with 14 additions and 8 deletions

View File

@@ -134,7 +134,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// the canvas properly. // the canvas properly.
this.fetchExerciseAsync((exercise) -> { this.fetchExerciseAsync((exercise) -> {
// 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(SENSOR_SAMPLE_RATE, this); motionProcessor = new InputProcessor(this);
motionProcessor.useExercise(exercise); motionProcessor.useExercise(exercise);
/* TODO: Remove if not needed */ /* TODO: Remove if not needed */
motionProcessor.setRecording(true, 10); motionProcessor.setRecording(true, 10);
@@ -162,8 +162,8 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
if (exercise == null) { if (exercise == null) {
runOnUiThread(() -> onFailedFetch.handle(null)); runOnUiThread(() -> onFailedFetch.handle(null));
} else { } else {
onSuccessfulFetch.handle(exercise);
runOnUiThread(() -> { runOnUiThread(() -> {
onSuccessfulFetch.handle(exercise);
exerciseNameTextView.setText(exercise.name); exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription); exerciseShortDescriptionTextView.setText(exercise.shortDescription);
// exerciseDescriptionTextView.setText(exercise.description); // exerciseDescriptionTextView.setText(exercise.description);
@@ -196,6 +196,9 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
Log.e("FitnessActivity", "VideoView is null. Check your layout XML."); Log.e("FitnessActivity", "VideoView is null. Check your layout XML.");
} }
// Start checking for user movement once the video has loaded
this.motionProcessor.startCheckingUserMovement();
return true; return true;
} }
return false; return false;

View File

@@ -27,9 +27,7 @@ public class InputProcessor {
//private Vector3f[][] selfRotationVectorPaths; // Relative path of the motion data //private Vector3f[][] selfRotationVectorPaths; // Relative path of the motion data
private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data
private final float sampleRate; // The sample rate of the motion sensor
private float exerciseRepetitionDurationInSeconds = 0.0f; private float exerciseRepetitionDurationInSeconds = 0.0f;
private int repetitionsRemaining = 0;
private int exercisesRemaining = 0; private int exercisesRemaining = 0;
private float errorCheckInterval_s; private float errorCheckInterval_s;
@@ -75,11 +73,8 @@ public class InputProcessor {
/** /**
* Constructor for the motion processor. * Constructor for the motion processor.
*
* @param inputSampleRate The sample rate of the motion sensor.
*/ */
public InputProcessor(float inputSampleRate, FitnessActivity parentActivity) { public InputProcessor(FitnessActivity parentActivity) {
this.sampleRate = inputSampleRate;
this.parentActivity = parentActivity; this.parentActivity = parentActivity;
} }
@@ -100,7 +95,15 @@ public class InputProcessor {
this.exercisesRemaining = 1; this.exercisesRemaining = 1;
this.nextExercise(exercise); this.nextExercise(exercise);
Pepper.say(STARTING_PHRASES[(int) Math.floor(Math.random() * STARTING_PHRASES.length)]); Pepper.say(STARTING_PHRASES[(int) Math.floor(Math.random() * STARTING_PHRASES.length)]);
}
/**
* Function that starts checking 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.
*/
public void startCheckingUserMovement()
{
// Error checking thread. // Error checking thread.
(new Thread(() -> { (new Thread(() -> {
while (this.exercisesRemaining > 0) while (this.exercisesRemaining > 0)