MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/sensing/ins_kf.hpp
00001 /*******************************************************************************
00002  * Copyright (c) 2009-2016, 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 ins_kf.hpp
00034  *
00035  * \author MAV'RIC Team
00036  * \author Julien Lecoeur
00037  * \author Simon Pyroth
00038  *
00039  * \brief   Kalman filter for position estimation
00040  *
00041  ******************************************************************************/
00042 
00043 
00044 #ifndef INS_KF_HPP_
00045 #define INS_KF_HPP_
00046 
00047 
00048 #include "status/state.hpp"
00049 #include "drivers/gps.hpp"
00050 #include "drivers/gps_mocap.hpp"
00051 #include "drivers/barometer.hpp"
00052 #include "drivers/sonar.hpp"
00053 #include "drivers/px4flow.hpp"
00054 #include "sensing/ahrs.hpp"
00055 #include "sensing/ins.hpp"
00056 
00057 #include "util/kalman.hpp"
00058 #include "util/constants.hpp"
00059 
00060 extern "C"
00061 {
00062 #include "sensing/altitude.h"
00063 }
00064 
00065 
00066 
00128 class INS_kf: public Kalman<11,3,3>, public INS
00129 {
00130     friend void ins_telemetry_send(const INS_kf* ins, const Mavlink_stream* mavlink_stream, mavlink_message_t* msg);
00131 public:
00135     struct conf_t
00136     {
00137         // Process covariance
00138         float sigma_bias_acc;
00139         float sigma_z_gnd;
00140         float sigma_bias_baro;
00141         float sigma_acc;
00142 
00143         // Measurement covariance
00144         float sigma_gps_xy;
00145         float sigma_gps_z;
00146         float sigma_gps_velxy;
00147         float sigma_gps_velz;
00148         float sigma_gps_mocap;
00149         float sigma_baro;
00150         float sigma_flow;
00151         float sigma_sonar;
00152 
00153         // Position of the origin
00154         global_position_t origin;
00155     };
00156 
00157 
00161     INS_kf( State& state,
00162             const Gps& gps,
00163             const Gps_mocap& gps_mocap,
00164             const Barometer& barometer,
00165             const Sonar& sonar,
00166             const PX4Flow& flow,
00167             const AHRS& ahrs,
00168             const conf_t config = default_config() );
00169 
00170 
00176     bool update(void);
00177 
00178 
00184     float last_update_s(void) const;
00185 
00186 
00192     std::array<float,3> position_lf(void) const;
00193 
00194 
00200     std::array<float,3> velocity_lf(void) const;
00201 
00202 
00208     float absolute_altitude(void) const;
00209 
00210 
00218     bool is_healthy(INS::healthy_t type) const;
00219 
00220 
00224     void init(void);
00225 
00226 
00230     static inline INS_kf::conf_t default_config(void);
00231 
00232 
00233     conf_t config_;                     
00234     uint32_t init_flag;                 
00235 
00236 
00237 private:
00238     State&              state_;             
00239     const Gps&          gps_;               
00240     const Gps_mocap&    gps_mocap_;         
00241     const Barometer&    barometer_;         
00242     const Sonar&        sonar_;             
00243     const PX4Flow&      flow_;              
00244     const AHRS&         ahrs_;              
00245 
00246     std::array<float,3> pos_;
00247     std::array<float,3> vel_;
00248     float absolute_altitude_;
00249 
00250     Mat<3,11> H_gpsvel_;
00251     Mat<3,3> R_gpsvel_;
00252     Mat<3,3> R_mocap_;
00253     Mat<1,11> H_baro_;
00254     Mat<1,1> R_baro_;
00255     Mat<1,11> H_sonar_;
00256     Mat<1,1> R_sonar_;
00257     Mat<3,11> H_flow_;
00258     Mat<3,3> R_flow_;
00259 
00260     float last_accel_update_s_;             
00261     float last_sonar_update_s_;             
00262     float last_flow_update_s_;              
00263     float last_baro_update_s_;              
00264     float last_gps_pos_update_s_;           
00265     float last_gps_vel_update_s_;           
00266     float last_gps_mocap_update_s_;         
00267     bool  first_fix_received_;              
00268 
00269 
00270     float dt_;                              
00271     float last_update_;                     
00272 
00273 
00277     void predict_kf(void);
00278 
00279 
00283     void update_gps_pos(void);
00284 
00285 
00289     void update_gps_vel(void);
00290 
00291 
00295     void update_gps_mocap(void);
00296 
00297 
00301     void update_barometer(void);
00302 
00303 
00307     void update_sonar(void);
00308 
00309 
00313     void update_flow(void);
00314 };
00315 
00316 
00317 INS_kf::conf_t INS_kf::default_config(void)
00318 {
00319     INS_kf::conf_t conf = {};
00320 
00321     // Process covariance (noise from state and input)
00322     conf.sigma_z_gnd        = 0.0f;        // previously 0.008f
00323     conf.sigma_bias_acc     = 0.00001f;
00324     conf.sigma_bias_baro    = 0.01f;       // previously 0.01f;
00325     conf.sigma_acc          = 5.0f;       // Measured: 0.6f (at rest 0.032f)
00326 
00327     // Measurement covariance   (noise from measurement)
00328     conf.sigma_gps_xy       = 0.04f;       // Measured: 0.316f
00329     conf.sigma_gps_z        = 0.13f;       // Measured: 0.879f
00330     conf.sigma_gps_velxy    = 0.02f;       // Measured: 0.064f
00331     conf.sigma_gps_velz     = 0.02f;       // Measured: 0.342f
00332     conf.sigma_gps_mocap    = 0.00001f;
00333     conf.sigma_baro         = 0.50f;       // Measured: 0.310f
00334     conf.sigma_flow         = 0.002f;
00335     conf.sigma_sonar        = 0.002f;       // Measured: 0.002f
00336 
00337     //default origin location (EFPL Esplanade)
00338     conf.origin = ORIGIN_EPFL;
00339 
00340     return conf;
00341 };
00342 
00343 
00344 
00345 static inline bool task_ins_kf_update(INS_kf* ins_kf)
00346 {
00347     return ins_kf->update();
00348 }
00349 
00350 #endif /* INS_KF_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines