From 9cf7fcb5548ee3a90d7783cedcabe8505294b041 Mon Sep 17 00:00:00 2001 From: Nils Schulte Date: Wed, 11 Mar 2026 22:45:22 +0100 Subject: [PATCH] CalibratedSensor: Allow calibration with provided lut If a lut was provided the calibration was simply skipped. If you do not provide a lut it gets allocated but you cant extract the data at runntime (only via printLUT). --- src/encoders/calibrated/CalibratedSensor.cpp | 7 +++---- src/encoders/calibrated/README.md | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/encoders/calibrated/CalibratedSensor.cpp b/src/encoders/calibrated/CalibratedSensor.cpp index 76b8ced..cfc6ee1 100644 --- a/src/encoders/calibrated/CalibratedSensor.cpp +++ b/src/encoders/calibrated/CalibratedSensor.cpp @@ -101,12 +101,11 @@ void CalibratedSensor::calibrate(FOCMotor &motor, int settle_time_ms) { // if the LUT is already defined, skip the calibration - if(calibrationLut == NULL) { + if (calibrationLut == NULL) { allocated = true; calibrationLut = new uint16_t[n_lut]; - }else{ - SIMPLEFOC_DEBUG("SEN_CAL: Using pre-defined LUT for calibration."); - return; + } else { + SIMPLEFOC_DEBUG("SEN_CAL: Overwriting pre-defined LUT for calibration."); } SIMPLEFOC_DEBUG("SEN_CAL: Starting Sensor Calibration."); diff --git a/src/encoders/calibrated/README.md b/src/encoders/calibrated/README.md index 01d467a..f8cfdb5 100644 --- a/src/encoders/calibrated/README.md +++ b/src/encoders/calibrated/README.md @@ -125,7 +125,7 @@ If you calibrate once during setup and save the LUT to EEPROM or hardcode it, yo 1. **First run**: Call `calibrate(motor)` → Serial outputs LUT 2. **Copy LUT**: Paste the generated values into your code -3. **Subsequent runs**: Pass LUT to constructor and `calibrate()` → instantaneous, no rotation needed +3. **Subsequent runs**: Pass LUT to constructor and DO NOT call `calibrate()` → instantaneous, no rotation needed Your code will look something like this: