Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/focus/focus.cpp
Show First 20 Lines • Show All 1183 Lines • ▼ Show 20 Line(s) | 1045 | { | |||
---|---|---|---|---|---|
1184 | { | 1184 | { | ||
1185 | // Check if we're done from polynomial fitting algorithm | 1185 | // Check if we're done from polynomial fitting algorithm | ||
1186 | if (focusAlgorithm == FOCUS_POLYNOMIAL && polySolutionFound == MINIMUM_POLY_SOLUTIONS) | 1186 | if (focusAlgorithm == FOCUS_POLYNOMIAL && polySolutionFound == MINIMUM_POLY_SOLUTIONS) | ||
1187 | { | 1187 | { | ||
1188 | polySolutionFound = 0; | 1188 | polySolutionFound = 0; | ||
1189 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | 1189 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | ||
1190 | stop(); | 1190 | stop(); | ||
1191 | setAutoFocusResult(true); | 1191 | setAutoFocusResult(true); | ||
1192 | graphPolynomialFunction(); | ||||
1192 | return; | 1193 | return; | ||
1193 | } | 1194 | } | ||
1194 | Edge *maxStarHFR = nullptr; | 1195 | Edge *maxStarHFR = nullptr; | ||
1195 | 1196 | | |||
1196 | // Center tracking box around selected star (if it valid) either in: | 1197 | // Center tracking box around selected star (if it valid) either in: | ||
1197 | // 1. Autofocus | 1198 | // 1. Autofocus | ||
1198 | // 2. CheckFocus (minimumHFRCheck) | 1199 | // 2. CheckFocus (minimumHFRCheck) | ||
1199 | // The starCenter _must_ already be defined, otherwise, we proceed until | 1200 | // The starCenter _must_ already be defined, otherwise, we proceed until | ||
▲ Show 20 Lines • Show All 312 Lines • ▼ Show 20 Line(s) | 1511 | else | |||
1512 | autoFocusRel(); | 1513 | autoFocusRel(); | ||
1513 | } | 1514 | } | ||
1514 | 1515 | | |||
1515 | void Focus::clearDataPoints() | 1516 | void Focus::clearDataPoints() | ||
1516 | { | 1517 | { | ||
1517 | maxHFR = 1; | 1518 | maxHFR = 1; | ||
1518 | hfr_position.clear(); | 1519 | hfr_position.clear(); | ||
1519 | hfr_value.clear(); | 1520 | hfr_value.clear(); | ||
1521 | polynomialGraph->data()->clear(); | ||||
1522 | focusPoint->data()->clear(); | ||||
1523 | polynomialGraphIsShown = false; | ||||
1524 | HFRPlot->clearItems(); | ||||
1520 | 1525 | | |||
1521 | drawHFRPlot(); | 1526 | drawHFRPlot(); | ||
1522 | } | 1527 | } | ||
1523 | 1528 | | |||
1524 | void Focus::drawHFRPlot() | 1529 | void Focus::drawHFRPlot() | ||
1525 | { | 1530 | { | ||
1526 | v_graph->setData(hfr_position, hfr_value); | 1531 | v_graph->setData(hfr_position, hfr_value); | ||
1527 | 1532 | | |||
1528 | if (inFocusLoop == false && (canAbsMove || canRelMove)) | 1533 | if (inFocusLoop == false && (canAbsMove || canRelMove)) | ||
1529 | { | 1534 | { | ||
1530 | //HFRPlot->xAxis->setLabel(i18n("Position")); | 1535 | //HFRPlot->xAxis->setLabel(i18n("Position")); | ||
1531 | HFRPlot->xAxis->setRange(minPos - pulseDuration, maxPos + pulseDuration); | 1536 | HFRPlot->xAxis->setRange(minPos - pulseDuration, maxPos + pulseDuration); | ||
1532 | HFRPlot->yAxis->setRange(currentHFR / 1.5, maxHFR); | 1537 | HFRPlot->yAxis->setRange(currentHFR / 2.5, maxHFR); | ||
1533 | } | 1538 | } | ||
1534 | else | 1539 | else | ||
1535 | { | 1540 | { | ||
1536 | //HFRPlot->xAxis->setLabel(i18n("Iteration")); | 1541 | //HFRPlot->xAxis->setLabel(i18n("Iteration")); | ||
1537 | HFRPlot->xAxis->setRange(1, hfr_value.count() + 1); | 1542 | HFRPlot->xAxis->setRange(1, hfr_value.count() + 1); | ||
1538 | HFRPlot->yAxis->setRange(currentHFR / 1.5, maxHFR * 1.25); | 1543 | HFRPlot->yAxis->setRange(currentHFR / 2.5, maxHFR * 1.25); | ||
1539 | } | 1544 | } | ||
1540 | 1545 | | |||
1541 | HFRPlot->replot(); | 1546 | HFRPlot->replot(); | ||
1542 | } | 1547 | } | ||
1543 | 1548 | | |||
1544 | void Focus::drawProfilePlot() | 1549 | void Focus::drawProfilePlot() | ||
1545 | { | 1550 | { | ||
1546 | QVector<double> currentIndexes; | 1551 | QVector<double> currentIndexes; | ||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | 1701 | { | |||
1698 | abort(); | 1703 | abort(); | ||
1699 | setAutoFocusResult(false); | 1704 | setAutoFocusResult(false); | ||
1700 | } | 1705 | } | ||
1701 | else | 1706 | else | ||
1702 | { | 1707 | { | ||
1703 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | 1708 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | ||
1704 | stop(); | 1709 | stop(); | ||
1705 | setAutoFocusResult(true); | 1710 | setAutoFocusResult(true); | ||
1711 | | ||||
1712 | if (focusAlgorithm == FOCUS_POLYNOMIAL) | ||||
1713 | graphPolynomialFunction(); | ||||
1706 | } | 1714 | } | ||
1707 | break; | 1715 | break; | ||
1708 | } | 1716 | } | ||
1709 | else if (currentHFR < lastHFR) | 1717 | else if (currentHFR < lastHFR) | ||
1710 | { | 1718 | { | ||
1711 | double slope = 0; | 1719 | double slope = 0; | ||
1712 | 1720 | | |||
1713 | // Let's try to calculate slope of the V curve. | 1721 | // Let's try to calculate slope of the V curve. | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 1842 | { | |||
1842 | qCDebug(KSTARS_EKOS_FOCUS) << "Found Minimum?" << (polyMinimumFound ? "Yes" : "No"); | 1850 | qCDebug(KSTARS_EKOS_FOCUS) << "Found Minimum?" << (polyMinimumFound ? "Yes" : "No"); | ||
1843 | 1851 | | |||
1844 | if (polyMinimumFound) | 1852 | if (polyMinimumFound) | ||
1845 | { | 1853 | { | ||
1846 | qCDebug(KSTARS_EKOS_FOCUS) << "Minimum Solution:" << min_hfr << "@" << min_position; | 1854 | qCDebug(KSTARS_EKOS_FOCUS) << "Minimum Solution:" << min_hfr << "@" << min_position; | ||
1847 | polySolutionFound++; | 1855 | polySolutionFound++; | ||
1848 | targetPosition = floor(min_position); | 1856 | targetPosition = floor(min_position); | ||
1849 | appendLogText(i18n("Found polynomial solution @ %1", QString::number(min_position, 'f', 0))); | 1857 | appendLogText(i18n("Found polynomial solution @ %1", QString::number(min_position, 'f', 0))); | ||
1858 | | ||||
1859 | graphPolynomialFunction(); | ||||
1860 | focusPoint->data()->clear(); | ||||
1861 | focusPoint->addData(min_position, min_hfr); | ||||
1862 | | ||||
1863 | HFRPlot->clearItems(); | ||||
1864 | | ||||
1865 | QCPItemText *textLabel = new QCPItemText(HFRPlot); | ||||
1866 | textLabel->setPositionAlignment(Qt::AlignVCenter | Qt::AlignHCenter); | ||||
1867 | textLabel->position->setType(QCPItemPosition::ptPlotCoords); | ||||
1868 | textLabel->position->setCoords(min_position, min_hfr / 2); | ||||
1869 | textLabel->setColor(Qt::red); | ||||
1870 | textLabel->setPadding(QMargins(0, 0, 0, 0)); | ||||
1871 | textLabel->setBrush(Qt::white); | ||||
1872 | textLabel->setPen(Qt::NoPen); | ||||
1873 | textLabel->setFont(QFont(font().family(), 8)); | ||||
1874 | textLabel->setText(QString::number(min_position)); | ||||
1875 | | ||||
1850 | } | 1876 | } | ||
1851 | } | 1877 | } | ||
1852 | 1878 | | |||
1853 | if (polyMinimumFound == false) | 1879 | if (polyMinimumFound == false) | ||
1854 | { | 1880 | { | ||
1855 | // Decrease pulse | 1881 | // Decrease pulse | ||
1856 | pulseDuration = pulseDuration * 0.75; | 1882 | pulseDuration = pulseDuration * 0.75; | ||
1857 | 1883 | | |||
Show All 26 Lines | 1909 | else if (targetPosition > absMotionMax) | |||
1884 | targetPosition = absMotionMax; | 1910 | targetPosition = absMotionMax; | ||
1885 | 1911 | | |||
1886 | // Ops, we can't go any further, we're done. | 1912 | // Ops, we can't go any further, we're done. | ||
1887 | if (targetPosition == currentPosition) | 1913 | if (targetPosition == currentPosition) | ||
1888 | { | 1914 | { | ||
1889 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | 1915 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | ||
1890 | stop(); | 1916 | stop(); | ||
1891 | setAutoFocusResult(true); | 1917 | setAutoFocusResult(true); | ||
1918 | if (focusAlgorithm == FOCUS_POLYNOMIAL) | ||||
1919 | graphPolynomialFunction(); | ||||
1892 | return; | 1920 | return; | ||
1893 | } | 1921 | } | ||
1894 | 1922 | | |||
1895 | // Ops, deadlock | 1923 | // Ops, deadlock | ||
1896 | if (focusOutLimit && focusOutLimit == focusInLimit) | 1924 | if (focusOutLimit && focusOutLimit == focusInLimit) | ||
1897 | { | 1925 | { | ||
1898 | appendLogText(i18n("Deadlock reached. Please try again with different settings.")); | 1926 | appendLogText(i18n("Deadlock reached. Please try again with different settings.")); | ||
1899 | abort(); | 1927 | abort(); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
1946 | { | 1974 | { | ||
1947 | abort(); | 1975 | abort(); | ||
1948 | setAutoFocusResult(false); | 1976 | setAutoFocusResult(false); | ||
1949 | } | 1977 | } | ||
1950 | break; | 1978 | break; | ||
1951 | } | 1979 | } | ||
1952 | } | 1980 | } | ||
1953 | 1981 | | |||
1982 | void Focus::graphPolynomialFunction() | ||||
1983 | { | ||||
1984 | polynomialGraph->data()->clear(); | ||||
1985 | QCPRange range =HFRPlot->xAxis->range(); | ||||
1986 | double interval = range.size()/20.0; | ||||
1987 | | ||||
1988 | for(double x = range.lower ; x < range.upper ; x+=interval) | ||||
1989 | { | ||||
1990 | double y = fn1(x, this); | ||||
1991 | polynomialGraph->addData(x,y); | ||||
1992 | } | ||||
1993 | HFRPlot->replot(); | ||||
1994 | polynomialGraphIsShown = true; | ||||
1995 | } | ||||
1996 | | ||||
1954 | void Focus::autoFocusRel() | 1997 | void Focus::autoFocusRel() | ||
1955 | { | 1998 | { | ||
1956 | static int noStarCount = 0; | 1999 | static int noStarCount = 0; | ||
1957 | static double minHFR = 1e6; | 2000 | static double minHFR = 1e6; | ||
1958 | QString deltaTxt = QString("%1").arg(fabs(currentHFR - minHFR) * 100.0, 0, 'g', 2); | 2001 | QString deltaTxt = QString("%1").arg(fabs(currentHFR - minHFR) * 100.0, 0, 'g', 2); | ||
1959 | QString minHFRText = QString("%1").arg(minHFR, 0, 'g', 3); | 2002 | QString minHFRText = QString("%1").arg(minHFR, 0, 'g', 3); | ||
1960 | QString HFRText = QString("%1").arg(currentHFR, 0, 'g', 3); | 2003 | QString HFRText = QString("%1").arg(currentHFR, 0, 'g', 3); | ||
1961 | 2004 | | |||
Show All 32 Lines | 2031 | { | |||
1994 | 2037 | | |||
1995 | case FOCUS_IN: | 2038 | case FOCUS_IN: | ||
1996 | case FOCUS_OUT: | 2039 | case FOCUS_OUT: | ||
1997 | if (fabs(currentHFR - minHFR) < (toleranceIN->value() / 100.0) && HFRInc == 0) | 2040 | if (fabs(currentHFR - minHFR) < (toleranceIN->value() / 100.0) && HFRInc == 0) | ||
1998 | { | 2041 | { | ||
1999 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | 2042 | appendLogText(i18n("Autofocus complete after %1 iterations.", hfr_position.count())); | ||
2000 | stop(); | 2043 | stop(); | ||
2001 | setAutoFocusResult(true); | 2044 | setAutoFocusResult(true); | ||
2045 | if (focusAlgorithm == FOCUS_POLYNOMIAL) | ||||
2046 | graphPolynomialFunction(); | ||||
2002 | break; | 2047 | break; | ||
2003 | } | 2048 | } | ||
2004 | else if (currentHFR < lastHFR) | 2049 | else if (currentHFR < lastHFR) | ||
2005 | { | 2050 | { | ||
2006 | if (currentHFR < minHFR) | 2051 | if (currentHFR < minHFR) | ||
2007 | minHFR = currentHFR; | 2052 | minHFR = currentHFR; | ||
2008 | 2053 | | |||
2009 | lastHFR = currentHFR; | 2054 | lastHFR = currentHFR; | ||
▲ Show 20 Lines • Show All 1282 Lines • ▼ Show 20 Line(s) | 3271 | { | |||
3292 | HFRPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen); | 3337 | HFRPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen); | ||
3293 | HFRPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen); | 3338 | HFRPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen); | ||
3294 | 3339 | | |||
3295 | HFRPlot->yAxis->setLabel(i18n("HFR")); | 3340 | HFRPlot->yAxis->setLabel(i18n("HFR")); | ||
3296 | 3341 | | |||
3297 | HFRPlot->setInteractions(QCP::iRangeZoom); | 3342 | HFRPlot->setInteractions(QCP::iRangeZoom); | ||
3298 | HFRPlot->setInteraction(QCP::iRangeDrag, true); | 3343 | HFRPlot->setInteraction(QCP::iRangeDrag, true); | ||
3299 | 3344 | | |||
3345 | polynomialGraph = HFRPlot->addGraph(); | ||||
3346 | polynomialGraph->setLineStyle(QCPGraph::lsLine); | ||||
3347 | polynomialGraph->setPen(QPen(QColor(140, 140, 140), 3, Qt::DotLine)); | ||||
3348 | polynomialGraph->setScatterStyle(QCPScatterStyle::ssNone); | ||||
3349 | | ||||
3350 | QCPAxis *xAxis = HFRPlot->xAxis; | ||||
3351 | | ||||
3352 | | ||||
3353 | connect(xAxis, static_cast<void(QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this, [this](){ | ||||
3354 | if(polynomialGraphIsShown) | ||||
3355 | { | ||||
3356 | if (focusAlgorithm == FOCUS_POLYNOMIAL) | ||||
3357 | graphPolynomialFunction(); | ||||
3358 | } | ||||
3359 | }); | ||||
3360 | | ||||
3361 | focusPoint = HFRPlot->addGraph(); | ||||
3362 | focusPoint->setLineStyle(QCPGraph::lsImpulse); | ||||
3363 | focusPoint->setPen(QPen(QColor(140, 140, 140), 3, Qt::SolidLine)); | ||||
3364 | focusPoint->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::white, Qt::yellow, 10)); | ||||
3365 | | ||||
3300 | v_graph = HFRPlot->addGraph(); | 3366 | v_graph = HFRPlot->addGraph(); | ||
3301 | v_graph->setLineStyle(QCPGraph::lsNone); | 3367 | v_graph->setLineStyle(QCPGraph::lsNone); | ||
3302 | v_graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::white, Qt::red, 3)); | 3368 | v_graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::white, Qt::red, 3)); | ||
3303 | 3369 | | |||
3304 | } | 3370 | } | ||
3305 | 3371 | | |||
3306 | void Focus::initConnections() | 3372 | void Focus::initConnections() | ||
3307 | { | 3373 | { | ||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |