Kstars

calibration.h
1/*
2 SPDX-FileCopyrightText: 2020 Hy Murveit <hy@murveit.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "matr.h"
10#include "vect.h"
11#include <QString>
12#include "ekos/ekos.h"
13#include "indi/indicommon.h"
14#include "indi/indimount.h"
15
16class Calibration
17{
18 public:
19 Calibration();
20 ~Calibration() {}
21
22 // Initialize the parameters needed to convert from pixels to arc-seconds,
23 // the current pier side, and the current pointing position.
24 void setParameters(double ccd_pix_width, double ccd_pix_height, double focalLengthMm,
25 int binX, int binY, ISD::Mount::PierSide pierSide,
26 const dms &mountRA, const dms &mountDec);
27
28 // Set the current binning, which may be different from what was used during calibration.
29 void setBinningUsed(int x, int y);
30
31 // Generate new calibrations according to the input parameters.
32 bool calculate1D(double start_x, double start_y,
33 double end_x, double end_y, int RATotalPulse);
34
35 bool calculate2D(
36 double start_ra_x, double start_ra_y, double end_ra_x, double end_ra_y,
37 double start_dec_x, double start_dec_y, double end_dec_x, double end_dec_y,
38 bool *swap_dec, int RATotalPulse, int DETotalPulse);
39
40 // Computes the drift from the detection relative to the reference position.
41 // If inputs are in pixels, then drift outputs are in pixels.
42 // If inputs are in arcsecond coordinates then drifts are in arcseconds.
43 void computeDrift(const GuiderUtils::Vector &detection, const GuiderUtils::Vector &reference,
44 double *raDrift, double *decDrift) const;
45
46 double getFocalLength() const
47 {
48 return focalMm;
49 }
50 double getAngle() const
51 {
52 return angle;
53 }
54 double getRAAngle() const
55 {
56 return calibrationAngleRA;
57 }
58 double getDECAngle() const
59 {
60 return calibrationAngleDEC;
61 }
62
63 // Converts the input x & y coordinates from pixels to arc-seconds.
64 // Does not rotate the input into RA/DEC.
65 GuiderUtils::Vector convertToArcseconds(const GuiderUtils::Vector &input) const;
66
67 // Converts the input x & y coordinates from arc-seconds to pixels.
68 // Does not rotate the input into RA/DEC.
69 GuiderUtils::Vector convertToPixels(const GuiderUtils::Vector &input) const;
70 void convertToPixels(double xArcseconds, double yArcseconds,
71 double *xPixel, double *yPixel) const;
72
73 // Given offsets, convert to RA and DEC coordinates
74 // by rotating according to the calibration.
75 // Also inverts the y-axis. Does not convert to arc-seconds.
76 GuiderUtils::Vector rotateToRaDec(const GuiderUtils::Vector &input) const;
77 void rotateToRaDec(double dx, double dy, double *ra, double *dec) const;
78
79 // Returns the number of milliseconds that should be pulsed to move
80 // RA by one arcsecond.
81 double raPulseMillisecondsPerArcsecond() const;
82
83 // Returns the number of milliseconds that should be pulsed to move
84 // DEC by one arcsecond.
85 double decPulseMillisecondsPerArcsecond() const;
86
87 // Returns the number of pixels per arc-second in X and Y and vica versa.
88 double xPixelsPerArcsecond() const;
89 double yPixelsPerArcsecond() const;
90 double xArcsecondsPerPixel() const;
91 double yArcsecondsPerPixel() const;
92
93 // Save the calibration to Options.
94 void save() const;
95 // Restore the saved calibration. If the pier side is different than
96 // when was calibrated, adjust the angle accordingly.
97 bool restore(ISD::Mount::PierSide currentPierSide, bool reverseDecOnPierChange,
98 int currentBinX, int currentBinY,
99 const dms *declination = nullptr);
100 // As above, but for testing.
101 bool restore(const QString &encoding, ISD::Mount::PierSide currentPierSide,
102 bool reverseDecOnPierChange, int currentBinX, int currentBinY,
103 const dms *declination = nullptr);
104
105 bool declinationSwapEnabled() const
106 {
107 return decSwap;
108 }
109 void setDeclinationSwapEnabled(bool value);
110
111 void reset()
112 {
113 initialized = false;
114 }
115 // Returns true if calculate1D, calculate2D or restore have been called.
116 bool isInitialized()
117 {
118 return initialized;
119 }
120 // Prints the calibration parameters in the debug log.
121 void logCalibration() const;
122
123 private:
124 // Internal calibration methods.
125 bool calculate1D(double dx, double dy, int RATotalPulse);
126 bool calculate2D(double ra_dx, double ra_dy, double dec_dx, double dec_dy,
127 bool *swap_dec, int RATotalPulse, int DETotalPulse);
128
129 // Serialize and restore the calibration state.
130 QString serialize() const;
131 bool restore(const QString &encoding);
132
133 // Adjusts the RA rate, according to the calibration and current declination values.
134 double correctRA(double raMsPerPixel, const dms &calibrationDec, const dms &currentDec);
135
136 // Compute a rotation angle given pixel change coordinates
137 static double calculateRotation(double x, double y);
138
139 // Set the rotation angle and the rotation matrix.
140 // The angles are in the arc-second coordinate system (not the pixels--though that would
141 // be the same thing if the pixels were square).
142 void setAngle(double rotationAngle);
143
144 // Set the calibrated ra and dec rates.
145 void setRaPulseMsPerArcsecond(double rate);
146 void setDecPulseMsPerArcsecond(double rate);
147
148 // computes the ratio of the binning currently used to the binning in use while calibrating.
149 double binFactor() const;
150 // Inverse of above.
151 double inverseBinFactor() const;
152
153 // Sub-binning in X and Y.
154 int subBinX { 1 };
155 int subBinY { 1 };
156
157 // It is possible that this calibration was done with one binning, but is now
158 // being used with another binning. This is the current binning (as opposed to the above
159 // which is the binning that was in-place during calibration.
160 int subBinXused { 1 };
161 int subBinYused { 1 };
162
163 // Pixel width mm, for each pixel,
164 // Binning does not affect this.
165 double ccd_pixel_width { 0.003 };
166 double ccd_pixel_height { 0.003 };
167
168 // Focal length in millimeters.
169 double focalMm { 500 };
170
171 // This angle is the one in use for calibrating. It may differ from the
172 // calibrationAngle below if the pier side changes.
173 double angle { 0 };
174
175 // The rotation matrix that converts between pixel coordinates and RA/DEC.
176 // This is derived from angle in setAngle().
177 GuiderUtils::Matrix ROT_Z;
178
179 // The angles associated with the calibration that was computed or
180 // restored. They won't change as we change pier sides.
181 double calibrationAngle { 0 };
182 double calibrationAngleRA = 0;
183 double calibrationAngleDEC = 0;
184
185 // The calibrated values of how many pulse milliseconds are required to
186 // move one arcsecond in RA and DEC.
187 double raPulseMsPerArcsecond { 0 };
188 double decPulseMsPerArcsecond { 0 };
189
190 // The decSwap that was computed in calibration.
191 bool calibrationDecSwap { false };
192
193 // The decSwap in use. May be the opposite of calibrationDecSwap if the calibration
194 // is being used on the opposite pier side as the calibration pier side.
195 bool decSwap { false };
196
197 // The RA and DEC when calibration was performed. For reference. Not currently used.
198 dms calibrationRA;
199 dms calibrationDEC;
200
201 // The side of the pier where the current calibration was calculated.
202 ISD::Mount::PierSide calibrationPierSide { ISD::Mount::PIER_UNKNOWN };
203
204 bool initialized { false };
205 friend class TestGuideStars;
206};
207
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.