class and script creation

This commit is contained in:
2024-05-08 14:09:03 +02:00
parent 21f1a844ba
commit 6a20c8f16d
4 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#include "SensorManager.h"
#include <Wire.h>
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.enableGameRotationVector(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 x = myIMU.getMagX();
float y = myIMU.getMagY();
float z = myIMU.getMagZ();
Rotation rotation = { x, y, z };
return rotation;
}
else {
float x = myIMU.getMagX();
float y = myIMU.getMagY();
float z = myIMU.getMagZ();
Rotation rotation = { x, y, z };
return rotation;
}
}