Kstars

focusalgorithms.h
1 /*
2  SPDX-FileCopyrightText: 2019 Hy Murveit <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QString>
10 #include <QList>
11 #include "focus.h"
12 #include "curvefit.h"
13 
14 class Edge;
15 
16 namespace Ekos
17 {
18 
19 /**
20  * @class FocusAlgorithmInterface
21  * @short Interface intender for autofocus algorithms.
22  *
23  * @author Hy Murveit
24  * @version 1.0
25  */
27 {
28  public:
29  // Invalid HFR result - this value (-1) is compatible with graph renderings
30  static double constexpr IGNORED_HFR = -1;
31 
32  public:
33  struct FocusParams
34  {
35  // Maximum movement from current position allowed for the algorithm.
36  int maxTravel;
37  // Initial sampling interval for the algorithm.
38  int initialStepSize;
39  // Absolute position of the focuser when the algorithm starts.
40  int startPosition;
41  // Minimum position the focuser is allowed to reach.
42  int minPositionAllowed;
43  // Maximum position the focuser is allowed to reach.
44  int maxPositionAllowed;
45  // Maximum number of iterations (captures) the focuser may try.
46  int maxIterations;
47  // The focus algorithm may terminate if it gets within this fraction of the best focus, e.g. 0.10.
48  double focusTolerance;
49  // The name of the filter used, if any.
50  QString filterName;
51  // The temperature measured when starting the focus (from focuser or observatory).
52  double temperature;
53  // The number of outward steps taken at the start of the algorithm.
54  double initialOutwardSteps;
55  // The focus algo
56  Focus::FocusAlgorithm focusAlgorithm;
57  // The user defined focuser backlash value
58  // The value does not need to be exact but needs to be >= focuser backlash
59  int backlash;
60  // Curve fit is the type of curve to fit to the data
61  CurveFitting::CurveFit curveFit;
62  // Whether we want to use weightings of datapoints in the curve fitting process
63  bool useWeights;
64 
65  FocusParams(int _maxTravel, int _initialStepSize, int _startPosition,
66  int _minPositionAllowed, int _maxPositionAllowed,
67  int _maxIterations, double _focusTolerance, const QString &filterName_,
68  double _temperature, double _initialOutwardSteps, Focus::FocusAlgorithm _focusAlgorithm,
69  int _backlash, CurveFitting::CurveFit _curveFit, bool _useWeights) :
70  maxTravel(_maxTravel), initialStepSize(_initialStepSize),
71  startPosition(_startPosition), minPositionAllowed(_minPositionAllowed),
72  maxPositionAllowed(_maxPositionAllowed), maxIterations(_maxIterations),
73  focusTolerance(_focusTolerance), filterName(filterName_),
74  temperature(_temperature), initialOutwardSteps(_initialOutwardSteps),
75  focusAlgorithm(_focusAlgorithm), backlash(_backlash), curveFit(_curveFit),
76  useWeights(_useWeights) {}
77  };
78 
79  // Constructor initializes an autofocus algorithm from the input params.
80  FocusAlgorithmInterface(const FocusParams &_params) : params(_params) {}
81  virtual ~FocusAlgorithmInterface() {}
82 
83  // After construction, this should be called to get the initial position desired by the
84  // focus algorithm. It returns the start position passed to the constructor if
85  // it has no movement request.
86  virtual int initialPosition() = 0;
87 
88  // Pass in the recent measurement. Returns the position for the next measurement,
89  // or -1 if the algorithms done or if there's an error.
90  // If stars is not nullptr, then the they may be used to modify the HFR value.
91  virtual int newMeasurement(int position, double value, const QList<Edge*> *stars = nullptr) = 0;
92 
93  // Returns true if the algorithm has terminated either successfully or in error.
94  bool isDone() const
95  {
96  return done;
97  }
98 
99  // Returns the best position. Should be called after isDone() returns true.
100  // Returns -1 if there's an error.
101  int solution() const
102  {
103  return focusSolution;
104  }
105 
106  // Returns human-readable extra error information about why the algorithm is done.
107  QString doneReason() const
108  {
109  return doneString;
110  }
111 
112  // Returns the params used to construct this object.
113  const FocusParams &getParams() const
114  {
115  return params;
116  }
117 
118  virtual double latestHFR() const = 0;
119 
120  virtual void getMeasurements(QVector<int> *positions, QVector<double> *hfrs,
121  QVector<double> *sigmas) const = 0;
122  virtual void getPass1Measurements(QVector<int> *positions, QVector<double> *hfrs,
123  QVector<double> *sigmas) const = 0;
124 
125  virtual QString getTextStatus(double R2 = 0) const = 0;
126 
127  // Curve fitting object
128  CurveFitting curveFit;
129 
130  // For testing.
131  virtual FocusAlgorithmInterface *Copy() = 0;
132 
133  protected:
134  FocusParams params;
135  bool done = false;
136  int focusSolution = -1;
137  double focusHFR = -1;
138  QString doneString;
139 };
140 
141 // Creates a LinearFocuser. Caller responsible for the memory.
142 FocusAlgorithmInterface *MakeLinearFocuser(const FocusAlgorithmInterface::FocusParams &params);
143 }
144 
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:70
Interface intender for autofocus algorithms.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.