4180 final project
Dependencies: LSM9DS0 USBDevice mbed
Quaternion/Quaternion.h@0:ebbc3cd3a61e, 2015-12-05 (annotated)
- Committer:
- jlee887
- Date:
- Sat Dec 05 18:39:33 2015 +0000
- Revision:
- 0:ebbc3cd3a61e
d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jlee887 | 0:ebbc3cd3a61e | 1 | #ifndef Quaternion_h |
jlee887 | 0:ebbc3cd3a61e | 2 | #define Quaternion_h |
jlee887 | 0:ebbc3cd3a61e | 3 | #include "mbed.h" |
jlee887 | 0:ebbc3cd3a61e | 4 | |
jlee887 | 0:ebbc3cd3a61e | 5 | |
jlee887 | 0:ebbc3cd3a61e | 6 | #define twoKpDef (2.0f * 0.5f) // 2 * proportional gain |
jlee887 | 0:ebbc3cd3a61e | 7 | #define twoKiDef (2.0f * 0.0f) // 2 * integral gain |
jlee887 | 0:ebbc3cd3a61e | 8 | |
jlee887 | 0:ebbc3cd3a61e | 9 | class Quaternion { |
jlee887 | 0:ebbc3cd3a61e | 10 | |
jlee887 | 0:ebbc3cd3a61e | 11 | public: |
jlee887 | 0:ebbc3cd3a61e | 12 | Quaternion(); |
jlee887 | 0:ebbc3cd3a61e | 13 | void update6DOF(float gx, float gy, float gz, float ax, float ay, float az); |
jlee887 | 0:ebbc3cd3a61e | 14 | void update9DOF(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); |
jlee887 | 0:ebbc3cd3a61e | 15 | void getQ(float * q); |
jlee887 | 0:ebbc3cd3a61e | 16 | void getEulerAngles(float * angles); |
jlee887 | 0:ebbc3cd3a61e | 17 | void getYawPitchRoll(double * ypr); |
jlee887 | 0:ebbc3cd3a61e | 18 | void getGravity(float * gravity); |
jlee887 | 0:ebbc3cd3a61e | 19 | void getLinearAcceleration(float * linearAccel, float ax, float ay, float az); |
jlee887 | 0:ebbc3cd3a61e | 20 | |
jlee887 | 0:ebbc3cd3a61e | 21 | private: |
jlee887 | 0:ebbc3cd3a61e | 22 | float invSqrt(float x); |
jlee887 | 0:ebbc3cd3a61e | 23 | volatile float q0, q1, q2, q3; |
jlee887 | 0:ebbc3cd3a61e | 24 | volatile float twoKp; // 2 * proportional gain (Kp) |
jlee887 | 0:ebbc3cd3a61e | 25 | volatile float twoKi; // 2 * integral gain (Ki) |
jlee887 | 0:ebbc3cd3a61e | 26 | volatile float integralFBx, integralFBy, integralFBz; |
jlee887 | 0:ebbc3cd3a61e | 27 | unsigned long lastUpdate, now; |
jlee887 | 0:ebbc3cd3a61e | 28 | float sampleFreq; |
jlee887 | 0:ebbc3cd3a61e | 29 | void updateSampleFrequency(); |
jlee887 | 0:ebbc3cd3a61e | 30 | }; |
jlee887 | 0:ebbc3cd3a61e | 31 | |
jlee887 | 0:ebbc3cd3a61e | 32 | #endif |