cermit
This commit is contained in:
@@ -45,6 +45,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
|||||||
|
|
||||||
GesturePath.Builder gesturePathBuilder = new GesturePath.Builder();
|
GesturePath.Builder gesturePathBuilder = new GesturePath.Builder();
|
||||||
|
|
||||||
|
/* Generate a random path to test the tracking system */
|
||||||
for ( int i = 0; i < 40; i++)
|
for ( int i = 0; i < 40; i++)
|
||||||
{
|
{
|
||||||
gesturePathBuilder.addVector(
|
gesturePathBuilder.addVector(
|
||||||
|
@@ -22,13 +22,16 @@ import org.joml.Vector2f;
|
|||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector4f;
|
import org.joml.Vector4f;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class PersonalMotionPreviewElement extends View {
|
public class PersonalMotionPreviewElement extends View {
|
||||||
|
|
||||||
private GesturePath[] paths;
|
private GesturePath[] paths;
|
||||||
private MotionProcessor motionProcessor;
|
private MotionProcessor motionProcessor;
|
||||||
|
|
||||||
private double pathTime = 0.0D; // The timestamp at which the path is currently at.
|
private double pathTime = 0.0D; // The timestamp at which the path is currently at.
|
||||||
private double exerciseProgress = 0.0D; // The progress of the exercise. Ranges from 0 to 1.
|
private final AtomicInteger exerciseProgress = new AtomicInteger(0); // The progress of the exercise. Ranges from 0 to 1000.
|
||||||
|
|
||||||
private QiContext qiContext;
|
private QiContext qiContext;
|
||||||
|
|
||||||
@@ -86,7 +89,6 @@ public class PersonalMotionPreviewElement extends View {
|
|||||||
this.targetPath = new Path();
|
this.targetPath = new Path();
|
||||||
|
|
||||||
this.startingTime = System.nanoTime(); // Set the last time to the current time
|
this.startingTime = System.nanoTime(); // Set the last time to the current time
|
||||||
this.exerciseProgress = 0.0d;
|
|
||||||
|
|
||||||
this.exercise = exercise;
|
this.exercise = exercise;
|
||||||
this.paths = exercise.getPath();
|
this.paths = exercise.getPath();
|
||||||
@@ -103,14 +105,14 @@ public class PersonalMotionPreviewElement extends View {
|
|||||||
this.qiContext = context;
|
this.qiContext = context;
|
||||||
if ( this.motionProcessor != null )
|
if ( this.motionProcessor != null )
|
||||||
this.motionProcessor.stopListening();
|
this.motionProcessor.stopListening();
|
||||||
|
|
||||||
this.motionProcessor = new MotionProcessor();
|
this.motionProcessor = new MotionProcessor();
|
||||||
this.motionProcessor.startListening();
|
this.motionProcessor.startListening();
|
||||||
|
|
||||||
// Handler that is called every time the motion processor receives new data.
|
// Handler that is called every time the motion processor receives new data.
|
||||||
this.motionProcessor.setMotionDataEventHandler((processed, preprocessed, sampleIndex, sampleRate, deviceId) -> {
|
this.motionProcessor.setMotionDataEventHandler((processed, preprocessed, sampleIndex, sampleRate, deviceId) -> {
|
||||||
double progress = this.motionProcessor.getAverageError(this.paths[0], 0);
|
int progress = (int)this.motionProcessor.getError(this.paths[0], processed);
|
||||||
this.exerciseProgress = Math.min(1, Math.max(0, progress));
|
this.exerciseProgress.set(Math.min(1000, Math.max(0, progress)));
|
||||||
this.invalidate();
|
|
||||||
Log.i("MotionProcessor", "Processed data: " + progress + " (" + preprocessed + ")");
|
Log.i("MotionProcessor", "Processed data: " + progress + " (" + preprocessed + ")");
|
||||||
});
|
});
|
||||||
saySomethingNice();
|
saySomethingNice();
|
||||||
@@ -147,16 +149,18 @@ public class PersonalMotionPreviewElement extends View {
|
|||||||
// Draw target circle
|
// Draw target circle
|
||||||
float targetRadius = (this.screenDimensions.x + this.screenDimensions.y) / 5.0f;
|
float targetRadius = (this.screenDimensions.x + this.screenDimensions.y) / 5.0f;
|
||||||
canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, targetRadius, this.targetPaint);
|
canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, targetRadius, this.targetPaint);
|
||||||
canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, (float)(targetRadius * exerciseProgress), this.referencePaint);
|
canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, (targetRadius * exerciseProgress.get()/1000.0f), this.referencePaint);
|
||||||
referencePaint.setColor(
|
referencePaint.setColor(
|
||||||
Color.argb(
|
Color.argb(
|
||||||
255,
|
255,
|
||||||
(int)(255 * (1.0 - exerciseProgress)),
|
(int)(255 * (1.0 - exerciseProgress.get()/1000.0f)),
|
||||||
(int)(255 * exerciseProgress),
|
(int)(255 * exerciseProgress.get()/1000.0f),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.invalidate();
|
||||||
|
|
||||||
timePassed = (System.nanoTime() - startingTime) / 1E9D;
|
timePassed = (System.nanoTime() - startingTime) / 1E9D;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user