Kstars

gmath.h
1/*
2 SPDX-FileCopyrightText: 2012 Andrew Stepanenko
3
4 Modified by Jasem Mutlaq <mutlaqja@ikarustech.com> for KStars:
5 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "vect.h"
13#include "indi/indicommon.h"
14
15#include <QObject>
16#include <QPointer>
17#include <QTime>
18#include <QVector>
19#include <QFile>
20#include <QElapsedTimer>
21
22#include <cstdint>
23#include <sys/types.h>
24#include "guidestars.h"
25#include "calibration.h"
26
27#include "gpg.h"
28
29class FITSData;
30class Edge;
31class GuideLog;
32
33// For now also copied in guidealgorithms.cpp
34#define SMART_THRESHOLD 0
35#define SEP_THRESHOLD 1
36#define CENTROID_THRESHOLD 2
37#define AUTO_THRESHOLD 3
38#define NO_THRESHOLD 4
39#define SEP_MULTISTAR 5
40
41#define GUIDE_RA 0
42#define GUIDE_DEC 1
43#define CHANNEL_CNT 2
44
45// input params
46class cproc_in_params
47{
48 public:
49 cproc_in_params();
50 void reset(void);
51
52 bool enabled[CHANNEL_CNT];
53 bool enabled_axis1[CHANNEL_CNT];
54 bool enabled_axis2[CHANNEL_CNT];
55 bool average;
56 double proportional_gain[CHANNEL_CNT];
57 double integral_gain[CHANNEL_CNT];
58 int max_pulse_arcsec[CHANNEL_CNT];
59 double min_pulse_arcsec[CHANNEL_CNT];
60};
61
62//output params
63class cproc_out_params
64{
65 public:
66 cproc_out_params();
67 void reset(void);
68
69 double delta[2];
70 GuideDirection pulse_dir[2];
71 int pulse_length[2];
72 double sigma[2];
73};
74
75typedef struct
76{
77 double focal_ratio;
78 double fov_wd, fov_ht;
79 double focal, aperture;
80} info_params_t;
81
82class cgmath : public QObject
83{
85
86 public:
87 cgmath();
88 virtual ~cgmath();
89
90 // functions
91 bool setVideoParameters(int vid_wd, int vid_ht, int binX, int binY);
92 bool setGuiderParameters(double ccd_pix_wd, double ccd_pix_ht, double guider_aperture, double guider_focal);
93
94 bool setTargetPosition(double x, double y);
95 bool getTargetPosition(double *x, double *y) const;
96
97 int getAlgorithmIndex(void) const;
98 void setAlgorithmIndex(int algorithmIndex);
99 bool usingSEPMultiStar() const;
100
101 GPG &getGPG()
102 {
103 return *gpg;
104 }
105 const cproc_out_params *getOutputParameters() const
106 {
107 return &out_params;
108 }
109
110 // Operations
111 void start();
112 bool reset();
113 // Currently only relevant to SEP MultiStar.
114 void abort();
115 void suspend(bool mode);
116 bool isSuspended() const;
117
118 // Star tracking
119 void getStarScreenPosition(double *dx, double *dy) const;
120 GuiderUtils::Vector findLocalStarPosition(QSharedPointer<FITSData> &imageData,
121 QSharedPointer<GuideView> &guideView, bool firstFrame);
122 bool isStarLost() const;
123 void setLostStar(bool is_lost);
124
125 // Main processing function
126 void performProcessing(Ekos::GuideState state,
127 QSharedPointer<FITSData> &imageData,
128 QSharedPointer<GuideView> &guideView,
129 const std::pair<Seconds, Seconds> &timeStep,
130 GuideLog *logger = nullptr);
131
132 void performDarkGuiding(Ekos::GuideState state, const std::pair<Seconds, Seconds> &timeStep);
133
134 bool calibrate1D(double start_x, double start_y, double end_x, double end_y, int RATotalPulse);
135 bool calibrate2D(double start_ra_x, double start_ra_y, double end_ra_x, double end_ra_y,
136 double start_dec_x, double start_dec_y, double end_dec_x, double end_dec_y,
137 bool *swap_dec, int RATotalPulse, int DETotalPulse);
138
139 const Calibration &getCalibration()
140 {
141 return calibration;
142 }
143 Calibration *getMutableCalibration()
144 {
145 return &calibration;
146 }
147 QVector3D selectGuideStar(const QSharedPointer<FITSData> &imageData);
148 double getGuideStarSNR();
149
150 const GuideStars &getGuideStars()
151 {
152 return guideStars;
153 }
154
155 signals:
156 void newAxisDelta(double delta_ra, double delta_dec);
157 void newStarPosition(QVector3D, bool);
158
159 // For Analyze.
160 void guideStats(double raError, double decError, int raPulse, int decPulse,
161 double snr, double skyBg, int numStars);
162
163 private:
164 // Templated functions
165 template <typename T>
166 GuiderUtils::Vector findLocalStarPosition(void) const;
167
168 void updateCircularBuffers(void);
169 GuiderUtils::Vector point2arcsec(const GuiderUtils::Vector &p) const;
170 void calculatePulses(Ekos::GuideState state, const std::pair<Seconds, Seconds> &timeStep);
171 void calculateRmsError(void);
172
173 // Old-stye Logging--deprecate.
174 void createGuideLog();
175
176 // For Analyze.
177 void emitStats();
178
179 uint32_t iterationCounter { 0 };
180
181 /// Video frame width
182 int video_width { -1 };
183 /// Video frame height
184 int video_height { -1 };
185 double aperture { 0 };
186 bool suspended { false };
187 bool lost_star { false };
188
189 /// Index of algorithm used
190 int algorithm { SMART_THRESHOLD };
191
192 // The latest guide star position (x,y on the image),
193 // and target position we're trying to keep it aligned to.
194 GuiderUtils::Vector starPosition;
195 GuiderUtils::Vector targetPosition;
196
197 // processing
198 // Drift is a circular buffer of the arcsecond drift for the 2 channels.
199 // It will be initialized with a double array of size 50.
200 // driftUpto points to the index of the next value to be written.
201 static constexpr int CIRCULAR_BUFFER_SIZE = 50;
202 double *drift[2];
203 uint32_t driftUpto[2];
204
205 double drift_integral[2];
206
207 // overlays...
208 cproc_in_params in_params;
209 cproc_out_params out_params;
210
211 // stat math...
212 bool do_statistics { true };
213
214 QFile logFile;
215 QElapsedTimer logTime;
216
217 GuideStars guideStars;
218
219 std::unique_ptr<GPG> gpg;
220 Calibration calibration;
221 bool configureInParams(Ekos::GuideState state);
222 void updateOutParams(int k, const double arcsecDrift, int pulseLength, GuideDirection pulseDirection);
223 void outputGuideLog();
224 void processAxis(const int k, const bool dithering, const bool darkGuiding, const Seconds &timeStep, const QString &label);
225};
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:01:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.