2012-11-14 12:10:15 -04:00
|
|
|
#ifndef __AP_AHRS_DCM_H__
|
|
|
|
#define __AP_AHRS_DCM_H__
|
2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-11 04:59:53 -03:00
|
|
|
/*
|
2012-08-21 23:19:51 -03:00
|
|
|
* DCM based AHRS (Attitude Heading Reference System) interface for
|
|
|
|
* ArduPilot
|
|
|
|
*
|
|
|
|
*/
|
2012-03-11 04:59:53 -03:00
|
|
|
|
|
|
|
class AP_AHRS_DCM : public AP_AHRS
|
2010-12-01 03:58:04 -04:00
|
|
|
{
|
|
|
|
public:
|
2012-08-21 23:19:51 -03:00
|
|
|
// Constructors
|
2014-03-30 08:00:25 -03:00
|
|
|
AP_AHRS_DCM(AP_InertialSensor &ins, AP_Baro &baro, AP_GPS &gps) :
|
2014-04-21 04:10:27 -03:00
|
|
|
AP_AHRS(ins, baro, gps),
|
2014-08-13 10:58:55 -03:00
|
|
|
_omega_I_sum_time(0.0f),
|
|
|
|
_renorm_val_sum(0.0f),
|
|
|
|
_renorm_val_count(0),
|
|
|
|
_error_rp_sum(0.0f),
|
|
|
|
_error_rp_count(0),
|
|
|
|
_error_rp_last(0.0f),
|
|
|
|
_error_yaw_sum(0.0f),
|
|
|
|
_error_yaw_count(0),
|
|
|
|
_error_yaw_last(0.0f),
|
|
|
|
_gps_last_update(0),
|
|
|
|
_ra_deltat(0.0f),
|
|
|
|
_ra_sum_start(0),
|
|
|
|
_last_declination(0.0f),
|
|
|
|
_mag_earth(1,0),
|
|
|
|
_have_gps_lock(false),
|
|
|
|
_last_lat(0),
|
|
|
|
_last_lng(0),
|
|
|
|
_position_offset_north(0.0f),
|
|
|
|
_position_offset_east(0.0f),
|
|
|
|
_have_position(false),
|
|
|
|
_last_wind_time(0),
|
|
|
|
_last_airspeed(0.0f),
|
|
|
|
_last_consistent_heading(0),
|
|
|
|
_last_failure_ms(0)
|
2012-08-21 23:19:51 -03:00
|
|
|
{
|
|
|
|
_dcm_matrix.identity();
|
|
|
|
|
|
|
|
// these are experimentally derived from the simulator
|
|
|
|
// with large drift levels
|
|
|
|
_ki = 0.0087;
|
|
|
|
_ki_yaw = 0.01;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the smoothed gyro vector corrected for drift
|
2014-07-13 08:56:39 -03:00
|
|
|
const Vector3f &get_gyro(void) const {
|
2014-07-13 04:36:27 -03:00
|
|
|
return _omega;
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
2014-01-17 04:19:42 -04:00
|
|
|
|
|
|
|
// return rotation matrix representing rotaton from body to earth axes
|
2013-04-21 09:27:04 -03:00
|
|
|
const Matrix3f &get_dcm_matrix(void) const {
|
2014-01-17 04:19:42 -04:00
|
|
|
return _body_dcm_matrix;
|
2012-08-21 23:19:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the current drift correction integrator value
|
2013-04-21 09:27:04 -03:00
|
|
|
const Vector3f &get_gyro_drift(void) const {
|
2012-08-21 23:19:51 -03:00
|
|
|
return _omega_I;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void update(void);
|
|
|
|
void reset(bool recover_eulers = false);
|
|
|
|
|
2013-11-22 21:37:23 -04:00
|
|
|
// reset the current attitude, used on new IMU calibration
|
|
|
|
void reset_attitude(const float &roll, const float &pitch, const float &yaw);
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// dead-reckoning support
|
2014-02-14 18:23:41 -04:00
|
|
|
virtual bool get_position(struct Location &loc);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// status reporting
|
|
|
|
float get_error_rp(void);
|
|
|
|
float get_error_yaw(void);
|
|
|
|
|
|
|
|
// return a wind estimation vector, in m/s
|
|
|
|
Vector3f wind_estimate(void) {
|
|
|
|
return _wind;
|
|
|
|
}
|
2012-08-12 22:08:10 -03:00
|
|
|
|
2012-08-24 08:22:58 -03:00
|
|
|
// return an airspeed estimate if available. return true
|
|
|
|
// if we have an estimate
|
2014-02-24 21:43:59 -04:00
|
|
|
bool airspeed_estimate(float *airspeed_ret) const;
|
2012-08-24 08:22:58 -03:00
|
|
|
|
2013-10-21 23:06:27 -03:00
|
|
|
bool use_compass(void);
|
2013-03-28 23:48:25 -03:00
|
|
|
|
2014-03-30 08:00:25 -03:00
|
|
|
void set_home(const Location &loc);
|
2014-02-08 04:11:12 -04:00
|
|
|
void estimate_wind(void);
|
2014-01-03 20:15:34 -04:00
|
|
|
|
2014-05-15 04:09:18 -03:00
|
|
|
// is the AHRS subsystem healthy?
|
|
|
|
bool healthy(void);
|
|
|
|
|
2010-12-01 03:58:04 -04:00
|
|
|
private:
|
2012-08-21 23:19:51 -03:00
|
|
|
float _ki;
|
|
|
|
float _ki_yaw;
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void matrix_update(float _G_Dt);
|
|
|
|
void normalize(void);
|
|
|
|
void check_matrix(void);
|
|
|
|
bool renorm(Vector3f const &a, Vector3f &result);
|
|
|
|
void drift_correction(float deltat);
|
|
|
|
void drift_correction_yaw(void);
|
|
|
|
float yaw_error_compass();
|
|
|
|
void euler_angles(void);
|
2013-07-07 22:25:40 -03:00
|
|
|
bool have_gps(void) const;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
2014-01-17 04:19:42 -04:00
|
|
|
// primary representation of attitude of board used for all inertial calculations
|
2012-08-21 23:19:51 -03:00
|
|
|
Matrix3f _dcm_matrix;
|
|
|
|
|
2014-01-17 04:19:42 -04:00
|
|
|
// primary representation of attitude of flight vehicle body
|
|
|
|
Matrix3f _body_dcm_matrix;
|
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
Vector3f _omega_P; // accel Omega proportional correction
|
|
|
|
Vector3f _omega_yaw_P; // proportional yaw correction
|
|
|
|
Vector3f _omega_I; // Omega Integrator correction
|
|
|
|
Vector3f _omega_I_sum;
|
|
|
|
float _omega_I_sum_time;
|
|
|
|
Vector3f _omega; // Corrected Gyro_Vector data
|
|
|
|
|
2013-11-04 00:50:33 -04:00
|
|
|
// variables to cope with delaying the GA sum to match GPS lag
|
2014-02-26 18:41:28 -04:00
|
|
|
Vector3f ra_delayed(uint8_t instance, const Vector3f &ra);
|
|
|
|
Vector3f _ra_delay_buffer[INS_MAX_INSTANCES];
|
2013-11-04 00:50:33 -04:00
|
|
|
|
2012-08-21 23:19:51 -03:00
|
|
|
// P term gain based on spin rate
|
|
|
|
float _P_gain(float spin_rate);
|
|
|
|
|
2014-01-18 03:18:12 -04:00
|
|
|
// P term yaw gain based on rate of change of horiz velocity
|
2014-02-26 18:41:28 -04:00
|
|
|
float _yaw_gain(void) const;
|
2014-01-18 03:18:12 -04:00
|
|
|
|
2012-08-21 23:19:51 -03: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_rp_last;
|
|
|
|
float _error_yaw_sum;
|
|
|
|
uint16_t _error_yaw_count;
|
|
|
|
float _error_yaw_last;
|
|
|
|
|
|
|
|
// time in millis when we last got a GPS heading
|
|
|
|
uint32_t _gps_last_update;
|
|
|
|
|
|
|
|
// state of accel drift correction
|
2014-02-26 18:41:28 -04:00
|
|
|
Vector3f _ra_sum[INS_MAX_INSTANCES];
|
2012-08-21 23:19:51 -03:00
|
|
|
Vector3f _last_velocity;
|
|
|
|
float _ra_deltat;
|
|
|
|
uint32_t _ra_sum_start;
|
|
|
|
|
2013-05-04 12:25:59 -03:00
|
|
|
// the earths magnetic field
|
|
|
|
float _last_declination;
|
2013-05-05 00:51:45 -03:00
|
|
|
Vector2f _mag_earth;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// whether we have GPS lock
|
|
|
|
bool _have_gps_lock;
|
|
|
|
|
|
|
|
// the lat/lng where we last had GPS lock
|
|
|
|
int32_t _last_lat;
|
|
|
|
int32_t _last_lng;
|
|
|
|
|
|
|
|
// position offset from last GPS lock
|
|
|
|
float _position_offset_north;
|
|
|
|
float _position_offset_east;
|
|
|
|
|
|
|
|
// whether we have a position estimate
|
|
|
|
bool _have_position;
|
|
|
|
|
|
|
|
// support for wind estimation
|
|
|
|
Vector3f _last_fuse;
|
|
|
|
Vector3f _last_vel;
|
|
|
|
uint32_t _last_wind_time;
|
|
|
|
float _last_airspeed;
|
2013-10-21 23:06:27 -03:00
|
|
|
uint32_t _last_consistent_heading;
|
2012-08-21 23:19:51 -03:00
|
|
|
|
|
|
|
// estimated wind in m/s
|
|
|
|
Vector3f _wind;
|
2014-05-15 04:09:18 -03:00
|
|
|
|
|
|
|
// last time AHRS failed in milliseconds
|
|
|
|
uint32_t _last_failure_ms;
|
2010-12-01 03:58:04 -04:00
|
|
|
};
|
|
|
|
|
2012-11-14 12:10:15 -04:00
|
|
|
#endif // __AP_AHRS_DCM_H__
|