inav icon indicating copy to clipboard operation
inav copied to clipboard

GPS glitch detection improvement

Open xdigyx opened this issue 10 years ago • 24 comments

Let me come back to this topic as the issue #431 has moved a different direction. As I already mentioned formula (INAV_GPS_GLITCH_RADIUS + 0.5f * INAV_GPS_GLITCH_ACCEL * dT * dT) will only work for certain model speed as either INAV_GPS_GLITCH_RADIUS and INAV_GPS_GLITCH_ACCEL are simply contants.

My proposal is to change it as follow:

  1. calc NewDistance between two points (lon,lat), means previous (good values) and new reading location
  2. if NewDistance < INAV_GPS_GLITCH_RADIUS(GPSmeasurementStaticError + 1.0f*sqrtf(sq(lastKnownGoodVelocity.V.X)+sq(lastKnownGoodVelocity.V.Y)) * dT) then accept the GPS readings else or skip it or replace it with predictedGpsPosition. Probably could be skipped if velocity is less than 1m/s.

where GPSmeasurementStaticError - normally GPS error is approx 0.5-10[m] depending of GPS type/model INAV_GPS_GLITCH_RADIUS - a constant, say 1.20f

xdigyx avatar Aug 27 '16 18:08 xdigyx

This will not always work. If the copter starts rapidly accelerating from zero velocoty then we might get outside of INAV_GPS_GLITCH_RADIUS and never get back in. We need something smart enough to detect this situation.

digitalentity avatar Aug 29 '16 00:08 digitalentity

That would need to be veeeery powerfull and light copter to pass a distance of (say) 3m from start (0m/s) within 200ms (5Hz)... Even though GPS speed is nearly never 0m/s. And even more: I can not see a chance that it would change its speed itself that much. Such speed/acc changes theoretically could be possible only when an operator is actually controlling the copter (by moving a stick), so under this circumstances FC does not control the flight and GPS readings (I believe) are used for indication only.

xdigyx avatar Aug 29 '16 05:08 xdigyx

GPS readings are never for indication only. They are always used to estimate position and if there's a chance that algorithm will start permanently ignoring GPS readings without a possibility to recover - it's not reliable.

digitalentity avatar Aug 29 '16 05:08 digitalentity

Hm...OK, agree. so we also need to take a care about predicted position, but this applies rather aside of PH mode (where glitch is most visible) or to be more generic - while no rcCommans are applied. Maybe here at least INAV_GPS_GLITCH_ACCEL could be then decreased?

Or.. also 10m/s/s seems to be quite high for some copters/users. Maybe a tuning function could be implemented for adaptation of INAV_GPS_GLITCH_RADIUS (this I believe depends on GPS model/num of sats) and INAV_GPS_GLITCH_ACCEL values or make it avaliable in CLI?

Or maybe it is also a need for the recovery algorithm improvement.

EDIT:

here is a piece of log: time (us) GPS_fixType GPS_numSat GPS_altitude GPS_speed (m/s) GPS_ground_course GPS_hdop GPS_eph GPS_epv 105727183 2 16 124 0.07 181.4 129 95 132 105927635 2 16 124 17.76 171.4 131 95 132

Second line is where glitch occurred. Here is visible, that GPS speed increased from 0.07m/s to 17.76 (within 200ms), which of course is not possible.

xdigyx avatar Aug 29 '16 05:08 xdigyx

I have made some work on the topic... after DE referenced #206 I actually had same feeling about GPS reading and tried make same tests and actually for some extends I have a different results: as for Pedestrian mode I had very similar position plot, but for A-1G mode besides less fluctuating plot, there were significant location jumps... such as @theArchLadder posted here: https://cloud.githubusercontent.com/assets/11679497/15257042/bb2141ba-1944-11e6-9a87-a6dd31ef08e4.png Which actually seems to be much closer to the truth, as in A-1G mode GPS module is less filtering (so most reads will be closer the actual position, but more jumps) the data than for Pedestrian mode. Therefore I believe that while iNav have not implemented a good GPS data filtering, it is safer to use the Pedestrian mode (at least no sudden "fly-away"s and smoother nav flights).

So at first, a part of glitch detection probably it would be more efficient to find a best GPS configuration. And regarding to this: I found out that although SBAS is set to NONE (iNav ver 1.2), after connecting it to u-center we can reed it's actually enabled (is the setting actually stored to GPS memory?).

Another point then once GPS filtering is implemented in my opinion the filtering for Position Hold should be stronger than for other modes (which are more dynamic). Probably this could be better solution than detecting a glitch (which as shown in the pic above is not just a single position read, but also few next readings).

I also need to check A-4G mode (where GPS module does not apply any filtering), maybe there even more readings would be very close to real position, most significant jumps could be just cut off, and the rest of the data filtered.

EDIT:

Just checked A-4G mode and as predicted: the circle of GPS readings spread is less (approx 3m) versus A-1G (approx 5m) and jumps are also bigger and faster returns to the initial position. @digitalentity my proposal is to set GPS module to A-4G dynamic mode (make sure the setting are saved, including SBAS), cut-off all jumps (based on acc readings with some margin) and filter the rest of readings. the next step could be prediction if the filtering would be not sufficient.

xdigyx avatar Sep 14 '16 11:09 xdigyx

@xdigyx I'm doing some smarter filtering in #543 now. However the code is completely untested. If you have some spare time - please fly it without any altitude hold/position hold/RTH modes and record some data for me to analyze.

digitalentity avatar Sep 14 '16 18:09 digitalentity

ok, just share the hex (target naze) or instruct me how to get it from travis and write some info what/how should I test. If someone also could verify SBAS not being disabled by FW gps autoconfig as I wrote in my previous post.

xdigyx avatar Sep 14 '16 19:09 xdigyx

@xdigyx hex attached. Please be extremely cautious when enabling AltHold or PosHold mode. Changes to position estimation code are large and might be buggy, inav_1.2.1_NAZE.hex.gz

Regarding SBAS - GPS autoconfig code in INAV doesn't save settings to GPS EEPROM or battery-backuped memory. Therefore configured settings are only active until power-cycling the module. Once power-cycled, settings from EEPROM will be in effect until INAV autoconfig re-configures the module.

digitalentity avatar Sep 16 '16 05:09 digitalentity

First data batch NewPosEst.TXT

xdigyx avatar Sep 16 '16 17:09 xdigyx

Thanks for testing! Looks like I made something very wrong in new position accuracy calculations. More thinking required.

digitalentity avatar Sep 16 '16 18:09 digitalentity

no problem. just to clarify one point (not sure whether this might affect the results), while flashing "full chip erase" was not performed, so settings from 1.2 RC5 were used. For a second I used Alt hold at the beginning and the model oscillated up and down +-5meters...

xdigyx avatar Sep 16 '16 18:09 xdigyx

Yes, I obviously messed up something.

digitalentity avatar Sep 16 '16 18:09 digitalentity

I think I know what might have happened, btt It will take time to analyse the data with Octave and confirm.

digitalentity avatar Sep 16 '16 18:09 digitalentity

ok I tried to follow the code changes but for now it's too complicated for me... Once new soft is ready, do not forget to provide .hex for further testing ;)

xdigyx avatar Sep 16 '16 18:09 xdigyx

@digitalentity are you sure the eq: powf(M_Ef, -sq(x) / (2.0f * sq(curveWidth))); is right?

I am a bit confused, but sq() => square root? normal distribution would be rather powf( e,-(x * x)/(2 * width * width) ) ...if I'm not mistaken

xdigyx avatar Sep 17 '16 12:09 xdigyx

@xdigyx sq = square, not square root

#define sq(x) ((x)*(x))

martinbudden avatar Sep 17 '16 13:09 martinbudden

@xdigyx hi, sorry for long delay. I've made some fixes to the code, would appreciate if you collect some more data for me to analyse. Use same protocol as last time - please don't use GPS/BARO-aware modes. inav_1.2.1_NAZE.hex.gz

digitalentity avatar Sep 24 '16 11:09 digitalentity

Hi @digitalentity here is the log. 1.12.1test.TXT Bad or not, within 2/3 of the flight baro is on. It took me a while to recognize that I flew with this being ON..

xdigyx avatar Sep 25 '16 18:09 xdigyx

@digitalentity Can this issue be closed due to #543 and the changes there in regard to the changed done there?

oleost avatar Nov 22 '16 21:11 oleost

Not really, there is still improvements to be made to GPS glitch detection. #543 only added better handling of the GPS outage itself.

digitalentity avatar Nov 22 '16 23:11 digitalentity