Repository navigation
Conversation
[Low impact] The change adds an optional utility without changing existing workflows. Fix the cutoff conversion and its test before merging.
|
Comment on lines
+93
to
+94
| param_.time_constant = | ||
| Scalar(1) / (Scalar(2) * static_cast<Scalar>(TWO_PI) * cutoff_frequency); |
There was a problem hiding this comment.
Cutoff settings smooth too little
SetCutoffFrequency computes 1 / (4πf) because TWO_PI already equals 2π. Calling SetCutoffFrequency(40) sets a time constant of about 0.001989 seconds instead of 0.003979 seconds. The filter responds faster and passes more noise than requested.
Remove the extra Scalar(2) and fix the test, which repeats the same formula.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/utils/lpfilter.hpp
Line: 93-94
Comment:
**Cutoff settings smooth too little**
`SetCutoffFrequency` computes `1 / (4πf)` because `TWO_PI` already equals `2π`. Calling `SetCutoffFrequency(40)` sets a time constant of about 0.001989 seconds instead of 0.003979 seconds. The filter responds faster and passes more noise than requested.
Remove the extra `Scalar(2)` and fix the test, which repeats the same formula.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Low-pass filtering was only available through the verdancy-org/LPFilter module, so a module that needs it pulls a repository dependency for twenty lines of arithmetic. Add the filter to src/utils, next to PID and the transform utilities. The filter follows the PID shape: a Param struct holding the time constant, a constructor that takes it, SetParam for a later change, one Reset(), and no default configuration, so an unconfigured filter cannot exist. It advances with the sample interval: alpha = dt / (tau + dt). SetCutoffFrequency and SetAlpha convert a cutoff or a coefficient into the time constant, keeping the rate dependence of a coefficient visible at the call site. The first sample becomes the state, so callers never track initialization. The filter allocates nothing and needs no exceptions or RTTI. test/automatic/utils/low_pass_filter covers the step response, dt <= 0, Reset, the two conversions, SetParam, and an Eigen vector, whose coefficient type is deduced from T.
molqzone
force-pushed
the
feat/low-pass-filter
branch
from
November 21, 2026 14:47
75dd0c4 to
89f242a
Compare
This branch has not been deployed
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.
Adds a first-order low-pass filter to
src/utils. Header-only, no allocation,no exceptions or RTTI.
The filter stores the time constant and advances with the sample interval:
alpha = dt / (tau + dt).SetCutoffFrequencyandSetAlphaconvert a cutoffor a coefficient into the time constant, so the rate dependence of a
coefficient stays visible at the call site. There is no default configuration,
so an unconfigured filter cannot exist.
The first sample becomes the state;
Reset()clears it.Tcan be a scalar oran Eigen vector, whose coefficient type is deduced from the matrix type.
test/automatic/utils/lpfiltercovers the step response,dt <= 0,Reset,the two conversions,
SetParam, and an Eigen vector.New files only:
src/utils/lpfilter.hppand its test.