juangallostra / AltitudeEstimation

A two-step Kalman/Complementary filter for Estimation of Vertical Position using an IMU-Barometer sytem
MIT License
58 stars 20 forks source link

Kalman Filter always outputs negative acceleration and velocity #21

Open nocs85 opened 5 months ago

nocs85 commented 5 months ago

Hello!

I am extremely interested in this Kalman Filter but unfortunately I am unable to let it calculate a positive acceleration, regardless of the Inputs (and signs) I provide. Here is a very simple sample code with two variations but the result is always the same, the Kalman filter returns always negative velocity and negative acceleration :(

float accelData[3];
accelData[0] = 0;
accelData[1] = 0;
accelData[2] = -0.1;

float gyroData[3];
gyroData[0] = 0;
gyroData[1] = 0;
gyroData[2] = 0;

altitude.estimate(accelData, gyroData, 0, micros());

altitude.getAltitude(), altitude.getVerticalVelocity() and altitude.getVerticalAcceleration() return always negative values, regardless of sign of value assigned to accelData[2], i.e. accelData[2] = -0.1; and accelData[2] = 0.1; lead always to the same results.

Can you please help?

PS: I previously tried with real IMU and pressure sensor data from BNO085 and BMP390 but since that didn't work I tried the basic example above and still I get the same results: always negative acceleration, negative velocity, decreasing altitude, regardless of the signs of the IMU signals

mgrouch commented 5 months ago

Might be because it includes gravitational g and you are not accelerating with higher than g in opposite direction?

nocs85 commented 5 months ago

Oh yeah, that did the trick! Assigning "1" stabilized the altitude at 0m, variations around 1 lead to increase or decrease of the altitude correctly! :)

I assume the accelerations passed to the kalman filter must be in global/inertial coordinate system (and not in local/body coordinate system), is that correct?

One more question: what is the purpose of the gyro-rates in the kalman filter?

mgrouch commented 5 months ago

Standing on Earth we are not at rest in inertial system. We actually accelerating with g. That’s why we feel gravity. Gravity really doesn’t exist as a force (compared to electromagnetic force which has a field and it’s quantum). We are accelerating not because of the force applied to us but rather because of time-space curving around masses. That’s the current view per general relativity theory.

nocs85 commented 5 months ago

What are the gyro values for in the kalman filter?