Skip to content

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 G, and process noise covariance Q:xk|k1=Φxk1|k1Pk|k1=ΦPk1|k1ΦT+GQGT
  • Chi-Squared (χ2) Outlier Rejection: A statistical threshold test validates each incoming measurement before correction. If a sample zk deviates too far from the predicted state xk|k1 such that:(zkHtxk|k1)2>χlimit2the 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:

  1. Voltage Bounds Gating: Raw ADC voltages must fall strictly between 0.5 V and 4.5 V (assuming a 3.3 V reference on the 12-bit ADC). Raw readings outside these limits indicate a short circuit or open circuit condition.
  2. Implausibility Divergence: The normalized readings from apps1 and apps2 must not diverge by more than 15% of the full-scale range:|APPS1APPS2|15%×ADCmax
  3. 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

Released under the MIT License.