motion processing stuff + logs + fix crash (luca)

This commit is contained in:
2024-06-04 10:31:24 +02:00
parent ffb90c001d
commit 3b65fffec8
3 changed files with 27 additions and 18 deletions

View File

@@ -40,6 +40,8 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
private TextView exerciseShortDescriptionTextView; private TextView exerciseShortDescriptionTextView;
private TextView exerciseDescriptionTextView; private TextView exerciseDescriptionTextView;
private final Object lock = new Object();
// Some nice little messages for the user // Some nice little messages for the user
private static final String[] EXERCISE_NOT_FOUND_MESSAGES = new String[]{ private static final String[] EXERCISE_NOT_FOUND_MESSAGES = new String[]{
"Ik heb momenteel helaas wat moeite met het ophalen van oefeningen, sorry.", "Ik heb momenteel helaas wat moeite met het ophalen van oefeningen, sorry.",
@@ -58,16 +60,14 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
QiSDK.register(this, this); QiSDK.register(this, this);
setContentView(R.layout.activity_fitness); setContentView(R.layout.activity_fitness);
// Remove the ugly ass bar on top of the view
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
// 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.exerciseDescriptionTextView = findViewById(R.id.textViewDialogDescription); //this.exerciseDescriptionTextView = findViewById(R.id.textViewDialogDescription);
this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription); this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription);
// Remove the ugly ass bar on top of the view
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
// Find the VideoView by its ID // Find the VideoView by its ID
VideoView videoView = findViewById(R.id.videoView); VideoView videoView = findViewById(R.id.videoView);
@@ -84,6 +84,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showInfoDialog(); showInfoDialog();
} }
}); });
} }
@@ -109,8 +110,8 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
exerciseStatusElement.initialize(exercise, motionProcessor, EXERCISE_COUNT); exerciseStatusElement.initialize(exercise, motionProcessor, EXERCISE_COUNT);
motionProcessor.useExercise(exercise); motionProcessor.useExercise(exercise);
/* TODO: Remove if not needed */motionProcessor.setRecording(true, 10); /* TODO: Remove if not needed */motionProcessor.setRecording(true, 10);
motionProcessor.startListening();
motionProcessor.setInputHandler(exerciseStatusElement); motionProcessor.setInputHandler(exerciseStatusElement);
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);
@@ -136,14 +137,17 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
if (exercise == null) { if (exercise == null) {
onFailedFetch.handle(null); onFailedFetch.handle(null);
} else { } else {
exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription);
exerciseDescriptionTextView.setText(exercise.description);
onSuccessfulFetch.handle(exercise); onSuccessfulFetch.handle(exercise);
this.runOnUiThread(() -> {
exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription);
// exerciseDescriptionTextView.setText(exercise.description);
});
} }
})).start(); })).start();
} }
/** /**
* Function for playing a video in a VideoView * Function for playing a video in a VideoView
* *

View File

@@ -14,7 +14,11 @@ public class GesturePath {
*/ */
public GesturePath(Vector3f[] vectors) { public GesturePath(Vector3f[] vectors) {
if (vectors.length < 2) { if (vectors.length < 2) {
this.segments = new PathSegment[0]; this.segments = new PathSegment[1];
this.segments[0] = new PathSegment(
new Vector3f(0, 0, 0),
new Vector3f(0, 0, 0)
);
return; return;
} }

View File

@@ -160,6 +160,8 @@ public class InputProcessor {
try { try {
Log.i("MotionProcessor", "Time passed: " + this.secondsPassed + "s");
Log.i("MotionProcessor", "Recording: " + this.recordingMovement + ", " + this.secondsPassed + " / " + this.recordingDurationInSeconds);
Log.i("MotionProcessor", "Received packet data: " + data); Log.i("MotionProcessor", "Received packet data: " + data);
JsonElement json = JsonParser.parseString(data); JsonElement json = JsonParser.parseString(data);
@@ -198,18 +200,12 @@ public class InputProcessor {
// Re-calculate time for index calculation // Re-calculate time for index calculation
secondsPassed = (System.currentTimeMillis() - lastTime) / 1000.0d; secondsPassed = (System.currentTimeMillis() - lastTime) / 1000.0d;
lastTime = System.currentTimeMillis();
// Supposed index of the current rotation vector in the `rotationVectorPaths` array // Supposed index of the current rotation vector in the `rotationVectorPaths` array
int selfIndex = (int) (secondsPassed * sampleRate); int selfIndex = (int) (secondsPassed * sampleRate);
motionDataConsumer.accept(rotation, deviceId); if ( this.recordingMovement && this.secondsPassed >= this.recordingDurationInSeconds) {
if (selfIndex >= selfRotationVectorPaths[deviceId].length || selfIndex < 0)
return;
selfRotationVectorPaths[deviceId][selfIndex] = rotation;
if ( this.recordingMovement && this.hasFinished()) {
// Do something with the recorded data. // Do something with the recorded data.
this.recordingMovement = false; this.recordingMovement = false;
// Convert recorded data from `selfRotationVectorPaths` to string, and // Convert recorded data from `selfRotationVectorPaths` to string, and
@@ -221,6 +217,11 @@ public class InputProcessor {
Log.i("MotionProcessor", "Converted data: "); Log.i("MotionProcessor", "Converted data: ");
Log.i("MotionProcessor", converted); Log.i("MotionProcessor", converted);
} }
motionDataConsumer.accept(rotation, deviceId);
if (selfIndex >= selfRotationVectorPaths[deviceId].length || selfIndex < 0)
return;
selfRotationVectorPaths[deviceId][selfIndex] = rotation;
} }
} }