Skip to content

Commit 754da2b

Browse files
ipa: rpi: controller: AutoFocus tweak earlyTerminationByPhase()
Increase threshold for ETBP, from "confEpsilon" to "confThresh". Correct sign test to take account of pdafGain sign (typically -ve). Reduce allowed extrapolation range, but relax the check in the case of Continuous AF, when we go back into the PDAF closed loop. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
1 parent 119c06f commit 754da2b

File tree

1 file changed

+6
-5
lines changed
  • src/ipa/rpi/controller/rpi

1 file changed

+6
-5
lines changed

src/ipa/rpi/controller/rpi/af.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void Af::doPDAF(double phase, double conf)
411411
bool Af::earlyTerminationByPhase(double phase)
412412
{
413413
if (scanData_.size() > 0 &&
414-
scanData_[scanData_.size() - 1].conf >= cfg_.confEpsilon) {
414+
scanData_[scanData_.size() - 1].conf >= cfg_.confThresh) {
415415
double oldFocus = scanData_[scanData_.size() - 1].focus;
416416
double oldPhase = scanData_[scanData_.size() - 1].phase;
417417

@@ -420,11 +420,12 @@ bool Af::earlyTerminationByPhase(double phase)
420420
* Interpolate/extrapolate the lens position for zero phase.
421421
* Check that the extrapolation is well-conditioned.
422422
*/
423-
if ((ftarget_ - oldFocus) * (phase - oldPhase) > 0.0) {
423+
if ((ftarget_ - oldFocus) * (phase - oldPhase) * cfg_.speeds[speed_].pdafGain < 0.0) {
424424
double param = phase / (phase - oldPhase);
425-
if (-3.0 <= param && param <= 3.5) {
426-
ftarget_ += param * (oldFocus - ftarget_);
425+
if ((-2.5 <= param || mode_ == AfModeContinuous) && param <= 3.0) {
427426
LOG(RPiAf, Debug) << "ETBP: param=" << param;
427+
param = std::max(param, -2.5);
428+
ftarget_ += param * (oldFocus - ftarget_);
428429
return true;
429430
}
430431
}
@@ -562,7 +563,7 @@ void Af::doAF(double contrast, double phase, double conf)
562563
else
563564
scanState_ = ScanState::Idle;
564565
scanData_.clear();
565-
} else if (conf >= cfg_.confEpsilon && earlyTerminationByPhase(phase)) {
566+
} else if (conf >= cfg_.confThresh && earlyTerminationByPhase(phase)) {
566567
scanState_ = ScanState::Settle;
567568
stepCount_ = (mode_ == AfModeContinuous) ? 0
568569
: cfg_.speeds[speed_].stepFrames;

0 commit comments

Comments
 (0)