imu_filter.h
Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2010, CCNY Robotics Lab
00003  *  Ivan Dryanovski <ivan.dryanovski@gmail.com>
00004  *
00005  *  http://robotics.ccny.cuny.edu
00006  *
00007  *  Based on implementation of Madgwick's IMU and AHRS algorithms.
00008  *  http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms
00009  *
00010  *
00011  *  This program is free software: you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation, either version 3 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public License
00022  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023  */
00024 
00025 #ifndef IMU_FILTER_MADWICK_IMU_FILTER_H
00026 #define IMU_FILTER_MADWICK_IMU_FILTER_H
00027 
00028 class ImuFilter
00029 {
00030   public:
00031 
00032     ImuFilter();
00033     virtual ~ImuFilter();
00034 
00035   private:
00036     // **** paramaters
00037     double gain_;     // algorithm gain
00038     double zeta_;         // gyro drift bias gain
00039 
00040     // **** state variables
00041     double q0, q1, q2, q3;  // quaternion
00042     float w_bx_, w_by_, w_bz_; // 
00043 
00044     // **** member functions
00045 
00046     // Fast inverse square-root
00047     // See: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Reciprocal_of_the_square_root
00048     static float invSqrt(float x)
00049     {
00050       float xhalf = 0.5f * x;
00051       union
00052       {
00053         float x;
00054         int i;
00055       } u;
00056       u.x = x;
00057       u.i = 0x5f3759df - (u.i >> 1);
00058       /* The next line can be repeated any number of times to increase accuracy */
00059       u.x = u.x * (1.5f - xhalf * u.x * u.x);
00060       return u.x;
00061     }
00062 
00063 public:
00064     void setAlgorithmGain(double gain)
00065     {
00066         gain_ = gain;
00067     }
00068 
00069     void setDriftBiasGain(double zeta)
00070     {
00071         zeta_ = zeta;
00072     }
00073 
00074     void getOrientation(double& q0, double& q1, double& q2, double& q3)
00075     {
00076         q0 = this->q0;
00077         q1 = this->q1;
00078         q2 = this->q2;
00079         q3 = this->q3;
00080     }
00081 
00082     void setOrientation(double q0, double q1, double q2, double q3)
00083     {
00084         this->q0 = q0;
00085         this->q1 = q1;
00086         this->q2 = q2;
00087         this->q3 = q3;
00088 
00089         w_bx_ = 0;
00090         w_by_ = 0;
00091         w_bz_ = 0;
00092     }
00093 
00094     void madgwickAHRSupdate(float gx, float gy, float gz,
00095                             float ax, float ay, float az,
00096                             float mx, float my, float mz,
00097                             float dt);
00098 
00099     void madgwickAHRSupdateIMU(float gx, float gy, float gz,
00100                                float ax, float ay, float az,
00101                                float dt);
00102 };
00103 
00104 #endif // IMU_FILTER_IMU_MADWICK_FILTER_H


imu_filter_madgwick
Author(s): Ivan Dryanovski
autogenerated on Wed Aug 26 2015 11:58:51