Skip to content

Commit 5bf45f8

Browse files
committed
Extract DEAD_DECAY_FACTOR and SENSOR_SANITY_LIMIT_MT to Config.h
Two feel-tuning magic numbers hardcoded by PR sb-ocr#3: - MotionController.cpp - 0.8f per-tick decay factor applied to the Kalman estimate when the current measurement is below the dead zone. - SensorController.cpp - 500.0f mT outer bound for the sensor sanity check. EXTRA_SHORT_RANGE actually peaks around 130 mT; the note about that is moved into the Config comment where it is discoverable. Both now live in Config.h alongside the other user-tunable knobs (KALMAN_Q, KALMAN_R, SENSITIVITY_EXP, etc.) as DEAD_DECAY_FACTOR and SENSOR_SANITY_LIMIT_MT.
1 parent a52c547 commit 5bf45f8

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

firmware/include/Config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ const float KALMAN_R = 4.0;
4343
// 1.0 = linear, 3.0 = cubic (fine control at small deflections, fast at large).
4444
const float SENSITIVITY_EXP = 3.0;
4545

46+
// Per-tick multiplier applied to the Kalman estimate when the measurement
47+
// is below the dead zone. Lower = faster decay to zero, 1.0 = no decay.
48+
const float DEAD_DECAY_FACTOR = 0.8;
49+
50+
// Sensor validation: reject any frame where a magnetic axis reads beyond
51+
// this magnitude. EXTRA_SHORT_RANGE peaks around 130 mT; anything past
52+
// this bound indicates a read fault or corrupted frame.
53+
const float SENSOR_SANITY_LIMIT_MT = 500.0;
54+
4655
// Final axis output range
4756
const float AXIS_LIMIT = 350.0;
4857

firmware/src/controllers/MotionController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void MotionController::compute(const float raw[9], const float* baseline, float
136136
if (fabsf(y[i]) < dead) {
137137
// Below dead zone: decay Kalman estimate toward zero gradually.
138138
// Preserve covariance so the filter doesn't jitter at the boundary.
139-
kalmanX_[i] *= 0.8f;
139+
kalmanX_[i] *= Config::DEAD_DECAY_FACTOR;
140140
kalmanP_[i] = fminf(kalmanP_[i] + Config::KALMAN_Q * 0.1f, 1.0f);
141141
} else {
142142
kalmanStep(i, y[i]);

firmware/src/controllers/SensorController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool SensorController::readRaw(float out[9]) {
7676
// Validate: reject frames where any axis reads exactly zero across all
7777
// components (likely I2C failure) or exceeds sane sensor range.
7878
for (int i = 0; i < 9; i++) {
79-
if (fabsf(out[i]) > 500.0f) return false; // Way outside EXTRA_SHORT_RANGE
79+
if (fabsf(out[i]) > Config::SENSOR_SANITY_LIMIT_MT) return false;
8080
}
8181
// Check for dead sensor (all three axes exactly zero)
8282
for (int s = 0; s < 3; s++) {

0 commit comments

Comments
 (0)