Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Revision:
40:8e852115fe55
Parent:
35:fb6e4601adf3
Child:
43:6251c0169f4f
--- a/SensorFusion.h	Tue May 19 14:18:30 2015 +0000
+++ b/SensorFusion.h	Tue May 26 11:28:37 2015 +0000
@@ -6,8 +6,9 @@
 #include "Accelerometer.h"
 #include "Gyroscope.h"
 #include "Quaternion.h"
+#include "Filter.h"
 
-class SensorFusion : public Sensor::Delegate
+class SensorFusion
 {
 public:
     class Delegate
@@ -16,26 +17,37 @@
         virtual void sensorTick(float dt, Vector3 fused, Vector3 accel, Vector3 magneto, Vector3 gyro, Quaternion q) {}
     };
     
-    SensorFusion(I2C &i2c);
-    void setDelegate(Delegate &d);
+    void setDelegate(Delegate &d) { delegate = &d; }
+
+    virtual bool start() { return false; }
+    virtual void stop() {}
 
-    bool start();
-    void stop();
-
-    virtual void sensorUpdate(Vector3 gyro_degrees); // gyro's callback
-    void getMagnetometerCalibration(Vector3 &min, Vector3 &max);
+protected:
+    // protected ctor so that base class cannot be instantiated directly
+    SensorFusion() : delegate(&defaultDelegate), q(1, 0, 0, 0) {}
+    Delegate        defaultDelegate; // to avoid check for existence every time
+    Delegate*       delegate;
+    Quaternion      q;
+};
 
-private:
-    Delegate defaultDelegate; // to avoid check for existence every time
-    Delegate* delegate;
-    Accelerometer accel;
-    Gyroscope gyro;
-    Magnetometer magneto;
-    Quaternion q;
-    float const deltat, beta;
-    Vector3 fused;
+class SensorFusion6 : public SensorFusion, public Sensor::Delegate
+{
+public:
+    SensorFusion6(I2C &i2c);
+    virtual void sensorUpdate(Vector3 gyro_degrees);
+    virtual bool start();
+    virtual void stop();
+    
+protected:
+    Accelerometer   accel;
+    Gyroscope       gyro;
+    float const     deltat, beta;
+    
+    LowPassFilter   lowpassX;
+    LowPassFilter   lowpassY;
+    LowPassFilter   lowpassZ;
+    
     void updateFilter(float ax, float ay, float az, float gx, float gy, float gz);
-    void updateFilter(float ax, float ay, float az, float gx, float gy, float gz, float mx, float my, float mz);
 };
 
 #endif
\ No newline at end of file