From cd1ff7b86fe0f9ffcf87c2dda30e11a55d6b7800 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 30 Aug 2017 01:15:33 -0700 Subject: [PATCH] AP_AHRS: DCM: add static create method --- libraries/AP_AHRS/AP_AHRS_DCM.h | 78 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/libraries/AP_AHRS/AP_AHRS_DCM.h b/libraries/AP_AHRS/AP_AHRS_DCM.h index 09bc7b09cf..5ceb530a1b 100644 --- a/libraries/AP_AHRS/AP_AHRS_DCM.h +++ b/libraries/AP_AHRS/AP_AHRS_DCM.h @@ -21,43 +21,19 @@ * */ -class AP_AHRS_DCM : public AP_AHRS -{ +class AP_AHRS_DCM : public AP_AHRS { public: - // Constructors - AP_AHRS_DCM(AP_InertialSensor &ins, AP_Baro &baro, AP_GPS &gps) : - AP_AHRS(ins, baro, gps), - _omega_I_sum_time(0.0f), - _renorm_val_sum(0.0f), - _renorm_val_count(0), - _error_rp(1.0f), - _error_yaw(1.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), - _imu1_weight(0.5f), - _last_failure_ms(0), - _last_startup_ms(0) - { - _dcm_matrix.identity(); - - // these are experimentally derived from the simulator - // with large drift levels - _ki = 0.0087f; - _ki_yaw = 0.01f; + static AP_AHRS_DCM create(AP_InertialSensor &ins, AP_Baro &baro, AP_GPS &gps) { + return AP_AHRS_DCM{ins, baro, gps}; } + constexpr AP_AHRS_DCM(AP_AHRS_DCM &&other) = default; + + /* Do not allow copies */ + AP_AHRS_DCM(const AP_AHRS_DCM &other) = delete; + AP_AHRS_DCM &operator=(const AP_AHRS_DCM&) = delete; + + // return the smoothed gyro vector corrected for drift const Vector3f &get_gyro() const override { return _omega; @@ -117,6 +93,40 @@ public: // time that the AHRS has been up uint32_t uptime_ms() const override; +protected: + AP_AHRS_DCM(AP_InertialSensor &ins, AP_Baro &baro, AP_GPS &gps) + : AP_AHRS(ins, baro, gps) + , _omega_I_sum_time(0.0f) + , _renorm_val_sum(0.0f) + , _renorm_val_count(0) + , _error_rp(1.0f) + , _error_yaw(1.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) + , _imu1_weight(0.5f) + , _last_failure_ms(0) + , _last_startup_ms(0) + { + _dcm_matrix.identity(); + + // these are experimentally derived from the simulator + // with large drift levels + _ki = 0.0087f; + _ki_yaw = 0.01f; + } + private: float _ki; float _ki_yaw;