19 Commits
Author SHA1 Message Date
Kevin O'Connor 9c3ba2e3a5 trigger_analog: Automatically determine frac_bits in MCU_SosFilter
The coeff_frac_bits and scale_frac_bits can be automatically
calculated, so there's no need for the callers to specify this
information.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-15 10:15:24 -04:00
Kevin O'Connor b1bbd6dabe trigger_analog: Implement rounding in to_fixed_32()
Round the SOS filter coefficients to the nearest integer (instead of
truncating).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-15 10:13:18 -04:00
Kevin O'Connor 2a5c2fe35c trigger_analog: Require trigger_value to be an integer
Have the callers convert convert the trigger_value from a float to an
integer (if necessary).  This is in preparation for implementing
rounding in to_fixed_32().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-15 10:13:18 -04:00
Kevin O'Connor 22dbdf1029 trigger_analog: Store pre-generated 25hz lowpass filter (at 250sps)
Store the 12 constants needed for the common probe_eddy_current "tap"
filter in trigger_analog.py code.  This avoids requiring "tap" users
to have the scipy python package installed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-12 12:05:39 -04:00
Kevin O'Connor c8b2ef0c21 probe_eddy_current: Allocate just enough SOS entries for filter
Support exporting the current SOS filter size from the DigitalFilter()
class.  Pass that value to the MCU_SosFilter() class to avoid
allocating unneccessary MCU memory (previously 5 entries were
allocated while only 3 are currently needed).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-12 12:05:39 -04:00
Kevin O'Connor 28c236df46 trigger_analog: Merge DerivativeFilter into DigitalFilter
Replace the DerivativeFilter() class with a new add_derivative()
method in DigitalFilter() class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-12 12:05:39 -04:00
Kevin O'Connor f05c66cb9e trigger_analog: Add filters individually in DigitalFilter
Add new add_lowpass(), add_highpass(), add_notch(), and
setup_initial_state() methods to DigitalFilter.  Use these instead of
creating the filters from the constructor.

Also remove the unused filtfilt() method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-04-12 12:05:39 -04:00
Kevin O'Connor 1fe9fb3ad4 trigger_analog: Don't report trigger time as the peak time
There are some rare corner cases where reporting the peak time could
cause hard to debug issues (for example, the peak time could
theoretically be a significant time prior to the actual trigger time,
which could possibly cause unexpected clock rollover issues).  Now
that the host code does not utilize the peak time for "tap" detection,
it can be removed from the mcu code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-29 20:57:55 -05:00
Timofey Titovets 0795fb0141 probe_eddy_current: analyze tap data
To cancel out any lag, filter data on the host
Then to avoid derivatives lag,
compute central difference.

Assume that peak velocity is always the moment
right before collision happens.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-29 20:57:55 -05:00
Timofey Titovets 5fb9902dda sos_filter: define filtfilt call
To implement host-side analysis of tap data,
we need a way to apply the same filtering as on the mcu.
As bonus, it cancels the induced signal delay.

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-29 20:57:55 -05:00
Kevin O'Connor 5c23f9296a probe_eddy_current: implement tap support
Use SOS filters + derivative filter to generate dF/dT on mcu.
Feed that to the MCU's trigger_analog peak detection.
Interpret peak time as a tap event

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2026-01-29 20:57:55 -05:00
Kevin O'Connor 9a97ade74f sos_filter: Implement auto_offset feature
Add a setting that will enable the mcu sos_filter code to
automatically set an offset using the first read measurement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:55:39 -05:00
Kevin O'Connor 30720d29b5 trigger_analog: Avoid storing value_frac_bits in MCU_SosFilter
It is simpler for callers to convert values to their desired format.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 36b9898117 trigger_analog: Set the MCU_SosFilter coeff_frac_bits in set_filter_design()
This parameter is rarely changed and is directly tied to the
coefficients in the filter "design".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 16755481cc trigger_analog: Support scaling the filter's initial start state
Add a new set_start_state() method to MCU_SosFilter that can arrange
for the filter to better handle a non-zero initial starting state.

Also, this removes the previous 1.0 gram initial start state for load
cells as it tares the initial value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 147022dee2 trigger_analog: Update to support generic trigger types
Rework the trigger_analog code to support different "trigger"
conditions.  This merges in features of ldc1612.c into
trigger_analog.c, such as error code reporting in the MCU.  This is in
preparation for using trigger_analog with ldc1612.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 87c8b505a7 trigger_analog: Attach trigger_analog to sensor during initialization
Avoid setting up a "connect" callback - just register the association
using mcu.add_config_cmd() .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor f9b1b9c1b5 trigger_analog: Create trigger_dispatch within MCU_trigger_analog
Don't require callers of MCU_trigger_analog to create the
mcu.TriggerDispatch() instance - instead, create it within the
MCU_trigger_analog() class.

Also, make it easier to use MCU_trigger_analog without an
MCU_SosFilter - the MCU_trigger_analog can automatically create an
empty filter if needed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00
Kevin O'Connor 402303aa22 trigger_analog: New trigger_analog.py file
Rename sos_filter.py to trigger_analog.py and copy MCU_trigger_analog
class from load_cell_probe.py to this new file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2026-01-25 12:49:01 -05:00