Kstars

gmath.h
1 /*
2  SPDX-FileCopyrightText: 2012 Andrew Stepanenko
3 
4  Modified by Jasem Mutlaq <[email protected]> for KStars:
5  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
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 
21 #include <cstdint>
22 #include <sys/types.h>
23 #include "guidelog.h"
24 #include "starcorrespondence.h"
25 #include "fitsviewer/fitssepdetector.h"
26 #include "guidestars.h"
27 #include "calibration.h"
28 
29 #include "gpg.h"
30 
31 class FITSData;
32 class Edge;
33 
34 // For now also copied in guidealgorithms.cpp
35 #define SMART_THRESHOLD 0
36 #define SEP_THRESHOLD 1
37 #define CENTROID_THRESHOLD 2
38 #define AUTO_THRESHOLD 3
39 #define NO_THRESHOLD 4
40 #define SEP_MULTISTAR 5
41 
42 #define GUIDE_RA 0
43 #define GUIDE_DEC 1
44 #define CHANNEL_CNT 2
45 
46 // input params
47 class cproc_in_params
48 {
49  public:
50  cproc_in_params();
51  void reset(void);
52 
53  bool enabled[CHANNEL_CNT];
54  bool enabled_axis1[CHANNEL_CNT];
55  bool enabled_axis2[CHANNEL_CNT];
56  bool average;
57  double proportional_gain[CHANNEL_CNT];
58  double integral_gain[CHANNEL_CNT];
59  int max_pulse_arcsec[CHANNEL_CNT];
60  double min_pulse_arcsec[CHANNEL_CNT];
61 };
62 
63 //output params
64 class cproc_out_params
65 {
66  public:
67  cproc_out_params();
68  void reset(void);
69 
70  double delta[2];
71  GuideDirection pulse_dir[2];
72  int pulse_length[2];
73  double sigma[2];
74 };
75 
76 typedef struct
77 {
78  double focal_ratio;
79  double fov_wd, fov_ht;
80  double focal, aperture;
81 } info_params_t;
82 
83 class cgmath : public QObject
84 {
85  Q_OBJECT
86 
87  public:
88  cgmath();
89  virtual ~cgmath();
90 
91  // functions
92  bool setVideoParameters(int vid_wd, int vid_ht, int binX, int binY);
93  bool setGuiderParameters(double ccd_pix_wd, double ccd_pix_ht, double guider_aperture, double guider_focal);
94 
95  bool setTargetPosition(double x, double y);
96  bool getTargetPosition(double *x, double *y) const;
97 
98  int getAlgorithmIndex(void) const;
99  void setAlgorithmIndex(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  GuideLog *logger = nullptr);
131 
132  bool calibrate1D(double start_x, double start_y, double end_x, double end_y, int RATotalPulse);
133  bool calibrate2D(double start_ra_x, double start_ra_y, double end_ra_x, double end_ra_y,
134  double start_dec_x, double start_dec_y, double end_dec_x, double end_dec_y,
135  bool *swap_dec, int RATotalPulse, int DETotalPulse);
136 
137  const Calibration &getCalibration()
138  {
139  return calibration;
140  }
141  Calibration *getMutableCalibration()
142  {
143  return &calibration;
144  }
145  QVector3D selectGuideStar(const QSharedPointer<FITSData> &imageData);
146  double getGuideStarSNR();
147 
148  signals:
149  void newAxisDelta(double delta_ra, double delta_dec);
150  void newStarPosition(QVector3D, bool);
151 
152  // For Analyze.
153  void guideStats(double raError, double decError, int raPulse, int decPulse,
154  double snr, double skyBg, int numStars);
155 
156  private:
157  // Templated functions
158  template <typename T>
159  GuiderUtils::Vector findLocalStarPosition(void) const;
160 
161  void updateCircularBuffers(void);
162  GuiderUtils::Vector point2arcsec(const GuiderUtils::Vector &p) const;
163  void calculatePulses(Ekos::GuideState state);
164  void calculateRmsError(void);
165 
166  // Old-stye Logging--deprecate.
167  void createGuideLog();
168 
169  // For Analyze.
170  void emitStats();
171 
172  uint32_t iterationCounter { 0 };
173 
174  /// Video frame width
175  int video_width { -1 };
176  /// Video frame height
177  int video_height { -1 };
178  double aperture { 0 };
179  bool suspended { false };
180  bool lost_star { false };
181 
182  /// Index of algorithm used
183  int algorithm { SMART_THRESHOLD };
184 
185  // The latest guide star position (x,y on the image),
186  // and target position we're trying to keep it aligned to.
187  GuiderUtils::Vector starPosition;
188  GuiderUtils::Vector targetPosition;
189 
190  // processing
191  // Drift is a circular buffer of the arcsecond drift for the 2 channels.
192  // It will be initialized with a double array of size 50.
193  // driftUpto points to the index of the next value to be written.
194  static constexpr int CIRCULAR_BUFFER_SIZE = 50;
195  double *drift[2];
196  uint32_t driftUpto[2];
197 
198  double drift_integral[2];
199 
200  // overlays...
201  cproc_in_params in_params;
202  cproc_out_params out_params;
203 
204  // stat math...
205  bool do_statistics { true };
206 
207  QFile logFile;
208  QElapsedTimer logTime;
209 
210  GuideStars guideStars;
211 
212  std::unique_ptr<GPG> gpg;
213  Calibration calibration;
214 };
Q_OBJECTQ_OBJECT
KGuiItem reset()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.