198 Commits

Author SHA1 Message Date
Cavan O'Horo
1beb6d70f0
fix(mathlib): correct MedianFilter comparator to satisfy strict-weak … (#26583)
* fix(mathlib): correct MedianFilter comparator to satisfy strict-weak ordering

- Add explicit NaN handling before comparison operators
- NaN sorted to high end, ensuring finite values cluster at median index
- Guard NaN checks with if constexpr for non-floating-point types
- Replace float equality check with < and > to avoid -Wfloat-equal

Fixes #25917

* fix(mathlib): remove type_traits dependency in MedianFilter

Replace std::is_floating_point_v<T> with a self-contained template
specialization to avoid <type_traits> header, which is unavailable
on NuttX targets compiled with -nostdinc++.

* fixed formating

* test(mathlib): add majority-finite and majority-NaN window tests for MedianFilter

* Moved structs inside namespace math

* clean up

* add two more tests

---------

Co-authored-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-02-25 20:55:35 -09:00
Jacob Dahl
d5ddc9135d
clang-tidy: fix issues (#26498) 2026-02-17 14:09:43 -09:00
Mathieu Bresciani
8ecb76aba2
[Multirotor] add yaw torque low pass filter (#24173)
co-authored-by: danielmellinger <107884356+danielmellinger@users.noreply.github.com>
co-authored-by: Eric Katzfey <eric.katzfey@modalai.com>
2025-01-15 14:02:28 +01:00
Alex Klimaj
1043aebf5d
analog_battery: add option for filter (#23987) 2025-01-03 16:01:16 +01:00
bresch
fa5a781e20 AlphaFilter: set time constant instead of alpha
Then the update function can set the dt at every iteration if needed
2024-12-18 14:11:08 +01:00
bresch
37401d6fd1 AlphaFilter: allow setting dt in update call 2024-12-18 14:11:08 +01:00
BazookaJoe1900
4d83badba1
fix files tags on the header comments (#23564) 2024-09-19 09:25:18 +03:00
Roman Bapst
8221940b60
Added pitot tube icing detection (#23206)
* lib: add FilteredDerivative class

* AirspeedValidator: add first principle check

- filters throttle, pitch and airspeed rate, and triggers
if the airspeed rate is negative even though the vehicle
is pitching down and giving high throttle.
Check has to fail for duration defined by ASPD_FP_T_WINDOW
to trigger an airspeed failure.

* AirspeedValidator: define constants for first principle check

* FilteredDerivative: set initialised to false if sample interval is invalid

* airspeed_selector: improved comment

* increase IAS derivative filter time constant from 4 to 5

* use legacy parameter handling for FW_PSP_OFF

* handle FW_THR_MAX as well

* ROMFS/airframes: exclude some airframes for v6x and v4pro to save flash on them

---------

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
Signed-off-by: RomanBapst <bapstroman@gmail.com>
Co-authored-by: Silvan Fuhrer <silvan@auterion.com>
2024-07-09 11:16:40 +02:00
Daniel Agar
8b9900cce3
mc_pos_control: new velocity low pass and notch filter (optional, disabled by default)
- MPC_VEL_LP: new velocity first order low pass filter (off by default)
 - MPC_VEL_NF_FRQ/MPC_VEL_NF_BW: new velocity notch filter (off by default)
 - MPC_VELD_LP: existing velocity derivative low pass filter, but I've dropped the remaining controllib usage
2024-06-18 11:47:19 -04:00
Daniel Agar
35532609c9
mathlib: utilities refactor float to function template (for optional double precision usage)
Co-authored-by: Mathieu Bresciani <brescianimathieu@gmail.com>
2024-03-20 11:10:37 -04:00
Matthias Grob
4c0b6dbe86 Remove trailing whitespaces and trailing duplicate newlines 2023-12-01 13:11:00 -05:00
bresch
15bb8c0f2e AlphaFilter: add unit tests for Rot3 filtering 2023-07-17 13:43:18 +02:00
bresch
c6aa82441f AlphaFilter: add quaternion specialization
Filtering 3D rotations require special care as they live on a curved space.
2023-07-17 13:43:18 +02:00
bresch
6bee0893de add circle intersection unit tests 2023-03-22 10:03:48 +01:00
bresch
af345c88e9 TrajMath: use fmaxf instead of max 2023-03-22 10:03:48 +01:00
bresch
c7bddda1db MC auto: add maximum RC assist distance during landing 2023-03-22 10:03:48 +01:00
Thomas Stastny
2da10183f3 welford mean: remove old comments 2022-12-06 08:59:12 -05:00
Daniel Agar
89b81b0bd6
create Welford mean Vector with covariance and improve precision with Kahan summation (#20676)
- WelfordMeanVector now computes covariance
 - use Kahan summation for Welford mean (but continue using float32 for actual mean, etc)
 - WelfordMean and WelfordMeanVector handle initial value and count roll over
 - Welford mean count rollover at 16 bit max to prevent numerical issues and shift weight to newer samples
 - sensors/vehicle_imu: update Welford mean usage (now simplified with resets removed)
    - fix vehicle_imu_status accel var, now properly rotated with full covariance matrix
 - gyro_calibration: update Welford mean usage
2022-11-30 14:50:13 -05:00
Matthias Grob
9de3af1cbc Functions: interpolate brackets and spacing 2022-11-23 11:06:44 -05:00
Matthias Grob
870229ef49 FunctionsTest: add isFinite() tests with Vector3f arguments 2022-10-19 19:09:20 +02:00
Matthias Grob
5ca28dd6dc Use isAllFinite() in all places that check finiteness on entire vectors or matrices 2022-10-19 19:09:20 +02:00
Thomas Stastny
da99387215 welford mean: protect against negative variances 2022-09-29 14:14:16 -04:00
Thomas Stastny
d3849c0265 welford mean: convert to matrix only template 2022-09-29 14:14:16 -04:00
Matthias Grob
e115095f70
Functions: correct interpolate function for N points 2022-09-07 08:00:27 +02:00
Matthias Grob
2edb35b1b5
Functions: add gradual function with arbitrary number of corner points 2022-09-07 08:00:26 +02:00
mcsauder
87a5705960 Rename math::gradual() to math::interpolate() and add unit tests to cover additional corner cases. 2022-08-18 14:18:02 +02:00
Daniel Agar
bce4237963 move ekf2 Matrix helper utilities to mathlib 2022-08-05 09:58:07 -04:00
Thomas Stastny
e4b11c49c3
mathlib: add second order reference model filter with optional rate feedback (#19246)
mathlib: add second order reference model filter with optional rate feedback (#19246)

Reference models can be used as filters which exhibit a particular, chosen (reference) dynamic behavior. This PR implements a simple second order transfer function which can be used as such a reference model, additionally with rate feedback. The system is parameterized by explicitly set natural frequency and damping ratio. Another nice externality is that the output state and rate are kinematically consistent. Forward-euler and bilinear transform discretizations for the state space integration step are available.
2022-04-05 10:31:41 +02:00
Matthias Grob
74c0ae6e55 Functions: add sign from boolean function with unit tests 2022-03-23 10:51:45 +01:00
Claudio Micheli
d122513197 extend support for Battery status message
Signed-off-by: Claudio Micheli <claudio@auterion.com>
2022-01-13 08:40:34 +01:00
Daniel Agar
ab547bb982 sensors/vehicle_angular_velocity: RPM notch don't fully disable if first harmonic frequency drops below minimum frequency
- keep higher frequency harmonics enabled per ESC
 - cleanup timestamp handling (timeouts, etc)
2022-01-10 14:51:29 -05:00
Daniel Agar
b58922a5d7 sensors/vehicle_angular_velocity: notch filters automatically reset on sufficient parameter change 2022-01-10 14:51:29 -05:00
Daniel Agar
7d632254be NotchFilter push initialization/reset into filter
- this simplifies the reset by allowing a notch filter to reset as
needed
 - improves cascade initialization, on reset each filter will reset
properly from the previous
2022-01-10 14:51:29 -05:00
Daniel Agar
ecc2ca7f98 mathlib: int16_t negate explicitly handle both INT16_MIN and INT16_MAX
- technically negating INT16_MAX doesn't need special handling, but
this ensures any simple saturation logic downstream works by default
2021-12-15 12:45:58 -05:00
bresch
67a893ac6d WelfordMean: remove unnecessary case for first sample
setting the mean to the sample value and then adding 0 is the same as
setting the mean to zero and then add the sample value divided by 1
2021-12-13 11:42:48 -05:00
bresch
5468841aa5 WelfordMean: add unit test 2021-12-13 11:42:48 -05:00
Matthias Grob
68e2940f58 math: support max of three values additional to min and use it everywhere 2021-12-07 21:06:51 +01:00
Matthias Grob
e8676fe87a BATTERY_STATUS: improve filling cell voltage
according to review comment
2021-12-07 21:06:51 +01:00
bresch
43fb076828 AngularAcceleration: explicitly disable filter when cutoff <= 0 2021-11-18 09:25:47 +01:00
Daniel Agar
0ec3f0d2cb mathlib: LowPassFilter2p update cutoff freq min to match NotchFilter
- numerically the cutoff frequency not being smaller than 1% of the
sample frequency is probably a better choice, but we're mostly filtering
16 bit data now stored in 32 bit float
2021-11-11 11:17:15 -05:00
Daniel Agar
78436e706c mathlib: NotchFilter add optimized parameter update if only notch frequency changes 2021-11-11 11:17:15 -05:00
Matthias Grob
8b37db7825 Functions: fix corner case x_low == x_high == value resulting in NAN
and added unit test to cover it
2021-10-13 17:24:16 -04:00
bresch
1b58202b0d AlphaFilter: add function to set param from cutoff frequency 2021-10-06 16:26:03 +02:00
Matthias Grob
58ea97a699 MulticopterPositionControl: add horizontal margin for saturation cases 2021-09-08 19:55:27 +02:00
Daniel Agar
65745a3676 purge broken qurt support and atlflight boards 2021-07-16 08:53:36 -04:00
Daniel Agar
b5430c22c4 AlphaFilter: move from ecl -> mathlib 2021-07-15 10:38:24 -04:00
Daniel Agar
a5ee28883a gyro_fft: track FFT peaks and median filter frequency 2021-07-06 12:32:25 -04:00
Daniel Agar
d430e13401 sensors: wait for real sample rate to initialize LowPassFilter2p 2021-06-01 08:58:10 -04:00
Daniel Agar
438b0abc7a mathlib: Biquad filters use internal fields for parameter update 2021-06-01 08:58:10 -04:00
Daniel Agar
9661eddef8 mathlib: LowPassFilter2p initialize b0 to 1 for safety 2021-06-01 08:58:10 -04:00