Data Processing
The data-processing layer turns ADC samples and sensor updates into board values that the rest of the firmware can trust. It is where the CAN-Gateway cleans up noisy measurements, keeps the runtime sensor objects fresh, and decides when the board has enough data to move on.
The core implementation is found in repos/CAN-Gateway/Core/Src/App/DataProcessing/data_processing.c with header definitions in repos/CAN-Gateway/Core/Inc/App/DataProcessing/data_processing.h.
Signal Processing & Safety Gating
Kalman Filtering (kalman_takasu)
To filter out severe electro-magnetic interference (EMI) and power bus ripple, all continuous analog measurements are fed into a Kalman filter state-space tracker (kalman_takasu).
- Mathematical Model: The system propagates state estimates and covariance matrices using the state-transition matrix
, control distribution matrix , and process noise covariance : - Chi-Squared (
) Outlier Rejection: A statistical threshold test validates each incoming measurement before correction. If a sample deviates too far from the predicted state such that: the filter flags an outlier rejection ( kalman_status = 2). The measurement is discarded, preventing noise spikes or EMI from corrupting the system's filtered estimation.
APPS Safety Validation
The Accelerator Pedal Position Sensors (APPS) are safety-critical. The driver executes strict validation checks in the is_apps_valid function in repos/CAN-Gateway/Core/Src/App/DataProcessing/data_processing.c before forwarding displacement percentages:
- Voltage Bounds Gating: Raw ADC voltages must fall strictly between
and (assuming a reference on the 12-bit ADC). Raw readings outside these limits indicate a short circuit or open circuit condition. - Implausibility Divergence: The normalized readings from
apps1andapps2must not diverge by more thanof the full-scale range: - Fail-Safe Mode: If either boundary is breached, the displacement is immediately overridden to a default fault value of
255. The ECU catches this specific output to trigger a shutdown or power clamp.
Source & Layout Reference
- repos/CAN-Gateway/Core/Src/App/DataProcessing/data_processing.c: Owns the sensor update routines (
process_sensor_data) and the Kalman callback linkages. - repos/CAN-Gateway/Core/Inc/App/DataProcessing/DP_scheduler_vals.h: Defines update frequencies and schedule constants (e.g.
APPS_UPDATE_MS,STEERING_UPDATE_MS). - repos/CAN-Gateway/docs/modules/data-processing/adc-buffer.md: Tracks DMA mapping setups.
