TM autotune: fail if value is outside of the boundaries
Ensure we never fall into the boundary values provided by the min/max limits. Save/restore the initial guess value, so that a convergence failure restores the initial model state.
This commit is contained in:
parent
d1864011f4
commit
5dc0d5f7fa
|
|
@ -2695,6 +2695,7 @@ float estimate(uint16_t samples,
|
||||||
float thr, uint16_t max_itr,
|
float thr, uint16_t max_itr,
|
||||||
uint8_t fan_pwm, float ambient)
|
uint8_t fan_pwm, float ambient)
|
||||||
{
|
{
|
||||||
|
float orig = *var;
|
||||||
float e = NAN;
|
float e = NAN;
|
||||||
float points[2];
|
float points[2];
|
||||||
float bounds[2] = {min, max};
|
float bounds[2] = {min, max};
|
||||||
|
|
@ -2710,10 +2711,19 @@ float estimate(uint16_t samples,
|
||||||
e = (1-GOLDEN_RATIO) * fabsf((bounds[0]-bounds[1]) / x);
|
e = (1-GOLDEN_RATIO) * fabsf((bounds[0]-bounds[1]) / x);
|
||||||
|
|
||||||
printf_P(PSTR("TM iter:%u v:%.2f e:%.3f\n"), it, x, e);
|
printf_P(PSTR("TM iter:%u v:%.2f e:%.3f\n"), it, x, e);
|
||||||
if(e < thr) return e;
|
if(e < thr) {
|
||||||
|
if(x == min || x == max) {
|
||||||
|
// real value likely outside of the search boundaries
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*var = x;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SERIAL_ECHOLNPGM("TM estimation did not converge");
|
SERIAL_ECHOLNPGM("TM estimation did not converge");
|
||||||
|
*var = orig;
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue