diff --git a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino new file mode 100644 index 0000000..d20f77e --- /dev/null +++ b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino @@ -0,0 +1,34 @@ +#include "SensorManager.h" + +SensorManager sensorManager; + +void setup() { + Wire.setClockStretchLimit(150000L); // Default stretch limit 150mS + Serial.begin(9600); + Serial.println("startup"); + delay(10000); + sensorManager.sensorSetup(); + +} + +void loop() { + SensorManager::Rotation rotation = sensorManager.readLoop(); + + // Convert quaternion to Euler angles in radians + float roll = atan2(2.0f * (rotation.w * rotation.i + rotation.j * rotation.k), 1.0f - 2.0f * (rotation.i * rotation.i + rotation.j * rotation.j)); + float pitch = asin(2.0f * (rotation.w * rotation.j - rotation.k * rotation.i)); + float yaw = atan2(2.0f * (rotation.w * rotation.k + rotation.i * rotation.j), 1.0f - 2.0f * (rotation.j * rotation.j + rotation.k * rotation.k)); + + // Convert to degrees + float rollDegrees = roll * 180.0f / PI; + float pitchDegrees = pitch * 180.0f / PI; + float yawDegrees = yaw * 180.0f / PI; + + Serial.print(roll); + Serial.print(" "); + Serial.print(pitch); + Serial.print(" "); + Serial.print(yaw); + + Serial.println(); +} \ No newline at end of file diff --git a/code/arduino/Movement-sensor-code/SensorManager.cpp b/code/arduino/Movement-sensor-code/SensorManager.cpp new file mode 100644 index 0000000..a43c923 --- /dev/null +++ b/code/arduino/Movement-sensor-code/SensorManager.cpp @@ -0,0 +1,52 @@ +#include "SensorManager.h" +#include + +SensorManager::SensorManager() {} + +void SensorManager::sensorSetup() { + Serial.println(); + Serial.println("BNO080 Read Example"); + + delay(1000); // Wait for BNO to boot + + Wire.begin(); + + if (myIMU.begin() == false) { + delay(1000); + Serial.println("."); + } + + Wire.setClock(400000); //Increase I2C data rate to 400kHz + myIMU.calibrateAll(); //Turn on cal for Accel, Gyro, and Mag + myIMU.enableGyroIntegratedRotationVector(100); + myIMU.enableMagnetometer(100); //Send data update every 100ms + myIMU.saveCalibration(); //Saves the current dynamic calibration data (DCD) to memory + myIMU.requestCalibrationStatus(); //Sends command to get the latest calibration status + + if (myIMU.calibrationComplete() == true) { + Serial.println("Calibration data successfully stored"); + } + + Serial.println(F("magnetometer rotation enabled")); +} + +SensorManager::Rotation SensorManager::readLoop() { + if (myIMU.dataAvailable() == true) { + float i = myIMU.getQuatI(); + float j = myIMU.getQuatJ(); + float k = myIMU.getQuatK(); + float w = myIMU.getQuatReal(); + + Rotation rotation = { i, j, k, w }; + return rotation; + } + else { + float i = myIMU.getQuatI(); + float j = myIMU.getQuatJ(); + float k = myIMU.getQuatK(); + float w = myIMU.getQuatReal(); + + Rotation rotation = { i, j, k, w }; + return rotation; + } +} \ No newline at end of file diff --git a/code/arduino/Movement-sensor-code/SensorManager.h b/code/arduino/Movement-sensor-code/SensorManager.h new file mode 100644 index 0000000..3c4b231 --- /dev/null +++ b/code/arduino/Movement-sensor-code/SensorManager.h @@ -0,0 +1,22 @@ +#ifndef SensorManager_h +#define SensorManager_h + +#include "Arduino.h" +#include "SparkFun_BNO080_Arduino_Library.h" + +class SensorManager { + public: + SensorManager(); + void sensorSetup(); + struct Rotation { + float i; + float j; + float k; + float w; + }; + Rotation readLoop(); + private: + BNO080 myIMU; +}; + +#endif \ No newline at end of file diff --git a/code/arduino/Movement-sensor-code/headerFIle.h b/code/arduino/Movement-sensor-code/headerFIle.h new file mode 100644 index 0000000..4b96a47 --- /dev/null +++ b/code/arduino/Movement-sensor-code/headerFIle.h @@ -0,0 +1 @@ +#include "SensorManager.h" \ No newline at end of file diff --git a/code/src/Fitbot/.idea/misc.xml b/code/src/Fitbot/.idea/misc.xml index 7b1e4ee..429eb49 100644 --- a/code/src/Fitbot/.idea/misc.xml +++ b/code/src/Fitbot/.idea/misc.xml @@ -3,19 +3,18 @@ diff --git a/code/src/Fitbot/app/src/main/AndroidManifest.xml b/code/src/Fitbot/app/src/main/AndroidManifest.xml index 1c9e481..bd9a6b6 100644 --- a/code/src/Fitbot/app/src/main/AndroidManifest.xml +++ b/code/src/Fitbot/app/src/main/AndroidManifest.xml @@ -16,7 +16,8 @@ android:exported="false" /> + android:exported="true"> + @@ -25,7 +26,7 @@ android:exported="false" /> + android:exported="true" /> diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java index debfd76..e90e88c 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java @@ -1,24 +1,20 @@ package com.example.fitbot; import android.content.Intent; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.widget.Button; import com.aldebaran.qi.sdk.QiContext; import com.aldebaran.qi.sdk.QiSDK; import com.aldebaran.qi.sdk.RobotLifecycleCallbacks; -import com.aldebaran.qi.sdk.builder.AnimateBuilder; -import com.aldebaran.qi.sdk.builder.AnimationBuilder; import com.aldebaran.qi.sdk.builder.SayBuilder; import com.aldebaran.qi.sdk.design.activity.RobotActivity; -import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy; -import com.aldebaran.qi.sdk.object.actuation.Animate; -import com.aldebaran.qi.sdk.object.actuation.Animation; import com.aldebaran.qi.sdk.object.conversation.Phrase; import com.aldebaran.qi.sdk.object.conversation.Say; import com.aldebaran.qi.sdk.object.locale.Language; import com.aldebaran.qi.sdk.object.locale.Locale; import com.aldebaran.qi.sdk.object.locale.Region; +import com.example.fitbot.ui.SportMenuActivity; public class MainActivity extends RobotActivity implements RobotLifecycleCallbacks { @@ -26,7 +22,12 @@ public class MainActivity extends RobotActivity implements RobotLifecycleCallbac protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Register the RobotLifecycleCallbacks to this Activity. + Button button = findViewById(R.id.menu_switch_btn); + button.setOnClickListener(v -> { + startActivity(new Intent(MainActivity.this, SportMenuActivity.class)); + }); QiSDK.register(this, this); + } @Override diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java index 61b2211..323641c 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java @@ -36,6 +36,7 @@ public class MainScreen extends AppCompatActivity { /*---Navigation Drawer Menu---*/ navigationView.bringToFront(); + ActionBarDrawerToggle toggle=new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close); drawerLayout.addDrawerListener(toggle); diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java new file mode 100644 index 0000000..4cc2abf --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java @@ -0,0 +1,55 @@ +package com.example.fitbot.processing; + +public class MotionData { + + // Data of the motion sensor + public float accelerationX; + public float accelerationY; + public float accelerationZ; + public float rotationX; + public float rotationY; + public float rotationZ; + + // Delimiter for the data received from the motion sensor + private static final String DATA_DELIMITER = ";"; + + /** + * Constructor for the MotionData class. + * + * @param accelerationX The acceleration in the X axis in m/s^2. + * @param accelerationY The acceleration in the Y axis in m/s^2. + * @param accelerationZ The acceleration in the Z axis in m/s^2. + * @param rotationX The rotation in the X axis in degrees. + * @param rotationY The rotation in the Y axis in degrees. + * @param rotationZ The rotation in the Z axis in degrees. + */ + public MotionData(float accelerationX, float accelerationY, float accelerationZ, float rotationX, float rotationY, float rotationZ) { + this.accelerationX = accelerationX; + this.accelerationY = accelerationY; + this.accelerationZ = accelerationZ; + this.rotationX = rotationX; + this.rotationY = rotationY; + this.rotationZ = rotationZ; + } + + /** + * Function for decoding a string into a MotionData object. + * This string must contain the data of the motion sensor + * separated by the delimiter. (;) + * + * @param data The string containing the data of the motion sensor. + * @return An instance of MotionData. + */ + public static MotionData decode(String data) { + String[] parts = data.split(DATA_DELIMITER); + return new MotionData( + Float.parseFloat(parts[0]), + Float.parseFloat(parts[1]), + Float.parseFloat(parts[2]), + Float.parseFloat(parts[3]), + Float.parseFloat(parts[4]), + Float.parseFloat(parts[5]) + ); + } + +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java new file mode 100644 index 0000000..1598693 --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java @@ -0,0 +1,31 @@ +package com.example.fitbot.processing; + +import java.io.InputStream; + +/** + * Class representing the input stream of the motion sensor. + * This class will be responsible for reading the data from + * the motion sensor and processing it, by creating a + * server and starting a WebSocket connection with the ESP32. + */ +public class MotionInputStream extends InputStream { + + /** + * Function for starting the listening process + * of the motion sensor. This function will + * @return An instance of MotionInputStream. + */ + public static MotionInputStream startListening() + { + // Create server + + + return null; + } + + + @Override + public int read() { + return 0; + } +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java new file mode 100644 index 0000000..9e0e13e --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java @@ -0,0 +1,4 @@ +package com.example.fitbot.processing; + +public class MotionProcessor { +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java index 61c265a..c731a72 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java @@ -6,6 +6,9 @@ import com.aldebaran.qi.sdk.object.locale.Language; import com.aldebaran.qi.sdk.object.locale.Locale; import com.aldebaran.qi.sdk.object.locale.Region; +/** + * SpeechGenerator class for generating speech for the robot + */ public class SpeechGenerator { private static final Locale DUTCH_LOCALE = new Locale(Language.DUTCH, Region.NETHERLANDS); @@ -21,13 +24,18 @@ public class SpeechGenerator { say(phrase, ctx, DUTCH_LOCALE); } - - - public static void say(String text, QiContext ctx, Locale locale) + /** + * Function for making the robot say something with a specific locale + * @param phrase The phrase to make the robot say + * @param ctx The QiContext to use + * @param locale The locale to use + */ + public static void say(String phrase, QiContext ctx, Locale locale) { - SayBuilder.with(ctx) + SayBuilder + .with(ctx) .withLocale(locale) - .withText(text) + .withText(phrase) .build() .run(); } diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java deleted file mode 100644 index 481605d..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.fitbot.ui; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - -import com.example.fitbot.R; - -public class SportItemActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sport_item); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - -} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java deleted file mode 100644 index d6d060a..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.fitbot.ui; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - -import com.example.fitbot.R; - - -public class SportMenuActivity extends AppCompatActivity { - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sport_menu); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } -} \ No newline at end of file diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java deleted file mode 100644 index 1d6f394..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.example.fitbot.ui; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.view.View; - -import com.example.fitbot.sports.ESportType; - -public class SportMenuItem extends View { - - private Paint backgroundPaint, textPaint; - private String title, description; - private Bitmap imageResource; - private Rect imageRect, elementRect; - private ESportType type; - - public SportMenuItem(Context context, ESportType type, String title, String description, Bitmap backgroundImage) { - super(context); - this.title = title; - this.description = description; - this.imageResource = backgroundImage; - this.imageRect = new Rect(0, 0, this.imageResource.getWidth(), this.imageResource.getHeight()); - this.elementRect = new Rect(0, 0, this.getWidth(), this.getHeight()); - this.type = type; - this.backgroundPaint = new Paint(); - this.textPaint = new Paint(); - this.textPaint.setTextAlign(Paint.Align.CENTER); - this.backgroundPaint.setColor(0xFFF0F0F0); - this.textPaint.setColor(0xFF000000); - - this.setOnClickListener(v -> context.startActivity(new Intent(context, SportItemActivity.class))); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - canvas.drawBitmap(this.imageResource, this.imageRect, this.elementRect, null); - canvas.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10, backgroundPaint); - canvas.drawText(title, getWidth() / 2.0f, this.textPaint.getFontMetrics().top, textPaint); - } -} diff --git a/code/src/Fitbot/app/src/main/res/drawable/robotLogo.png b/code/src/Fitbot/app/src/main/res/drawable/robot_logo.png similarity index 100% rename from code/src/Fitbot/app/src/main/res/drawable/robotLogo.png rename to code/src/Fitbot/app/src/main/res/drawable/robot_logo.png diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_main.xml b/code/src/Fitbot/app/src/main/res/layout/activity_main.xml index 75bba1c..b160bcf 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_main.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_main.xml @@ -19,14 +19,17 @@ android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/header" + app:menu="@menu/main_menu" />