8#include "polaralignmentassistant.h"
13#include "kstarsdata.h"
14#include "ksmessagebox.h"
15#include "ekos/auxiliary/stellarsolverprofile.h"
16#include "ekos/auxiliary/solverutils.h"
18#include "polaralignwidget.h"
19#include <ekos_align_debug.h>
21#define PAA_VERSION "v3.0"
28 {PAH_IDLE,
ki18n(
"Idle")},
29 {PAH_FIRST_CAPTURE,
ki18n(
"First Capture")},
30 {PAH_FIRST_SOLVE,
ki18n(
"First Solve")},
31 {PAH_FIND_CP,
ki18n(
"Finding CP")},
32 {PAH_FIRST_ROTATE,
ki18n(
"First Rotation")},
33 {PAH_FIRST_SETTLE,
ki18n(
"First Settle")},
34 {PAH_SECOND_CAPTURE,
ki18n(
"Second Capture")},
35 {PAH_SECOND_SOLVE,
ki18n(
"Second Solve")},
36 {PAH_SECOND_ROTATE,
ki18n(
"Second Rotation")},
37 {PAH_SECOND_SETTLE,
ki18n(
"Second Settle")},
38 {PAH_THIRD_CAPTURE,
ki18n(
"Third Capture")},
39 {PAH_THIRD_SOLVE,
ki18n(
"Third Solve")},
40 {PAH_STAR_SELECT,
ki18n(
"Select Star")},
41 {PAH_REFRESH,
ki18n(
"Refreshing")},
42 {PAH_POST_REFRESH,
ki18n(
"Refresh Complete")},
48 polarAlignWidget =
new PolarAlignWidget();
49 mainPALayout->insertWidget(0, polarAlignWidget);
51 m_AlignInstance = parent;
54 showUpdatedError((pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM) ||
55 (pAHRefreshAlgorithm->currentIndex() == MOVE_STAR_UPDATE_ERR_ALGORITHM));
59 setPAHRefreshAlgorithm(
static_cast<RefreshAlgorithm
>(index));
61 starCorrespondencePAH.reset();
64 PAHWidgets->setCurrentWidget(PAHIntroPage);
65 connect(
this, &PolarAlignmentAssistant::PAHEnabled, [&](
bool enabled)
67 PAHStartB->setEnabled(enabled);
68 directionLabel->setEnabled(enabled);
69 pAHDirection->setEnabled(enabled);
70 pAHRotation->setEnabled(enabled);
71 pAHMountSpeed->setEnabled(enabled);
72 pAHManualSlew->setEnabled(enabled);
81 hemisphere = KStarsData::Instance()->
geo()->
lat()->
Degrees() > 0 ? NORTH_HEMISPHERE : SOUTH_HEMISPHERE;
83 label_PAHOrigErrorAz->setText(
"Az: ");
84 label_PAHOrigErrorAlt->setText(
"Alt: ");
87PolarAlignmentAssistant::~PolarAlignmentAssistant()
91void PolarAlignmentAssistant::showUpdatedError(
bool show)
93 label_PAHUpdatedErrorTotal->setVisible(show);
94 PAHUpdatedErrorTotal->setVisible(show);
95 label_PAHUpdatedErrorAlt->setVisible(show);
96 PAHUpdatedErrorAlt->setVisible(show);
97 label_PAHUpdatedErrorAz->setVisible(show);
98 PAHUpdatedErrorAz->setVisible(show);
101void PolarAlignmentAssistant::syncMountSpeed(
const QString &speed)
103 pAHMountSpeed->blockSignals(
true);
104 pAHMountSpeed->clear();
105 pAHMountSpeed->addItems(m_CurrentTelescope->slewRates());
106 pAHMountSpeed->setCurrentText(speed);
107 pAHMountSpeed->blockSignals(
false);
110void PolarAlignmentAssistant::setEnabled(
bool enabled)
114 emit PAHEnabled(enabled);
117 PAHWidgets->setToolTip(
QString());
118 FOVDisabledLabel->hide();
122 PAHWidgets->setToolTip(
i18n(
"<p>Polar Alignment tool requires a German Equatorial Mount.</p>"));
123 FOVDisabledLabel->show();
129void PolarAlignmentAssistant::startSolver()
131 auto profiles = getDefaultAlignOptionsProfiles();
132 SSolver::Parameters parameters;
137 parameters = profiles.at(Options::solveOptionsProfile());
139 catch (std::out_of_range
const &)
141 parameters = profiles[0];
145 parameters.search_radius = parameters.search_radius * 2;
146 constexpr double solverTimeout = 10.0;
152 m_Solver->useScale(Options::astrometryUseImageScale(), m_LastPixscale * 0.9, m_LastPixscale * 1.1);
153 m_Solver->usePosition(
true, m_LastRa, m_LastDec);
154 m_Solver->setHealpix(m_IndexToUse, m_HealpixToUse);
155 m_Solver->runSolver(m_ImageData);
158void PolarAlignmentAssistant::solverDone(
bool timedOut,
bool success,
const FITSImage::Solution &solution,
159 double elapsedSeconds)
161 disconnect(m_Solver.get(), &SolverUtils::done,
this, &PolarAlignmentAssistant::solverDone);
163 if (m_PAHStage != PAH_REFRESH)
166 if (timedOut || !success)
172 constexpr int MAX_NUM_HEALPIX_FAILURES = 2;
173 if (++m_NumHealpixFailures >= MAX_NUM_HEALPIX_FAILURES)
183 m_Solver->getSolutionHealpix(&m_IndexToUse, &m_HealpixToUse);
188 emit newLog(
i18n(
"Refresh solver timed out: %1s",
QString(
"%L1").arg(elapsedSeconds, 0,
'f', 1)));
189 emit captureAndSolve();
193 emit newLog(
i18n(
"Refresh solver failed: %1s",
QString(
"%L1").arg(elapsedSeconds, 0,
'f', 1)));
194 emit updatedErrorsChanged(-1, -1, -1);
195 emit captureAndSolve();
199 m_NumHealpixFailures = 0;
201 const double ra = solution.ra;
202 const double dec = solution.dec;
203 m_LastRa = solution.ra;
204 m_LastDec = solution.dec;
205 m_LastOrientation = solution.orientation;
206 m_LastPixscale = solution.pixscale;
208 emit newLog(
QString(
"Refresh solver success %1s: ra %2 dec %3 scale %4")
209 .arg(elapsedSeconds, 0,
'f', 1).arg(ra, 0,
'f', 3)
210 .arg(dec, 0,
'f', 3).arg(solution.pixscale));
213 SkyPoint refreshCoords(ra / 15.0, dec);
214 double azError = 0, altError = 0;
215 if (polarAlign.processRefreshCoords(refreshCoords, m_ImageData->getDateTime(), &azError, &altError))
217 updateRefreshDisplay(azError, altError);
219 const bool eastToTheRight = solution.parity == FITSImage::POSITIVE ? false :
true;
222 m_AlignView->injectWCS(solution.orientation, ra, dec, solution.pixscale, eastToTheRight,
false);
223 updatePlateSolveTriangle(m_ImageData);
226 emit newLog(
QString(
"Could not estimate mount rotation"));
229 emit captureAndSolve();
243 const SkyPoint &originalCoords = polarAlign.getPoint(2);
244 QPointF originalPixel, solutionPixel, altOnlyPixel, dummy;
245 QPointF centerPixel(image->width() / 2, image->height() / 2);
246 if (image->wcsToPixel(originalCoords, originalPixel, dummy) &&
247 image->wcsToPixel(refreshSolution, solutionPixel, dummy) &&
248 image->wcsToPixel(altOnlyRefreshSolution, altOnlyPixel, dummy))
250 m_AlignView->setCorrectionParams(originalPixel, solutionPixel, altOnlyPixel);
251 m_AlignView->setStarCircle(centerPixel);
255 qCDebug(KSTARS_EKOS_ALIGN) <<
"wcs failed";
264void upArrow(
QPainter *painter,
int w,
int h)
266 const double wCenter = w / 2, lineTop = 0.38, lineBottom = 0.9;
267 const double lineLength = h * (lineBottom - lineTop);
268 painter->
drawRect(wCenter - w * .1, h * lineTop, w * .2, lineLength);
273void downArrow(
QPainter *painter,
int w,
int h)
275 const double wCenter = w / 2, lineBottom = 0.62, lineTop = 0.1;
276 const double lineLength = h * (lineBottom - lineTop);
277 painter->
drawRect(wCenter - w * .1, h * lineTop, w * .2, lineLength);
282void leftArrow(
QPainter *painter,
int w,
int h)
284 const double hCenter = h / 2, lineLeft = 0.38, lineRight = 0.9;
285 const double lineLength = w * (lineRight - lineLeft);
286 painter->
drawRect(h * lineLeft, hCenter - h * .1, lineLength, h * .2);
291void rightArrow(
QPainter *painter,
int w,
int h)
293 const double hCenter = h / 2, lineLeft = .1, lineRight = .62;
294 const double lineLength = w * (lineRight - lineLeft);
295 painter->
drawRect(h * lineLeft, hCenter - h * .1, lineLength, h * .2);
304void PolarAlignmentAssistant::drawArrows(
double azError,
double altError)
306 constexpr double minError = 20.0 / 3600.0;
307 double absError = fabs(altError);
311 constexpr double largeErr = 10.0 / 60.0, smallErr = 1.0 / 60.0, largeSize = 100, smallSize = 20, c1 = 533.33, c2 = 11.111;
314 if (absError > largeErr)
316 else if (absError < smallErr)
318 else size = absError * c1 + c2;
321 altPixmap.fill(
QColor(
"transparent"));
325 if (altError > minError)
326 downArrow(&altPainter, size, size);
327 else if (altError < -minError)
328 upArrow(&altPainter, size, size);
329 arrowAlt->setPixmap(altPixmap);
331 absError = fabs(azError);
332 if (absError > largeErr)
334 else if (absError < smallErr)
336 else size = absError * c1 + c2;
339 azPixmap.fill(
QColor(
"transparent"));
343 if (azError > minError)
344 leftArrow(&azPainter, size, size);
345 else if (azError < -minError)
346 rightArrow(&azPainter, size, size);
347 arrowAz->setPixmap(azPixmap);
350bool PolarAlignmentAssistant::detectStarsPAHRefresh(
QList<Edge> *stars,
int num,
int x,
int y,
int *starIndex)
356 QVariantMap settings;
357 settings[
"optionsProfileIndex"] = Options::solveOptionsProfile();
358 settings[
"optionsProfileGroup"] =
static_cast<int>(Ekos::AlignProfiles);
359 m_ImageData->setSourceExtractorSettings(settings);
362 m_ImageData->findStars(ALGORITHM_SEP).waitForFinished();
364 QString debugString =
QString(
"PAA Refresh: Detected %1 stars (%2s)")
365 .
arg(m_ImageData->getStarCenters().size()).
arg(timer.elapsed() / 1000.0, 5,
'f', 3);
366 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
370 std::sort(detectedStars.
begin(), detectedStars.
end(), [](
const Edge * edge1,
const Edge * edge2) ->
bool { return edge1->sum > edge2->sum;});
373 double bestDist = 1e9;
375 for (
int i = 0; i < detectedStars.
size(); i++)
377 double dx = detectedStars[i]->x - x;
378 double dy = detectedStars[i]->y - y;
379 double dist = dx * dx + dy * dy;
387 int starCount = qMin(num, detectedStars.
count());
388 for (
int i = 0; i < starCount; i++)
389 stars->
append(*(detectedStars[i]));
390 if (bestIndex >= starCount)
394 stars->
append(*(detectedStars[bestIndex]));
395 *starIndex = starCount;
399 *starIndex = bestIndex;
401 debugString =
QString(
"PAA Refresh: User's star(%1,%2) is index %3").
arg(x).
arg(y).
arg(*starIndex);
402 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
404 detectedStars.
clear();
406 return stars->
count();
409void PolarAlignmentAssistant::updateRefreshDisplay(
double azE,
double altE)
411 drawArrows(azE, altE);
412 const double errDegrees = hypot(azE, altE);
413 dms totalError(errDegrees), azError(azE), altError(altE);
414 PAHUpdatedErrorTotal->setText(totalError.toDMSString());
415 PAHUpdatedErrorAlt->setText(altError.toDMSString());
416 PAHUpdatedErrorAz->setText(azError.toDMSString());
418 QString debugString =
QString(
"PAA Refresh(%1): Corrected az: %2 alt: %4 total: %6")
419 .
arg(refreshIteration).
arg(azError.toDMSString())
420 .
arg(altError.toDMSString()).
arg(totalError.toDMSString());
421 emit newLog(debugString);
422 emit updatedErrorsChanged(totalError.Degrees(), azError.Degrees(), altError.Degrees());
425void PolarAlignmentAssistant::processPAHRefresh()
427 m_AlignView->setStarCircle();
428 PAHUpdatedErrorTotal->clear();
429 PAHIteration->clear();
430 PAHUpdatedErrorAlt->clear();
431 PAHUpdatedErrorAz->clear();
434 PAHIteration->setText(
QString(
"Image %1").arg(imageNumber));
436 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
446 if ((pAHRefreshAlgorithm->currentIndex() == MOVE_STAR_UPDATE_ERR_ALGORITHM) || (refreshIteration == 0))
448 constexpr int MIN_PAH_REFRESH_STARS = 10;
454 int clickedStarIndex;
455 detectStarsPAHRefresh(&stars, 100, correctionFrom.x(), correctionFrom.y(), &clickedStarIndex);
456 if (clickedStarIndex < 0)
458 debugString =
QString(
"PAA Refresh(%1): Didn't find the clicked star near %2,%3")
459 .
arg(refreshIteration).
arg(correctionFrom.x()).
arg(correctionFrom.y());
460 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
462 emit newAlignTableResult(Align::ALIGN_RESULT_FAILED);
463 emit captureAndSolve();
467 debugString =
QString(
"PAA Refresh(%1): Refresh star(%2,%3) is index %4 with offset %5 %6")
468 .
arg(refreshIteration + 1).
arg(correctionFrom.x(), 4,
'f', 0)
469 .
arg(correctionFrom.y(), 4,
'f', 0).
arg(clickedStarIndex)
470 .
arg(stars[clickedStarIndex].x - correctionFrom.x(), 4,
'f', 0)
471 .
arg(stars[clickedStarIndex].y - correctionFrom.y(), 4,
'f', 0);
472 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
474 if (stars.
size() > MIN_PAH_REFRESH_STARS)
480 if (refreshIteration++ == 0)
484 starCorrespondencePAH.initialize(stars, clickedStarIndex);
485 if (clickedStarIndex >= 0)
487 setupCorrectionGraphics(
QPointF(stars[clickedStarIndex].x, stars[clickedStarIndex].y));
488 emit newCorrectionVector(
QLineF(correctionFrom, correctionTo));
489 emit newFrame(m_AlignView);
498 starCorrespondencePAH.find(stars, 200.0, &starMap,
false, 0.40);
502 for (
int i = 0; i < starMap.
size(); ++i)
504 if (starMap[i] == starCorrespondencePAH.guideStar())
506 dx = stars[i].x - correctionFrom.x();
507 dy = stars[i].y - correctionFrom.y();
515 for (
int i = 0; i < starMap.
size(); ++i)
517 if (starMap[i] != -1)
520 debugString =
QString(
"PAA Refresh(%1): starMap %2").
arg(refreshIteration).
arg(allOnes ?
"ALL -1's" :
"not all -1's");
521 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
528 m_AlignView->setStarCircle(
QPointF(stars[starIndex].x, stars[starIndex].y));
529 debugString =
QString(
"PAA Refresh(%1): User's star is now at %2,%3, with movement = %4,%5").
arg(refreshIteration)
530 .
arg(stars[starIndex].x, 4,
'f', 0).
arg(stars[starIndex].y, 4,
'f', 0).
arg(dx).
arg(dy);
531 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
534 if (polarAlign.pixelError(m_AlignView->keptImage(),
QPointF(stars[starIndex].x, stars[starIndex].y),
535 correctionTo, &azE, &altE))
537 updateRefreshDisplay(azE, altE);
538 debugString =
QString(
"PAA Refresh(%1): %2,%3 --> %4,%5 @ %6,%7")
539 .
arg(refreshIteration).
arg(correctionFrom.x(), 4,
'f', 0).
arg(correctionFrom.y(), 4,
'f', 0)
540 .
arg(correctionTo.x(), 4,
'f', 0).
arg(correctionTo.y(), 4,
'f', 0)
541 .
arg(stars[starIndex].x, 4,
'f', 0).
arg(stars[starIndex].y, 4,
'f', 0);
542 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
546 debugString =
QString(
"PAA Refresh(%1): pixelError failed to estimate the remaining correction").
arg(refreshIteration);
547 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
552 if (refreshIteration > 1)
554 debugString =
QString(
"PAA Refresh(%1): Didn't find the user's star").
arg(refreshIteration);
555 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
561 debugString =
QString(
"PAA Refresh(%1): Too few stars detected (%2)").
arg(refreshIteration).
arg(stars.
size());
562 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
563 emit updatedErrorsChanged(-1, -1, -1);
567 emit captureAndSolve();
570bool PolarAlignmentAssistant::processSolverFailure()
572 if ((m_PAHStage == PAH_FIRST_CAPTURE ||
573 m_PAHStage == PAH_SECOND_CAPTURE ||
574 m_PAHStage == PAH_THIRD_CAPTURE ||
575 m_PAHStage == PAH_FIRST_SOLVE ||
576 m_PAHStage == PAH_SECOND_SOLVE ||
577 m_PAHStage == PAH_THIRD_SOLVE)
578 && ++m_PAHRetrySolveCounter < 4)
580 emit newLog(
i18n(
"PAA: Solver failed, retrying."));
581 emit captureAndSolve();
585 if (m_PAHStage != PAH_IDLE)
587 emit newLog(
i18n(
"PAA: Stopping, solver failed too many times."));
594void PolarAlignmentAssistant::setPAHStage(Stage stage)
596 if (stage != m_PAHStage)
599 polarAlignWidget->updatePAHStage(stage);
600 emit newPAHStage(m_PAHStage);
604void PolarAlignmentAssistant::processMountRotation(
const dms &ra,
double settleDuration)
613 if (m_PAHStage == PAH_FIRST_ROTATE)
615 rotProgressMessage =
"First mount rotation remaining degrees:";
616 rotDoneMessage =
i18n(
"Mount first rotation is complete.");
617 nextCapture = PAH_SECOND_CAPTURE;
618 nextSettle = PAH_FIRST_SETTLE;
620 else if (m_PAHStage == PAH_SECOND_ROTATE)
622 rotProgressMessage =
"Second mount rotation remaining degrees:";
623 rotDoneMessage =
i18n(
"Mount second rotation is complete.");
624 nextCapture = PAH_THIRD_CAPTURE;
625 nextSettle = PAH_SECOND_SETTLE;
629 if (m_PAHStage == PAH_FIRST_ROTATE || m_PAHStage == PAH_SECOND_ROTATE)
632 if(!pAHManualSlew->isChecked())
634 qCDebug(KSTARS_EKOS_ALIGN) << rotProgressMessage << deltaAngle;
635 if (deltaAngle <= PAH_ROTATION_THRESHOLD)
637 m_CurrentTelescope->StopWE();
638 emit newLog(rotDoneMessage);
640 if (settleDuration <= 0)
642 setPAHStage(nextCapture);
643 updateDisplay(m_PAHStage, getPAHMessage());
647 setPAHStage(nextSettle);
648 updateDisplay(m_PAHStage, getPAHMessage());
650 emit newLog(
i18n(
"Settling..."));
653 setPAHStage(nextCapture);
654 updateDisplay(m_PAHStage, getPAHMessage());
659 else if (deltaAngle > pAHRotation->value() * 1.25)
661 m_CurrentTelescope->abort();
662 emit newLog(
i18n(
"Mount aborted. Reverse RA axis direction and try again."));
670bool PolarAlignmentAssistant::checkPAHForMeridianCrossing()
673 double hourAngle = m_CurrentTelescope->hourAngle().Degrees();
674 while (hourAngle < -180)
676 while (hourAngle > 180)
678 double ra = 0,
dec = 0;
679 m_CurrentTelescope->getEqCoords(&ra, &dec);
686 bool nearThePole = fabs(dec) > 88;
690 double degreesPerSlew = pAHRotation->value();
691 bool closeToMeridian = fabs(hourAngle) < 2.0 * degreesPerSlew;
692 bool goingWest = pAHDirection->currentIndex() == 0;
697 bool wouldCrossMeridian =
698 ((m_CurrentTelescope->pierSide() == ISD::Mount::PIER_EAST && !goingWest && closeToMeridian) ||
699 (m_CurrentTelescope->pierSide() == ISD::Mount::PIER_WEST && goingWest && closeToMeridian) ||
700 (m_CurrentTelescope->pierSide() == ISD::Mount::PIER_UNKNOWN && closeToMeridian));
702 return wouldCrossMeridian;
705void PolarAlignmentAssistant::updateDisplay(Stage stage,
const QString &message)
709 case PAH_FIRST_ROTATE:
710 case PAH_SECOND_ROTATE:
711 if (pAHManualSlew->isChecked())
713 polarAlignWidget->updatePAHStage(stage);
714 PAHWidgets->setCurrentWidget(PAHManualRotatePage);
715 manualRotateText->setText(message);
716 emit newPAHMessage(message);
720 case PAH_FIRST_CAPTURE:
721 case PAH_SECOND_CAPTURE:
722 case PAH_THIRD_CAPTURE:
723 case PAH_FIRST_SOLVE:
724 case PAH_SECOND_SOLVE:
725 case PAH_THIRD_SOLVE:
726 polarAlignWidget->updatePAHStage(stage);
727 PAHWidgets->setCurrentWidget(PAHMessagePage);
728 PAHMessageText->setText(message);
729 emit newPAHMessage(message);
738void PolarAlignmentAssistant::startPAHProcess()
740 qCInfo(KSTARS_EKOS_ALIGN) <<
QString(
"Starting Polar Alignment Assistant process %1 ...").
arg(PAA_VERSION);
742 auto executePAH = [ this ]()
744 setPAHStage(PAH_FIRST_CAPTURE);
746 if (Options::limitedResourcesMode())
747 emit newLog(
i18n(
"Warning: Equatorial Grid Lines will not be drawn due to limited resources mode."));
749 if (m_CurrentTelescope->hasAlignmentModel())
751 emit newLog(
i18n(
"Clearing mount Alignment Model..."));
752 m_CurrentTelescope->clearAlignmentModel();
756 m_CurrentTelescope->unpark();
759 if (m_CurrentTelescope->canControlTrack() && m_CurrentTelescope->isTracking() ==
false)
760 m_CurrentTelescope->setTrackEnabled(
true);
762 PAHStartB->setEnabled(
false);
763 PAHStopB->setEnabled(
true);
765 PAHUpdatedErrorTotal->clear();
766 PAHUpdatedErrorAlt->clear();
767 PAHUpdatedErrorAz->clear();
768 PAHOrigErrorTotal->clear();
769 PAHOrigErrorAlt->clear();
770 PAHOrigErrorAz->clear();
771 PAHIteration->setText(
"");
773 updateDisplay(m_PAHStage, getPAHMessage());
777 m_PAHRetrySolveCounter = 0;
778 emit captureAndSolve();
783 if (checkPAHForMeridianCrossing())
792 KSMessageBox::Instance()->warningContinueCancel(
i18n(
"This could cause the telescope to cross the meridian."),
793 i18n(
"Warning"), 15);
799void PolarAlignmentAssistant::stopPAHProcess()
801 if (m_PAHStage == PAH_IDLE)
811 if (m_PAHStage == PAH_REFRESH)
813 setPAHStage(PAH_POST_REFRESH);
814 polarAlignWidget->updatePAHStage(m_PAHStage);
816 qCInfo(KSTARS_EKOS_ALIGN) <<
"Stopping Polar Alignment Assistant process...";
819 if (m_CurrentTelescope && m_CurrentTelescope->isInMotion())
820 m_CurrentTelescope->abort();
822 setPAHStage(PAH_IDLE);
823 polarAlignWidget->updatePAHStage(m_PAHStage);
825 PAHStartB->setEnabled(
true);
826 PAHStopB->setEnabled(
false);
827 PAHRefreshB->setEnabled(
true);
828 PAHWidgets->setCurrentWidget(PAHIntroPage);
829 emit newPAHMessage(introText->text());
831 m_AlignView->reset();
832 m_AlignView->setRefreshEnabled(
false);
834 emit newFrame(m_AlignView);
835 disconnect(m_AlignView.get(), &AlignView::trackingStarSelected,
this,
836 &Ekos::PolarAlignmentAssistant::setPAHCorrectionOffset);
837 disconnect(m_AlignView.get(), &AlignView::newCorrectionVector,
this, &Ekos::PolarAlignmentAssistant::newCorrectionVector);
839 if (Options::pAHAutoPark())
841 m_CurrentTelescope->park();
842 emit newLog(
i18n(
"Parking the mount..."));
846void PolarAlignmentAssistant::rotatePAH()
848 double TargetDiffRA = pAHRotation->value();
849 bool westMeridian = pAHDirection->currentIndex() == 0;
861 if (pAHManualSlew->isChecked())
866 const SkyPoint telescopeCoord = m_CurrentTelescope->currentCoordinates();
869 dms newTelescopeRA = (telescopeCoord.
ra() +
dms(TargetDiffRA)).
reduce();
871 targetPAH.setRA(newTelescopeRA);
872 targetPAH.setDec(telescopeCoord.
dec());
876 if (pAHMountSpeed->currentIndex() >= 0)
877 m_CurrentTelescope->setSlewRate(pAHMountSpeed->currentIndex());
879 m_CurrentTelescope->MoveWE(westMeridian ? ISD::Mount::MOTION_WEST : ISD::Mount::MOTION_EAST,
880 ISD::Mount::MOTION_START);
882 emit newLog(
i18n(
"Please wait until mount completes rotating to RA (%1) DE (%2)", targetPAH.ra().toHMSString(),
883 targetPAH.dec().toDMSString()));
886void PolarAlignmentAssistant::setupCorrectionGraphics(
const QPointF &pixel)
888 polarAlign.refreshSolution(&refreshSolution, &altOnlyRefreshSolution);
896 if (!polarAlign.findCorrectedPixel(imageData, pixel, &correctionAltTo,
true))
898 qCInfo(KSTARS_EKOS_ALIGN) <<
QString(
i18n(
"PAA: Failed to findCorrectedPixel."));
902 if (!polarAlign.findCorrectedPixel(imageData, pixel, &correctionTo))
904 qCInfo(KSTARS_EKOS_ALIGN) <<
QString(
i18n(
"PAA: Failed to findCorrectedPixel."));
907 QString debugString =
QString(
"PAA: Correction: %1,%2 --> %3,%4 (alt only %5,%6)")
908 .
arg(pixel.
x(), 4,
'f', 0).
arg(pixel.
y(), 4,
'f', 0)
909 .
arg(correctionTo.x(), 4,
'f', 0).
arg(correctionTo.y(), 4,
'f', 0)
910 .
arg(correctionAltTo.x(), 4,
'f', 0).
arg(correctionAltTo.y(), 4,
'f', 0);
911 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
912 correctionFrom = pixel;
914 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
915 updatePlateSolveTriangle(imageData);
917 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
923bool PolarAlignmentAssistant::calculatePAHError()
926 m_AlignView->holdOnToImage();
928 if (!polarAlign.findAxis())
930 emit newLog(
i18n(
"PAA: Failed to find RA Axis center."));
935 double azimuthError, altitudeError;
936 polarAlign.calculateAzAltError(&azimuthError, &altitudeError);
937 drawArrows(azimuthError, altitudeError);
938 dms polarError(hypot(altitudeError, azimuthError));
939 dms azError(azimuthError), altError(altitudeError);
946 .
arg(polarError.toDMSString()).
arg(azError.toDMSString())
947 .
arg(altError.toDMSString());
948 emit newLog(
QString(
"Polar Alignment Error: %1").arg(msg));
950 polarAlign.setMaxPixelSearchRange(polarError.Degrees() + 1);
953 PAHOrigErrorTotal->setText(polarError.toDMSString());
954 PAHOrigErrorAlt->setText(altError.toDMSString());
955 PAHOrigErrorAz->setText(azError.toDMSString());
957 setupCorrectionGraphics(
QPointF(m_ImageData->width() / 2, m_ImageData->height() / 2));
960 SkyPoint CP(0, (hemisphere == NORTH_HEMISPHERE) ? 90 : -90);
961 QPointF imagePoint, celestialPolePoint;
962 m_ImageData->wcsToPixel(CP, celestialPolePoint, imagePoint);
963 if (m_ImageData->contains(celestialPolePoint))
965 m_AlignView->setCelestialPole(celestialPolePoint);
967 if (polarAlign.findCorrectedPixel(m_ImageData, celestialPolePoint, &raAxis))
968 m_AlignView->setRaAxis(raAxis);
971 connect(m_AlignView.get(), &AlignView::trackingStarSelected,
this, &Ekos::PolarAlignmentAssistant::setPAHCorrectionOffset);
972 emit polarResultUpdated(
QLineF(correctionFrom, correctionTo), polarError.Degrees(), azError.Degrees(), altError.Degrees());
974 connect(m_AlignView.get(), &AlignView::newCorrectionVector,
this, &Ekos::PolarAlignmentAssistant::newCorrectionVector,
976 syncCorrectionVector();
977 emit newFrame(m_AlignView);
982void PolarAlignmentAssistant::syncCorrectionVector()
984 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
986 emit newCorrectionVector(
QLineF(correctionFrom, correctionTo));
987 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
990void PolarAlignmentAssistant::setPAHCorrectionOffsetPercentage(
double dx,
double dy)
992 double x = dx * m_AlignView->zoomedWidth();
993 double y = dy * m_AlignView->zoomedHeight();
994 setPAHCorrectionOffset(
static_cast<int>(round(x)),
static_cast<int>(round(y)));
997void PolarAlignmentAssistant::setPAHCorrectionOffset(
int x,
int y)
999 if (m_PAHStage == PAH_REFRESH)
1001 emit newLog(
i18n(
"Polar-alignment star cannot be updated during refresh phase as it might affect error measurements."));
1005 setupCorrectionGraphics(
QPointF(x, y));
1006 emit newCorrectionVector(
QLineF(correctionFrom, correctionTo));
1007 emit newFrame(m_AlignView);
1011void PolarAlignmentAssistant::setPAHSlewDone()
1013 emit newPAHMessage(
"Manual slew done.");
1016 case PAH_FIRST_ROTATE :
1017 setPAHStage(PAH_SECOND_CAPTURE);
1018 emit newLog(
i18n(
"First manual rotation done."));
1019 updateDisplay(m_PAHStage, getPAHMessage());
1021 case PAH_SECOND_ROTATE :
1022 setPAHStage(PAH_THIRD_CAPTURE);
1023 emit newLog(
i18n(
"Second manual rotation done."));
1024 updateDisplay(m_PAHStage, getPAHMessage());
1033void PolarAlignmentAssistant::startPAHRefreshProcess()
1035 qCInfo(KSTARS_EKOS_ALIGN) <<
"Starting Polar Alignment Assistant refreshing...";
1037 refreshIteration = 0;
1039 m_NumHealpixFailures = 0;
1041 setPAHStage(PAH_REFRESH);
1042 polarAlignWidget->updatePAHStage(m_PAHStage);
1043 auto message = getPAHMessage();
1044 refreshText->setText(message);
1045 emit newPAHMessage(message);
1047 PAHRefreshB->setEnabled(
false);
1050 if (m_AlignView->isEQGridShown())
1051 m_AlignView->toggleEQGrid();
1053 m_AlignView->setRefreshEnabled(
true);
1055 Options::setAstrometrySolverWCS(
false);
1056 Options::setAutoWCS(
false);
1059 emit captureAndSolve();
1062void PolarAlignmentAssistant::processPAHStage(
double orientation,
double ra,
double dec,
double pixscale,
1063 bool eastToTheRight,
short healpix,
short index)
1065 if (m_PAHStage == PAH_FIND_CP)
1068 i18n(
"Mount is synced to celestial pole. You can now continue Polar Alignment Assistant procedure."));
1069 setPAHStage(PAH_FIRST_CAPTURE);
1070 polarAlignWidget->updatePAHStage(m_PAHStage);
1074 if (m_PAHStage == PAH_FIRST_SOLVE || m_PAHStage == PAH_SECOND_SOLVE || m_PAHStage == PAH_THIRD_SOLVE)
1079 m_LastOrientation = orientation;
1080 m_LastPixscale = pixscale;
1081 m_HealpixToUse = healpix;
1082 m_IndexToUse = index;
1084 bool doWcs = (m_PAHStage == PAH_THIRD_SOLVE) || !Options::limitedResourcesMode();
1087 emit newLog(
i18n(
"Please wait while WCS data is processed..."));
1088 PAHMessageText->setText(
1089 m_PAHStage == PAH_FIRST_SOLVE
1090 ?
"Calculating WCS for the first image...</p>"
1091 : (m_PAHStage == PAH_SECOND_SOLVE ?
"Calculating WCS for the second image...</p>"
1092 :
"Calculating WCS for the third image...</p>"));
1094 connect(m_AlignView.get(), &AlignView::wcsToggled,
this, &Ekos::PolarAlignmentAssistant::setWCSToggled,
1096 m_AlignView->injectWCS(orientation, ra, dec, pixscale, eastToTheRight);
1103 m_ImageData = image;
1105 if (m_PAHStage == PAH_FIRST_CAPTURE)
1106 setPAHStage(PAH_FIRST_SOLVE);
1107 else if (m_PAHStage == PAH_SECOND_CAPTURE)
1108 setPAHStage(PAH_SECOND_SOLVE);
1109 else if (m_PAHStage == PAH_THIRD_CAPTURE)
1110 setPAHStage(PAH_THIRD_SOLVE);
1113 updateDisplay(m_PAHStage, getPAHMessage());
1116void PolarAlignmentAssistant::setWCSToggled(
bool result)
1118 emit newLog(
i18n(
"WCS data processing is complete."));
1120 disconnect(m_AlignView.get(), &AlignView::wcsToggled,
this, &Ekos::PolarAlignmentAssistant::setWCSToggled);
1122 if (m_PAHStage == PAH_FIRST_CAPTURE || m_PAHStage == PAH_FIRST_SOLVE)
1125 if (result ==
false && m_AlignInstance->wcsSynced() ==
true)
1127 emit newLog(
i18n(
"WCS info is now valid. Capturing next frame..."));
1128 emit captureAndSolve();
1133 polarAlign.addPoint(m_ImageData);
1135 setPAHStage(PAH_FIRST_ROTATE);
1136 auto msg = getPAHMessage();
1137 if (pAHManualSlew->isChecked())
1139 msg =
QString(
"Please rotate your mount about %1 deg in RA")
1140 .
arg(pAHRotation->value());
1143 updateDisplay(m_PAHStage, msg);
1147 else if (m_PAHStage == PAH_SECOND_CAPTURE || m_PAHStage == PAH_SECOND_SOLVE)
1149 setPAHStage(PAH_SECOND_ROTATE);
1150 auto msg = getPAHMessage();
1152 if (pAHManualSlew->isChecked())
1154 msg =
QString(
"Please rotate your mount about %1 deg in RA")
1155 .
arg(pAHRotation->value());
1158 updateDisplay(m_PAHStage, msg);
1160 polarAlign.addPoint(m_ImageData);
1164 else if (m_PAHStage == PAH_THIRD_CAPTURE || m_PAHStage == PAH_THIRD_SOLVE)
1167 if (result ==
false)
1169 emit newLog(
i18n(
"Failed to process World Coordinate System: %1. Try again.", m_ImageData->getLastError()));
1173 polarAlign.addPoint(m_ImageData);
1177 if (calculatePAHError())
1179 setPAHStage(PAH_STAR_SELECT);
1180 polarAlignWidget->updatePAHStage(m_PAHStage);
1181 PAHWidgets->setCurrentWidget(PAHRefreshPage);
1182 refreshText->setText(getPAHMessage());
1183 emit newPAHMessage(getPAHMessage());
1187 emit newLog(
i18n(
"PAA: Failed to find the RA axis. Quitting."));
1193void PolarAlignmentAssistant::setMountStatus(ISD::Mount::Status newState)
1197 case ISD::Mount::MOUNT_PARKING:
1198 case ISD::Mount::MOUNT_SLEWING:
1199 case ISD::Mount::MOUNT_MOVING:
1200 PAHStartB->setEnabled(
false);
1204 if (m_PAHStage == PAH_IDLE)
1205 PAHStartB->setEnabled(
true);
1210QString PolarAlignmentAssistant::getPAHMessage()
const
1216 return introText->text();
1217 case PAH_FIRST_CAPTURE:
1218 return i18n(
"<p>The assistant requires three images to find a solution. Ekos is now capturing the first image...</p>");
1219 case PAH_FIRST_SOLVE:
1220 return i18n(
"<p>Solving the <i>first</i> image...</p>");
1221 case PAH_FIRST_ROTATE:
1222 return i18n(
"<p>Executing the <i>first</i> mount rotation...</p>");
1223 case PAH_FIRST_SETTLE:
1224 return i18n(
"<p>Settling after the <i>first</i> mount rotation.</p>");
1225 case PAH_SECOND_SETTLE:
1226 return i18n(
"<p>Settling after the <i>second</i> mount rotation.</p>");
1227 case PAH_SECOND_CAPTURE:
1228 return i18n(
"<p>Capturing the second image...</p>");
1229 case PAH_SECOND_SOLVE:
1230 return i18n(
"<p>Solving the <i>second</i> image...</p>");
1231 case PAH_SECOND_ROTATE:
1232 return i18n(
"<p>Executing the <i>second</i> mount rotation...</p>");
1233 case PAH_THIRD_CAPTURE:
1234 return i18n(
"<p>Capturing the <i>third</i> and final image...</p>");
1235 case PAH_THIRD_SOLVE:
1236 return i18n(
"<p>Solving the <i>third</i> image...</p>");
1237 case PAH_STAR_SELECT:
1238 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
1239 return i18n(
"<p>Choose your exposure time & select an adjustment method. Then click <i>refresh</i> to begin adjustments.</p>");
1241 return i18n(
"<p>Choose your exposure time & select an adjustment method. Click <i>Refresh</i> to begin.</p><p>Correction triangle is plotted above. <i>Zoom in and select a bright star</i> to reposition the correction vector. Use the <i>MoveStar & Calc Error</i> method to estimate the remaining error.</p>");
1243 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
1244 return i18n(
"<p>Adjust mount's <i>Altitude and Azimuth knobs</i> to reduce the polar alignment error.</p><p>Be patient, plate solving can be affected by knob movement. Consider using results after 2 images. Click <i>Stop</i> when you're finished.</p>");
1246 return i18n(
"<p>Adjust mount's <i>Altitude knob</i> to move the star along the yellow line, then adjust the <i>Azimuth knob</i> to move it along the Green line until the selected star is centered within the crosshair.</p><p>Click <i>Stop</i> when the star is centered.</p>");
1254void PolarAlignmentAssistant::setPAHRefreshAlgorithm(RefreshAlgorithm value)
1258 if ((m_PAHStage == PAH_REFRESH) && refreshIteration > 0 && (value != PLATE_SOLVE_ALGORITHM)
1259 && !starCorrespondencePAH.size())
1261 pAHRefreshAlgorithm->setCurrentIndex(PLATE_SOLVE_ALGORITHM);
1262 emit newLog(
i18n(
"Cannot change to MoveStar algorithm once refresh has begun"));
1265 if (m_PAHStage == PAH_REFRESH || m_PAHStage == PAH_STAR_SELECT)
1267 refreshText->setText(getPAHMessage());
1268 emit newPAHMessage(getPAHMessage());
1271 showUpdatedError((value == PLATE_SOLVE_ALGORITHM) ||
1272 (value == MOVE_STAR_UPDATE_ERR_ALGORITHM));
1273 if (value == PLATE_SOLVE_ALGORITHM)
1274 updatePlateSolveTriangle(m_ImageData);
1276 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
const CachingDms * lat() const
The sky coordinates of a point in the sky.
const CachingDms & dec() const
const CachingDms & ra() const
An angle, stored as degrees, but expressible in many ways.
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
const dms deltaAngle(dms angle) const
deltaAngle Return the shortest difference (path) between this angle and the supplied angle.
const double & Degrees() const
KLocalizedString KI18N_EXPORT ki18n(const char *text)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
void currentIndexChanged(int index)
void append(QList< T > &&value)
qsizetype count() const const
qsizetype size() const const
bool disconnect(const QMetaObject::Connection &connection)
void drawConvexPolygon(const QPoint *points, int pointCount)
void drawRect(const QRect &rectangle)
bool isNull() const const
QString arg(Args &&... args) const const
QTextStream & dec(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)