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-03-11 04:59:53 -03:00
|
|
|
_kp_roll_pitch = 0.13;
|
|
|
|
_kp_yaw = 0.4;
|
|
|
|
_dcm_matrix(Vector3f(1, 0, 0),
|
|
|
|
Vector3f(0, 1, 0),
|
|
|
|
Vector3f(0, 0, 1));
|
|
|
|
|
|
|
|
// base the ki values on the sensors drift rate
|
2012-03-08 18:03:47 -04:00
|
|
|
_ki_roll_pitch = _gyro_drift_limit * 5;
|
|
|
|
_ki_yaw = _gyro_drift_limit * 8;
|
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-03-11 04:59:53 -03:00
|
|
|
Vector3f get_gyro(void) {return _omega; }
|
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
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
private:
|
2011-06-12 20:49:01 -03:00
|
|
|
float _kp_roll_pitch;
|
|
|
|
float _ki_roll_pitch;
|
|
|
|
float _kp_yaw;
|
2011-07-08 00:57:12 -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
|
2012-03-02 20:53:31 -04:00
|
|
|
void accel_adjust(Vector3f &accel);
|
2010-12-01 03:58:04 -04:00
|
|
|
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);
|
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-03-08 03:12:46 -04:00
|
|
|
Vector3f _omega_P; // accel Omega Proportional correction
|
|
|
|
Vector3f _omega_yaw_P; // yaw Omega Proportional correction
|
|
|
|
Vector3f _omega_I; // Omega Integrator correction
|
|
|
|
Vector3f _omega_integ_corr; // Partially corrected Gyro_Vector data - used for centrepetal correction
|
|
|
|
Vector3f _omega; // Corrected Gyro_Vector data
|
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;
|
|
|
|
float _error_yaw_sum;
|
|
|
|
uint16_t _error_yaw_count;
|
|
|
|
|
2012-03-07 00:09:17 -04:00
|
|
|
// time in millis when we last got a GPS heading
|
|
|
|
uint32_t _gps_last_update;
|
2010-12-01 03:58:04 -04:00
|
|
|
};
|
|
|
|
|
2012-03-11 04:59:53 -03:00
|
|
|
#endif // AP_AHRS_DCM_H
|