2012-03-03 00:49:38 -04:00
|
|
|
#ifndef AP_Quaternion_h
|
|
|
|
#define AP_Quaternion_h
|
|
|
|
|
|
|
|
#include <AP_Math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <AP_Compass.h>
|
|
|
|
#include <AP_GPS.h>
|
|
|
|
#include <AP_IMU.h>
|
|
|
|
|
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
|
|
|
#include "Arduino.h"
|
|
|
|
#else
|
|
|
|
#include "WProgram.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-11 05:00:19 -03:00
|
|
|
class AP_AHRS_Quaternion : public AP_AHRS
|
2012-03-03 00:49:38 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor
|
2012-03-11 05:00:19 -03:00
|
|
|
AP_AHRS_Quaternion(IMU *imu, GPS *&gps) : AP_AHRS(imu, gps)
|
2012-03-03 00:49:38 -04:00
|
|
|
{
|
|
|
|
// scaled gyro drift limits
|
|
|
|
beta = sqrt(3.0f / 4.0f) * gyroMeasError;
|
2012-03-11 05:00:19 -03:00
|
|
|
zeta = sqrt(3.0f / 4.0f) * _gyro_drift_limit;
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2012-03-11 05:00:19 -03:00
|
|
|
// reset attitude
|
|
|
|
reset();
|
|
|
|
}
|
2012-03-03 00:49:38 -04:00
|
|
|
|
|
|
|
// Methods
|
2012-03-03 01:00:57 -04:00
|
|
|
void update(void);
|
2012-03-11 05:00:19 -03:00
|
|
|
void reset(bool recover_eulers=false);
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2012-03-11 05:00:19 -03:00
|
|
|
// get corrected gyro vector
|
2012-03-04 20:27:45 -04:00
|
|
|
Vector3f get_gyro(void) {
|
|
|
|
// notice the sign reversals here
|
2012-03-12 08:50:38 -03:00
|
|
|
return Vector3f(_gyro_corrected.x, _gyro_corrected.y, _gyro_corrected.z);
|
2012-03-04 20:27:45 -04:00
|
|
|
}
|
2012-03-11 05:00:19 -03:00
|
|
|
|
2012-03-08 03:14:40 -04:00
|
|
|
Vector3f get_gyro_drift(void) {
|
2012-03-11 05:00:19 -03:00
|
|
|
// notice the sign reversals here. The quaternion
|
|
|
|
// system uses a -ve gyro bias, DCM uses a +ve
|
2012-03-12 08:50:38 -03:00
|
|
|
return Vector3f(-gyro_bias.x, -gyro_bias.y, -gyro_bias.z);
|
2012-03-04 20:27:45 -04:00
|
|
|
}
|
2012-03-11 05:00:19 -03:00
|
|
|
|
2012-03-03 08:32:31 -04:00
|
|
|
float get_error_rp(void);
|
|
|
|
float get_error_yaw(void);
|
2012-03-11 05:00:19 -03:00
|
|
|
|
|
|
|
// convert quaternion to a DCM matrix, used by compass
|
|
|
|
// null offsets code
|
2012-03-07 00:16:21 -04:00
|
|
|
Matrix3f get_dcm_matrix(void) {
|
|
|
|
Matrix3f ret;
|
2012-03-10 02:07:20 -04:00
|
|
|
q.rotation_matrix(ret);
|
2012-03-07 00:16:21 -04:00
|
|
|
return ret;
|
|
|
|
}
|
2012-03-03 03:32:50 -04:00
|
|
|
|
2012-03-03 00:49:38 -04:00
|
|
|
private:
|
|
|
|
void update_IMU(float deltat, Vector3f &gyro, Vector3f &accel);
|
|
|
|
void update_MARG(float deltat, Vector3f &gyro, Vector3f &accel, Vector3f &mag);
|
|
|
|
|
|
|
|
bool _have_initial_yaw;
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void accel_adjust(void);
|
|
|
|
|
2012-03-07 03:31:35 -04:00
|
|
|
// maximum gyroscope measurement error in rad/s (set to 7 degrees/second)
|
2012-03-08 18:02:04 -04:00
|
|
|
static const float gyroMeasError = 20.0 * (M_PI/180.0);
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2012-03-11 05:00:19 -03:00
|
|
|
// scaled tuning constants
|
2012-03-03 00:49:38 -04:00
|
|
|
float beta;
|
|
|
|
float zeta;
|
|
|
|
|
|
|
|
// quaternion elements
|
2012-03-05 00:07:04 -04:00
|
|
|
Quaternion q;
|
2012-03-03 00:49:38 -04:00
|
|
|
|
2012-03-05 00:07:04 -04:00
|
|
|
// magnetic flux estimates. These are used for the automatic
|
|
|
|
// magnetometer calibration
|
2012-03-03 00:49:38 -04:00
|
|
|
float b_x;
|
|
|
|
float b_z;
|
|
|
|
|
|
|
|
// estimate gyroscope biases error
|
|
|
|
Vector3f gyro_bias;
|
2012-03-03 03:32:50 -04:00
|
|
|
|
2012-03-04 20:27:45 -04:00
|
|
|
// the current corrected gyro vector
|
|
|
|
Vector3f _gyro_corrected;
|
2012-03-03 08:32:31 -04:00
|
|
|
|
|
|
|
// estimate of error
|
|
|
|
float _error_rp_sum;
|
|
|
|
uint16_t _error_rp_count;
|
2012-03-28 18:57:53 -03:00
|
|
|
float _error_rp_last;
|
2012-03-03 08:32:31 -04:00
|
|
|
float _error_yaw_sum;
|
|
|
|
uint16_t _error_yaw_count;
|
2012-03-28 18:57:53 -03:00
|
|
|
float _error_yaw_last;
|
2012-03-03 00:49:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|