MAV'RIC
|
00001 /******************************************************************************* 00002 * Copyright (c) 2009-2014, MAV'RIC Development Team 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of the copyright holder nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software without 00017 * specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 ******************************************************************************/ 00031 00032 /******************************************************************************* 00033 * \file ahrs_ekf.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Nicolas Dousse 00037 * \author Matthew Douglas 00038 * 00039 * \brief Extended Kalman Filter attitude estimation, mixing accelerometer and magnetometer 00040 * x[0] : bias_x 00041 * x[1] : bias_y 00042 * x[2] : bias_z 00043 * x[3] : q0 00044 * x[4] : q1 00045 * x[5] : q2 00046 * x[6] : q3 00047 * 00048 ******************************************************************************/ 00049 00050 #ifndef __AHRS_EKF_HPP__ 00051 #define __AHRS_EKF_HPP__ 00052 00053 #include "sensing/ahrs.hpp" 00054 #include "sensing/imu.hpp" 00055 #include "util/kalman.hpp" 00056 #include "util/matrix.hpp" 00057 00058 00062 class AHRS_ekf : public Kalman<7, 0, 3>, public AHRS 00063 { 00064 public: 00065 00069 struct conf_t 00070 { 00071 float sigma_w_sqr; 00072 float sigma_r_sqr; 00073 00074 float R_acc; 00075 float R_acc_norm; 00076 float R_mag; 00077 00078 uint32_t use_accelerometer; 00079 uint32_t use_magnetometer; 00080 }; 00081 00088 AHRS_ekf(const Imu& imu, const AHRS_ekf::conf_t config = default_config()); 00089 00095 bool update(void); 00096 00100 void calibrating_north_vector(void); 00101 00105 static inline AHRS_ekf::conf_t default_config(); 00106 00107 00113 float last_update_s(void) const; 00114 00115 00123 bool is_healthy(void) const; 00124 00125 00131 quat_t attitude(void) const; 00132 00133 00139 std::array<float,3> angular_speed(void) const; 00140 00141 00147 std::array<float,3> linear_acceleration(void) const; 00148 00149 00150 conf_t config_; 00151 00152 protected: 00153 00157 void init_kalman(void); 00158 00162 void predict_step(void); 00163 00167 void update_step_acc(void); 00168 00172 void update_step_mag(void); 00173 00174 const Imu& imu_; 00175 00176 quat_t attitude_; 00177 std::array<float,3> angular_speed_; 00178 std::array<float,3> linear_acc_; 00179 00180 ahrs_state_t internal_state_; 00181 00182 Mat<3,3> R_acc_; 00183 Mat<3,3> R_acc_norm_; 00184 Mat<3,3> R_mag_; 00185 00186 float dt_s_; 00187 float last_update_s_; 00188 }; 00189 00190 AHRS_ekf::conf_t AHRS_ekf::default_config() 00191 { 00192 AHRS_ekf::conf_t conf = {}; 00193 00194 conf.sigma_w_sqr = 0.0000000001f; 00195 conf.sigma_r_sqr = 0.000001f; 00196 conf.R_acc = 0.004f; 00197 conf.R_acc_norm = 0.05f; 00198 // conf.R_mag = 0.040f; 00199 conf.R_mag = 0.0040f; 00200 00201 conf.use_accelerometer = 1; 00202 conf.use_magnetometer = 1; 00203 00204 return conf; 00205 }; 00206 00207 #endif // __AHRS_EKF_HPP__