Kstars

adaptivefocus.h
1/*
2 SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "focus.h"
10
11namespace Ekos
12{
13
14// AdaptiveFocus is setup as a friend class of Focus because it is tightly coupled to Focus relying on many
15// members of Focus, both variables and functions.
16//
17// adaptiveFocus is signalled (by capture). Check each adaptive dimension (temp, alt) to determine whether a focus move is required.
18// Total the movements from each dimension and, if required, adjust focus.
19//
20// Use the adaptive focus parameters associated with the current filter unless that has a lock filter, in which case use the lock filter.
21// Use the last good autofocus run as the reference that provides the focus position, temperature
22// and altitude. Adaptive focus then calculates the proposed position based on the current temperature and altitude
23// and calculates how to move from the current position to the proposed position - note there may be an overscan involved.
24//
25// To keep track of the movements the data are passed to Analyze which allows the user to review everything. Analyze displays the
26// deltas from the previous adaptive focus run for temperature and altitude to the next adaptive focus run.
27//
28// Calculations are performed as doubles and rounded to int for the final movement.
29//
30// A complication is that not all focusers move exactly to the requested position - 'bad boy' focusers. E.g. a request to
31// goto position X results in the focuser moving to X, X +/- 1 or X +/- 2. These position errors need to be managed. There
32// are 2 aspects to this; before an Adaptive Focus iteration, the focuser may be "off" where it should be. This could be
33// because the focuser is a "bad boy" so it moved to the correct position +/- 1 or 2 ticks; this is the Last Pos Error.
34// Adaptive Focus will attempt to correct this error even if there are no temperature or altitude changes (providing the
35// movement is above the user defined minimum movement.
36// When the Adaptive Focus iteration runs, the focuser may again experience a Pos Error.
37// These Position Errors are passed to Analyze to breakdown each focuser movement.
38//
39// Proposed Position = Ref Position (from last Autofocus) + adjustment for temperature + adjustment for altitude
40//
41// Accounting since last Adaptive Focus
42// Last Pos Error Reversal = Last Iteration Proposed Move - Focuser position at start of Adaptive Focus iteration
43// This Pos Error = Focuser position at end of Adaptive Focus iteration - Proposed Move
44// End Position = Start Position + temperature adjustment + altitude adjustment + Last Pos Error Reversal + This Pos Error
45//
46// Example: Last Autofocus Run, Pos=100 0C 70Alt. Parameters: 10ticks/Degree C, 1tick/Degree Alt
47// 1st Adaptive Focus: 0.5C 71Alt
48// Proposed Position = 100 + 5 + 1 = 106
49// Actual Position = 105 (focuser movement error)
50// Accounting: Start Position = 100
51// Temperature Adjustment = 5
52// Altitude Adjustment = 1
53// Last Pos Error Reversal = 0
54// This Pos Error = -1
55// End Position = 100 + 5 + 1 + 0 - 1 = 105
56//
57// 2nd Adaptive Focus: 0.75C 72Alt
58// Proposed Position = 100 + 7.5 + 2 = 110
59// Actual Position = 112 (focuser movement error)
60// Accounting: Start Position = 105
61// Temperature Adjustment = 2.5
62// Altitude Adjustment = 1
63// Last Pos Error Reversal = 1
64// This Pos Error = 2
65// End Position = 100 + 5 + 1 + 0 - 1 = 112
66//
67// 3rd Adaptive Focus: 0.25C 72Alt
68// Proposed Position = 100 + 2.5 + 2 = 105
69// Actual Position = 105 (no focuser movement error)
70// Accounting: Start Position = 112
71// Temperature Adjustment = -5
72// Altitude Adjustment = 0
73// Last Pos Error Reversal = -2
74// This Pos Error =
75// End Position = 100 + 5 + 1 + 0 - 1 = 105
76//
77// Adaptive Focus moves the focuser between Autofocus runs.
78// Adapt Start Pos adjusts the start position of an autofocus run based on Adaptive Focus settings
79// The start position uses the last successful AF run for the active filter and adapts that position
80// based on the temperature and altitude delta between now and when the last successful AF run happened
81// Only enabled for LINEAR 1 PASS
82
83class AdaptiveFocus
84{
85 public:
86
87 AdaptiveFocus(Focus* _focus);
88 ~AdaptiveFocus();
89
90 /**
91 * @brief runAdaptiveFocus runs the next iteration of Adaptive Focus
92 * @param current focuser position
93 * @param active filter
94 */
95 void runAdaptiveFocus(const int currentPosition, const QString &filter);
96
97 /**
98 * @brief Perform admin functions on Adaptive Focus to inform other modules of
99 * @param current focuser position
100 * @param success (or not)
101 * @param focuserMoved (or not)
102 */
103 void adaptiveFocusAdmin(const int currentPosition, const bool success, const bool focuserMoved);
104
105 /**
106 * @brief Reset the variables used by Adaptive Focus
107 */
108 void resetAdaptiveFocusCounters();
109
110 /**
111 * @brief Return whether Adaptive Focus is running
112 * @return inAdaptiveFocus
113 */
114 bool inAdaptiveFocus()
115 {
116 return m_inAdaptiveFocus;
117 }
118
119 /**
120 * @brief Set the value of inAdaptiveFocus
121 * @param value
122 */
123 void setInAdaptiveFocus(bool value);
124
125 /**
126 * @brief adapt the start position based on temperature and altitude
127 * @param position is the unadapted focuser position
128 * @param AFfilter is the filter to run autofocus on
129 * @return adapted start position
130 */
131 int adaptStartPosition(int position, QString &AFfilter);
132
133 private:
134
135 /**
136 * @brief Get the Adaptive Filter to use
137 * @param active filter
138 * @return filter
139 */
140 QString getAdaptiveFilter(const QString filter);
141
142 /**
143 * @brief Get filter offset between active and adaptive filters
144 * @param Active filter
145 * @param Adaptive filter
146 * @return offset
147 */
148 int getAdaptiveFilterOffset(const QString &activeFilter, const QString &adaptiveFilter);
149
150 Focus *m_focus { nullptr };
151
152 // Focuser is processing an adaptive focus request
153 bool m_inAdaptiveFocus { false };
154
155 // m_ThisAdaptiveFocus* variables hold values for the current Adaptive Focus run
156 int m_ThisAdaptiveFocusStartPos { INVALID_VALUE };
157 double m_ThisAdaptiveFocusTemperature { INVALID_VALUE };
158 double m_ThisAdaptiveFocusAlt { INVALID_VALUE };
159 double m_ThisAdaptiveFocusTempTicks { INVALID_VALUE };
160 double m_ThisAdaptiveFocusAltTicks { INVALID_VALUE };
161 int m_ThisAdaptiveFocusRoundingError { 0 };
162 // m_LastAdaptiveFocus* variables hold values for the previous Adaptive Focus run
163 QString m_LastAdaptiveFilter { NULL_FILTER };
164 double m_LastAdaptiveFocusTemperature { INVALID_VALUE };
165 double m_LastAdaptiveFocusAlt { INVALID_VALUE };
166 int m_LastAdaptiveFocusPosErrorReversal { INVALID_VALUE };
167
168 int m_AdaptiveFocusPositionReq { INVALID_VALUE };
169 int m_AdaptiveTotalMove { 0 };
170};
171
172}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.