Merge remote-tracking branch 'origin/main'

# Conflicts:
#	code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java
This commit is contained in:
Luca Warmenhoven
2024-05-29 15:39:34 +02:00
12 changed files with 118 additions and 40 deletions

View File

@@ -4,7 +4,7 @@ void Connectivity::connectWiFi(char* ssid, char* pass){
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("connecting to wifi");
// Serial.println("connecting to wifi");
delay(1000);
}
Serial.println(WiFi.localIP());

View File

@@ -3,35 +3,38 @@
// SensorManager::Rotation offset;
void setup() {
Serial.begin(9600);
Serial.println("startup");
// Serial.begin(9600);
// Serial.println("startup");
//connect to internet and start sensor
connectivity.connectWiFi(ssid, pass);
sensorManager.sensorSetup();
}
unsigned long lastTime = 0; // will store the last time the code was run
void loop() {
SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles();
SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration();
unsigned long lastTime = 0; // will store the last time the code was run
Serial.print(eulerRotation.roll);
Serial.print(" ");
Serial.print(eulerRotation.yaw);
Serial.print(" ");
Serial.print(eulerRotation.pitch);
Serial.println();
unsigned long currentTime = millis();
if (currentTime - lastTime >= 100) { // 100 ms has passed
String message = "{\"deviceId\": 1, \"rotationX\":\"" + String(eulerRotation.roll) + "\",\"rotationY\":\"" + String(eulerRotation.pitch) + "\",\"rotationZ\":\"" + String(eulerRotation.yaw) + "\",\"accelerationX\":\"" + String(rotationAcceleration.x) + "\",\"accelerationY\":\"" + String(rotationAcceleration.y) + "\",\"accelerationZ\":\"" + String(rotationAcceleration.z) + "\",\"type\":\"data\"}";
Serial.println(connectivity.httpPost("192.168.137.146", "/", 3445, message.c_str(), message.length(), "json"));
Serial.println(message);
memset(buffer, 0, BUFFER_SIZE);
sprintf(
buffer,
"{\"deviceId\": %d, \"rotationX\": %f, \"rotationY\": %f, \"rotationZ\": %f, \"accelerationX\": %f, \"accelerationY\": %f, \"accelerationZ\": %f, \"type\": %s}",
DEVICE_ID,
eulerRotation.roll,
eulerRotation.pitch,
eulerRotation.yaw,
rotationAcceleration.x,
rotationAcceleration.y,
rotationAcceleration.z,
"data");
// %d = int, %f = floatation, %s = string
connectivity.httpPost("192.168.137.45", "/", 3445, buffer, strlen(buffer), "application/json");
lastTime = currentTime;
}
}
}
//acceleration.X
//acceleration.Y
//acceleration.Z

View File

@@ -9,15 +9,15 @@ void SensorManager::sensorSetup() {
//wait for the sensor to start before continue
if (myIMU.begin() == false) {
delay(1000);
Serial.println(".");
// Serial.println(".");
}
//start sensorfunction and start autocalibration
//once calibration is enabled it attempts to every 5 min
Wire.setClock(400000);
myIMU.enableGyroIntegratedRotationVector(100); //send data every 100ms
myIMU.enableAccelerometer(100); //Send data update every 100ms
Serial.println(F("magnetometer rotation enabled"));
myIMU.enableStepCounter(500); //Send data update every 500ms
}
//get sensordata
SensorManager::RotationQuintillions SensorManager::getQuintillions() {
@@ -39,7 +39,7 @@ SensorManager::RotationQuintillions SensorManager::getQuintillions() {
return rotation;
}
}
//calculate Quintillions to Euler angles from -1π to +1π
//calculate Quintillions to Euler angles from -1π to +1π
SensorManager::eulerAngles SensorManager::getEulerAngles() {
SensorManager::RotationQuintillions rotation = getQuintillions();
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));
@@ -48,11 +48,24 @@ SensorManager::eulerAngles SensorManager::getEulerAngles() {
eulerAngles EulerAngles = { roll, pitch, yaw };
return EulerAngles;
}
SensorManager::acceleration SensorManager::getAcelleration(){
float x = myIMU.getAccelX();
float y = myIMU.getAccelY();
float z = myIMU.getAccelZ();
acceleration Acceleration = { x, y, z };
SensorManager::acceleration SensorManager::getAcelleration() {
float x = myIMU.getAccelX();
float y = myIMU.getAccelY();
float z = myIMU.getAccelZ();
acceleration Acceleration = { x, y, z };
return Acceleration;
return Acceleration;
}
bool SensorManager::sensorTap() {
int taps = 0;
if (myIMU.dataAvailable() == true) {
int taps = myIMU.getStepCount();
}
if (taps) {
return true;
}
else {
return false;
}
}

View File

@@ -21,7 +21,7 @@ public:
eulerAngles getEulerAngles();
acceleration getAcelleration();
bool sensorTap();
private:
struct RotationQuintillions {
float i;

View File

@@ -8,6 +8,8 @@ Connectivity connectivity;
WebSocketsClient webSocket;
#define USE_SERIAL Serial
#define ssid "1235678i"
#define pass "12345678"
#define BUFFER_SIZE 1024
#define DEVICE_ID 1
char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE);

View File

@@ -16,6 +16,7 @@
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/activity_end_screen.xml" value="0.165" />
<entry key="..\:/Users/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/activity_endscreen.xml" value="0.1" />
<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_help.xml" value="0.1" />
<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/Niels/muupooviixee66-3/code/src/Fitbot/app/src/main/res/layout/toolbar.xml" value="0.1234375" />

View File

@@ -70,9 +70,11 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
@Override
public void onRobotFocusGained(QiContext qiContext) {
personalMotionPreviewElement.provideQiContext(qiContext);
// Find the VideoView by its ID
//CompletableFuture.runAsync(() -> FitnessCycle.executeMovement("bicepcurl", 10, qiContext));
// CompletableFuture.runAsync(() -> FitnessCycle.executeMovement("bicepcurl", 10, qiContext));
Log.i("Motion", "qiContext provided");
personalMotionPreviewElement.provideQiContext(qiContext);
// FitnessCycle.playVideo(qiContext, videoView, this);
}

View File

@@ -4,6 +4,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.fitbot.R;
import com.example.fitbot.util.ButtonNavigation;
public class HelpActivity extends AppCompatActivity {
@@ -11,5 +12,8 @@ public class HelpActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
ButtonNavigation.setupButtonNavigation(this, R.id.homeButton, MainActivity.class);
}
}

View File

@@ -14,6 +14,7 @@ import android.util.Log;
import android.widget.Button;
import com.example.fitbot.R;
import com.example.fitbot.util.ButtonNavigation;
public class MainActivity extends AppCompatActivity {
@@ -48,11 +49,8 @@ public class MainActivity extends AppCompatActivity {
toolbar = findViewById(R.id.toolbar);
startButton = findViewById(R.id.startButton);
startButton.setOnClickListener(v -> { // Switch to fitness activity
Log.i("MainActivity", "Switching to FitnessActivity");
Intent intent = new Intent(MainActivity.this, FitnessActivity.class);
startActivity(intent);
});
ButtonNavigation.setupButtonNavigation(this, R.id.startButton, FitnessActivity.class);
ButtonNavigation.setupButtonNavigation(this, R.id.helpButton, HelpActivity.class);
/*---Tool Bar---*/
setSupportActionBar(toolbar); // Make the toolbar act as the action bar

View File

@@ -56,14 +56,12 @@
style="@style/TextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="539dp"
android:layout_marginEnd="533dp"
android:text="Gefeliciteerd"
app:layout_constraintBottom_toTopOf="@+id/workoutText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/myRectangleView" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.155" />
<TextView
android:id="@+id/workoutText"

View File

@@ -4,6 +4,61 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".ui.activities.HelpActivity">
<View
android:id="@+id/myRectangleView"
android:layout_width="1075dp"
android:layout_height="510dp"
android:background="@drawable/rectangle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.168"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/homeButton"
android:layout_width="200dp"
android:layout_height="75dp"
android:background="@drawable/red_button_gradient"
android:text="@string/home"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.852" />
<TextView
android:id="@+id/textView4.2"
style="@style/TextStyle"
android:layout_width="1053dp"
android:layout_height="191dp"
android:text="@string/uitleg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.133" />
<TextView
android:id="@+id/textView4"
style="@style/TextStyle"
android:layout_width="1053dp"
android:layout_height="191dp"
android:text="Als je klaar bent kunt u op de COMPLETE knop drukken in het sport scherm en dan kunt u uw punten inzien"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.482" />
</android.support.constraint.ConstraintLayout>

View File

@@ -13,6 +13,8 @@
<string name="home">Home</string>
<string name="skip">Skip</string>
<string name="complete">Complete</string>
<string name="uitleg">Als je op de startknop drukt komen oefingen op het scherm. Het doel is om die zo goedmogelijk na te doen zodat je punten verzameld. Als je klaar bent kunt u op de COMPLETE knop drukken in het sport scherm en dan kunt u uw punten inzien</string>
<color name="red">#f22b1d</color>
</resources>