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
AP_Compass: Add an index to avoid ergodicity of search in '_samples_collected', w… #12177
Conversation
…hich would certainly met the input sample itself to force the distance to zero and return false.
Please help me review this bug fix trial which is concern to issue 12171 |
Please see here, the state trasition of mag-cal from ...STEP_ONE to ...STEP_TWO:
And then in thin_samples():
Finally, in accept_sample():
You would clearly find out the sample send into accept_sample() would be elimilated by the ergodicity search of distance check in the same total sample buffer which include the sample sent in itself. |
@tridge , I looded through all the history to find you committed these part. Would you help me review this PR here? |
@rmackay9, can you please have a look? |
@@ -383,7 +383,8 @@ void CompassCalibrator::thin_samples() { | |||
} | |||
|
|||
for(uint16_t i=0; i < _samples_collected; i++) { | |||
if(!accept_sample(_sample_buffer[i])) { | |||
CompassSample temp = _sample_buffer[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the extra temporary variable 'temp' ?
@@ -393,6 +394,29 @@ void CompassCalibrator::thin_samples() { | |||
update_completion_mask(); | |||
} | |||
|
|||
bool CompassCalibrator::accept_sample(const Vector3f& sample, const uint16_t idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a comment to this function explaining what it is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a copy of the existing accept_sample which exempts an item from the distance check.
It would better be done with an optional int32_t idx
with a magic value of -1
meaning don't exempt any element from the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made a simple commit which I would thought it could be somewhat a litter clear for you guys to understand what I mean to talked about in my PR. I then would push a better commit to this PR based in @peterbarker mentioned above.
do you have a tlog of the old method failing? I don't quite see how it fails |
@tridge this definitely looks suspect. When we're thinning samples we pass in an element from the sample buffer into accept_sample - note that we don't pass in anything about which sample we're testing. In accept_sample, we loop over all of the samples in the sample buffer - and that must include the one we've just passed in (as no index variable have been modifed). This line here:
Will always get a distance of zero, accept will then return false. We prune exactly half the samples (the first half in the list). |
OK, after discussing with @peterbarker we understand the problem now. We will include this in an upcoming PR that cleans up this calibrator. |
@peterbarker Thank you for your reply, but I didn't get the query message or e-mail from @tridge from github. Which I shall carefully check my account setting later. @rmackay9 ,Yes, that's exactly what I mean here. |
@lukezhqin Randy is incorporating this fix into a more elaborate PR here: https://github.com/ArduPilot/ardupilot/pull/12864/files Many thanks for tracking this one down. |
If it's OK, I will close this PR because the fix is included in this PR: #12864 |
@peterbarker @rmackay9 This did bother me a lot in the past days. Many thanks to you guys at last. |
Add an index to avoid ergodicity of search in '_samples_collected', which would certainly met the input sample itself to force the distance to zero and return false.