Kstars

polaralignmentassistant.cpp
1/* Ekos Polar Alignment Assistant Tool
2 SPDX-FileCopyrightText: 2018-2021 Jasem Mutlaq
3 SPDX-FileCopyrightText: 2020-2021 Hy Murveit
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#include "polaralignmentassistant.h"
9
10#include "align.h"
11#include "alignview.h"
12#include "kstars.h"
13#include "kstarsdata.h"
14#include "ksmessagebox.h"
15#include "ekos/auxiliary/stellarsolverprofile.h"
16#include "ekos/auxiliary/solverutils.h"
17#include "Options.h"
18#include "polaralignwidget.h"
19#include <ekos_align_debug.h>
20
21#define PAA_VERSION "v3.0"
22
23namespace Ekos
24{
25
26const QMap<PolarAlignmentAssistant::Stage, KLocalizedString> PolarAlignmentAssistant::PAHStages =
27{
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")},
43};
44
45PolarAlignmentAssistant::PolarAlignmentAssistant(Align *parent, const QSharedPointer<AlignView> &view) : QWidget(parent)
46{
47 setupUi(this);
48 polarAlignWidget = new PolarAlignWidget();
49 mainPALayout->insertWidget(0, polarAlignWidget);
50
51 m_AlignInstance = parent;
52 m_AlignView = view;
53
54 showUpdatedError((pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM) ||
55 (pAHRefreshAlgorithm->currentIndex() == MOVE_STAR_UPDATE_ERR_ALGORITHM));
56
57 connect(pAHRefreshAlgorithm, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index)
58 {
59 setPAHRefreshAlgorithm(static_cast<RefreshAlgorithm>(index));
60 });
61 starCorrespondencePAH.reset();
62
63 // PAH Connections
64 PAHWidgets->setCurrentWidget(PAHIntroPage);
65 connect(this, &PolarAlignmentAssistant::PAHEnabled, [&](bool enabled)
66 {
67 PAHStartB->setEnabled(enabled);
68 directionLabel->setEnabled(enabled);
69 pAHDirection->setEnabled(enabled);
70 pAHRotation->setEnabled(enabled);
71 pAHMountSpeed->setEnabled(enabled);
72 pAHManualSlew->setEnabled(enabled);
73 });
74 connect(PAHStartB, &QPushButton::clicked, this, &Ekos::PolarAlignmentAssistant::startPAHProcess);
75 // PAH StopB is just a shortcut for the regular stop
76 connect(PAHStopB, &QPushButton::clicked, this, &PolarAlignmentAssistant::stopPAHProcess);
77 connect(PAHRefreshB, &QPushButton::clicked, this, &Ekos::PolarAlignmentAssistant::startPAHRefreshProcess);
78 // done button for manual slewing during polar alignment:
79 connect(PAHManualDone, &QPushButton::clicked, this, &Ekos::PolarAlignmentAssistant::setPAHSlewDone);
80
81 hemisphere = KStarsData::Instance()->geo()->lat()->Degrees() > 0 ? NORTH_HEMISPHERE : SOUTH_HEMISPHERE;
82
83 label_PAHOrigErrorAz->setText("Az: ");
84 label_PAHOrigErrorAlt->setText("Alt: ");
85}
86
87PolarAlignmentAssistant::~PolarAlignmentAssistant()
88{
89}
90
91void PolarAlignmentAssistant::showUpdatedError(bool show)
92{
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);
99}
100
101void PolarAlignmentAssistant::syncMountSpeed(const QString &speed)
102{
103 pAHMountSpeed->blockSignals(true);
104 pAHMountSpeed->clear();
105 pAHMountSpeed->addItems(m_CurrentTelescope->slewRates());
106 pAHMountSpeed->setCurrentText(speed);
107 pAHMountSpeed->blockSignals(false);
108}
109
110void PolarAlignmentAssistant::setEnabled(bool enabled)
111{
112 QWidget::setEnabled(enabled);
113
114 emit PAHEnabled(enabled);
115 if (enabled)
116 {
117 PAHWidgets->setToolTip(QString());
118 FOVDisabledLabel->hide();
119 }
120 else
121 {
122 PAHWidgets->setToolTip(i18n("<p>Polar Alignment tool requires a German Equatorial Mount.</p>"));
123 FOVDisabledLabel->show();
124 }
125
126}
127
128// This solver is only used by the refresh plate-solving scheme.
129void PolarAlignmentAssistant::startSolver()
130{
131 auto profiles = getDefaultAlignOptionsProfiles();
132 SSolver::Parameters parameters;
133 // Get solver parameters
134 // In case of exception, use first profile
135 try
136 {
137 parameters = profiles.at(Options::solveOptionsProfile());
138 }
139 catch (std::out_of_range const &)
140 {
141 parameters = profiles[0];
142 }
143
144 // Double search radius
145 parameters.search_radius = parameters.search_radius * 2;
146 constexpr double solverTimeout = 10.0;
147
148 m_Solver.reset(new SolverUtils(parameters, solverTimeout), &QObject::deleteLater);
149 connect(m_Solver.get(), &SolverUtils::done, this, &PolarAlignmentAssistant::solverDone, Qt::UniqueConnection);
150
151 // Use the scale and position from the most recent solve.
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);
156}
157
158void PolarAlignmentAssistant::solverDone(bool timedOut, bool success, const FITSImage::Solution &solution,
159 double elapsedSeconds)
160{
161 disconnect(m_Solver.get(), &SolverUtils::done, this, &PolarAlignmentAssistant::solverDone);
162
163 if (m_PAHStage != PAH_REFRESH)
164 return;
165
166 if (timedOut || !success)
167 {
168 // I'm torn between 1 and 2 for this constant.
169 // 1: If a solve failed, open up the search next time.
170 // 2: A common reason for a solve to fail is because a knob was adjusted during the exposure.
171 // Let it try one more time.
172 constexpr int MAX_NUM_HEALPIX_FAILURES = 2;
173 if (++m_NumHealpixFailures >= MAX_NUM_HEALPIX_FAILURES)
174 {
175 // Don't use the previous index and healpix next time we solve.
176 m_IndexToUse = -1;
177 m_HealpixToUse = -1;
178 }
179 }
180 else
181 {
182 // Get the index and healpix from the successful solve.
183 m_Solver->getSolutionHealpix(&m_IndexToUse, &m_HealpixToUse);
184 }
185
186 if (timedOut)
187 {
188 emit newLog(i18n("Refresh solver timed out: %1s", QString("%L1").arg(elapsedSeconds, 0, 'f', 1)));
189 emit captureAndSolve();
190 }
191 else if (!success)
192 {
193 emit newLog(i18n("Refresh solver failed: %1s", QString("%L1").arg(elapsedSeconds, 0, 'f', 1)));
194 emit updatedErrorsChanged(-1, -1, -1);
195 emit captureAndSolve();
196 }
197 else
198 {
199 m_NumHealpixFailures = 0;
200 refreshIteration++;
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;
207
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));
211
212 // RA is input in hours, not degrees!
213 SkyPoint refreshCoords(ra / 15.0, dec);
214 double azError = 0, altError = 0;
215 if (polarAlign.processRefreshCoords(refreshCoords, m_ImageData->getDateTime(), &azError, &altError))
216 {
217 updateRefreshDisplay(azError, altError);
218
219 const bool eastToTheRight = solution.parity == FITSImage::POSITIVE ? false : true;
220 // The 2nd false means don't block. The code below doesn't work if we block
221 // because wcsToPixel in updateTriangle() depends on the injectWCS being finished.
222 m_AlignView->injectWCS(solution.orientation, ra, dec, solution.pixscale, eastToTheRight, false);
223 updatePlateSolveTriangle(m_ImageData);
224 }
225 else
226 emit newLog(QString("Could not estimate mount rotation"));
227 }
228 // Start the next refresh capture.
229 emit captureAndSolve();
230}
231
232void PolarAlignmentAssistant::updatePlateSolveTriangle(const QSharedPointer<FITSData> &image)
233{
234 if (image.isNull())
235 return;
236
237 // To render the triangle for the plate-solve refresh, we need image coordinates for
238 // - the original (3rd image) center point (originalPoint)
239 // - the solution point (solutionPoint),
240 // - the alt-only solution point (altOnlyPoint),
241 // - the current center of the image (centerPixel),
242 // The triangle is made from the first 3 above.
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))
249 {
250 m_AlignView->setCorrectionParams(originalPixel, solutionPixel, altOnlyPixel);
251 m_AlignView->setStarCircle(centerPixel);
252 }
253 else
254 {
255 qCDebug(KSTARS_EKOS_ALIGN) << "wcs failed";
256 }
257}
258
259namespace
260{
261
262// These functions paint up/down/left/right-pointing arrows in a box of size w x h.
263
264void upArrow(QPainter *painter, int w, int h)
265{
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);
269 QPolygonF arrowHead;
270 arrowHead << QPointF(wCenter, h * .1) << QPointF(w * .2, h * .4) << QPointF(w * .8, h * .4);
271 painter->drawConvexPolygon(arrowHead);
272}
273void downArrow(QPainter *painter, int w, int h)
274{
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);
278 QPolygonF arrowHead;
279 arrowHead << QPointF(wCenter, h * .9) << QPointF(w * .2, h * .6) << QPointF(w * .8, h * .6);
280 painter->drawConvexPolygon(arrowHead);
281}
282void leftArrow(QPainter *painter, int w, int h)
283{
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);
287 QPolygonF arrowHead;
288 arrowHead << QPointF(w * .1, hCenter) << QPointF(w * .4, h * .2) << QPointF(w * .4, h * .8);
289 painter->drawConvexPolygon(arrowHead);
290}
291void rightArrow(QPainter *painter, int w, int h)
292{
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);
296 QPolygonF arrowHead;
297 arrowHead << QPointF(w * .9, hCenter) << QPointF(w * .6, h * .2) << QPointF(w * .6, h * .8);
298 painter->drawConvexPolygon(arrowHead);
299}
300} // namespace
301
302// Draw arrows that give the user a hint of how he/she needs to adjust the azimuth and altitude
303// knobs. The arrows' size changes depending on the azimuth and altitude error.
304void PolarAlignmentAssistant::drawArrows(double azError, double altError)
305{
306 constexpr double minError = 20.0 / 3600.0; // 20 arcsec
307 double absError = fabs(altError);
308
309 // these constants are worked out so a 10' error gives a size of 100
310 // and a 1' error gives a size of 20.
311 constexpr double largeErr = 10.0 / 60.0, smallErr = 1.0 / 60.0, largeSize = 100, smallSize = 20, c1 = 533.33, c2 = 11.111;
312
313 int size = 0;
314 if (absError > largeErr)
315 size = largeSize;
316 else if (absError < smallErr)
317 size = smallSize;
318 else size = absError * c1 + c2;
319
320 QPixmap altPixmap(size, size);
321 altPixmap.fill(QColor("transparent"));
322 QPainter altPainter(&altPixmap);
323 altPainter.setBrush(arrowAlt->palette().color(QPalette::WindowText));
324
325 if (altError > minError)
326 downArrow(&altPainter, size, size);
327 else if (altError < -minError)
328 upArrow(&altPainter, size, size);
329 arrowAlt->setPixmap(altPixmap);
330
331 absError = fabs(azError);
332 if (absError > largeErr)
333 size = largeSize;
334 else if (absError < smallErr)
335 size = smallSize;
336 else size = absError * c1 + c2;
337
338 QPixmap azPixmap(size, size);
339 azPixmap.fill(QColor("transparent"));
340 QPainter azPainter(&azPixmap);
341 azPainter.setBrush(arrowAz->palette().color(QPalette::WindowText));
342
343 if (azError > minError)
344 leftArrow(&azPainter, size, size);
345 else if (azError < -minError)
346 rightArrow(&azPainter, size, size);
347 arrowAz->setPixmap(azPixmap);
348}
349
350bool PolarAlignmentAssistant::detectStarsPAHRefresh(QList<Edge> *stars, int num, int x, int y, int *starIndex)
351{
352 stars->clear();
353 *starIndex = -1;
354
355 // Use the solver settings from the align tab for for "polar-align refresh" star detection.
356 QVariantMap settings;
357 settings["optionsProfileIndex"] = Options::solveOptionsProfile();
358 settings["optionsProfileGroup"] = static_cast<int>(Ekos::AlignProfiles);
359 m_ImageData->setSourceExtractorSettings(settings);
360
361 QElapsedTimer timer;
362 m_ImageData->findStars(ALGORITHM_SEP).waitForFinished();
363
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;
367
368 QList<Edge *> detectedStars = m_ImageData->getStarCenters();
369 // Let's sort detectedStars by flux, starting with widest
370 std::sort(detectedStars.begin(), detectedStars.end(), [](const Edge * edge1, const Edge * edge2) -> bool { return edge1->sum > edge2->sum;});
371
372 // Find the closest star to the x,y position, which is where the user clicked on the alignView.
373 double bestDist = 1e9;
374 int bestIndex = -1;
375 for (int i = 0; i < detectedStars.size(); i++)
376 {
377 double dx = detectedStars[i]->x - x;
378 double dy = detectedStars[i]->y - y;
379 double dist = dx * dx + dy * dy;
380 if (dist < bestDist)
381 {
382 bestDist = dist;
383 bestIndex = i;
384 }
385 }
386
387 int starCount = qMin(num, detectedStars.count());
388 for (int i = 0; i < starCount; i++)
389 stars->append(*(detectedStars[i]));
390 if (bestIndex >= starCount)
391 {
392 // If we found the star, but requested 'num' stars, and the user's star
393 // is lower down in the list, add it and return num+1 stars.
394 stars->append(*(detectedStars[bestIndex]));
395 *starIndex = starCount;
396 }
397 else
398 {
399 *starIndex = bestIndex;
400 }
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;
403
404 detectedStars.clear();
405
406 return stars->count();
407}
408
409void PolarAlignmentAssistant::updateRefreshDisplay(double azE, double altE)
410{
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());
417
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());
423}
424
425void PolarAlignmentAssistant::processPAHRefresh()
426{
427 m_AlignView->setStarCircle();
428 PAHUpdatedErrorTotal->clear();
429 PAHIteration->clear();
430 PAHUpdatedErrorAlt->clear();
431 PAHUpdatedErrorAz->clear();
432 QString debugString;
433 imageNumber++;
434 PAHIteration->setText(QString("Image %1").arg(imageNumber));
435
436 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
437 {
438 startSolver();
439 return;
440 }
441
442 // Always run on the initial iteration to setup the user's star,
443 // so that if it is enabled later the star could be tracked.
444 // Flaw here is that if enough stars are not detected, iteration is not incremented,
445 // so it may repeat.
446 if ((pAHRefreshAlgorithm->currentIndex() == MOVE_STAR_UPDATE_ERR_ALGORITHM) || (refreshIteration == 0))
447 {
448 constexpr int MIN_PAH_REFRESH_STARS = 10;
449
450 QList<Edge> stars;
451 // Index of user's star in the detected stars list. In the first iteration
452 // the stars haven't moved and we can just use the location of the click.
453 // Later we'll need to find the star with starCorrespondence.
454 int clickedStarIndex;
455 detectStarsPAHRefresh(&stars, 100, correctionFrom.x(), correctionFrom.y(), &clickedStarIndex);
456 if (clickedStarIndex < 0)
457 {
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;
461
462 emit newAlignTableResult(Align::ALIGN_RESULT_FAILED);
463 emit captureAndSolve();
464 return;
465 }
466
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;
473
474 if (stars.size() > MIN_PAH_REFRESH_STARS)
475 {
476 int dx = 0;
477 int dy = 0;
478 int starIndex = -1;
479
480 if (refreshIteration++ == 0)
481 {
482 // First iteration. Setup starCorrespondence so we can find the user's star.
483 // clickedStarIndex should be the index of a detected star near where the user clicked.
484 starCorrespondencePAH.initialize(stars, clickedStarIndex);
485 if (clickedStarIndex >= 0)
486 {
487 setupCorrectionGraphics(QPointF(stars[clickedStarIndex].x, stars[clickedStarIndex].y));
488 emit newCorrectionVector(QLineF(correctionFrom, correctionTo));
489 emit newFrame(m_AlignView);
490 }
491 }
492 else
493 {
494 // Or, in other iterations find the movement of the "user's star".
495 // The 0.40 means it's OK if star correspondence only finds 40% of the
496 // reference stars (as we'd have more issues near the image edge otherwise).
497 QVector<int> starMap;
498 starCorrespondencePAH.find(stars, 200.0, &starMap, false, 0.40);
499
500 // Go through the starMap, and find the user's star, and compare its position
501 // to its initial position.
502 for (int i = 0; i < starMap.size(); ++i)
503 {
504 if (starMap[i] == starCorrespondencePAH.guideStar())
505 {
506 dx = stars[i].x - correctionFrom.x();
507 dy = stars[i].y - correctionFrom.y();
508 starIndex = i;
509 break;
510 }
511 }
512 if (starIndex == -1)
513 {
514 bool allOnes = true;
515 for (int i = 0; i < starMap.size(); ++i)
516 {
517 if (starMap[i] != -1)
518 allOnes = false;
519 }
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;
522 }
523 }
524
525 if (starIndex >= 0)
526 {
527 // Annotate the user's star on the alignview.
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;
532
533 double azE, altE;
534 if (polarAlign.pixelError(m_AlignView->keptImage(), QPointF(stars[starIndex].x, stars[starIndex].y),
535 correctionTo, &azE, &altE))
536 {
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;
543 }
544 else
545 {
546 debugString = QString("PAA Refresh(%1): pixelError failed to estimate the remaining correction").arg(refreshIteration);
547 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
548 }
549 }
550 else
551 {
552 if (refreshIteration > 1)
553 {
554 debugString = QString("PAA Refresh(%1): Didn't find the user's star").arg(refreshIteration);
555 qCDebug(KSTARS_EKOS_ALIGN) << debugString;
556 }
557 }
558 }
559 else
560 {
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);
564 }
565 }
566 // Finally start the next capture
567 emit captureAndSolve();
568}
569
570bool PolarAlignmentAssistant::processSolverFailure()
571{
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)
579 {
580 emit newLog(i18n("PAA: Solver failed, retrying."));
581 emit captureAndSolve();
582 return true;
583 }
584
585 if (m_PAHStage != PAH_IDLE)
586 {
587 emit newLog(i18n("PAA: Stopping, solver failed too many times."));
588 stopPAHProcess();
589 }
590
591 return false;
592}
593
594void PolarAlignmentAssistant::setPAHStage(Stage stage)
595{
596 if (stage != m_PAHStage)
597 {
598 m_PAHStage = stage;
599 polarAlignWidget->updatePAHStage(stage);
600 emit newPAHStage(m_PAHStage);
601 }
602}
603
604void PolarAlignmentAssistant::processMountRotation(const dms &ra, double settleDuration)
605{
606 double deltaAngle = fabs(ra.deltaAngle(targetPAH.ra()).Degrees());
607
608 QString rotProgressMessage;
609 QString rotDoneMessage;
610 Stage nextCapture;
611 Stage nextSettle;
612
613 if (m_PAHStage == PAH_FIRST_ROTATE)
614 {
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;
619 }
620 else if (m_PAHStage == PAH_SECOND_ROTATE)
621 {
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;
626 }
627 else return;
628
629 if (m_PAHStage == PAH_FIRST_ROTATE || m_PAHStage == PAH_SECOND_ROTATE)
630 {
631 // only wait for telescope to slew to new position if manual slewing is switched off
632 if(!pAHManualSlew->isChecked())
633 {
634 qCDebug(KSTARS_EKOS_ALIGN) << rotProgressMessage << deltaAngle;
635 if (deltaAngle <= PAH_ROTATION_THRESHOLD)
636 {
637 m_CurrentTelescope->StopWE();
638 emit newLog(rotDoneMessage);
639
640 if (settleDuration <= 0)
641 {
642 setPAHStage(nextCapture);
643 updateDisplay(m_PAHStage, getPAHMessage());
644 }
645 else
646 {
647 setPAHStage(nextSettle);
648 updateDisplay(m_PAHStage, getPAHMessage());
649
650 emit newLog(i18n("Settling..."));
651 QTimer::singleShot(settleDuration, [nextCapture, this]()
652 {
653 setPAHStage(nextCapture);
654 updateDisplay(m_PAHStage, getPAHMessage());
655 });
656 }
657 }
658 // If for some reason we didn't stop, let's stop if we get too far
659 else if (deltaAngle > pAHRotation->value() * 1.25)
660 {
661 m_CurrentTelescope->abort();
662 emit newLog(i18n("Mount aborted. Reverse RA axis direction and try again."));
663 stopPAHProcess();
664 }
665 return;
666 } // endif not manual slew
667 }
668}
669
670bool PolarAlignmentAssistant::checkPAHForMeridianCrossing()
671{
672 // Make sure using -180 to 180 for hourAngle and DEC. (Yes dec should be between -90 and 90).
673 double hourAngle = m_CurrentTelescope->hourAngle().Degrees();
674 while (hourAngle < -180)
675 hourAngle += 360;
676 while (hourAngle > 180)
677 hourAngle -= 360;
678 double ra = 0, dec = 0;
679 m_CurrentTelescope->getEqCoords(&ra, &dec);
680 while (dec < -180)
681 dec += 360;
682 while (dec > 180)
683 dec -= 360;
684
685 // Don't do this check within 2 degrees of the poles.
686 bool nearThePole = fabs(dec) > 88;
687 if (nearThePole)
688 return false;
689
690 double degreesPerSlew = pAHRotation->value();
691 bool closeToMeridian = fabs(hourAngle) < 2.0 * degreesPerSlew;
692 bool goingWest = pAHDirection->currentIndex() == 0;
693
694 // If the pier is on the east side (pointing west) and will slew west and is within 2 slews of the HA=0,
695 // or on the west side (pointing east) and will slew east, and is within 2 slews of HA=0
696 // then warn and give the user a chance to cancel.
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));
701
702 return wouldCrossMeridian;
703}
704
705void PolarAlignmentAssistant::updateDisplay(Stage stage, const QString &message)
706{
707 switch(stage)
708 {
709 case PAH_FIRST_ROTATE:
710 case PAH_SECOND_ROTATE:
711 if (pAHManualSlew->isChecked())
712 {
713 polarAlignWidget->updatePAHStage(stage);
714 PAHWidgets->setCurrentWidget(PAHManualRotatePage);
715 manualRotateText->setText(message);
716 emit newPAHMessage(message);
717 return;
718 }
719 // fall through
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);
730 break;
731
732 default:
733 break;
734
735 }
736}
737
738void PolarAlignmentAssistant::startPAHProcess()
739{
740 qCInfo(KSTARS_EKOS_ALIGN) << QString("Starting Polar Alignment Assistant process %1 ...").arg(PAA_VERSION);
741
742 auto executePAH = [ this ]()
743 {
744 setPAHStage(PAH_FIRST_CAPTURE);
745
746 if (Options::limitedResourcesMode())
747 emit newLog(i18n("Warning: Equatorial Grid Lines will not be drawn due to limited resources mode."));
748
749 if (m_CurrentTelescope->hasAlignmentModel())
750 {
751 emit newLog(i18n("Clearing mount Alignment Model..."));
752 m_CurrentTelescope->clearAlignmentModel();
753 }
754
755 // Unpark
756 m_CurrentTelescope->unpark();
757
758 // Set tracking ON if not already
759 if (m_CurrentTelescope->canControlTrack() && m_CurrentTelescope->isTracking() == false)
760 m_CurrentTelescope->setTrackEnabled(true);
761
762 PAHStartB->setEnabled(false);
763 PAHStopB->setEnabled(true);
764
765 PAHUpdatedErrorTotal->clear();
766 PAHUpdatedErrorAlt->clear();
767 PAHUpdatedErrorAz->clear();
768 PAHOrigErrorTotal->clear();
769 PAHOrigErrorAlt->clear();
770 PAHOrigErrorAz->clear();
771 PAHIteration->setText("");
772
773 updateDisplay(m_PAHStage, getPAHMessage());
774
775 m_AlignView->setCorrectionParams(QPointF(), QPointF(), QPointF());
776
777 m_PAHRetrySolveCounter = 0;
778 emit captureAndSolve();
779 };
780
781 // Right off the bat, check if this alignment might cause a pier crash.
782 // If we're crossing the meridian, warn unless within 5-degrees from the pole.
783 if (checkPAHForMeridianCrossing())
784 {
785 // Continue
786 connect(KSMessageBox::Instance(), &KSMessageBox::accepted, this, [this, executePAH]()
787 {
788 KSMessageBox::Instance()->disconnect(this);
789 executePAH();
790 });
791
792 KSMessageBox::Instance()->warningContinueCancel(i18n("This could cause the telescope to cross the meridian."),
793 i18n("Warning"), 15);
794 }
795 else
796 executePAH();
797}
798
799void PolarAlignmentAssistant::stopPAHProcess()
800{
801 if (m_PAHStage == PAH_IDLE)
802 return;
803
804 // Only display dialog if user clicked.
805 // if ((static_cast<QPushButton *>(sender()) == PAHStopB) && KMessageBox::questionYesNo(KStars::Instance(),
806 // i18n("Are you sure you want to stop the polar alignment process?"),
807 // i18n("Polar Alignment Assistant"), KStandardGuiItem::yes(), KStandardGuiItem::no(),
808 // "restart_PAA_process_dialog") == KMessageBox::No)
809 // return;
810
811 if (m_PAHStage == PAH_REFRESH)
812 {
813 setPAHStage(PAH_POST_REFRESH);
814 polarAlignWidget->updatePAHStage(m_PAHStage);
815 }
816 qCInfo(KSTARS_EKOS_ALIGN) << "Stopping Polar Alignment Assistant process...";
817
818
819 if (m_CurrentTelescope && m_CurrentTelescope->isInMotion())
820 m_CurrentTelescope->abort();
821
822 setPAHStage(PAH_IDLE);
823 polarAlignWidget->updatePAHStage(m_PAHStage);
824
825 PAHStartB->setEnabled(true);
826 PAHStopB->setEnabled(false);
827 PAHRefreshB->setEnabled(true);
828 PAHWidgets->setCurrentWidget(PAHIntroPage);
829 emit newPAHMessage(introText->text());
830
831 m_AlignView->reset();
832 m_AlignView->setRefreshEnabled(false);
833
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);
838
839 if (Options::pAHAutoPark())
840 {
841 m_CurrentTelescope->park();
842 emit newLog(i18n("Parking the mount..."));
843 }
844}
845
846void PolarAlignmentAssistant::rotatePAH()
847{
848 double TargetDiffRA = pAHRotation->value();
849 bool westMeridian = pAHDirection->currentIndex() == 0;
850
851 // West
852 if (westMeridian)
853 TargetDiffRA *= -1;
854 // East
855 else
856 TargetDiffRA *= 1;
857
858 // JM 2018-05-03: Hemispheres shouldn't affect rotation direction in RA
859
860 // if Manual slewing is selected, don't move the mount
861 if (pAHManualSlew->isChecked())
862 {
863 return;
864 }
865
866 const SkyPoint telescopeCoord = m_CurrentTelescope->currentCoordinates();
867
868 // TargetDiffRA is in degrees
869 dms newTelescopeRA = (telescopeCoord.ra() + dms(TargetDiffRA)).reduce();
870
871 targetPAH.setRA(newTelescopeRA);
872 targetPAH.setDec(telescopeCoord.dec());
873
874 //m_CurrentTelescope->Slew(&targetPAH);
875 // Set Selected Speed
876 if (pAHMountSpeed->currentIndex() >= 0)
877 m_CurrentTelescope->setSlewRate(pAHMountSpeed->currentIndex());
878 // Go to direction
879 m_CurrentTelescope->MoveWE(westMeridian ? ISD::Mount::MOTION_WEST : ISD::Mount::MOTION_EAST,
880 ISD::Mount::MOTION_START);
881
882 emit newLog(i18n("Please wait until mount completes rotating to RA (%1) DE (%2)", targetPAH.ra().toHMSString(),
883 targetPAH.dec().toDMSString()));
884}
885
886void PolarAlignmentAssistant::setupCorrectionGraphics(const QPointF &pixel)
887{
888 polarAlign.refreshSolution(&refreshSolution, &altOnlyRefreshSolution);
889
890 // We use the previously stored image (the 3rd PAA image)
891 // so we can continue to estimate the correction even after
892 // capturing new images during the refresh stage.
893 const QSharedPointer<FITSData> &imageData = m_AlignView->keptImage();
894
895 // Just the altitude correction
896 if (!polarAlign.findCorrectedPixel(imageData, pixel, &correctionAltTo, true))
897 {
898 qCInfo(KSTARS_EKOS_ALIGN) << QString(i18n("PAA: Failed to findCorrectedPixel."));
899 return;
900 }
901 // The whole correction.
902 if (!polarAlign.findCorrectedPixel(imageData, pixel, &correctionTo))
903 {
904 qCInfo(KSTARS_EKOS_ALIGN) << QString(i18n("PAA: Failed to findCorrectedPixel."));
905 return;
906 }
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;
913
914 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
915 updatePlateSolveTriangle(imageData);
916 else
917 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
918
919 return;
920}
921
922
923bool PolarAlignmentAssistant::calculatePAHError()
924{
925 // Hold on to the imageData so we can use it during the refresh phase.
926 m_AlignView->holdOnToImage();
927
928 if (!polarAlign.findAxis())
929 {
930 emit newLog(i18n("PAA: Failed to find RA Axis center."));
931 stopPAHProcess();
932 return false;
933 }
934
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);
940
941 // No need to toggle EQGrid
942 // if (m_AlignView->isEQGridShown() == false && !Options::limitedResourcesMode())
943 // m_AlignView->toggleEQGrid();
944
945 QString msg = QString("%1. Azimuth: %2 Altitude: %3")
946 .arg(polarError.toDMSString()).arg(azError.toDMSString())
947 .arg(altError.toDMSString());
948 emit newLog(QString("Polar Alignment Error: %1").arg(msg));
949
950 polarAlign.setMaxPixelSearchRange(polarError.Degrees() + 1);
951
952 // These are viewed during the refresh phase.
953 PAHOrigErrorTotal->setText(polarError.toDMSString());
954 PAHOrigErrorAlt->setText(altError.toDMSString());
955 PAHOrigErrorAz->setText(azError.toDMSString());
956
957 setupCorrectionGraphics(QPointF(m_ImageData->width() / 2, m_ImageData->height() / 2));
958
959 // Find Celestial pole location and mount's RA axis
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))
964 {
965 m_AlignView->setCelestialPole(celestialPolePoint);
966 QPointF raAxis;
967 if (polarAlign.findCorrectedPixel(m_ImageData, celestialPolePoint, &raAxis))
968 m_AlignView->setRaAxis(raAxis);
969 }
970
971 connect(m_AlignView.get(), &AlignView::trackingStarSelected, this, &Ekos::PolarAlignmentAssistant::setPAHCorrectionOffset);
972 emit polarResultUpdated(QLineF(correctionFrom, correctionTo), polarError.Degrees(), azError.Degrees(), altError.Degrees());
973
974 connect(m_AlignView.get(), &AlignView::newCorrectionVector, this, &Ekos::PolarAlignmentAssistant::newCorrectionVector,
976 syncCorrectionVector();
977 emit newFrame(m_AlignView);
978
979 return true;
980}
981
982void PolarAlignmentAssistant::syncCorrectionVector()
983{
984 if (pAHRefreshAlgorithm->currentIndex() == PLATE_SOLVE_ALGORITHM)
985 return;
986 emit newCorrectionVector(QLineF(correctionFrom, correctionTo));
987 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
988}
989
990void PolarAlignmentAssistant::setPAHCorrectionOffsetPercentage(double dx, double dy)
991{
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)));
995}
996
997void PolarAlignmentAssistant::setPAHCorrectionOffset(int x, int y)
998{
999 if (m_PAHStage == PAH_REFRESH)
1000 {
1001 emit newLog(i18n("Polar-alignment star cannot be updated during refresh phase as it might affect error measurements."));
1002 }
1003 else
1004 {
1005 setupCorrectionGraphics(QPointF(x, y));
1006 emit newCorrectionVector(QLineF(correctionFrom, correctionTo));
1007 emit newFrame(m_AlignView);
1008 }
1009}
1010
1011void PolarAlignmentAssistant::setPAHSlewDone()
1012{
1013 emit newPAHMessage("Manual slew done.");
1014 switch(m_PAHStage)
1015 {
1016 case PAH_FIRST_ROTATE :
1017 setPAHStage(PAH_SECOND_CAPTURE);
1018 emit newLog(i18n("First manual rotation done."));
1019 updateDisplay(m_PAHStage, getPAHMessage());
1020 break;
1021 case PAH_SECOND_ROTATE :
1022 setPAHStage(PAH_THIRD_CAPTURE);
1023 emit newLog(i18n("Second manual rotation done."));
1024 updateDisplay(m_PAHStage, getPAHMessage());
1025 break;
1026 default :
1027 return; // no other stage should be able to trigger this event
1028 }
1029}
1030
1031
1032
1033void PolarAlignmentAssistant::startPAHRefreshProcess()
1034{
1035 qCInfo(KSTARS_EKOS_ALIGN) << "Starting Polar Alignment Assistant refreshing...";
1036
1037 refreshIteration = 0;
1038 imageNumber = 0;
1039 m_NumHealpixFailures = 0;
1040
1041 setPAHStage(PAH_REFRESH);
1042 polarAlignWidget->updatePAHStage(m_PAHStage);
1043 auto message = getPAHMessage();
1044 refreshText->setText(message);
1045 emit newPAHMessage(message);
1046
1047 PAHRefreshB->setEnabled(false);
1048
1049 // Hide EQ Grids if shown
1050 if (m_AlignView->isEQGridShown())
1051 m_AlignView->toggleEQGrid();
1052
1053 m_AlignView->setRefreshEnabled(true);
1054
1055 Options::setAstrometrySolverWCS(false);
1056 Options::setAutoWCS(false);
1057
1058 // We for refresh, just capture really
1059 emit captureAndSolve();
1060}
1061
1062void PolarAlignmentAssistant::processPAHStage(double orientation, double ra, double dec, double pixscale,
1063 bool eastToTheRight, short healpix, short index)
1064{
1065 if (m_PAHStage == PAH_FIND_CP)
1066 {
1067 emit newLog(
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);
1071 return;
1072 }
1073
1074 if (m_PAHStage == PAH_FIRST_SOLVE || m_PAHStage == PAH_SECOND_SOLVE || m_PAHStage == PAH_THIRD_SOLVE)
1075 {
1076 // Used by refresh, when looking at the 3rd image.
1077 m_LastRa = ra;
1078 m_LastDec = dec;
1079 m_LastOrientation = orientation;
1080 m_LastPixscale = pixscale;
1081 m_HealpixToUse = healpix;
1082 m_IndexToUse = index;
1083
1084 bool doWcs = (m_PAHStage == PAH_THIRD_SOLVE) || !Options::limitedResourcesMode();
1085 if (doWcs)
1086 {
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>"));
1093 }
1094 connect(m_AlignView.get(), &AlignView::wcsToggled, this, &Ekos::PolarAlignmentAssistant::setWCSToggled,
1096 m_AlignView->injectWCS(orientation, ra, dec, pixscale, eastToTheRight);
1097 return;
1098 }
1099}
1100
1101void PolarAlignmentAssistant::setImageData(const QSharedPointer<FITSData> &image)
1102{
1103 m_ImageData = image;
1104
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);
1111 else
1112 return;
1113 updateDisplay(m_PAHStage, getPAHMessage());
1114}
1115
1116void PolarAlignmentAssistant::setWCSToggled(bool result)
1117{
1118 emit newLog(i18n("WCS data processing is complete."));
1119
1120 disconnect(m_AlignView.get(), &AlignView::wcsToggled, this, &Ekos::PolarAlignmentAssistant::setWCSToggled);
1121
1122 if (m_PAHStage == PAH_FIRST_CAPTURE || m_PAHStage == PAH_FIRST_SOLVE)
1123 {
1124 // We need WCS to be synced first
1125 if (result == false && m_AlignInstance->wcsSynced() == true)
1126 {
1127 emit newLog(i18n("WCS info is now valid. Capturing next frame..."));
1128 emit captureAndSolve();
1129 return;
1130 }
1131
1132 polarAlign.reset();
1133 polarAlign.addPoint(m_ImageData);
1134
1135 setPAHStage(PAH_FIRST_ROTATE);
1136 auto msg = getPAHMessage();
1137 if (pAHManualSlew->isChecked())
1138 {
1139 msg = QString("Please rotate your mount about %1 deg in RA")
1140 .arg(pAHRotation->value());
1141 emit newLog(msg);
1142 }
1143 updateDisplay(m_PAHStage, msg);
1144
1145 rotatePAH();
1146 }
1147 else if (m_PAHStage == PAH_SECOND_CAPTURE || m_PAHStage == PAH_SECOND_SOLVE)
1148 {
1149 setPAHStage(PAH_SECOND_ROTATE);
1150 auto msg = getPAHMessage();
1151
1152 if (pAHManualSlew->isChecked())
1153 {
1154 msg = QString("Please rotate your mount about %1 deg in RA")
1155 .arg(pAHRotation->value());
1156 emit newLog(msg);
1157 }
1158 updateDisplay(m_PAHStage, msg);
1159
1160 polarAlign.addPoint(m_ImageData);
1161
1162 rotatePAH();
1163 }
1164 else if (m_PAHStage == PAH_THIRD_CAPTURE || m_PAHStage == PAH_THIRD_SOLVE)
1165 {
1166 // Critical error
1167 if (result == false)
1168 {
1169 emit newLog(i18n("Failed to process World Coordinate System: %1. Try again.", m_ImageData->getLastError()));
1170 return;
1171 }
1172
1173 polarAlign.addPoint(m_ImageData);
1174
1175 // We have 3 points which uniquely defines a circle with its center representing the RA Axis
1176 // We have celestial pole location. So correction vector is just the vector between these two points
1177 if (calculatePAHError())
1178 {
1179 setPAHStage(PAH_STAR_SELECT);
1180 polarAlignWidget->updatePAHStage(m_PAHStage);
1181 PAHWidgets->setCurrentWidget(PAHRefreshPage);
1182 refreshText->setText(getPAHMessage());
1183 emit newPAHMessage(getPAHMessage());
1184 }
1185 else
1186 {
1187 emit newLog(i18n("PAA: Failed to find the RA axis. Quitting."));
1188 stopPAHProcess();
1189 }
1190 }
1191}
1192
1193void PolarAlignmentAssistant::setMountStatus(ISD::Mount::Status newState)
1194{
1195 switch (newState)
1196 {
1197 case ISD::Mount::MOUNT_PARKING:
1198 case ISD::Mount::MOUNT_SLEWING:
1199 case ISD::Mount::MOUNT_MOVING:
1200 PAHStartB->setEnabled(false);
1201 break;
1202
1203 default:
1204 if (m_PAHStage == PAH_IDLE)
1205 PAHStartB->setEnabled(true);
1206 break;
1207 }
1208}
1209
1210QString PolarAlignmentAssistant::getPAHMessage() const
1211{
1212 switch (m_PAHStage)
1213 {
1214 case PAH_IDLE:
1215 case PAH_FIND_CP:
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>");
1240 else
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>");
1242 case PAH_REFRESH:
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>");
1245 else
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>");
1247 default:
1248 break;
1249 }
1250
1251 return QString();
1252}
1253
1254void PolarAlignmentAssistant::setPAHRefreshAlgorithm(RefreshAlgorithm value)
1255{
1256 // If the star-correspondence method of tracking polar alignment error wasn't initialized,
1257 // at the start, it can't be turned on mid process.
1258 if ((m_PAHStage == PAH_REFRESH) && refreshIteration > 0 && (value != PLATE_SOLVE_ALGORITHM)
1259 && !starCorrespondencePAH.size())
1260 {
1261 pAHRefreshAlgorithm->setCurrentIndex(PLATE_SOLVE_ALGORITHM);
1262 emit newLog(i18n("Cannot change to MoveStar algorithm once refresh has begun"));
1263 return;
1264 }
1265 if (m_PAHStage == PAH_REFRESH || m_PAHStage == PAH_STAR_SELECT)
1266 {
1267 refreshText->setText(getPAHMessage());
1268 emit newPAHMessage(getPAHMessage());
1269 }
1270
1271 showUpdatedError((value == PLATE_SOLVE_ALGORITHM) ||
1272 (value == MOVE_STAR_UPDATE_ERR_ALGORITHM));
1273 if (value == PLATE_SOLVE_ALGORITHM)
1274 updatePlateSolveTriangle(m_ImageData);
1275 else
1276 m_AlignView->setCorrectionParams(correctionFrom, correctionTo, correctionAltTo);
1277
1278}
1279
1280}
const CachingDms * lat() const
Definition geolocation.h:70
GeoLocation * geo()
Definition kstarsdata.h:232
The sky coordinates of a point in the sky.
Definition skypoint.h:45
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra() const
Definition skypoint.h:263
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
Definition dms.cpp:251
const dms deltaAngle(dms angle) const
deltaAngle Return the shortest difference (path) between this angle and the supplied angle.
Definition dms.cpp:267
const double & Degrees() const
Definition dms.h:141
KLocalizedString KI18N_EXPORT ki18n(const char *text)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
void clicked(bool checked)
void currentIndexChanged(int index)
void accepted()
void append(QList< T > &&value)
iterator begin()
void clear()
qsizetype count() const const
iterator end()
qsizetype size() const const
void deleteLater()
bool disconnect(const QMetaObject::Connection &connection)
void drawConvexPolygon(const QPoint *points, int pointCount)
void drawRect(const QRect &rectangle)
qreal x() const const
qreal y() const const
bool isNull() const const
QString arg(Args &&... args) const const
UniqueConnection
QTextStream & dec(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:11:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.