Kstars

polaralignmentassistant.h
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 #pragma once
9 
10 #include "ui_polaralignmentassistant.h"
11 #include "ekos/ekos.h"
12 #include "ekos/guide/internalguide/starcorrespondence.h"
13 #include "polaralign.h"
14 #include "alignview.h"
15 #include "align.h"
16 #include "indi/indimount.h"
17 
18 class QProgressIndicator;
19 class SolverUtils;
20 
21 namespace Ekos
22 {
23 
24 class PolarAlignWidget;
25 
26 /**
27  * @brief The PolarAlignmentAssistant class
28  *
29  * Captures three images rotated by a set number of degrees decided by the user (default 30).
30  * Each image is plate solver to find the center RA,DE coordinates. The three points are then
31  * used to generate a unique circle with its center as the RA axis. As the mount rotated around
32  * these point, we can identify the RA rotational axis. From there, we compare the distance from RA axis
33  * to the celestial pole axis. For a perfectly aligned mount, the two points would overlap exactly.
34  * In reality, there is also some differences due to the mount mechanical limitations and measurements
35  * errors.
36  *
37  * The user is then presented with a triangle that couples the corrections required in Altitude and Azimuth
38  * knobs to move the RA axis to the celestial pole. An optional feature is available the calculates the error
39  * in real time as the user move the mount around during refresh, but this feature is computationally intensive
40  * as we need to extract stars from each frame.
41  *
42  * @author Jasem Mutlaq
43  * @author Hy Murveit
44  */
45 class PolarAlignmentAssistant : public QWidget, public Ui::PolarAlignmentAssistant
46 {
47  Q_OBJECT
48 
49  public:
52 
53  typedef enum
54  {
55  PAH_IDLE,
56  PAH_FIRST_CAPTURE,
57  PAH_FIRST_SOLVE,
58  PAH_FIND_CP,
59  PAH_FIRST_ROTATE,
60  PAH_FIRST_SETTLE,
61  PAH_SECOND_CAPTURE,
62  PAH_SECOND_SOLVE,
63  PAH_SECOND_ROTATE,
64  PAH_SECOND_SETTLE,
65  PAH_THIRD_CAPTURE,
66  PAH_THIRD_SOLVE,
67  PAH_STAR_SELECT,
68  PAH_REFRESH,
69  PAH_POST_REFRESH
70  } Stage;
71 
72  // Algorithm choice in UI
73  typedef enum
74  {
75  PLATE_SOLVE_ALGORITHM,
76  MOVE_STAR_ALGORITHM,
77  MOVE_STAR_UPDATE_ERR_ALGORITHM
78  } RefreshAlgorithm;
79 
80  enum CircleSolution
81  {
82  NO_CIRCLE_SOLUTION,
83  ONE_CIRCLE_SOLUTION,
84  TWO_CIRCLE_SOLUTION,
85  INFINITE_CIRCLE_SOLUTION
86  };
87  typedef enum { NORTH_HEMISPHERE, SOUTH_HEMISPHERE } HemisphereType;
88 
89  // Set the mount used in Align class.
90  void setCurrentTelescope(ISD::Mount *scope)
91  {
92  m_CurrentTelescope = scope;
93  }
94  // Sync mount slew speed and available rates from the telescope object
95  void syncMountSpeed(const QString &speed);
96  // Enable PAA if the FOV is sufficient
97  void setEnabled(bool enabled);
98  // Return the exposure used in the refresh phase.
99  double getPAHExposureDuration() const
100  {
101  return pAHExposure->value();
102  }
103  // Handle updates during the refresh phase such as error estimation.
104  void processPAHRefresh();
105  // Handle solver failure and retry to capture until a preset number of retries is met.
106  bool processSolverFailure();
107  // Handle both automated and manual mount rotations.
108  void processMountRotation(const dms &ra, double settleDuration);
109  // After solver is complete, handle PAH Stage processing
110  void processPAHStage(double orientation, double ra, double dec, double pixscale, bool eastToTheRight, short healpix,
111  short index);
112  // Return current PAH stage
113  Stage getPAHStage() const
114  {
115  return m_PAHStage;
116  }
117  // Set active stage.
118  void setPAHStage(Stage stage);
119  // Start the polar alignment process.
120  void startPAHProcess();
121  // Stops the polar alignment process.
122  void stopPAHProcess();
123  // Process the results of WCS from the solving process. If the results are good, we continue to the next phase.
124  // Otherwise, we abort the operation.
125  void setWCSToggled(bool result);
126  // Update GUI to reflect mount status.
127  void setMountStatus(ISD::Mount::Status newState);
128  // Update the correction offset by this percentage in order to move the triangle around when clicking on
129  // for example.
130  void setPAHCorrectionOffsetPercentage(double dx, double dy);
131  // Update the PAH refresh duration
132  void setPAHRefreshDuration(double value)
133  {
134  pAHExposure->setValue(value);
135  }
136  // Start the refresh process.
137  void startPAHRefreshProcess();
138  // This should be called when manual slewing is complete.
139  void setPAHSlewDone();
140  // Return current active stage label
141  QString getPAHStageString(bool translated = true) const
142  {
143  return translated ? i18n(PAHStages[m_PAHStage]) : PAHStages[m_PAHStage];
144  }
145  // Return last message
146  QString getPAHMessage() const;
147  // Set image data from align class
148  void setImageData(const QSharedPointer<FITSData> &image);
149 
150  void setPAHRefreshAlgorithm(RefreshAlgorithm value);
151 
152  protected:
153  // Polar Alignment Helper slots
154  void rotatePAH();
155  void setPAHCorrectionOffset(int x, int y);
156 
157  private:
158  /**
159  * @brief Warns the user if the polar alignment might cross the meridian.
160  */
161  bool checkPAHForMeridianCrossing();
162 
163  /**
164  * @brief calculatePAHError Calculate polar alignment error in the Polar Alignment Helper (PAH) method
165  * @return True if calculation is successsful, false otherwise.
166  */
167  bool calculatePAHError();
168 
169  /**
170  * @brief syncCorrectionVector Flip correction vector based on user settings.
171  */
172  void syncCorrectionVector();
173 
174  /**
175  * @brief setupCorrectionGraphics Update align view correction graphics.
176  * @param pixel
177  */
178  void setupCorrectionGraphics(const QPointF &pixel);
179 
180  /**
181  * @brief supdateRefreshDisplay Updates the UI's refresh error stats.
182  * @param azError the azimuth error in degrees
183  * @param altError the altitude error in degrees
184  */
185  void updateRefreshDisplay(double azError, double altError);
186 
187  signals:
188  // Report new log
189  void newLog(const QString &);
190  // Request new capture and solve
191  void captureAndSolve();
192  // Report correction vector and original errors
193  void polarResultUpdated(QLineF correctionVector, double polarError, double azError, double altError);
194  // Report updated errors
195  void updatedErrorsChanged(double total, double az, double alt);
196  // Report new correction vector
197  void newCorrectionVector(QLineF correctionVector);
198  // Report new PAH stage
199  void newPAHStage(Stage stage);
200  // Report new PAH message
201  void newPAHMessage(const QString &message);
202  // Report whether the tool is enabled or not
203  void PAHEnabled(bool);
204  // Request to set alignment table result
205  void newAlignTableResult(Align::AlignResult result);
206  // Report that the align view was updated.
207  void newFrame(const QSharedPointer<FITSView> &view);
208 
209  private:
210  void updateDisplay(Stage stage, const QString &message);
211  void drawArrows(double altError, double azError);
212  void showUpdatedError(bool show);
213  // These are only used in the plate-solve refresh scheme.
214  void solverDone(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
215  void startSolver();
216  void updatePlateSolveTriangle(const QSharedPointer<FITSData> &image);
217 
218  // Polar Alignment Helper
219  Stage m_PAHStage { PAH_IDLE };
220 
221  SkyPoint targetPAH;
222 
223  // Which hemisphere are we located on?
224  HemisphereType hemisphere;
225 
226  // Polar alignment will retry capture & solve a few times if solve fails.
227  int m_PAHRetrySolveCounter { 0 };
228 
229  // Points on the image to correct mount's ra axis.
230  // correctionFrom is the star the user selected (or center of the image at start).
231  // correctionTo is where theuser should move that star.
232  // correctionAltTo is where the use should move that star to only fix altitude.
233  QPointF correctionFrom, correctionTo, correctionAltTo;
234 
235  // RA/DEC coordinates where the image center needs to be move to to correct the RA axis.
236  SkyPoint refreshSolution, altOnlyRefreshSolution;
237 
238 
239  bool detectStarsPAHRefresh(QList<Edge> *stars, int num, int x, int y, int *xyIndex);
240 
241  // Incremented every time sufficient # of stars are detected (for move-star refresh) or
242  // when solver is successful (for plate-solve refresh).
243  int refreshIteration { 0 };
244  // Incremented on every image received.
245  int imageNumber { 0 };
246  StarCorrespondence starCorrespondencePAH;
247 
248  // Class used to estimate alignment error.
249  PolarAlign polarAlign;
250 
251  // Pointer to image data
252  QSharedPointer<FITSData> m_ImageData;
253 
254  // Reference to parent
255  Align *m_AlignInstance {nullptr};
256 
257  // Reference to current active telescope
258  ISD::Mount *m_CurrentTelescope { nullptr };
259 
260  // Reference to align view
261  QSharedPointer<AlignView> m_AlignView;
262 
263  // PAH Stage Map
264  static const QMap<Stage, const char *> PAHStages;
265 
266  // Threshold to stop PAH rotation in degrees
267  static constexpr uint8_t PAH_ROTATION_THRESHOLD { 5 };
268 
269  PolarAlignWidget *polarAlignWidget {nullptr};
270 
271  // Used in the refresh part of polar alignment.
273  double m_LastRa {0};
274  double m_LastDec {0};
275  double m_LastOrientation {0};
276  double m_LastPixscale {0};
277 
278  // Restricts (the internal solver) to using the index and healpix
279  // from the previous solve, if that solve was successful.
280  int m_IndexToUse { -1 };
281  int m_HealpixToUse { -1 };
282  int m_NumHealpixFailures { 0 };
283 };
284 }
Q_OBJECTQ_OBJECT
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:69
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
The QProgressIndicator class lets an application display a progress indicator to show that a long tas...
QString i18n(const char *text, const TYPE &arg...)
The PolarAlignmentAssistant class.
void show()
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
Align class handles plate-solving and polar alignment measurement and correction using astrometry....
Definition: align.h:75
QObject * parent() const const
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jun 5 2023 03:56:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.