-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Clock correction tests #328
Conversation
Truncates a timestamp to 40 bits, which is the number of bits used to timestamp events in the DW1000 chip. This truncation ensures that the value returned is a valid time event, even if the DW1000 wrapped around at some point. | ||
*/ | ||
uint64_t truncateTimeStampFromDW1000(uint64_t timeStamp) { | ||
uint64_t mask = 0xFFFFFFFFFF; // 40 bits |
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 was previously masked to 32 bits (0xFFFFFFFF) instead of 40 (0xFFFFFFFFFF). Any reason for it? I understand that, in this case, with 32 bits is enough because the timestamp represents a very short amount of time that can be represented in 32bits, but in general the truncation should be done in 40 bits, right?
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.
Yes, both TDoA2 and TDoA3 only has 32 bits in the protocol for DWM timestamps (see https://wiki.bitcraze.io/doc:lps:tdoa3:protocol). This works as long as we transmit packets more often than the wrap time (about 67 ms) and use sequence numbers.
The current implementation is a bit dirty in that protocol properties leaks into the algorithm. I suggest that you add a parameter with a bit mask to the functions that require truncation of timestamps in your generalized implementation.
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.
It took me some time to see why using 40 bits would throw a wrong result, but I finally got it.
An unrelated question: why in calcClockCorrection in the tdoa3 engine you use uint64_t instead of uint32_t?
bool updateClockCorrection(clockCorrectionStorage_t* storage, const double clockCorrectionCandidate) { | ||
bool sampleIsAccepted = false; | ||
|
||
if (CLOCK_CORRECTION_SPEC_MIN < clockCorrectionCandidate && clockCorrectionCandidate < CLOCK_CORRECTION_SPEC_MAX) { |
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 moved the spec check to the start of the function, so there is no processing of the sample if it is not inside the specs range
if (shouldAcceptANewClockReference) { | ||
fillClockCorrectionBucket(storage); | ||
storage->clockCorrection = clockCorrectionCandidate; | ||
sampleIsAccepted = true; |
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.
In previous implementation, when the sample was accepted after the bucket was emptied, fillClockCorrectionBucket(storage)
and sampleIsAccepted = true
where not called. As a result, the clock was set, but the function was returning false.
I think it can be useful to extract the clock correction functionality. A few comments before I merge it though.
Good job! |
…ine, so the algorithm using it can specify the necessary mask
Added tests for the clockCorrectionEngine
There you go :) |
I have done some testing and I found 3 issues
|
I just added logging capabilities for the clock correction engine. Thanks to it I realised that between two of my drones, the clock correction is going out of the specs values. Did you experience something like this? See attached video: the clock correction candidate grows (due to temperature I guess) and surpasses the maximum spec limit. |
Sorry for the delay... Thanks! |
I extracted the clock correction logic from tdoa3 in its own engine, so it is possible to test it (and reuse it). I created several tests, and fixed some things in the updateClockCorrection() function.
The previous clock correction code is untouched for now. I would like to know if: