Kstars

hysteresisguider.cpp
1/*
2 SPDX-FileCopyrightText: 2025 Hy Murveit <hy@murveit.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "hysteresisguider.h"
8
9#include <cmath>
10#include "ekos_guide_debug.h"
11
12HysteresisGuider::HysteresisGuider(const QString &id) : m_ID(id)
13{
14 reset();
15}
16
17void HysteresisGuider::reset()
18{
19 m_LastOutput = 0.0;
20 m_LastGuideTime = QDateTime();
21 m_GuiderIteration = 0;
22}
23double HysteresisGuider::guide(double offset)
24{
25 QString comment;
26
27 const double hysteresis = m_Hysteresis;
28
29 // Reset the guider if we haven't guided recently.
30 const QDateTime now = QDateTime::currentDateTime();
31 if (m_LastGuideTime.isValid())
32 {
33 constexpr int MAX_GUIDE_LAG = 30;
34 const int interval = m_LastGuideTime.secsTo(now);
35 if (interval < 0 || interval > MAX_GUIDE_LAG)
36 {
37 reset();
38 comment = QString("Reset: guide lag %1s").arg(interval);
39 }
40 }
41 else
42 reset();
43 m_LastGuideTime = now;
44
45 const double time = ++m_GuiderIteration;
46 double guideVal = m_Gain * ((1.0 - hysteresis) * offset + hysteresis * m_LastOutput);
47
48 if (fabs(guideVal) > 0 && fabs(guideVal) < m_MinMove)
49 {
50
51 comment.append(QString("%1%2 < minMove %3").arg(!comment.isEmpty() ? ", " : "")
52 .arg(guideVal, 0, 'f', 2).arg(m_MinMove, 0, 'f', 2));
53 guideVal = 0;
54 }
55
56 qCDebug(KSTARS_EKOS_GUIDE) << QString("HysteresisGuide(%1,%2) %3 * ((%4 * %5) + (%6 * %7)) --> %8: %9")
57 .arg(m_ID, 3).arg(time, 3, 'f', 0).arg(m_Gain, 4, 'f', 2)
58 .arg((1.0 - hysteresis), 4, 'f', 2).arg(offset, 4, 'f', 2)
59 .arg(hysteresis, 4, 'f', 2).arg(m_LastOutput, 4, 'f', 2)
60 .arg(guideVal, 5, 'f', 2).arg(comment);
61 m_LastOutput = guideVal;
62 return guideVal;
63}
64
65
KGuiItem reset()
QDateTime currentDateTime()
QString & append(QChar ch)
QString arg(Args &&... args) const const
bool isEmpty() const const
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.