fix nullobject reference (luca) and made it so the repetitioncount resets properly

This commit is contained in:
2024-06-10 11:46:52 +02:00
parent 2453b8581f
commit 63a3e6870e
2 changed files with 24 additions and 22 deletions

View File

@@ -35,6 +35,7 @@ import com.example.fitbot.util.processing.InputProcessor;
public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks { public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks {
public static int progress = 1;
// Private fields for the FitnessActivity class. // Private fields for the FitnessActivity class.
private InputProcessor motionProcessor; private InputProcessor motionProcessor;
private Exercise currentExercise; private Exercise currentExercise;
@@ -42,7 +43,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// Progress circle for the exercises // Progress circle for the exercises
private ProgressBar progressCircle; private ProgressBar progressCircle;
private TextView progressText; private TextView progressText;
private int progress = 1;
private final int maxProgress = 10; private final int maxProgress = 10;
// Exercise status element data // Exercise status element data
@@ -78,7 +78,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
QiSDK.register(this, this); QiSDK.register(this, this);
setContentView(R.layout.activity_fitness); setContentView(R.layout.activity_fitness);
videoView = findViewById(R.id.videoView); videoView = findViewById(R.id.videoView);
ExerciseManager.TOTAL_REPETITIONS_PERFORMED = 0;
// Fill empty objects with exercise data // Fill empty objects with exercise data
this.exerciseNameTextView = findViewById(R.id.textViewFitnessTitle); this.exerciseNameTextView = findViewById(R.id.textViewFitnessTitle);
this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription); this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription);
@@ -190,6 +190,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
if (progress >= 10) { if (progress >= 10) {
runOnUiThread(() -> NavigationManager.navigateToActivity(this, EndScreenActivity.class)); runOnUiThread(() -> NavigationManager.navigateToActivity(this, EndScreenActivity.class));
InputProcessor.exercisesRemaining = 1; InputProcessor.exercisesRemaining = 1;
progress = 1;
} }
} }

View File

@@ -25,7 +25,7 @@ import java.util.List;
public class InputProcessor { public class InputProcessor {
private List<Vector3f>[] selfRotationVectorPaths = null; private List<Vector3f>[] selfRotationVectorPaths = new ArrayList[2];
// Relative path of the motion data // Relative path of the motion data
private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data
@@ -78,11 +78,10 @@ public class InputProcessor {
* Constructor for the motion processor. * Constructor for the motion processor.
*/ */
public InputProcessor(FitnessActivity parentActivity) { public InputProcessor(FitnessActivity parentActivity) {
this.parentActivity = parentActivity;
// Initialize each ArrayList in the array
this.selfRotationVectorPaths[0] = new ArrayList<>(); this.selfRotationVectorPaths[0] = new ArrayList<>();
this.selfRotationVectorPaths[1] = new ArrayList<>(); this.selfRotationVectorPaths[1] = new ArrayList<>();
this.parentActivity = parentActivity;
// Initialize each ArrayList in the array
} }
/** /**
@@ -118,10 +117,11 @@ public class InputProcessor {
while (exercisesRemaining > 0) { while (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] == null
|| this.selfRotationVectorPaths[1].size() == 0) || this.selfRotationVectorPaths[0].size() == 0
|| this.selfRotationVectorPaths[1].size() == 0)
continue; continue;
boolean isFaulty = this.isFaultyMovement(); boolean isFaulty = this.isFaultyMovement();
@@ -134,8 +134,7 @@ public class InputProcessor {
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();
@@ -244,9 +243,11 @@ public class InputProcessor {
* incoming connections. * incoming connections.
*/ */
public void startListening() { public void startListening() {
this.selfRotationVectorPaths = new ArrayList[]{new ArrayList(), new ArrayList()};
// Create socket server // Create socket server
this.server = WebServer.createServer(); this.server = WebServer.createServer();
//
FitnessActivity.progress = 1;
Log.i("MotionProcessor", "Listening for incoming connections."); Log.i("MotionProcessor", "Listening for incoming connections.");
// Check if the socket // Check if the socket
@@ -264,8 +265,7 @@ public class InputProcessor {
*/ */
private void acquireExercise() { private void acquireExercise() {
if ( this.exercisesRemaining <= 0) if (this.exercisesRemaining <= 0) {
{
Log.i("InputProcessor", "Exercises finished"); Log.i("InputProcessor", "Exercises finished");
this.parentActivity.runOnUiThread(() -> { this.parentActivity.runOnUiThread(() -> {
NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class); NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class);
@@ -430,28 +430,29 @@ public class InputProcessor {
public boolean isFaultyMovement() { public boolean isFaultyMovement() {
boolean upMovementDetected = false; boolean upMovementDetected = false;
boolean downMovementDetected = false; boolean downMovementDetected = false;
for (List<Vector3f> path : selfRotationVectorPaths) { for (List<Vector3f> path : selfRotationVectorPaths) {
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
} }
Vector3f firstPoint = path.get(0); Vector3f firstPoint = path.get(0);
Vector3f lastPoint = path.get(path.size() - 1); Vector3f lastPoint = path.get(path.size() - 1);
float y1 = firstPoint.y; float y1 = firstPoint.y;
float y2 = lastPoint.y; float y2 = lastPoint.y;
if (y2 > y1) { if (y2 > y1) {
upMovementDetected = true; upMovementDetected = true;
} else if (y2 < y1) { } else if (y2 < y1) {
downMovementDetected = true; downMovementDetected = true;
} }
if (upMovementDetected && downMovementDetected) { if (upMovementDetected && downMovementDetected) {
return false; // Return false for faulty movement if both up and down movements are detected return false; // Return false for faulty movement if both up and down movements are detected
} }
} }
return true; // Return true for faulty movement if only up or down movement is detected return true; // Return true for faulty movement if only up or down movement is detected
}} }
}