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 #include <imu_filter_madgwick/world_frame.h>
00029 #include <iostream>
00030 #include <cmath>
00031 
00032 class ImuFilter
00033 {
00034   public:
00035 
00036     ImuFilter();
00037     virtual ~ImuFilter();
00038 
00039   private:
00040     // **** paramaters
00041     double gain_;    // algorithm gain
00042     double zeta_;    // gyro drift bias gain
00043     WorldFrame::WorldFrame world_frame_;    // NWU, ENU, NED
00044 
00045     // **** state variables
00046     double q0, q1, q2, q3;  // quaternion
00047     float w_bx_, w_by_, w_bz_; // 
00048 
00049 public:
00050     void setAlgorithmGain(double gain)
00051     {
00052         gain_ = gain;
00053     }
00054 
00055     void setDriftBiasGain(double zeta)
00056     {
00057         zeta_ = zeta;
00058     }
00059 
00060     void setWorldFrame(WorldFrame::WorldFrame frame)
00061     {
00062         world_frame_ = frame;
00063     }
00064 
00065     void getOrientation(double& q0, double& q1, double& q2, double& q3)
00066     {
00067         q0 = this->q0;
00068         q1 = this->q1;
00069         q2 = this->q2;
00070         q3 = this->q3;
00071 
00072         // perform precise normalization of the output, using 1/sqrt()
00073         // instead of the fast invSqrt() approximation. Without this,
00074         // TF2 complains that the quaternion is not normalized.
00075         double recipNorm = 1 / sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
00076         q0 *= recipNorm;
00077         q1 *= recipNorm;
00078         q2 *= recipNorm;
00079         q3 *= recipNorm;
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 Sat Jun 8 2019 18:39:11