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

KDE's Doxygen guidelines are available online.