Repository navigation
Add one euro filter to KER streams to stabilize - #22
Merged
Merged
Conversation
Contributor
|
How about using the I checked the firmware, and
So when The firmware already sends the acquisition time as
The change is small. The wraparound and restart handling can stay as it is: class SampleClock:
"""Sample time in seconds from the device "timestamp" field (micros())."""
def __init__(self):
self.timestamp_prev = None
self.t = 0.0
def update(self, timestamp_us: int) -> tuple[float, bool]:
if self.timestamp_prev is None:
self.timestamp_prev = timestamp_us
return self.t, False
# micros() is uint32 and wraps about every 71.6 minutes.
gap = (timestamp_us - self.timestamp_prev) & 0xFFFFFFFF
self.timestamp_prev = timestamp_us
# A huge gap is the timestamp going back (device restart).
if gap >= 1 << 31:
return self.t, True
self.t += gap * 1e-6
return self.t, False- if one_euro is not None and "seq" in data:
- t, restarted = clock.update(data["seq"])
+ if one_euro is not None and "timestamp" in data:
+ t, restarted = clock.update(data["timestamp"])What do you think? |
seq counts frames the firmware sends, not samples it acquires: when streamTask falls behind and xQueueOverwrite() drops a sample, time passes but seq does not advance, so seq * period underestimates dt. The 1 kHz rate is also only nominal. The firmware stamps every sample with micros() at acquisition and sends it as "timestamp", so use that instead. This drops the --ker-rate-hz option. Wraparound and restart handling stay the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@kou I made some change to the timestamp detection. What do you think? |
Contributor
|
Merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent irrelevant shakiness