# Can a Madgwick IMU filter be used to determinate the tilt angle with respect to the horizontal plane

I am using a 3-axis accelerometer and a 3-axis gyroscope to estimate the tilte angle between the X axis of the IMU sensor and the ground (horizontal plane). My robot is stationary at power up, so I can determine the initial tilt angle just by using the data acquired from the accelerometer. However, when he starts moving I can not do that anymore. That is why I need a sensor fusion algorithm.

Can I use the Madgwick filter which does not include a magnetometer? Note that my robot can rotate around any of the three Cartesian coordinate system axis while he operates in free space. I still need time to understand the filter myself, so I do not know the answer yet.

• Gravity always points down, and North always points North. If you don't have a magnetometer then you can't fix the rotation/heading, but you can still fix roll and tilt angles. Madgwick filter has an implementation for both with and without a magnetometer. You can find implementations at the bottom of this page, in the Downloads section or here on GitHub.
– Chuck
Jan 31 at 1:23

Unless your robot is experiencing sustained accelerations on the order of 1g, ignoring linear accelerations to compute the tilt angle should work well. Besides, typically the weight on the accelerometer measurement is much lower than that on the gyroscope measurement in a standard complementary filter so any linear accelerations should only add a small bias. How is your robot moving at startup? What sort of accelerations are you seeing?

If on startup, the robot is at an arbitrary orientation AND experiencing excessive linear accelerations (not velocities), then it may be tricky as the initial orientation computed may be quite wrong. In that case, if there is any way to know the linear motion in advance, e.g. if the motion is a result of control inputs, then that known acceleration can be subtracted before the accelerometer readings are used in the filter.

A particularly tricky case may be when the robot starts in free fall. If it doesn't hit terminal velocity to experience a drag force, and without any other forces acting on it, I don't see a way to measure the tilt relative to the ground with an accelerometer and gyroscope. The accelerometer will measure all zeros and give no tilt information. However, the drag force in most situations may be enough to give some bearing, but you are not guaranteed that the force is parallel to the force of gravity.

If one wishes to estimate the tilt of a robot in a parabolic free fall with air resistance. Then I can imagine some algorithm that attempts to estimate the tilt using the direction of the drag force and some estimated progress along a parabolic arc. It sounds complicated though.

I'm not familiar with the Madgwick filter specifically, but to me it sounds like some variant of a complementary filter.

• Hello Alex, At startup my robot is not moving. He is completely stationary, so I am able to calculate the tilt angle just by reading the X and Y acceleration values from the accelerometer. That lets me generate an inital vector that I can use in the Madgwick filter algorytm. As far as I understand the algorythm of the filter, I should be able to do what I inteded. However I do not completely undestand everything about the algorythm, so I cannot say for sure yet. The Madgwick filter differs from Kalman and complementary filter. After startup my robot can do linear and rotational motion. Sep 13, 2021 at 9:20
• The Madgwick filter is based on a gradient descent algorithm and outperforms the Kalman filter. You can read Madgwick's thesis here. A complimentary filter is a fancy term for asymmetric averaging. Instead of taking 50% of one reading and 50% of another, you can take $\alpha$ percent of one reading and (1-$\alpha$) of the other. If $\alpha$ is 0.5 then it's an average.
– Chuck
Jan 31 at 1:12
• Your answer here is a bit backwards; you can ignore gyro outputs because they don't give you any constant reference. Gravity always points down, so unless there's some sustained acceleration (rotating machine, etc.) you can always count on the long-term acceleration to point down. This gives the Madgwick filter some way to find the roll and tilt angles. Yaw/heading is only fixed with a magnetometer. Gyros give better short-term estimates of motion, but the bias and bias instability will cause drift in gyro-only angle estimates. Roll and pitch are fixed by gravity and come from acclerometers.
– Chuck
Jan 31 at 1:25