class and script creation
This commit is contained in:
24
code/arduino/Movement-sensor-code/Movement-sensor-code.ino
Normal file
24
code/arduino/Movement-sensor-code/Movement-sensor-code.ino
Normal file
@@ -0,0 +1,24 @@
|
||||
#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();
|
||||
|
||||
Serial.print(rotation.x);
|
||||
Serial.print(" ");
|
||||
Serial.print(rotation.y);
|
||||
Serial.print(" ");
|
||||
Serial.print(rotation.z);
|
||||
|
||||
Serial.println();
|
||||
}
|
50
code/arduino/Movement-sensor-code/SensorManager.cpp
Normal file
50
code/arduino/Movement-sensor-code/SensorManager.cpp
Normal 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;
|
||||
}
|
||||
}
|
21
code/arduino/Movement-sensor-code/SensorManager.h
Normal file
21
code/arduino/Movement-sensor-code/SensorManager.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef SensorManager_h
|
||||
#define SensorManager_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SparkFun_BNO080_Arduino_Library.h"
|
||||
|
||||
class SensorManager {
|
||||
public:
|
||||
SensorManager();
|
||||
void sensorSetup();
|
||||
struct Rotation {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
Rotation readLoop();
|
||||
private:
|
||||
BNO080 myIMU;
|
||||
};
|
||||
|
||||
#endif
|
1
code/arduino/Movement-sensor-code/headerFIle.h
Normal file
1
code/arduino/Movement-sensor-code/headerFIle.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "SensorManager.h"
|
Reference in New Issue
Block a user