maddevsio / mad-location-manager

Mad Location Manager is a library for GPS and Accelerometer data "fusion" with Kalman filter
MIT License
539 stars 157 forks source link

Speed values and Q matrix #50

Open thxmxx opened 5 years ago

thxmxx commented 5 years ago

Can someone tell me why rebuildQ is in function of m_predictCount since the accDev does not change over time?

Also, do you have some clue on why the speed readings are so wrong?

Thank you

Pstoppani commented 5 years ago

I’ve also been working on fixing the speed reading and this is what I came up with (in C++):

void GPSAccKalmanFilter::rebuildQ(double dtUpdate, double accDev) { double velDev = accDev dtUpdate 100; double posDev = velDev dtUpdate 100; double covDev = velDev posDev; double posSig = posDev posDev; double velSig = velDev * velDev;

m_kf.Q.setData(16,
               posSig, 0.0, covDev, 0.0,
               0.0, posSig, 0.0, covDev,
               covDev, 0.0, velSig, 0.0,
               0.0, covDev, 0.0, velSig);

}

On Sep 2, 2019, at 8:52 AM, Lucas Thom Ramos notifications@github.com wrote:

Can someone tell me why rebuildQ is in function of m_predictCount since the accDev does not change over time?

Also, do you have some clue on why the speed readings are so wrong?

Thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/maddevsio/mad-location-manager/issues/50?email_source=notifications&email_token=AACQKTTZPAUTLBIF3OG6AP3QHUZEHA5CNFSM4IS6XBZ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HI2DP5Q, or mute the thread https://github.com/notifications/unsubscribe-auth/AACQKTWOYIXQQ3J6HMSNLALQHUZEHANCNFSM4IS6XBZQ.

thxmxx commented 5 years ago

@Pstoppani I'm also using a similar approach:

private void rebuildQ(double dtUpdate, double accDev) {
        double velDev = accDev * dtUpdate;
        double posDev = (accDev * dtUpdate * dtUpdate) / 2.0;
        double covDev = velDev * posDev;

        double posSig = posDev * posDev;
        double velSig = velDev * velDev;

        double Q[] = {
                posSig, 0.0, covDev, 0.0,
                0.0, posSig, 0.0, covDev,
                covDev, 0.0, velSig, 0.0,
                0.0, covDev, 0.0, velSig
        };
        m_kf.Q.setData(Q);
    }

I'm working on android btw, there was also a wrong size of B matrix and u vector. They should be (4x2) and (2x1) respectively.

Btw, now it seems the vectors (east, north) from accelerometer are not on the same orientation as the gps speed vectors.

thxmxx commented 5 years ago

I think it's also a mistake to use the orientation from the gps on update cause we have this data more accurate from magnetometer.

Pstoppani commented 5 years ago

Agreed. I did the same thing.

On Sep 2, 2019, at 12:41 PM, Lucas Thom Ramos notifications@github.com wrote:

I think it's also a mistake to use the orientation from the gps on update cause we have this data more accurate from magnetometer.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/maddevsio/mad-location-manager/issues/50?email_source=notifications&email_token=AACQKTWJLDGA34GMP24N2DDQHVT6TA5CNFSM4IS6XBZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5WOWBI#issuecomment-527231749, or mute the thread https://github.com/notifications/unsubscribe-auth/AACQKTWB4VX3PFPQACY6VU3QHVT6TANCNFSM4IS6XBZQ.

farfromrefug commented 5 years ago

@thxmxx @Pstoppani can you elaborate on what you changed for gps orientation?

Pstoppani commented 5 years ago

Sorry, I misunderstood the previous comment. I think it is fine to use the GPS orientation on update since the accel “predicts” are from the IMU at a higher rate than GPS. The Kalman filter combines them properly and I think it is best to use both GPS and IMU orientation.

On Sep 16, 2019, at 8:21 AM, Martin Guillon notifications@github.com wrote:

@thxmxx https://github.com/thxmxx @Pstoppani https://github.com/Pstoppani can you elaborate on what you changed for gps orientation?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/maddevsio/mad-location-manager/issues/50?email_source=notifications&email_token=AACQKTVVLOADCNVCZDTAKYTQJ6QAHA5CNFSM4IS6XBZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6ZQLVI#issuecomment-531826133, or mute the thread https://github.com/notifications/unsubscribe-auth/AACQKTWT52ORHCU7SLSAXE3QJ6QAHANCNFSM4IS6XBZQ.

farfromrefug commented 5 years ago

@Pstoppani thanks! Will test it on my side. I ported the code to JS as i use it within Nativescript cross platform environment. Thanks

thxmxx commented 5 years ago

@farfromrefug Instead of using loc.getBearing() on the SensorGpsDataItem (used on update step), I used the magnetometer reading. I did that because the GPS reading can be 0 in case the bearing is not delivered...

[https://developer.android.com/reference/android/location/Location.html#getBearing()](https://developer.android.com/reference/android/location/Location.html#getBearing())

farfromrefug commented 5 years ago

@thxmxx thanks a lot! will use that too. Now did you get the speed to be accurate? That s actually the reason why i am looking at this lib. My client find the GPS speed to not be accurate and responsive enough. So i look here. Now i have to lib working correctly except for the speed. The reading are wrong. I have looked at both rebuildQ implementations here but i dont get a correct result. Well it see wrong result with my JS port. Need to test android version with your implementation to see what i get

thxmxx commented 5 years ago

@farfromrefug you should also use this #51 It's already merged btw

thxmxx commented 5 years ago

Now did you get the speed to be accurate?

I'm getting the error of +-5Km/h. But I'm still working on that, since I'm using GPS speed on updates and the predict results are still bad.

farfromrefug commented 5 years ago

@thxmxx Thanks for the infos! I added the bearing from sensors as you mentioned (Also reported in test app for easier debug). You can see it here : https://github.com/farfromrefug/mad-location-manager Now what i am seeing is a lot more accurate speed reading from the GPS right now.

My question is this. When updating the Kalman filter with the GPS location, what we are doing is using GPS speed as a reference for the Kalman Filter to "predict" it afterwards based on Linear ACceleration, right? I am not that familiar with the Kalman Filter But if it is so shouldn't we "reset" the Q matrix on new Location update?

What i am seeing when outside is that the GPS speed pretty quickly goes to 0 when i stop walking. But the Filtered speed does not want to go to 0. It just slowly goes down. Also Do you use the m_useGpsSpeed of the GPSKalmanFilter? I am not sure what it does. Thanks

EDIT: found out that article. And i think it is the inspiration for that repo http://scottlobdell.me/2017/01/gps-accelerometer-sensor-fusion-kalman-filter-practical-walkthrough And the output that i have is exactly what a comment is talking about http://scottlobdell.me/2017/01/gps-accelerometer-sensor-fusion-kalman-filter-practical-walkthrough/#comment-3733623833