Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite climb bug when using EK3_OGN_HGT_MASK #26917

Merged
merged 3 commits into from
May 23, 2024

Conversation

peterbarker
Copy link
Contributor

This bug-finding and fix are not mine. The autotest is mine, however :-)

@pavloblindnology reported them here: #24039

@pavloblindnology was this the fix you were recommending?

This PR is based on #26916 which adds some infrastructure changes to make autotesting with baro drift easier.

@peterbarker peterbarker force-pushed the pr/ogn-bug branch 2 times, most recently from 04f24e7 to c57c5c0 Compare April 29, 2024 07:52
@rmackay9
Copy link
Contributor

@peterbarker,

I guess this is a bug that can happen on a real vehicle as well? It's not just a SITL issue is it?

@peterbarker
Copy link
Contributor Author

Some pictures from a log where we never install the check_altitude message hook (pre-fix):
image

@peterbarker
Copy link
Contributor Author

I guess this is a bug that can happen on a real vehicle as well? It's not just a SITL issue is it?

I have no idea.

I'm not even sure I'm replicating what @pavloblindnology is seeing.

@tridge tridge requested a review from priseborough May 1, 2024 07:12
@tridge tridge removed the DevCallEU label May 1, 2024
@tridge tridge mentioned this pull request May 1, 2024
52 tasks
@pavloblindnology
Copy link
Contributor

@peterbarker Sorry for late response. Yes, the fix is right.

I guess this is a bug that can happen on a real vehicle as well? It's not just a SITL issue is it?

@rmackay9 I tested this in SITL only, but I don't see any reason why it can't happen on a real vehicle. I don't remember all the details of my tests as it was quite a while ago. But the main idea is that with EK3_OGN_HGT_MASK=5, Ardupilot doesn't use previously computed value of ekfGpsRefHgt to convert new GPS measurements. And as barometer altitude usually rises faster than GPS altitude, this results in constant ekfGpsRefHgt monotonical correction.

} else {
gpsDataNew.hgt = 0.01 * (gpsloc.alt - EKF_origin.alt);
}
gpsDataNew.hgt = (ftype)((double)0.01 * (double)gpsloc.alt - ekfGpsRefHgt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this removes the (1<<2) bit check on the input side, do we need to change the two on the output side?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the divergence, but leaves the feature broken. If a hot fix is required, remove the option to set bit 2. Looking at the code I think the underlying problem is that the offset beteween the origin height and ekfGpsRefHgt is is not being added tot he baro alt if bit 0 is set or to the range finder if bit 1 is set when in combination with bit 2. I will look at the code this week and try to come up with a longer term fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forked this PR branch here https://github.com/priseborough/ardupilot/commits/PR26917/ and pushed an alternative set of patches for this issue that preserve the intent of the EK3_OGN_HGT_MASK bit 2 option.

priseborough@a38c01a
priseborough@f6a56d4

It passes the new autotests on my PC.

@rmackay9 rmackay9 mentioned this pull request May 20, 2024
92 tasks
@davidbuzz
Copy link
Collaborator

@priseborough

@peterbarker
Copy link
Contributor Author

Note that my autotest only reproduces the issue - I didn't point any fail condition in for the specific bug

Copy link
Contributor

@priseborough priseborough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forked this PR branch here https://github.com/priseborough/ardupilot/commits/PR26917/ and pushed an alternative set of patches for this issue that preserve the intent of the EK3_OGN_HGT_MASK bit 2 option.

priseborough/ardupilot@a38c01a
priseborough/ardupilot@f6a56d4

It passes the new autotests on my PC.

} else {
gpsDataNew.hgt = 0.01 * (gpsloc.alt - EKF_origin.alt);
}
gpsDataNew.hgt = (ftype)((double)0.01 * (double)gpsloc.alt - ekfGpsRefHgt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the divergence, but leaves the feature broken. If a hot fix is required, remove the option to set bit 2. Looking at the code I think the underlying problem is that the offset beteween the origin height and ekfGpsRefHgt is is not being added tot he baro alt if bit 0 is set or to the range finder if bit 1 is set when in combination with bit 2. I will look at the code this week and try to come up with a longer term fix.

} else {
gpsDataNew.hgt = 0.01 * (gpsloc.alt - EKF_origin.alt);
}
gpsDataNew.hgt = (ftype)((double)0.01 * (double)gpsloc.alt - ekfGpsRefHgt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forked this PR branch here https://github.com/priseborough/ardupilot/commits/PR26917/ and pushed an alternative set of patches for this issue that preserve the intent of the EK3_OGN_HGT_MASK bit 2 option.

priseborough@a38c01a
priseborough@f6a56d4

It passes the new autotests on my PC.

@peterbarker
Copy link
Contributor Author

peterbarker commented May 22, 2024

I've reset this to Paul's branch and rebased this PR on master and removed the commit/revert pair.

So some less-than-fortunate news. Somehow tridge's PR to use a better atmospheric model (#26915) also fixed the autotest.

I bisected the code to work that out:
image

IOW the autotest passes before the fixes in this branch are applied, which is Less Than Good. OTOH, since I've no idea how tridge's patch influences things, I'm quite happy to just carry on.

@priseborough are you OK with merging this even 'though the problem doesn't reproduce on master post-tridge-patches?

@priseborough
Copy link
Contributor

Will check log and get back to you

@tridge tridge removed the DevCallEU label May 22, 2024
@priseborough
Copy link
Contributor

The better atmospheric model changes how the offset between baro height and GPs height varies so it makes sense the autotest would be sensitive to this. I'm happy to merge on the basis the old model shows it failing before. It should be possible to make it fail on the new model by fudging the baro scale factor or similar.

peterbarker and others added 3 commits May 22, 2024 20:21
The offset generated by the EK3_OGN_HGT_MASK parameter bit 2 option is applied to the baro or range finder sensor so it does not have to be applied to the local position height.
@peterbarker
Copy link
Contributor Author

The better atmospheric model changes how the offset between baro height and GPs height varies so it makes sense the autotest would be sensitive to this. I'm happy to merge on the basis the old model shows it failing before. It should be possible to make it fail on the new model by fudging the baro scale factor or similar.

Thanks Paul. Marking as MergeOnCIPass.

@peterbarker peterbarker merged commit 91423d4 into ArduPilot:master May 23, 2024
91 checks passed
@peterbarker
Copy link
Contributor Author

Thanks @pavloblindnology - we've merged a fix for the bug you found.

@peterbarker peterbarker deleted the pr/ogn-bug branch May 25, 2024 00:33
@ddomit
Copy link

ddomit commented Jun 10, 2024

Any idea to which version of arducopter is going to include this?

Does ":Apply corrections to local position" mean that it will update the home altitude accordingly? i have tried using it set to 1, but when it comes back to home its sometimes 10 meters off...

Log:
https://drive.google.com/file/d/1oEntDXzGjo2kmv54ihtVaRBwAyEa0qKx/view?usp=drive_link

@rmackay9
Copy link
Contributor

rmackay9 commented Jun 12, 2024

Hi @ddomit,

This PR's fix will most likely be included in 4.5.5. We would normally have included it in the next release (4.5.4) but that's likely to include only a single small fix

@ddomit
Copy link

ddomit commented Jun 13, 2024

Hi @ddomit,

This PR's fix will most likely be included in 4.5.5. We would normally have included it in the next release (4.5.4) but that's likely to include only a single small fix

Thanks!! Do you think this fix and update will solve the issue im having? Will it update the home location with the altitude corrections it does?

@rmackay9
Copy link
Contributor

@ddomit,

I think it's best to move this to the support forums. Support within a PR is difficult and the issue may very well be unrelated. Could you create a new topic in the support forum?

@ddomit
Copy link

ddomit commented Jun 14, 2024

@ddomit,

I think it's best to move this to the support forums. Support within a PR is difficult and the issue may very well be unrelated. Could you create a new topic in the support forum?

Thanks @rmackay9 it is okay i'll wait for the release, i dont need to create an issue.

I just have one doubt, i havent found anywhere, does "Apply corrections to local position" mean that it will update home altitude as well?

@rmackay9
Copy link
Contributor

Hi @ddomit,

If bit2 ("Apply corrections to local position") is set then the vehicle's current altitude estimate is adjusted (instead of adjusting the EKF origin's altitude). The EKF doesn't have access to the AHRS home location (including its altitude) so it is not directly adjusting it. To put it another way, if bit2 is set and the EKF adjusts the vehicle's current altitude, before and after a flight, if you asked the AHRS what the home lat, lon and alt are it should show that they have not changed.

@postelzhuk
Copy link

Hi everyone. I made some SITL-tests from master, Plane-4.4, Plane-4.5. Almost sure this changes also fixes problem with baro drift:
https://discuss.ardupilot.org/t/ekf3-use-barometer-and-gps-for-altitude-posz/119540/2
EK3_OGN_HGT_MASK, 5 does help with SLOW baro drifts after this changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 4.5.5-beta1
Development

Successfully merging this pull request may close these issues.

8 participants