File indexing completed on 2024-05-12 15:23:44
0001 /* 0002 SPDX-FileCopyrightText: 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>. 0003 0004 Based on lin_guider 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "matr.h" 0012 #include "indi/indicommon.h" 0013 #include "../guideinterface.h" 0014 #include "guidelog.h" 0015 #include "calibration.h" 0016 #include "calibrationprocess.h" 0017 #include "gmath.h" 0018 #include "ekos_guide_debug.h" 0019 #include <QFile> 0020 #include <QPointer> 0021 #include <QQueue> 0022 #include <QTime> 0023 0024 #include <memory> 0025 0026 class QVector3D; 0027 class FITSData; 0028 class cgmath; 0029 class GuideView; 0030 class Edge; 0031 0032 namespace Ekos 0033 { 0034 class InternalGuider : public GuideInterface 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 InternalGuider(); 0040 0041 bool Connect() override 0042 { 0043 state = GUIDE_IDLE; 0044 return true; 0045 } 0046 bool Disconnect() override 0047 { 0048 return true; 0049 } 0050 bool isConnected() override 0051 { 0052 return true; 0053 } 0054 0055 bool calibrate() override; 0056 bool guide() override; 0057 bool abort() override; 0058 bool suspend() override; 0059 bool resume() override; 0060 0061 bool dither(double pixels) override; 0062 bool ditherXY(double x, double y); 0063 0064 bool clearCalibration() override; 0065 bool restoreCalibration(); 0066 0067 bool reacquire() override; 0068 0069 bool setFrameParams(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t binX, uint16_t binY) override; 0070 bool setGuiderParams(double ccdPixelSizeX, double ccdPixelSizeY, double mountAperture, 0071 double mountFocalLength) override; 0072 0073 // Set Star Position 0074 void setStarPosition(QVector3D &starCenter) override; 0075 0076 // Select algorithm 0077 void setSquareAlgorithm(int index); 0078 0079 // Reticle Parameters 0080 bool getReticleParameters(double *x, double *y); 0081 0082 // Guide Square Box Size 0083 void setGuideBoxSize(uint32_t value) 0084 { 0085 guideBoxSize = value; 0086 } 0087 0088 // Guide View 0089 void setGuideView(const QSharedPointer<GuideView> &guideView); 0090 // Image Data 0091 void setImageData(const QSharedPointer<FITSData> &data); 0092 0093 bool start(); 0094 0095 bool isGuiding(void) const; 0096 void setInterface(void); 0097 0098 void setSubFramed(bool enable) 0099 { 0100 m_isSubFramed = enable; 0101 } 0102 0103 bool useSubFrame(); 0104 0105 const Calibration &getCalibration() const; 0106 0107 // Select a guide star automatically 0108 bool selectAutoStar(); 0109 bool selectAutoStarSEPMultistar(); 0110 bool SEPMultiStarEnabled(); 0111 0112 // Manual Dither 0113 bool processManualDithering(); 0114 0115 void updateGPGParameters(); 0116 void resetGPG() override; 0117 void resetDarkGuiding(); 0118 void setExposureTime(); 0119 void setDarkGuideTimerInterval(); 0120 void setTimer(std::unique_ptr<QTimer> &timer, Seconds seconds); 0121 0122 public slots: 0123 void setDECSwap(bool enable); 0124 0125 0126 protected slots: 0127 void trackingStarSelected(int x, int y); 0128 void setDitherSettled(); 0129 void darkGuide(); 0130 0131 signals: 0132 void newMultiPulse(GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs, 0133 CaptureAfterPulses followWithCapture); 0134 void newSinglePulse(GuideDirection dir, int msecs, CaptureAfterPulses followWithCapture); 0135 //void newStarPosition(QVector3D, bool); 0136 void DESwapChanged(bool enable); 0137 private: 0138 // Guiding 0139 bool processGuiding(); 0140 void startDarkGuiding(); 0141 bool abortDither(); 0142 bool onePulseDither(double pixels); 0143 0144 void reset(); 0145 0146 // Logging 0147 void fillGuideInfo(GuideLog::GuideInfo *info); 0148 0149 std::unique_ptr<cgmath> pmath; 0150 QSharedPointer<GuideView> m_GuideFrame; 0151 QSharedPointer<FITSData> m_ImageData; 0152 bool m_isStarted { false }; 0153 bool m_isSubFramed { false }; 0154 bool m_isFirstFrame { false }; 0155 int m_starLostCounter { 0 }; 0156 0157 QFile logFile; 0158 uint32_t guideBoxSize { 32 }; 0159 0160 GuiderUtils::Vector m_DitherTargetPosition; 0161 uint8_t m_DitherRetries {0}; 0162 0163 QElapsedTimer reacquireTimer; 0164 int m_highRMSCounter {0}; 0165 0166 GuiderUtils::Matrix ROT_Z; 0167 Ekos::GuideState rememberState { GUIDE_IDLE }; 0168 0169 // Progressive Manual Dither 0170 QQueue<GuiderUtils::Vector> m_ProgressiveDither; 0171 0172 // Dark guiding timer 0173 std::unique_ptr<QTimer> m_darkGuideTimer; 0174 std::unique_ptr<QTimer> m_captureTimer; 0175 std::pair<Seconds, Seconds> calculateGPGTimeStep(); 0176 bool isInferencePeriodFinished(); 0177 0178 0179 // How many high RMS pulses before we stop 0180 static const uint8_t MAX_RMS_THRESHOLD = 10; 0181 // How many lost stars before we stop 0182 static const uint8_t MAX_LOST_STAR_THRESHOLD = 5; 0183 0184 // Maximum pulse time limit for immediate capture. Any pulses longer that this 0185 // will be delayed until pulse is over 0186 static const uint16_t MAX_IMMEDIATE_CAPTURE = 250; 0187 // When to start capture before pulse delay is over 0188 static const uint16_t PROPAGATION_DELAY = 100; 0189 0190 // How many 'random' pixels can we move before we have to force direction reversal? 0191 static const uint8_t MAX_DITHER_TRAVEL = 15; 0192 0193 // This keeps track of the distance dithering has moved. It's used to make sure 0194 // the "random walk" dither doesn't wander too far away. 0195 QVector3D m_DitherOrigin; 0196 0197 GuideLog guideLog; 0198 0199 void iterateCalibration(); 0200 std::unique_ptr<CalibrationProcess> calibrationProcess; 0201 double calibrationStartX = 0; 0202 double calibrationStartY = 0; 0203 0204 0205 bool isPoorGuiding(const cproc_out_params *out); 0206 void emitAxisPulse(const cproc_out_params *out); 0207 }; 0208 }