Kstars

focus.h
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "ui_focus.h"
10 #include "focusprofileplot.h"
11 #include "ekos/ekos.h"
12 #include "ekos/auxiliary/filtermanager.h"
13 #include "ekos/auxiliary/stellarsolverprofileeditor.h"
14 #include "ekos/auxiliary/darkprocessor.h"
15 #include "ekos/mount/mount.h"
16 #include "fitsviewer/fitsviewer.h"
17 #include "indi/indicamera.h"
18 #include "indi/indifocuser.h"
19 #include "indi/indistd.h"
20 #include "indi/indiweather.h"
21 #include "indi/indimount.h"
22 
23 #include <QtDBus/QtDBus>
24 #include <parameters.h>
25 
26 namespace Ekos
27 {
28 
29 class FocusAlgorithmInterface;
30 class PolynomialFit;
31 
32 /**
33  * @class Focus
34  * @short Supports manual focusing and auto focusing using relative and absolute INDI focusers.
35  *
36  * @author Jasem Mutlaq
37  * @version 1.5
38  */
39 class Focus : public QWidget, public Ui::Focus
40 {
41  Q_OBJECT
42  Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.Ekos.Focus")
43  Q_PROPERTY(Ekos::FocusState status READ status NOTIFY newStatus)
44  Q_PROPERTY(QStringList logText READ logText NOTIFY newLog)
45  Q_PROPERTY(QString camera READ camera WRITE setCamera)
46  Q_PROPERTY(QString focuser READ focuser WRITE setFocuser)
47  Q_PROPERTY(QString filterWheel READ filterWheel WRITE setFilterWheel)
48  Q_PROPERTY(QString filter READ filter WRITE setFilter)
49  Q_PROPERTY(double HFR READ getHFR NOTIFY newHFR)
50  Q_PROPERTY(double exposure READ exposure WRITE setExposure)
51 
52  public:
53  Focus();
54  ~Focus();
55 
56  typedef enum { FOCUS_NONE, FOCUS_IN, FOCUS_OUT } FocusDirection;
57  typedef enum { FOCUS_MANUAL, FOCUS_AUTO } FocusType;
58  typedef enum { FOCUS_ITERATIVE, FOCUS_POLYNOMIAL, FOCUS_LINEAR, FOCUS_LINEAR1PASS } FocusAlgorithm;
59  //typedef enum { FOCUSER_TEMPERATURE, OBSERVATORY_TEMPERATURE, NO_TEMPERATURE } TemperatureSource;
60 
61  /** @defgroup FocusDBusInterface Ekos DBus Interface - Focus Module
62  * Ekos::Focus interface provides advanced scripting capabilities to perform manual and automatic focusing operations.
63  */
64 
65  /*@{*/
66 
67  /** DBUS interface function.
68  * select the CCD device from the available CCD drivers.
69  * @param device The CCD device name
70  * @return Returns true if CCD device is found and set, false otherwise.
71  */
72  Q_SCRIPTABLE bool setCamera(const QString &device);
73  Q_SCRIPTABLE QString camera();
74 
75  /** DBUS interface function.
76  * select the focuser device from the available focuser drivers. The focuser device can be the same as the CCD driver if the focuser functionality was embedded within the driver.
77  * @param device The focuser device name
78  * @return Returns true if focuser device is found and set, false otherwise.
79  */
80  Q_SCRIPTABLE bool setFocuser(const QString &device);
81  Q_SCRIPTABLE QString focuser();
82 
83  /** DBUS interface function.
84  * select the filter device from the available filter drivers. The filter device can be the same as the CCD driver if the filter functionality was embedded within the driver.
85  * @param device The filter device name
86  * @return Returns true if filter device is found and set, false otherwise.
87  */
88  Q_SCRIPTABLE bool setFilterWheel(const QString &device);
89  Q_SCRIPTABLE QString filterWheel();
90 
91  /** DBUS interface function.
92  * select the filter from the available filters.
93  * @param filter The filter name
94  * @return Returns true if filter is found and set, false otherwise.
95  */
96  Q_SCRIPTABLE bool setFilter(const QString &filter);
97  Q_SCRIPTABLE QString filter();
98 
99  /** DBUS interface function.
100  * @return Returns True if current focuser supports auto-focusing
101  */
102  Q_SCRIPTABLE bool canAutoFocus()
103  {
104  return (focusType == FOCUS_AUTO);
105  }
106 
107  /** DBUS interface function.
108  * @return Returns Half-Flux-Radius in pixels.
109  */
110  Q_SCRIPTABLE double getHFR()
111  {
112  return currentHFR;
113  }
114 
115  /** DBUS interface function.
116  * Set CCD exposure value
117  * @param value exposure value in seconds.
118  */
119  Q_SCRIPTABLE Q_NOREPLY void setExposure(double value);
120  Q_SCRIPTABLE double exposure()
121  {
122  return exposureIN->value();
123  }
124 
125  /** DBUS interface function.
126  * Set CCD binning
127  * @param binX horizontal binning
128  * @param binY vertical binning
129  */
130  Q_SCRIPTABLE Q_NOREPLY void setBinning(int binX, int binY);
131 
132  /** DBUS interface function.
133  * Set image filter to apply to the image after capture.
134  * @param value Image filter (Auto Stretch, High Contrast, Equalize, High Pass)
135  */
136  Q_SCRIPTABLE Q_NOREPLY void setImageFilter(const QString &value);
137 
138  /** DBUS interface function.
139  * Set Auto Focus options. The options must be set before starting the autofocus operation. If no options are set, the options loaded from the user configuration are used.
140  * @param enable If true, Ekos will attempt to automatically select the best focus star in the frame. If it fails to select a star, the user will be asked to select a star manually.
141  */
142  Q_SCRIPTABLE Q_NOREPLY void setAutoStarEnabled(bool enable);
143 
144  /** DBUS interface function.
145  * Set Auto Focus options. The options must be set before starting the autofocus operation. If no options are set, the options loaded from the user configuration are used.
146  * @param enable if true, Ekos will capture a subframe around the selected focus star. The subframe size is determined by the boxSize parameter.
147  */
148  Q_SCRIPTABLE Q_NOREPLY void setAutoSubFrameEnabled(bool enable);
149 
150  /** DBUS interface function.
151  * Set Autofocus parameters
152  * @param boxSize the box size around the focus star in pixels. The boxsize is used to subframe around the focus star.
153  * @param stepSize the initial step size to be commanded to the focuser. If the focuser is absolute, the step size is in ticks. For relative focusers, the focuser will be commanded to focus inward for stepSize milliseconds initially.
154  * @param maxTravel the maximum steps permitted before the autofocus operation aborts.
155  * @param tolerance Measure of how accurate the autofocus algorithm is. If the difference between the current HFR and minimum measured HFR is less than %tolerance after the focuser traversed both ends of the V-curve, then the focusing operation
156  * is deemed successful. Otherwise, the focusing operation will continue.
157  */
158  Q_SCRIPTABLE Q_NOREPLY void setAutoFocusParameters(int boxSize, int stepSize, int maxTravel, double tolerance);
159 
160  /** DBUS interface function.
161  * resetFrame Resets the CCD frame to its full native resolution.
162  */
163  Q_SCRIPTABLE Q_NOREPLY void resetFrame();
164 
165  /** DBUS interface function.
166  * Return state of Focuser module (Ekos::FocusState)
167  */
168 
169  Q_SCRIPTABLE Ekos::FocusState status()
170  {
171  return state;
172  }
173 
174  /** @}*/
175 
176  /**
177  * @brief Add CCD to the list of available CCD.
178  * @param newCCD pointer to CCD device.
179  * @return True if added successfully, false if duplicate or failed to add.
180  */
181  bool addCamera(ISD::Camera *device);
182 
183  /**
184  * @brief addFocuser Add focuser to the list of available focusers.
185  * @param newFocuser pointer to focuser device.
186  * @return True if added successfully, false if duplicate or failed to add.
187  */
188  bool addFocuser(ISD::Focuser *device);
189 
190  /**
191  * @brief addFilter Add filter to the list of available filters.
192  * @param newFilter pointer to filter device.
193  * @return True if added successfully, false if duplicate or failed to add.
194  */
195  bool addFilterWheel(ISD::FilterWheel *device);
196 
197 
198  /**
199  * @brief addTemperatureSource Add temperature source to the list of available sources.
200  * @param newSource Device with temperature reporting capability
201  * @return True if added successfully, false if duplicate or failed to add.
202  */
204 
205  /**
206  * @brief removeDevice Remove device from Focus module
207  * @param deviceRemoved pointer to device
208  */
209  void removeDevice(ISD::GenericDevice *deviceRemoved);
210 
211  void setFilterManager(const QSharedPointer<FilterManager> &manager);
212 
213  void clearLog();
214  QStringList logText()
215  {
216  return m_LogText;
217  }
218  QString getLogText()
219  {
220  return m_LogText.join("\n");
221  }
222 
223  // Presets
224  QJsonObject getSettings() const;
225  void setSettings(const QJsonObject &settings);
226  // Primary Settings
227  QJsonObject getPrimarySettings() const;
228  void setPrimarySettings(const QJsonObject &settings);
229  // Process Settings
230  QJsonObject getProcessSettings() const;
231  void setProcessSettings(const QJsonObject &settings);
232  // Mechanics Settings
233  QJsonObject getMechanicsSettings() const;
234  void setMechanicsSettings(const QJsonObject &settings);
235 
236  public slots:
237 
238  /** \addtogroup FocusDBusInterface
239  * @{
240  */
241 
242  /* Focus */
243  /** DBUS interface function.
244  * Start the autofocus operation.
245  */
246  Q_SCRIPTABLE Q_NOREPLY void start();
247 
248  /** DBUS interface function.
249  * Abort the autofocus operation.
250  */
251  Q_SCRIPTABLE Q_NOREPLY void abort();
252 
253  /** DBUS interface function.
254  * Capture a focus frame.
255  * @param settleTime if > 0 wait for the given time in seconds before starting to capture
256  */
257  Q_SCRIPTABLE Q_NOREPLY void capture(double settleTime = 0.0);
258 
259  /** DBUS interface function.
260  * Focus inward
261  * @param ms If set, focus inward for ms ticks (Absolute Focuser), or ms milliseconds (Relative Focuser). If not set, it will use the value specified in the options.
262  */
263  Q_SCRIPTABLE bool focusIn(int ms = -1);
264 
265  /** DBUS interface function.
266  * Focus outward
267  * @param ms If set, focus outward for ms ticks (Absolute Focuser), or ms milliseconds (Relative Focuser). If not set, it will use the value specified in the options.
268  */
269  Q_SCRIPTABLE bool focusOut(int ms = -1);
270 
271  /**
272  * @brief checkFocus Given the minimum required HFR, check focus and calculate HFR. If current HFR exceeds required HFR, start autofocus process, otherwise do nothing.
273  * @param requiredHFR Minimum HFR to trigger autofocus process.
274  */
275  Q_SCRIPTABLE Q_NOREPLY void checkFocus(double requiredHFR);
276 
277  /** @}*/
278 
279  /**
280  * @brief startFraming Begins continuous capture of the CCD and calculates HFR every frame.
281  */
282  void startFraming();
283 
284  /**
285  * @brief Move the focuser to the initial focus position.
286  */
287  void resetFocuser();
288 
289  /**
290  * @brief checkStopFocus Perform checks before stopping the autofocus operation. Some checks are necessary for in-sequence focusing.
291  * @param abort true iff focusing should be aborted, false if it should only be stopped and marked as failed
292  */
293  void checkStopFocus(bool abort);
294 
295  /**
296  * @brief React when a meridian flip has been started
297  */
298  void meridianFlipStarted();
299 
300  /**
301  * @brief Check CCD and make sure information is updated accordingly. This simply calls syncCameraInfo for the current CCD.
302  * @param CCDNum By default, we check the already selected CCD in the dropdown menu. If CCDNum is specified, the check is made against this specific CCD in the dropdown menu.
303  * CCDNum is the index of the CCD in the dropdown menu.
304  */
305  void checkCamera(int CCDNum = -1);
306 
307  /**
308  * @brief syncCameraInfo Read current CCD information and update settings accordingly.
309  */
310  void syncCameraInfo();
311 
312  /**
313  * @brief Update camera controls like Gain, ISO, Offset...etc
314  */
315  void syncCCDControls();
316 
317  /**
318  * @brief Check Focuser and make sure information is updated accordingly.
319  * @param FocuserNum By default, we check the already selected focuser in the dropdown menu. If FocuserNum is specified, the check is made against this specific focuser in the dropdown menu.
320  * FocuserNum is the index of the focuser in the dropdown menu.
321  */
322  void checkFocuser(int FocuserNum = -1);
323 
324  /**
325  * @brief Check Filter and make sure information is updated accordingly.
326  * @param filterNum By default, we check the already selected filter in the dropdown menu. If filterNum is specified, the check is made against this specific filter in the dropdown menu.
327  * filterNum is the index of the filter in the dropdown menu.
328  */
329  void checkFilter(int filterNum = -1);
330 
331  /**
332  * @brief Check temperature source and make sure information is updated accordingly.
333  * @param index Index of source in combo box. If -1, then use the currently selected source.
334  */
335  void checkTemperatureSource(int index = -1);
336 
337  /**
338  * @brief clearDataPoints Remove all data points from HFR plots
339  */
340  void clearDataPoints();
341 
342  /**
343  * @brief focusStarSelected The user selected a focus star, save its coordinates and subframe it if subframing is enabled.
344  * @param x X coordinate
345  * @param y Y coordinate
346  */
347  void focusStarSelected(int x, int y);
348 
349  /**
350  * @brief selectFocusStarFraction Select the focus star based by fraction of the overall size.
351  * It calls focusStarSelected after multiplying the fractions (0.0 to 1.0) with the focus view width and height.
352  * @param x final x = x * focusview_width
353  * @param y final y = y * focusview_height
354  */
355  void selectFocusStarFraction(double x, double y);
356 
357  /**
358  * @brief newFITS A new FITS blob is received by the CCD driver.
359  * @param bp pointer to blob data
360  */
361  void processData(const QSharedPointer<FITSData> &data);
362 
363  /**
364  * @brief processFocusNumber Read focus number properties of interest as they arrive from the focuser driver and process them accordingly.
365  * @param nvp pointer to updated focuser number property.
366  */
367  void processFocusNumber(INumberVectorProperty *nvp);
368 
369  /**
370  * @brief processTemperatureSource Updates focus temperature source.
371  * @param nvp pointer to updated focuser number property.
372  */
373  void processTemperatureSource(INumberVectorProperty *nvp);
374 
375  /**
376  * @brief setFocusStatus Upon completion of the focusing process, set its status (fail or pass) and reset focus process to clean state.
377  * @param status If true, the focus process finished successfully. Otherwise, it failed.
378  */
379  //void setAutoFocusResult(bool status);
380 
381  /**
382  * @brief filterChangeWarning Warn the user it is not a good idea to apply image filter in the filter process as they can skew the HFR calculations.
383  * @param index Index of image filter selected by the user.
384  */
385  void filterChangeWarning(int index);
386 
387  // Logging methods - one for INFO messages to the kstars log, and one for a CSV auto-focus log
388  void appendLogText(const QString &);
389  void appendFocusLogText(const QString &);
390 
391  // Adjust focuser offset, relative or absolute
392  void adjustFocusOffset(int value, bool useAbsoluteOffset);
393 
394  // Update Mount module status
395  void setMountStatus(ISD::Mount::Status newState);
396 
397  // Update Altitude From Mount
398  void setMountCoords(const SkyPoint &position, ISD::Mount::PierSide pierSide, const dms &ha);
399 
400  /**
401  * @brief toggleVideo Turn on and off video streaming if supported by the camera.
402  * @param enabled Set to true to start video streaming, false to stop it if active.
403  */
404  void toggleVideo(bool enabled);
405 
406  /**
407  * @brief setWeatherData Updates weather data that could be used to extract focus temperature from observatory
408  * in case focus native temperature is not available.
409  */
410  //void setWeatherData(const std::vector<ISD::Weather::WeatherData> &data);
411 
412  /**
413  * @brief loadOptionsProfiles Load StellarSolver Profile
414  */
416 
417  /**
418  * @brief getStellarSolverProfiles
419  * @return list of StellarSolver profile names
420  */
422 
423 
424 
425  protected:
426  void addPlotPosition(int pos, double hfr, bool plot = true);
427 
428  private slots:
429  /**
430  * @brief toggleSubframe Process enabling and disabling subfrag.
431  * @param enable If true, subframing is enabled. If false, subframing is disabled. Even if subframing is enabled, it must be supported by the CCD driver.
432  */
433  void toggleSubframe(bool enable);
434 
435  void checkAutoStarTimeout();
436 
437  void setAbsoluteFocusTicks();
438 
439  void updateBoxSize(int value);
440 
441  void processCaptureTimeout();
442 
443  void processCaptureError(ISD::Camera::ErrorType type);
444 
445  void setCaptureComplete();
446 
447  void showFITSViewer();
448 
449  void toggleFocusingWidgetFullScreen();
450 
451  void setVideoStreamEnabled(bool enabled);
452 
453  void syncSettings();
454 
455  void calculateHFR();
456  void setCurrentHFR(double value);
457 
458  signals:
459  void newLog(const QString &text);
460  void newStatus(Ekos::FocusState state);
461  void newHFR(double hfr, int position);
462  void newFocusTemperatureDelta(double delta, double absTemperature);
463 
464  void absolutePositionChanged(int value);
465  void focusPositionAdjusted();
466 
467  void suspendGuiding();
468  void resumeGuiding();
469  void newImage(const QSharedPointer<FITSView> &view);
470  void newStarPixmap(QPixmap &);
471  void settingsUpdated(const QJsonObject &settings);
472 
473  // Signals for Analyze.
474  void autofocusStarting(double temperature, const QString &filter);
475  void autofocusComplete(const QString &filter, const QString &points);
476  void autofocusAborted(const QString &filter, const QString &points);
477 
478  // HFR V curve plot events
479  /**
480  * @brief initialize the HFR V plot
481  * @param showPosition show focuser position (true) or count focus iterations (false)
482  */
483  void initHFRPlot(bool showPosition);
484 
485  /**
486  * @brief new HFR plot position
487  * @param pos focuser position
488  * @param hfr measured star HFR value
489  * @param pulseDuration Pulse duration in ms for relative focusers that only support timers,
490  * or the number of ticks in a relative or absolute focuser
491  * */
492  void newHFRPlotPosition(double pos, double hfr, int pulseDuration, bool plot = true);
493 
494  /**
495  * @brief new HFR plot position with sigma
496  * @param pos focuser position with associated error (sigma)
497  * @param hfr measured star HFR value
498  * @param sigma is the standard deviation of star HFRs
499  * @param pulseDuration Pulse duration in ms for relative focusers that only support timers,
500  * or the number of ticks in a relative or absolute focuser
501  * */
502  void newHFRPlotPositionWithSigma(double pos, double hfr, double sigma, int pulseDuration, bool plot = true);
503 
504  /**
505  * @brief draw the approximating polynomial into the HFR V-graph
506  * @param poly pointer to the polynomial approximation
507  * @param isVShape has the solution a V shape?
508  * @param activate make the graph visible?
509  */
510  void drawPolynomial(PolynomialFit *poly, bool isVShape, bool activate, bool plot = true);
511 
512  /**
513  * @brief draw the curve into the HFR V-graph
514  * @param poly pointer to the polynomial approximation
515  * @param isVShape has the solution a V shape?
516  * @param activate make the graph visible?
517  */
518  void drawCurve(CurveFitting *curve, bool isVShape, bool activate, bool plot = true);
519 
520  /**
521  * @brief Focus solution with minimal HFR found
522  * @param solutionPosition focuser position
523  * @param solutionValue HFR value
524  */
525  void minimumFound(double solutionPosition, double solutionValue, bool plot = true);
526 
527  /**
528  * @brief redraw the entire HFR plot
529  * @param poly pointer to the polynomial approximation
530  * @param solutionPosition solution focuser position
531  * @param solutionValue solution HFR value
532  */
533  void redrawHFRPlot(PolynomialFit *poly, double solutionPosition, double solutionValue);
534 
535  /**
536  * @brief draw a title on the focus plot
537  * @param title the title
538  */
539  void setTitle(const QString &title, bool plot = true);
540 
541  /**
542  * @brief update the title on the focus plot
543  * @param title
544  */
545  void updateTitle(const QString &title, bool plot = true);
546 
547  private:
548 
549  QList<SSolver::Parameters> m_StellarSolverProfiles;
550  QString savedOptionsProfiles;
551  StellarSolverProfileEditor *optionsProfileEditor { nullptr };
552 
553  ////////////////////////////////////////////////////////////////////
554  /// Connections
555  ////////////////////////////////////////////////////////////////////
556  void initConnections();
557 
558  ////////////////////////////////////////////////////////////////////
559  /// Settings
560  ////////////////////////////////////////////////////////////////////
561 
562  /**
563  * @brief initSettings Connect settings to slots to update the value when changed
564  */
565  void initSettingsConnections();
566  /**
567  * @brief loadSettings Load setting from Options and set them accordingly.
568  */
569  void loadSettings();
570 
571  ////////////////////////////////////////////////////////////////////
572  /// HFR Plot
573  ////////////////////////////////////////////////////////////////////
574  void initPlots();
575 
576  ////////////////////////////////////////////////////////////////////
577  /// Positions
578  ////////////////////////////////////////////////////////////////////
579  void getAbsFocusPosition();
580  bool autoFocusChecks();
581  void autoFocusAbs();
582  void autoFocusLinear();
583  void autoFocusRel();
584 
585  // Linear does plotting differently from the rest.
586  void plotLinearFocus();
587 
588  // Linear final updates to the curve
589  void plotLinearFinalUpdates();
590 
591  /** @brief Helper function determining whether the focuser behaves like a position
592  * based one (vs. a timer based)
593  */
594  bool isPositionBased()
595  {
596  return (canAbsMove || canRelMove || (focusAlgorithm == FOCUS_LINEAR) || (focusAlgorithm == FOCUS_LINEAR1PASS));
597  }
598  void resetButtons();
599  void stop(FocusState completionState = FOCUS_ABORTED);
600 
601  void initView();
602 
603  /**
604  * @brief prepareCapture Set common settings for capture for focus module
605  * @param targetChip target Chip
606  */
607  void prepareCapture(ISD::CameraChip *targetChip);
608  ////////////////////////////////////////////////////////////////////
609  /// HFR
610  ////////////////////////////////////////////////////////////////////
611  void setHFRComplete();
612 
613  // Sets the algorithm and enables/disables various UI inputs.
614  void setFocusAlgorithm(FocusAlgorithm algorithm);
615 
616  void setCurveFit(CurveFitting::CurveFit curvefit);
617 
618  // Move the focuser in (negative) or out (positive amount).
619  bool changeFocus(int amount);
620 
621  // Start up capture, or occasionally move focuser again, after current focus-move accomplished.
622  void autoFocusProcessPositionChange(IPState state);
623 
624  // For the Linear algorithm, which always scans in (from higher position to lower position)
625  // if we notice the new position is higher than the current position (that is, it is the start
626  // of a new scan), we adjust the new position to be several steps further out than requested
627  // and set focuserAdditionalMovement to the extra motion, so that after this motion completes
628  // we will then scan back in (back to the originally requested position). This "dance" is done
629  // to reduce backlash on such movement changes and so that we've always focused in before capture.
630  // For LINEAR1PASS algo use the user-defined backlash value to adjust by
631  int adjustLinearPosition(int position, int newPosition, int backlash);
632 
633  /**
634  * @brief syncTrackingBoxPosition Sync the tracking box to the current selected star center
635  */
636  void syncTrackingBoxPosition();
637 
638  /** @internal Search for stars using the method currently configured, and return the consolidated HFR.
639  * @param image_data is the FITS frame to work with.
640  * @return the HFR of the star or field of stars in the frame, depending on the consolidation method, or -1 if it cannot be estimated.
641  */
642  void analyzeSources();
643 
644  /** @internal Add a new HFR for the current focuser position.
645  * @param newHFR is the new HFR to consider for the current focuser position.
646  * @return true if a new sample is required, else false.
647  */
648  bool appendHFR(double newHFR);
649 
650 
651  /**
652  * @brief completeAutofocusProcedure finishes off autofocus and emits a message for other modules.
653  */
654  void completeFocusProcedure(FocusState completionState, bool plot = true);
655 
656  /**
657  * @brief activities to be executed after the configured settling time
658  * @param completionState state the focuser completed with
659  * @param autoFocusUsed is autofocus running?
660  */
661  void settle(const FocusState completionState, const bool autoFocusUsed);
662 
663  void setLastFocusTemperature();
664  bool findTemperatureElement(ISD::GenericDevice *device);
665 
666  bool syncControl(const QJsonObject &settings, const QString &key, QWidget * widget);
667 
668  /**
669  * @brief handleFocusMotionTimeout When focuser is command to go to a target position, we expect to receive a notification
670  * that it arrived at the desired destination. If not, we command it again.
671  */
672  void handleFocusMotionTimeout();
673 
674  /// Focuser device needed for focus operation
675  ISD::Focuser *m_Focuser { nullptr };
676  /// CCD device needed for focus operation
677  ISD::Camera *m_Camera { nullptr };
678  /// Optional device filter
679  ISD::FilterWheel *m_FilterWheel { nullptr };
680  /// Optional temperature source element
681  INumber *currentTemperatureSourceElement {nullptr};
682 
683  /// Current filter position
684  int currentFilterPosition { -1 };
685  int fallbackFilterPosition { -1 };
686  /// True if we need to change filter position and wait for result before continuing capture
687  bool filterPositionPending { false };
688  bool fallbackFilterPending { false };
689 
690  /// List of Focusers
691  QList<ISD::Focuser *> m_Focusers;
692  /// List of CCDs
693  QList<ISD::Camera *> m_Cameras;
694  /// They're generic GDInterface because they could be either ISD::Camera or ISD::FilterWheel
695  QList<ISD::FilterWheel *> m_FilterWheels;
696  /// They're generic GDInterface because they could be either ISD::Camera or ISD::FilterWheel or ISD::Weather
697  QList<ISD::GenericDevice *> m_TemperatureSources;
698 
699  /// As the name implies
700  FocusDirection m_LastFocusDirection { FOCUS_NONE };
701  /// Keep track of the last requested steps
702  uint32_t m_LastFocusSteps {0};
703  /// What type of focusing are we doing right now?
704  FocusType focusType { FOCUS_MANUAL };
705  /// Focus HFR & Centeroid algorithms
706  StarAlgorithm focusDetection { ALGORITHM_GRADIENT };
707  /// Focus Process Algorithm
708  FocusAlgorithm focusAlgorithm { FOCUS_ITERATIVE };
709  /// Curve fit, default to Quadratic
710  CurveFitting::CurveFit curveFit { CurveFitting::FOCUS_QUADRATIC };
711 
712  /*********************
713  * HFR Club variables
714  *********************/
715 
716  /// Current HFR value just fetched from FITS file
717  double currentHFR { 0 };
718  /// Last HFR value recorded
719  double lastHFR { 0 };
720  /// If (currentHFR > deltaHFR) we start the autofocus process.
721  double minimumRequiredHFR { -1 };
722  /// Maximum HFR recorded
723  double maxHFR { 1 };
724  /// Is HFR increasing? We're going away from the sweet spot! If HFRInc=1, we re-capture just to make sure HFR calculations are correct, if HFRInc > 1, we switch directions
725  int HFRInc { 0 };
726  /// If HFR decreasing? Well, good job. Once HFR start decreasing, we can start calculating HFR slope and estimating our next move.
727  int HFRDec { 0 };
728 
729  /****************************
730  * Absolute position focusers
731  ****************************/
732  /// Absolute focus position
733  int currentPosition { 0 };
734  /// Motion state of the absolute focuser
735  IPState currentPositionState {IPS_IDLE};
736  /// What was our position before we started the focus process?
737  int initialFocuserAbsPosition { -1 };
738  /// Pulse duration in ms for relative focusers that only support timers, or the number of ticks in a relative or absolute focuser
739  int pulseDuration { 1000 };
740  /// Does the focuser support absolute motion?
741  bool canAbsMove { false };
742  /// Does the focuser support relative motion?
743  bool canRelMove { false };
744  /// Does the focuser support timer-based motion?
745  bool canTimerMove { false };
746  /// Maximum range of motion for our lovely absolute focuser
747  double absMotionMax { 0 };
748  /// Minimum range of motion for our lovely absolute focuser
749  double absMotionMin { 0 };
750  /// How many iterations have we completed now in our absolute autofocus algorithm? We can't go forever
751  int absIterations { 0 };
752 
753  /****************************
754  * Misc. variables
755  ****************************/
756 
757  /// Are we in the process of capturing an image?
758  bool captureInProgress { false };
759  /// Are we in the process of calculating HFR?
760  bool hfrInProgress { false };
761  // Was the frame modified by us? Better keep track since we need to return it to its previous state once we are done with the focus operation.
762  //bool frameModified;
763  /// Was the modified frame subFramed?
764  bool subFramed { false };
765  /// If the autofocus process fails, let's not ruin the capture session probably taking place in the next tab. Instead, we should restart it and try again, but we keep count until we hit MAXIMUM_RESET_ITERATIONS
766  /// and then we truly give up.
767  int resetFocusIteration { 0 };
768  /// Which filter must we use once the autofocus process kicks in?
769  int lockedFilterIndex { -1 };
770  /// Keep track of what we're doing right now
771  bool inAutoFocus { false };
772  bool inFocusLoop { false };
773  //bool inSequenceFocus { false };
774  /// Keep track of request to retry or abort an AutoFocus run after focus position has been reset
775  /// RESTART_NONE = normal operation, no restart
776  /// RESTART_NOW = restart the autofocus routine
777  /// RESTART_ABORT = when autofocus has been tried MAXIMUM_RESET_ITERATIONS times, abort the routine
778  typedef enum { RESTART_NONE = 0, RESTART_NOW, RESTART_ABORT } FocusRestartState;
779  FocusRestartState m_RestartState { RESTART_NONE };
780  /// Did we reverse direction?
781  bool reverseDir { false };
782  /// Did the user or the auto selection process finish selecting our focus star?
783  bool starSelected { false };
784  /// Adjust the focus position to a target value
785  bool adjustFocus { false };
786  // Target frame dimensions
787  //int fx,fy,fw,fh;
788  /// If HFR=-1 which means no stars detected, we need to decide how many times should the re-capture process take place before we give up or reverse direction.
789  int noStarCount { 0 };
790  /// Track which upload mode the CCD is set to. If set to UPLOAD_LOCAL, then we need to switch it to UPLOAD_CLIENT in order to do focusing, and then switch it back to UPLOAD_LOCAL
791  ISD::Camera::UploadMode rememberUploadMode { ISD::Camera::UPLOAD_CLIENT };
792  /// Previous binning setting
793  int activeBin { 0 };
794  /// HFR values for captured frames before averages
795  QVector<double> HFRFrames;
796  // Camera Fast Exposure
797  bool m_RememberCameraFastExposure = { false };
798  // Future Watch
799  QFutureWatcher<bool> m_StarFinderWatcher;
800  // R2 as a measure of how well the curve fits the datapoints. Passed to the V-curve graph for display
801  double R2 = 0;
802  // Counter to retry the auto focus run if the R2Limit has not been reached
803  int R2Retries = 0;
804 
805  /// Autofocus log file info.
806  QStringList m_LogText;
807  QFile m_FocusLogFile;
808  QString m_FocusLogFileName;
809  bool m_FocusLogEnabled { false };
810 
811  ITextVectorProperty *filterName { nullptr };
812  INumberVectorProperty *filterSlot { nullptr };
813 
814  /****************************
815  * Plot variables
816  ****************************/
817 
818  /// Plot minimum positions
819  double minPos { 1e6 };
820  /// Plot maximum positions
821  double maxPos { 0 };
822 
823  /// HFR V curve plot points
824  QVector<double> hfr_position, hfr_value;
825  bool isVShapeSolution = false;
826 
827  /// State
828  Ekos::FocusState state { Ekos::FOCUS_IDLE };
829 
830  /// FITS Scale
831  FITSScale defaultScale;
832 
833  /// CCD Chip frame settings
835 
836  /// Selected star coordinates
837  QVector3D starCenter;
838 
839  // Remember last star center coordinates in case of timeout in manual select mode
840  QVector3D rememberStarCenter;
841 
842  /// Focus Frame
843  QSharedPointer<FITSView> m_FocusView;
844 
845  /// Star Select Timer
846  QTimer waitStarSelectTimer;
847 
848  /// FITS Viewer in case user want to display in it instead of internal view
850 
851  /// Track star position and HFR to know if we're detecting bogus stars due to detection algorithm false positive results
852  QVector<QVector3D> starsHFR;
853 
854  /// Relative Profile
855  FocusProfilePlot *profilePlot { nullptr };
856  QDialog *profileDialog { nullptr };
857 
858  /// Polynomial fitting.
859  std::unique_ptr<PolynomialFit> polynomialFit;
860 
861  // Curve fitting.
862  std::unique_ptr<CurveFitting> curveFitting;
863 
864  // Capture timers
865  QTimer captureTimer;
866  QTimer captureTimeout;
867  uint8_t captureTimeoutCounter { 0 };
868  uint8_t captureFailureCounter { 0 };
869 
870  // Focus motion timer.
871  QTimer m_FocusMotionTimer;
872  uint8_t m_FocusMotionTimerCounter {0};
873 
874  // Guide Suspend
875  bool m_GuidingSuspended { false };
876 
877  // Filter Manager
878  QSharedPointer<FilterManager> m_FilterManager;
879 
880  // Data
881  QSharedPointer<FITSData> m_ImageData;
882 
883  // Linear focuser.
884  std::unique_ptr<FocusAlgorithmInterface> linearFocuser;
885  int focuserAdditionalMovement { 0 };
886  int linearRequestedPosition { 0 };
887 
888  bool hasDeviation { false };
889 
890  //double observatoryTemperature { INVALID_VALUE };
891  double m_LastSourceAutofocusTemperature { INVALID_VALUE };
892  //TemperatureSource lastFocusTemperatureSource { NO_TEMPERATURE };
893 
894  // Mount altitude value for logging
895  double mountAlt { INVALID_VALUE };
896 
897  static constexpr uint8_t MAXIMUM_FLUCTUATIONS {10};
898 
899  // Dark Processor
900  QPointer<DarkProcessor> m_DarkProcessor;
901 };
902 }
Q_OBJECTQ_OBJECT
void minimumFound(double solutionPosition, double solutionValue, bool plot=true)
Focus solution with minimal HFR found.
void clearDataPoints()
clearDataPoints Remove all data points from HFR plots
Definition: focus.cpp:2241
Q_PROPERTY(...)
Q_SCRIPTABLE Q_NOREPLY void setAutoSubFrameEnabled(bool enable)
DBUS interface function.
Definition: focus.cpp:3577
Q_SCRIPTABLE Q_NOREPLY void capture(double settleTime=0.0)
DBUS interface function.
Definition: focus.cpp:1229
Q_SCRIPTABLE Q_NOREPLY void abort()
DBUS interface function.
Definition: focus.cpp:1161
Q_SCRIPTABLE Ekos::FocusState status()
DBUS interface function.
Definition: focus.h:169
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:70
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
Q_CLASSINFO(Name, Value)
bool addFocuser(ISD::Focuser *device)
addFocuser Add focuser to the list of available focusers.
Definition: focus.cpp:621
void loadStellarSolverProfiles()
setWeatherData Updates weather data that could be used to extract focus temperature from observatory ...
Definition: focus.cpp:156
Q_SCRIPTABLE bool canAutoFocus()
DBUS interface function.
Definition: focus.h:102
void drawPolynomial(PolynomialFit *poly, bool isVShape, bool activate, bool plot=true)
draw the approximating polynomial into the HFR V-graph
void checkTemperatureSource(int index=-1)
Check temperature source and make sure information is updated accordingly.
Definition: focus.cpp:467
Q_SCRIPTABLE Q_NOREPLY void setAutoFocusParameters(int boxSize, int stepSize, int maxTravel, double tolerance)
DBUS interface function.
Definition: focus.cpp:3583
Q_SCRIPTABLE bool setFilterWheel(const QString &device)
DBUS interface function.
Definition: focus.cpp:545
void syncCameraInfo()
syncCameraInfo Read current CCD information and update settings accordingly.
Definition: focus.cpp:371
void drawCurve(CurveFitting *curve, bool isVShape, bool activate, bool plot=true)
draw the curve into the HFR V-graph
Q_SCRIPTABLE bool setCamera(const QString &device)
DBUS interface function.
Definition: focus.cpp:223
void meridianFlipStarted()
React when a meridian flip has been started.
Definition: focus.cpp:1145
void filterChangeWarning(int index)
setFocusStatus Upon completion of the focusing process, set its status (fail or pass) and reset focus...
Definition: focus.cpp:3526
void checkStopFocus(bool abort)
checkStopFocus Perform checks before stopping the autofocus operation.
Definition: focus.cpp:1116
Q_SCRIPTABLE Q_NOREPLY void start()
DBUS interface function.
Definition: focus.cpp:930
void startFraming()
startFraming Begins continuous capture of the CCD and calculates HFR every frame.
Definition: focus.cpp:3240
void newHFRPlotPositionWithSigma(double pos, double hfr, double sigma, int pulseDuration, bool plot=true)
new HFR plot position with sigma
void removeDevice(ISD::GenericDevice *deviceRemoved)
removeDevice Remove device from Focus module
Definition: focus.cpp:3771
bool addFilterWheel(ISD::FilterWheel *device)
addFilter Add filter to the list of available filters.
Definition: focus.cpp:409
void selectFocusStarFraction(double x, double y)
selectFocusStarFraction Select the focus star based by fraction of the overall size.
Definition: focus.cpp:3347
void processTemperatureSource(INumberVectorProperty *nvp)
processTemperatureSource Updates focus temperature source.
Definition: focus.cpp:820
Q_SCRIPTABLE Q_NOREPLY void checkFocus(double requiredHFR)
checkFocus Given the minimum required HFR, check focus and calculate HFR.
Definition: focus.cpp:3489
void resetFocuser()
Move the focuser to the initial focus position.
Definition: focus.cpp:1825
void updateTitle(const QString &title, bool plot=true)
update the title on the focus plot
QString join(const QString &separator) const const
void processData(const QSharedPointer< FITSData > &data)
newFITS A new FITS blob is received by the CCD driver.
Definition: focus.cpp:1499
Q_SCRIPTABLE Q_NOREPLY void setImageFilter(const QString &value)
DBUS interface function.
Definition: focus.cpp:3560
Q_SCRIPTABLE Q_NOREPLY void setExposure(double value)
DBUS interface function.
Definition: focus.cpp:3549
QStringList getStellarSolverProfiles()
getStellarSolverProfiles
Definition: focus.cpp:170
Q_SCRIPTABLE bool setFilter(const QString &filter)
DBUS interface function.
Definition: focus.cpp:571
void processFocusNumber(INumberVectorProperty *nvp)
processFocusNumber Read focus number properties of interest as they arrive from the focuser driver an...
Definition: focus.cpp:2966
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
void initHFRPlot(bool showPosition)
initialize the HFR V plot
Q_SCRIPTABLE Q_NOREPLY void resetFrame()
DBUS interface function.
Definition: focus.cpp:188
void redrawHFRPlot(PolynomialFit *poly, double solutionPosition, double solutionValue)
redraw the entire HFR plot
Q_SCRIPTABLE bool focusIn(int ms=-1)
DBUS interface function.
Definition: focus.cpp:1392
void focusStarSelected(int x, int y)
focusStarSelected The user selected a focus star, save its coordinates and subframe it if subframing ...
Definition: focus.cpp:3360
void toggleVideo(bool enabled)
toggleVideo Turn on and off video streaming if supported by the camera.
Definition: focus.cpp:3966
Q_SCRIPTABLE Q_NOREPLY void setBinning(int binX, int binY)
DBUS interface function.
Definition: focus.cpp:3554
Q_SCRIPTABLE Q_NOREPLY void setAutoStarEnabled(bool enable)
DBUS interface function.
Definition: focus.cpp:3571
bool addCamera(ISD::Camera *device)
Add CCD to the list of available CCD.
Definition: focus.cpp:769
void syncCCDControls()
Update camera controls like Gain, ISO, Offset...etc.
Definition: focus.cpp:321
void checkFocuser(int FocuserNum=-1)
Check Focuser and make sure information is updated accordingly.
Definition: focus.cpp:660
void setTitle(const QString &title, bool plot=true)
draw a title on the focus plot
Q_SCRIPTABLE bool focusOut(int ms=-1)
DBUS interface function.
Definition: focus.cpp:1399
Supports manual focusing and auto focusing using relative and absolute INDI focusers.
Definition: focus.h:39
Q_SCRIPTABLE double getHFR()
DBUS interface function.
Definition: focus.h:110
bool addTemperatureSource(ISD::GenericDevice *device)
addTemperatureSource Add temperature source to the list of available sources.
Definition: focus.cpp:441
Q_SCRIPTABLE bool setFocuser(const QString &device)
DBUS interface function.
Definition: focus.cpp:639
void checkFilter(int filterNum=-1)
Check Filter and make sure information is updated accordingly.
Definition: focus.cpp:587
void checkCamera(int CCDNum=-1)
Check CCD and make sure information is updated accordingly.
Definition: focus.cpp:244
void newHFRPlotPosition(double pos, double hfr, int pulseDuration, bool plot=true)
new HFR plot position
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 8 2022 04:13:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.