Compare commits

...

3 commits

Author SHA1 Message Date
hathach
2e20d45a26
only add virtual to superclass function 2020-02-26 10:54:19 +07:00
hathach
87459557b2
clang format 2020-02-21 11:09:08 +07:00
hathach
0475fc7ad0
added abstract class Adafruit_AHRS_FusionInterface 2020-02-21 10:20:58 +07:00
5 changed files with 54 additions and 3 deletions

View file

@ -1,3 +1,8 @@
#ifndef __ADAFRUIT_AHRS_H_
#define __ADAFRUIT_AHRS_H_
#include <Adafruit_AHRS_Madgwick.h> #include <Adafruit_AHRS_Madgwick.h>
#include <Adafruit_AHRS_Mahony.h> #include <Adafruit_AHRS_Mahony.h>
#include <Adafruit_AHRS_NXPFusion.h> #include <Adafruit_AHRS_NXPFusion.h>
#endif // __ADAFRUIT_AHRS_H_

View file

@ -0,0 +1,41 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Ha Thach (tinyusb.org) for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef ADAFRUIT_AHRS_FUSIONINTERFACE_H_
#define ADAFRUIT_AHRS_FUSIONINTERFACE_H_
// Interface for Fusion Algorithm
class Adafruit_AHRS_FusionInterface {
public:
virtual void begin(float sampleFrequency) = 0;
virtual void update(float gx, float gy, float gz, float ax, float ay,
float az, float mx, float my, float mz) = 0;
virtual float getRoll() = 0;
virtual float getPitch() = 0;
virtual float getYaw() = 0;
virtual void getQuaternion(float *w, float *x, float *y, float *z) = 0;
};
#endif /* ADAFRUIT_AHRS_FUSIONINTERFACE_H_ */

View file

@ -16,11 +16,13 @@
//============================================================================================= //=============================================================================================
#ifndef __Adafruit_Madgwick_h__ #ifndef __Adafruit_Madgwick_h__
#define __Adafruit_Madgwick_h__ #define __Adafruit_Madgwick_h__
#include "Adafruit_AHRS_FusionInterface.h"
#include <math.h> #include <math.h>
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
// Variable declaration // Variable declaration
class Adafruit_Madgwick { class Adafruit_Madgwick : public Adafruit_AHRS_FusionInterface {
private: private:
static float invSqrt(float x); static float invSqrt(float x);
float beta; // algorithm gain float beta; // algorithm gain

View file

@ -12,12 +12,14 @@
//============================================================================================= //=============================================================================================
#ifndef __Adafruit_Mahony_h__ #ifndef __Adafruit_Mahony_h__
#define __Adafruit_Mahony_h__ #define __Adafruit_Mahony_h__
#include "Adafruit_AHRS_FusionInterface.h"
#include <math.h> #include <math.h>
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
// Variable declaration // Variable declaration
class Adafruit_Mahony { class Adafruit_Mahony : public Adafruit_AHRS_FusionInterface {
private: private:
float twoKp; // 2 * proportional gain (Kp) float twoKp; // 2 * proportional gain (Kp)
float twoKi; // 2 * integral gain (Ki) float twoKi; // 2 * integral gain (Ki)

View file

@ -1,3 +1,4 @@
#include "Adafruit_AHRS_FusionInterface.h"
#include <Arduino.h> #include <Arduino.h>
// This is a modification of // This is a modification of
@ -31,7 +32,7 @@
// //
// changed class name to avoid collision // changed class name to avoid collision
class Adafruit_NXPSensorFusion { class Adafruit_NXPSensorFusion : public Adafruit_AHRS_FusionInterface {
public: public:
void begin(float sampleRate = 100.0f); void begin(float sampleRate = 100.0f);
void update(float gx, float gy, float gz, float ax, float ay, float az, void update(float gx, float gy, float gz, float ax, float ay, float az,