2012-03-11 04:59:53 -03:00
|
|
|
#ifndef AP_AHRS_DCM_H
|
|
|
|
#define AP_AHRS_DCM_H
|
|
|
|
/*
|
|
|
|
DCM based AHRS (Attitude Heading Reference System) interface for
|
|
|
|
ArduPilot
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AP_AHRS_DCM : public AP_AHRS
|
2010-12-01 03:58:04 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructors
|
2012-03-11 04:59:53 -03:00
|
|
|
AP_AHRS_DCM(IMU *imu, GPS *&gps) : AP_AHRS(imu, gps)
|
2012-03-08 03:12:46 -04:00
|
|
|
{
|
2012-06-27 22:09:22 -03:00
|
|
|
_dcm_matrix.identity();
|
|
|
|
|
|
|
|
// these are experimentally derived from the simulator
|
|
|
|
// with large drift levels
|
|
|
|
_ki = 0.0087;
|
|
|
|
_ki_yaw = 0.01;
|
|
|
|
|
|
|
|
_kp = 0.4;
|
|
|
|
_kp_yaw.set(0.4);
|
2012-03-08 03:12:46 -04:00
|
|
|
}
|
2010-12-01 03:58:04 -04:00
|
|
|
|
2012-03-07 00:09:17 -04:00
|
|
|
// return the smoothed gyro vector corrected for drift
|
2012-06-29 08:46:14 -03:00
|
|
|
Vector3f get_gyro(void) {return _omega + _omega_P + _omega_yaw_P; }
|
2010-12-14 14:39:02 -04:00
|
|
|
Matrix3f get_dcm_matrix(void) {return _dcm_matrix; }
|
2012-03-07 00:09:17 -04:00
|
|
|
|
|
|
|
// return the current drift correction integrator value
|
2012-03-08 03:12:46 -04:00
|
|
|
Vector3f get_gyro_drift(void) {return _omega_I; }
|
2011-12-03 21:57:12 -04:00
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
// Methods
|
2012-03-11 04:59:53 -03:00
|
|
|
void update(void);
|
|
|
|
void reset(bool recover_eulers = false);
|
2010-12-01 03:58:04 -04:00
|
|
|
|
2012-03-01 00:22:39 -04:00
|
|
|
// status reporting
|
|
|
|
float get_error_rp(void);
|
|
|
|
float get_error_yaw(void);
|
2011-06-12 20:49:01 -03:00
|
|
|
|
2012-04-16 07:51:46 -03:00
|
|
|
// settable parameters
|
|
|
|
AP_Float _kp_yaw;
|
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
private:
|
2012-06-27 22:09:22 -03:00
|
|
|
float _kp;
|
|
|
|
float _ki;
|
2012-06-19 01:47:09 -03:00
|
|
|
float _ki_yaw;
|
2012-02-23 20:44:21 -04:00
|
|
|
bool _have_initial_yaw;
|
2011-07-08 00:57:12 -03:00
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
// Methods
|
|
|
|
void matrix_update(float _G_Dt);
|
|
|
|
void normalize(void);
|
2012-02-22 17:00:25 -04:00
|
|
|
void check_matrix(void);
|
2012-03-07 00:09:17 -04:00
|
|
|
bool renorm(Vector3f const &a, Vector3f &result);
|
|
|
|
void drift_correction(float deltat);
|
2012-06-27 22:09:22 -03:00
|
|
|
void drift_correction_yaw(void);
|
|
|
|
float yaw_error_compass();
|
|
|
|
float yaw_error_gps();
|
2010-12-01 03:58:04 -04:00
|
|
|
void euler_angles(void);
|
|
|
|
|
2012-03-11 04:59:53 -03:00
|
|
|
// primary representation of attitude
|
2010-12-01 03:58:04 -04:00
|
|
|
Matrix3f _dcm_matrix;
|
|
|
|
|
2012-03-08 03:12:46 -04:00
|
|
|
Vector3f _gyro_vector; // Store the gyros turn rate in a vector
|
2012-03-11 04:59:53 -03:00
|
|
|
Vector3f _accel_vector; // current accel vector
|
|
|
|
|
2012-06-27 22:09:22 -03:00
|
|
|
Vector3f _omega_P; // accel Omega proportional correction
|
|
|
|
Vector3f _omega_yaw_P; // proportional yaw correction
|
2012-03-08 03:12:46 -04:00
|
|
|
Vector3f _omega_I; // Omega Integrator correction
|
2012-06-27 22:09:22 -03:00
|
|
|
Vector3f _omega_I_sum;
|
2012-06-19 01:47:09 -03:00
|
|
|
float _omega_I_sum_time;
|
2012-03-08 03:12:46 -04:00
|
|
|
Vector3f _omega; // Corrected Gyro_Vector data
|
2012-03-01 00:22:39 -04:00
|
|
|
|
2012-06-27 22:09:22 -03:00
|
|
|
// P term gain based on spin rate
|
|
|
|
float _P_gain(float spin_rate);
|
|
|
|
|
2012-03-01 00:22:39 -04:00
|
|
|
// state to support status reporting
|
|
|
|
float _renorm_val_sum;
|
|
|
|
uint16_t _renorm_val_count;
|
|
|
|
float _error_rp_sum;
|
|
|
|
uint16_t _error_rp_count;
|
2012-03-28 18:57:53 -03:00
|
|
|
float _error_rp_last;
|
2012-03-01 00:22:39 -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-01 00:22:39 -04:00
|
|
|
|
2012-03-07 00:09:17 -04:00
|
|
|
// time in millis when we last got a GPS heading
|
|
|
|
uint32_t _gps_last_update;
|
2012-06-27 22:09:22 -03:00
|
|
|
|
|
|
|
// state of accel drift correction
|
|
|
|
Vector3f _ra_sum;
|
|
|
|
Vector3f _last_velocity;
|
|
|
|
float _ra_deltat;
|
|
|
|
uint32_t _ra_sum_start;
|
|
|
|
|
|
|
|
// current drift error in earth frame
|
|
|
|
Vector3f _drift_error_earth;
|
2010-12-01 03:58:04 -04:00
|
|
|
};
|
|
|
|
|
2012-03-11 04:59:53 -03:00
|
|
|
#endif // AP_AHRS_DCM_H
|