CCNYRoboticsLab / imu_tools

ROS tools for IMU devices
Other
929 stars 432 forks source link

What is the difference between these complimentary and madgwick filters when compared with bayesian filters like EKF & UKF? #150

Closed SahanGura closed 2 years ago

SahanGura commented 3 years ago

I want to know the pros and cons between these two different approaches when estimating orientation using a 9DOF IMU. What I know is; when using Bayesian filters we use an error estimation(covariance) of the measurements and calculates a final estimation with an error(covariance). So how this affects to the final result of Bayesian filters and complimentary filter? What is more accurate in long term?

mintar commented 3 years ago

@robertogl : Do you have a good answer to this?

robertogl commented 3 years ago

Bayesian filters as KFs use a probabilistic approach to obtain the optimal estimate of the systems' state (in this case the orientation). In particular, the so called Kalman gain (for a Kalman filter), which is used to correct the predicted state along with the measurement value, is dynamically calculated based on the uncertainty (covariance) of the predicted state and the uncertainty of the measurement noise. Therefore, for a linear system, the estimated value is optimal, assuming that you feed the filter with the correct noise covariance values. However, most of the time you have to deal with non linear systems for which you have to apply linearization (see EKFs, UKFs) and thus some errors are introduced. Moreover, you do not always have an accurate estimation of the covariance matrices.

You can think of a complementary filter (CF) as a Kalman filter with a constant Kalman gain (no noise probability distribution is considered). Thus, in theory, less accurate. However, complementary filters are easier, computationally lighter, and have faster convergence. So, in applications where you have high dynamic systems, a CF may even have a better accuracy.

Let me also add that the Madgwick filter still falls into the complementary filters category. It adopts an optimization algorithm (gradient descend) to find the quaternion correction.

I hope this helps.

SahanGura commented 3 years ago

Thank you very much for the detailed explanation @robertogl. In that case, better option with a high dynamic system (like a drone) is either the Complementary filter or Madgwick filter. But, I am wondering whether there might be an orientation drift after a certain period of time when using these filters?

mintar commented 3 years ago

All filters (complementary, Madgwick, Kalman) have an orientation drift if you don't have any external reference. To correct the orientation drift of the roll and pitch angles, the filters use the gravity vector (as measured by the accelerometer) as an external reference, which works nicely (unless you're in space, I guess). To correct the orientation drift in the yaw angle, the filters can optionally fuse magnetometer input to use the earth's magnetic field as an external reference.

Using a magnetometer has its limitations. If the IMU is mounted on a mobile robot near electric motors, or if you drive inside a building with ferromagnetic structures such as steel girders, the earth's magnetic field is quickly lost in the noise (it's very weak). In such cases, it's common to use a (laser scan-based or camera-based) localization algorithm (such as AMCL) on top of the IMU filter. The yaw drift doesn't matter to the localization algorithm, because it can use external features in the environment as an external reference.

robertogl commented 3 years ago

As @mintar said correctly with a detailed explanation, these filters do not have orientation drift.

The only issue may derive from the high linear acceleration of the drone because the filters assume that the acceleration measured by the sensor is only gravity. However, this is a good assumption for many conditions. In case the vehicle has a very high acceleration for quite a long time, then the filter will use a wrong reference vector, that will be given by gravity + vehicle acceleration, for correcting the attitude.

If you think you may be using the drone under these circumstances, like aggressive maneuvers, then an EKF may be more appropriate because you can include the motion's acceleration as part of the state to estimate it and then remove it from the total acceleration vector. However, that is easier said than done!