2024-05-24 12:27:11 +02:00
29 changed files with 1006 additions and 115 deletions

View File

@@ -4,6 +4,8 @@
<option name="filePathToZoomLevelMap">
<map>
<entry key="../../../../../../../../layout/custom_preview.xml" value="0.35989583333333336" />
<entry key="../../../../../../.gradle/caches/transforms-3/9c4b978f8e84c8bb9ebef5f19e8c189e/transformed/qisdk-design-1.7.5/res/layout/activity_robot.xml" value="0.1" />
<entry key="../../../../../../.gradle/caches/transforms-3/9c4b978f8e84c8bb9ebef5f19e8c189e/transformed/qisdk-design-1.7.5/res/layout/view_always_top_speech_bar.xml" value="0.167877197265625" />
<entry key="..\:/Users/31687/muupooviixee66-1/code/src/Fitbot/app/src/main/res/drawable/button_background.xml" value="0.128" />
<entry key="..\:/Users/31687/muupooviixee66-1/code/src/Fitbot/app/src/main/res/drawable/rectangle.xml" value="0.128" />
<entry key="..\:/Users/31687/muupooviixee66-1/code/src/Fitbot/app/src/main/res/layout/activity_bicepvideo.xml" value="0.2015625" />
@@ -16,8 +18,7 @@
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml" value="0.1234375" />
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/activity_main.xml" value="0.1" />
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/header.xml" value="0.1234375" />
<entry key="..\:/Users/sebas/.gradle/caches/transforms-3/9c4b978f8e84c8bb9ebef5f19e8c189e/transformed/qisdk-design-1.7.5/res/layout/activity_robot.xml" value="0.1" />
<entry key="..\:/Users/sebas/.gradle/caches/transforms-3/9c4b978f8e84c8bb9ebef5f19e8c189e/transformed/qisdk-design-1.7.5/res/layout/view_always_top_speech_bar.xml" value="0.1" />
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/toolbar.xml" value="0.1234375" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.25" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/darkred_button_gradient.xml" value="0.346" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/ic_baseline_home_48.xml" value="0.25" />
@@ -26,16 +27,13 @@
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/ic_launcher_background.xml" value="0.25" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/drawable/red_button_gradient.xml" value="0.346" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_bicepvideo.xml" value="0.22826086956521738" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml" value="0.10499174917491749" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml" value="0.33" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_main.xml" value="0.25" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_main.xml" value="0.176" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_main_screen.xml" value="0.1" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_power_screen.xml" value="0.1" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_sport_item.xml" value="0.1" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/activity_sport_menu.xml" value="0.1" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/header.xml" value="0.1" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/header.xml" value="0.125" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/layout/toolbar.xml" value="0.125" />
<entry key="..\:/Users/sebas/Documents/HvA/Reposetories/muupooviixee66/code/src/Fitbot/app/src/main/res/menu/main_menu.xml" value="0.33" />
<entry key="app/src/main/res/layout/activity_end_screen.xml" value="0.1" />
<entry key="app/src/main/res/layout/activity_fitness.xml" value="0.23550724637681159" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />

View File

@@ -20,7 +20,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Fitbot" >
android:theme="@style/AppTheme" >
<activity
android:name=".ui.activities.EndScreenActivity"
android:exported="false" />

View File

@@ -14,7 +14,7 @@ import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLConnection;
public class FitnessManager {
public class ExerciseManager {
private static final String HOST_ADDRESS = "http://145.92.8.132";
@@ -22,7 +22,20 @@ public class FitnessManager {
private static final String PROPERTY_VECTORS = "vector_data";
private static final String PROPERTY_NAME = "name";
private static final String PROPERTY_MUSCLE_GROUP = "muscle_group";
private static final String PROPERTY_SEGMENT_SPEED = "segment_speed";
private static final float DEFAULT_SEGMENT_SPEED = 1.0f;
/**
* Function for sending an HTTP request to the server.
*
* @param url The URL to send the request to.
* @param method The method to use for the request, e.g. GET or POST.
* @param contentType The content type of the request.
* @param body The body of the request.
*
* @return The response from the server.
*/
private static String sendHTTP(String url, String method, String contentType, String body) {
try {
URLConnection connection = new URL(url).openConnection();
@@ -50,7 +63,7 @@ public class FitnessManager {
* @param uniqueIdentifier The unique identifier of the exercise
* @return The exercise, if it exists on the server. Otherwise null.
*/
public static <T extends Exercise> Exercise acquireExercise(String uniqueIdentifier, Class<T> referenceClass) {
public static Exercise retrieveExercise(String uniqueIdentifier) {
String response = sendHTTP(
HOST_ADDRESS + "/acquire", "GET", "application/json", "{\"kind\":\"" + uniqueIdentifier + "\"}"
);
@@ -58,17 +71,13 @@ public class FitnessManager {
if (response != null) {
try {
JsonObject content = JsonParser.parseString(response).getAsJsonObject();
Constructor<T> constructor = referenceClass.getConstructor(referenceClass);
T instance = null;
try {
instance = constructor.newInstance(
EMuscleGroup.parse(content.get(PROPERTY_MUSCLE_GROUP).getAsInt()),
gesturePathFromString(content.get(PROPERTY_VECTORS).getAsString())
);
} catch (Exception e) {
e.printStackTrace();
}
return instance;
return new Exercise(
EMuscleGroup.parse(content.get(PROPERTY_MUSCLE_GROUP).getAsInt()),
content.get(PROPERTY_NAME).getAsString(),
content.get(PROPERTY_DESC).getAsString(),
gesturePathFromString(content.get(PROPERTY_VECTORS).getAsString()),
DEFAULT_SEGMENT_SPEED
);
} catch (Exception e) {
e.printStackTrace();
}
@@ -79,7 +88,9 @@ public class FitnessManager {
/**
* Function for converting a string to a GesturePath object.
* The input string bytes will be directly converted into 3d vectors.
* Every coordinate is composed of 32 bits, so four characters per coordinate.
* Every scalar is composed of 32 bits (4 characters), meaning 96 bits per vector.
*
* Note: ASCII to Vector conversion is done in Big Endian format (most significant byte first).
*
* @param input The string to convert
* @return The GesturePath object
@@ -96,6 +107,7 @@ public class FitnessManager {
float[] xyz = new float[3];
for (int i = 0; i < bytes.length; i += 12) {
for (int j = 0; j < 3; j++) {
xyz[j] = Float.intBitsToFloat(
(bytes[i + j * 4] & 0xFF) << 24 |
(bytes[i + j * 4 + 1] & 0xFF) << 16 |

View File

@@ -2,21 +2,28 @@ package com.example.fitbot.ui.activities;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.VideoView;
import com.aldebaran.qi.sdk.QiContext;
import com.aldebaran.qi.sdk.QiSDK;
import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
import com.aldebaran.qi.sdk.design.activity.RobotActivity;
import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy;
import com.example.fitbot.R;
import com.example.fitbot.sports.FitnessCycle;
import com.example.fitbot.exercise.EMuscleGroup;
import com.example.fitbot.exercise.Exercise;
import com.example.fitbot.ui.components.PersonalMotionPreviewElement;
import com.example.fitbot.util.Animations;
import com.example.fitbot.util.ButtonNavigation;
import com.example.fitbot.util.path.GesturePath;
import org.joml.Vector3f;
public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks {
// PersonalMotionPreviewElement personalMotionPreviewElement;
PersonalMotionPreviewElement personalMotionPreviewElement;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -24,12 +31,17 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
QiSDK.register(this, this);
setContentView(R.layout.activity_fitness);
// Remove the ugly ass bar on top of the view
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
// Find the VideoView by its ID
VideoView videoView = findViewById(R.id.videoView);
FitnessCycle.playVideo(videoView, this);
com.example.fitbot.util.ButtonNavigation.setupButtonNavigation(this, R.id.homeButton, MainActivity.class);
com.example.fitbot.util.ButtonNavigation.setupButtonNavigation(this, R.id.buttonComplete, EndScreenActivity.class);
ButtonNavigation.setupButtonNavigation(this, R.id.homeButton, MainActivity.class);
ButtonNavigation.setupButtonNavigation(this, R.id.buttonComplete, EndScreenActivity.class);
// Implement your logic when the robot focus is gained
GesturePath.Builder gesturePathBuilder = new GesturePath.Builder();
@@ -45,15 +57,14 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
gesturePathBuilder.addVector(new Vector3f(-.5f, .5f, .5f));
gesturePathBuilder.addVector(new Vector3f(-.5f, .5f, -.5f));
// Uncomment and fix if needed for personalMotionPreviewElement
// personalMotionPreviewElement = findViewById(R.id.personalMotionPreviewElement);
// personalMotionPreviewElement.post(() -> {
// Log.i("FitnessActivity", "PersonalMotionPreviewElement.post()");
//
// Exercise exercise = new Exercise(EMuscleGroup.ARMS, "Bicep Curls", "Oefening voor de biceps.", gesturePathBuilder.build(), 1);
//
// personalMotionPreviewElement.initialize(exercise);
// });
personalMotionPreviewElement = findViewById(R.id.personalMotionPreviewElement);
personalMotionPreviewElement.post(() -> {
Log.i("FitnessActivity", "PersonalMotionPreviewElement.post()");
Exercise exercise = new Exercise(EMuscleGroup.ARMS, "Bicep Curls", "Oefening voor de biceps.", gesturePathBuilder.build(), 1);
personalMotionPreviewElement.initialize(exercise);
});
}
@Override
@@ -64,6 +75,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// FitnessCycle.playVideo(qiContext, videoView, this);
personalMotionPreviewElement.provideQiContext(qiContext);
}
@Override

View File

@@ -8,7 +8,9 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.aldebaran.qi.sdk.QiContext;
import com.example.fitbot.exercise.Exercise;
import com.example.fitbot.speech.SpeechGenerator;
import com.example.fitbot.util.path.GesturePath;
import com.example.fitbot.util.path.PathSegment;
import com.example.fitbot.util.processing.MotionData;
@@ -25,6 +27,8 @@ public class PersonalMotionPreviewElement extends View {
private double pathTime = 0.0D; // The timestamp at which the path is currently at.
private MotionProcessor motionProcessor;
private QiContext qiContext;
private Exercise exercise;
private Path referencePath; // The path the user is supposed to follow.
@@ -35,6 +39,12 @@ public class PersonalMotionPreviewElement extends View {
private Paint performingPaint;
private Paint textPaint;
private static final String[] USER_PHRASES = {
"Veel success met de oefening!",
"Je kan het!",
"Veel plezier!"
};
// Matrices for the projection of the path segments onto the screen.
// Depth buffering sadly is not supported yet due to brain dysfunction
private Matrix4f modelViewMatrix = new Matrix4f();
@@ -51,7 +61,7 @@ public class PersonalMotionPreviewElement extends View {
private final float FOV = 80.0f; // The field of view of the preview path
private final float Z_NEAR = 0.1f; // The near clipping plane
private final float Z_FAR = 1000.0f; // The far clipping plane
private Vector3f objectPosition = new Vector3f(0.0f, 0.0f, 0.0f); // The position of the camera
private Vector3f objectPosition = new Vector3f(0.0f, 0.0f, -4.0f); // The position of the camera
private Vector2f screenDimensions = new Vector2f(); // Width and height dimensions of the screen
private Vector2f rotation = new Vector2f(); // Rotation vector (yaw, pitch)
@@ -136,13 +146,33 @@ public class PersonalMotionPreviewElement extends View {
});
}
/**
* Function for providing a QiContext to the PersonalMotionPreviewElement.
* @param context The QiContext to provide.
*/
public void provideQiContext(QiContext context) {
this.qiContext = context;
saySomethingNice();
}
/**
* Function to say something nice to the user :)
*/
private void saySomethingNice()
{
if (this.qiContext == null)
return;
SpeechGenerator.say(USER_PHRASES[(int) Math.floor(Math.random() * USER_PHRASES.length)], this.qiContext);
}
/**
* Method that calculates the path that will be drawn on the
* canvas. This method will be called every time new motion data is received.
*/
private void calculateDrawingPath(Vector3f transformedVector, MotionData motionData, int sampleIndex, double sampleRate) {
// Recalculate the personal path based on the new motion data
// TODO: Implement
}
/**
@@ -155,16 +185,6 @@ public class PersonalMotionPreviewElement extends View {
this.referencePath = getDrawablePath(path.getSegments());
}
/**
* Method for setting the rotation of the preview path.
*
* @param yaw The yaw rotation of the preview path.
* @param pitch The pitch rotation of the preview path.
*/
public void setRotation(float yaw, float pitch) {
this.rotation.set(Math.toRadians(yaw), Math.toRadians(pitch));
}
/**
* Method for projecting a 3D point onto the screen.
* This method converts the 3D point to 2D space using a Model-View-Projection matrix transformation.
@@ -240,11 +260,9 @@ public class PersonalMotionPreviewElement extends View {
canvas.drawPath(referencePath, referencePaint);
canvas.drawPath(performingPath, performingPaint);
canvas.drawText(this.exercise.getTitle(), 10, 40, textPaint);
timePassed = (System.nanoTime() - startingTime) / 1E9D;
this.rotation.add(1f, 0);
this.rotation.x = (float) (Math.sin(timePassed) * 45);
this.referencePath = getDrawablePath(this.path.getSegments());
this.invalidate(); // Causes a redraw.
}

View File

@@ -1,26 +1,17 @@
//usage: PlayAnimation(animationfile, Qicontext);
// https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch4_api/movement/reference/animation.html
package com.example.fitbot.sports;
import android.support.v7.app.AppCompatActivity;
package com.example.fitbot.util;
import com.aldebaran.qi.sdk.QiContext;
import com.aldebaran.qi.sdk.builder.AnimateBuilder;
import com.aldebaran.qi.sdk.builder.AnimationBuilder;
import com.aldebaran.qi.sdk.object.actuation.Animate;
import com.aldebaran.qi.sdk.object.actuation.Animation;
import com.example.fitbot.ui.activities.MainActivity;
public class Animations extends AppCompatActivity {
public class Animations {
public static void Animate(String AnimationFile, QiContext ctx)
{
PlayAnimation(AnimationFile, ctx);
}
public static void PlayAnimation(String AnimationFile, QiContext ctx)
{
int resId = ctx.getResources().getIdentifier(AnimationFile, "raw", ctx.getPackageName());

View File

@@ -8,6 +8,13 @@ import android.widget.Button;
public class ButtonNavigation {
/**
* Sets up a button to navigate to a different activity when clicked.
*
* @param currentActivity The activity that contains the button
* @param buttonId The ID of the button
* @param targetActivity The activity to navigate to
*/
public static void setupButtonNavigation(Activity currentActivity, int buttonId, Class<? extends Activity> targetActivity) {
Button button = currentActivity.findViewById(buttonId);
button.setOnClickListener(v -> {

View File

@@ -11,17 +11,6 @@ android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
tools:context=".ui.activities.FitnessActivity"
tools:openDrawer="start">
<!-- <com.example.fitbot.ui.components.PersonalMotionPreviewElement-->
<!-- android:id="@+id/personalMotionPreviewElement"-->
<!-- android:layout_width="600dp"-->
<!-- android:layout_height="550dp"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintHorizontal_bias="0.976"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintVertical_bias="0.064" />-->
<VideoView
android:id="@+id/videoView"
android:layout_width="450dp"
@@ -33,8 +22,8 @@ tools:openDrawer="start">
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.2" />
<VideoView
android:id="@+id/videoView2"
<com.example.fitbot.ui.components.PersonalMotionPreviewElement
android:id="@+id/personalMotionPreviewElement"
android:layout_width="450dp"
android:layout_height="450dp"
app:layout_constraintBottom_toBottomOf="parent"

View File

@@ -2,11 +2,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#00000000</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ButtonStyle">

View File

@@ -8,4 +8,69 @@
// die een `app` parameter en een `pool` parameter accepteert.
// Deze moet dan geëxporteerd worden om deze te kunnen gebruiken in `server.js`.
// Dit is een voorbeeld van hoe je dat zou kunnen doen:
// module.exports = function(app, pool) { ... }
// module.exports = function(app, pool) { ... }
/**
*
* @param {Request} request The incoming request
* @param {Response} response The response to send back
* @param {Express} app Express app instance
* @param {Pool} pool MariaDB pool instance
*/
function handleIncoming(request, response, app, pool)
{
if (!request.hasOwnProperty('uid') || typeof request.uid !== 'number')
{
response
.status(400)
.send(JSON.stringify({error: 'Missing valid UID in request'}));
return;
}
// Acquire database connection
pool.getConnection()
.then(conn => {
conn.query('SELECT * FROM Exercise WHERE ExerciseID = ?', [request.uid])
.then(rows => {
if (rows.length === 0)
{
response
.status(404)
.send(JSON.stringify({error: 'Exercise not found'}));
}
else
{
// Send back the data in the right format
let firstRow = rows[0];
response
.status(200)
.send(JSON.stringify({
name: firstRow.Name,
description: firstRow.Description,
muscleGroup: firstRow.MuscleGroup,
imageUrl: firstRow.ImageURL,
videoUrl: firstRow.VideoURL
}));
}
})
.catch(_ => {
response
.status(500)
.send(JSON.stringify({error: 'Internal server error'}));
})
.finally(() => {
conn.end();
});
})
.catch(_ => {
response
.status(500)
.send(JSON.stringify({error: 'Internal server error'}));
});
}
// Export the function that registers the incoming request handlers
module.exports = function(app, pool) {
app.get('/', (req, res) => handleIncoming(req, res, app, pool));
};

View File

@@ -1,7 +1,9 @@
const mariadb = require('mariadb');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
const serverPort = 3000;
const databaseCredentials = {
@@ -11,7 +13,7 @@ const databaseCredentials = {
database: 'fitbot',
connectionLimit: 5,
allowUnauthorized: true
}
};
// Create connection pool
const pool = mariadb.createPool(databaseCredentials);
@@ -20,6 +22,6 @@ const pool = mariadb.createPool(databaseCredentials);
require('incoming_request_handlers')(app, pool);
// Start server
app.listen(port, () => {
app.listen(serverPort, () => {
console.log(`Server running on port ${serverPort}`);
})
});