Kstars

sequencejobstate.h
1/* Ekos state machine for a single capture job sequence.
2 SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "indi/indicommon.h"
10#include "skypoint.h"
11#include "camerastate.h"
12#include "ekos/auxiliary/filtermanager.h"
13#include "fitsviewer/fitscommon.h"
14
15#include <QWidget>
16#include <QVector>
17#include <QMap>
18
19namespace Ekos
20{
21/* Status of a single {@see SequenceJob}. */
22typedef enum
23{
24 JOB_IDLE, /* Initial state, nothing happens. */
25 JOB_BUSY, /* Job is running. */
26 JOB_ERROR, /* Error occured, unresolved. */
27 JOB_ABORTED, /* Job stopped before completion. */
28 JOB_DONE /* Job completed. */
29} JOBStatus;
30
31class SequenceJobState: public QObject
32{
34
35 friend class SequenceJob;
36 friend class CaptureDeviceAdaptor;
37 // Fixme: too many friends
38 friend class Capture;
39
40 public:
41 typedef enum
42 {
43 CAL_NONE, /* initial state */
44 CAL_DUSTCAP_PARKING, /* unused */
45 CAL_DUSTCAP_PARKED, /* unused */
46 CAL_LIGHTBOX_ON, /* unused */
47 CAL_SLEWING, /* unused */
48 CAL_SLEWING_COMPLETE, /* unused */
49 CAL_MOUNT_PARKING, /* unused */
50 CAL_MOUNT_PARKED, /* unused */
51 CAL_DOME_PARKING, /* unused */
52 CAL_DOME_PARKED, /* unused */
53 CAL_PRECAPTURE_COMPLETE, /* unused */
54 CAL_CALIBRATION,
55 CAL_CALIBRATION_COMPLETE,
56 CAL_CAPTURING
57 } CalibrationStage;
58
59 typedef enum
60 {
61 PREP_NONE, /* preparation has not been executed */
62 PREP_BUSY, /* preparation started */
63 PREP_COMPLETED, /* preparation completed */
64 PREP_INIT_CAPTURE /* initialize capturing (last step before device capturing starts) */
65 } PreparationState;
66
67 typedef enum
68 {
69 CAL_CHECK_TASK,
70 CAL_CHECK_CONFIRMATION,
71 } CalibrationCheckType;
72
73 typedef enum
74 {
75 WP_NONE, /* slewing to wall position not started */
76 WP_UNPARKING, /* unpark before slewing */
77 WP_UNPARKED, /* scope unparked, ready to slew */
78 WP_SLEWING, /* slewing to wall position started */
79 WP_SLEW_COMPLETED, /* wall position reached */
80 WP_TRACKING_BUSY, /* turning tracking off running */
81 WP_TRACKING_OFF /* wall position reached, tracking off */
82 } ScopeWallPositionStatus;
83
84 typedef enum /* synching the focuser to the focus position */
85 {
86 FS_NONE, /* not started */
87 FS_BUSY, /* running */
88 FS_COMPLETED /* completed */
89 } FlatSyncStatus;
90
91 SequenceJobState(const QSharedPointer<CameraState> &sharedState);
92
93 /**
94 * @brief Initialize the state machine.
95 * @param frameType frame type for which the preparation should be done
96 */
97 void setFrameType(CCDFrameType frameType);
98 CCDFrameType getFrameType()
99 {
100 return m_frameType;
101 }
102
103 /**
104 * @brief initPreparation Reset all states properly for capture preparation
105 * @param isPreview flag if the captures are in the preview mode
106 */
107 void initPreparation(bool isPreview);
108
109 /**
110 * @brief Trigger all peparation actions before a capture may be started.
111 * @param enforceCCDTemp flag if the CCD temperature should be set to the target value.
112 * @param isPreview flag if the captures are in the preview mode
113 */
114 void prepareLightFrameCapture(bool enforceCCDTemp, bool isPreview);
115
116 /**
117 * @brief Initiate tasks required so that capturing of flats may start.
118 * @param enforceCCDTemp flag if the CCD temperature should be set to the target value.
119 * @param isPreview flag if the captures are in the preview mode
120 */
121 void prepareFlatFrameCapture(bool enforceCCDTemp, bool isPreview);
122
123 /**
124 * @brief Initiate tasks required so that capturing of darks may start.
125 * @param enforceCCDTemp flag if the CCD temperature should be set to the target value.
126 * @param isPreview flag if the captures are in the preview mode
127 */
128 void prepareDarkFrameCapture(bool enforceCCDTemp, bool isPreview);
129
130 /**
131 * @brief Initiate tasks required so that capturing of bias may start.
132 * @param enforceCCDTemp flag if the CCD temperature should be set to the target value.
133 * @param isPreview flag if the captures are in the preview mode
134 */
135 void prepareBiasFrameCapture(bool enforceCCDTemp, bool isPreview);
136
137 /**
138 * @brief initCapture Initialize capturing (currently only setting the
139 * target filter).
140 * @param frameType frame type to be captured
141 * @param isPreview is the captured frame only a preview?
142 * @param isAutofocusReady is an autofocus possible?
143 * @return true if the initialization is already completed
144 */
145 bool initCapture(CCDFrameType frameType, bool isPreview, bool isAutofocusReady, FITSMode mode);
146
147 /**
148 * @brief The current capture sequence job status
149 */
150 JOBStatus getStatus()
151 {
152 return m_status;
153 }
154
155 /**
156 * @brief Preparation state of the sequence job
157 */
158 PreparationState getPreparationState() const;
159
160 /**
161 * @brief Reset the status to a dedicated value.
162 * @param status new status, by default {@see JOB_IDLE}
163 */
164 void reset(JOBStatus status = JOB_IDLE)
165 {
166 m_status = status;
167 }
168
169 public slots:
170 //////////////////////////////////////////////////////////////////////
171 // Slots for device events that change the state.
172 //////////////////////////////////////////////////////////////////////
173
174 /**
175 * @brief setFilterStatus Update the current filter state
176 */
177 void setFilterStatus(FilterState filterState);
178
179 /**
180 * @brief Update the currently active filter ID
181 */
182 void setCurrentFilterID(int value);
183
184 /**
185 * @brief Update the current CCD temperature
186 */
187 void setCurrentCCDTemperature(double value);
188 /**
189 * @brief Set the target CCD temperature
190 */
191 void setTargetCCDTemperature(double value)
192 {
193 targetTemperature = value;
194 }
195
196 /**
197 * @brief setFocusStatus Evaluate the current focus state
198 */
199 void setFocusStatus(FocusState state);
200
201 /**
202 * @brief Update the current rotator position (calculated from the rotator angle)
203 */
204 void setCurrentRotatorPositionAngle(double currentRotation, IPState state);
205 /**
206 * @brief Set the target rotation angle
207 */
208 void setTargetRotatorAngle(double value)
209 {
210 targetPositionAngle = value;
211 }
212
213 /**
214 * @brief Cover for the scope with a flats light source or dark cover done
215 */
216 void updateManualScopeCover(bool closed, bool success, bool light);
217 /**
218 * @brief Light box light is on.
219 */
220 void lightBoxLight(bool on);
221 /**
222 * @brief dust cap status change
223 */
224 void dustCapStateChanged(ISD::DustCap::Status status);
225 /**
226 * @brief telescope status change
227 */
228 void scopeStatusChanged(ISD::Mount::Status status);
229 /**
230 * @brief telescope status change
231 */
232 void scopeParkStatusChanged(ISD::ParkStatus status);
233 /**
234 * @brief dome status change
235 */
236 void domeStatusChanged(ISD::Dome::Status status);
237 /**
238 * @brief flat sync focus status change
239 */
240 void flatSyncFocusChanged(bool completed);
241 /**
242 * @brief CCD has a shutter
243 */
244 void hasShutter(bool present);
245
246 signals:
247 // communicate that a preparation step needs to be executed
248 void prepareState(Ekos::CaptureState state);
249 // ask for the current device state
250 void readCurrentState(Ekos::CaptureState state);
251 // ask for the current mount park state
252 void readCurrentMountParkState();
253 // Capture preparation complete(d)
254 void prepareComplete(bool success = true);
255 // Capture initialization complete(d)
256 void initCaptureComplete(FITSMode mode);
257 // change the rotator angle
258 void setRotatorAngle(double rawAngle);
259 // ask for the current filter position
260 void readFilterPosition();
261 // Change the filter to the given position and the filter change policy
262 void changeFilterPosition(int targetFilterPosition, FilterManager::FilterPolicy policy);
263 // set the CCD target temperature
264 void setCCDTemperature(double temp);
265 // set CCD to preview mode
266 void setCCDBatchMode(bool m_preview);
267 // ask for manually covering the scope with a flat light source or dark cover
268 void askManualScopeCover(QString question, QString title, bool light);
269 // ask for manually opening the scope cover
270 void askManualScopeOpen(bool light);
271 // turn light on in the light box
272 void setLightBoxLight(bool on);
273 // turn light on in the dust cap
274 void setDustCapLight(bool on);
275 // park the dust cap
276 void parkDustCap(bool park);
277 // slew the telescope to a target
278 void slewTelescope(SkyPoint &target);
279 // turn scope tracking on and off
280 void setScopeTracking(bool on);
281 // park / unpark telescope
282 void setScopeParked(bool parked);
283 // park / unpark dome
284 void setDomeParked(bool parked);
285 // check if the focuser needs to be moved to the focus position.
286 void flatSyncFocus(int targetFilterID);
287 // ask whether the CCD has a shutter
288 void queryHasShutter();
289 // abort capturing
290 void abortCapture();
291 // log entry
292 void newLog(QString);
293
294 private:
295 // current status of the capture sequence job
296 JOBStatus m_status { JOB_IDLE };
297
298 // Is the capture preparation ready?
299 PreparationState m_PreparationState { PREP_NONE };
300
301 // ////////////////////////////////////////////////////////////////////
302 // capture preparation relevant flags
303 // ////////////////////////////////////////////////////////////////////
304
305 // Mapping PrepareActions --> bool marks whether a certain action is completed (=true) or not (=false)
306 QMap<CaptureWorkflowActionType, bool> prepareActions;
307 // This is a workaround for a specific INDI behaviour. If a INDI property is set, it sends this value
308 // back to the clients. If the value does not immediately change to the target value (like e.g. the CCD
309 // temperature), the first value after setting a property must be ignored.
310 QMap<CaptureWorkflowActionType, bool> ignoreNextValue;
311
312 // capture frame type (light, flat, dark, bias)
313 CCDFrameType m_frameType { FRAME_NONE };
314 // do we shoot a preview?
315 bool m_isPreview { false };
316 // should a certain temperature should be enforced?
317 bool m_enforceTemperature { false };
318 // flag if auto focus has been completed for the selected filter
319 bool autoFocusReady;
320 // Capturing mode, necessary for the display in the FITS viewer
321 FITSMode m_fitsMode;
322 // Capture Operations Timeout
323 QTimer m_CaptureOperationsTimer;
324 // ////////////////////////////////////////////////////////////////////
325 // flat preparation attributes
326 // ////////////////////////////////////////////////////////////////////
327 // status of the focuser synchronisation
328 FlatSyncStatus flatSyncStatus { FS_NONE };
329 // Timer for flat sync status
330 QTimer m_FlatSyncCheck;
331 // light source for flat capturing
332 uint32_t m_CalibrationPreAction { CAPTURE_PREACTION_NONE };
333 // wall coordinates for capturing flats with the wall as light source
334 SkyPoint wallCoord;
335 // telescope status for flats using the wall position
336 ScopeWallPositionStatus wpScopeStatus { WP_NONE };
337
338 // ////////////////////////////////////////////////////////////////////
339 // capture preparation state
340 // ////////////////////////////////////////////////////////////////////
341 /**
342 * @brief Check if all actions are ready and emit {@see prepareComplete()} if all are ready.
343 */
344 void checkAllActionsReady();
345
346 /**
347 * @brief Check if all preparation actions are completed
348 * @return true if all preparation actions are completed
349 */
350 bool areActionsReady();
351
352 /**
353 * @brief preparationCompleted helper function for checking, if the preparation has been completed
354 */
355 bool preparationCompleted()
356 {
357 return m_PreparationState == PREP_COMPLETED;
358 }
359
360 /**
361 * @brief Clear all actions required for preparation
362 */
363 void setAllActionsReady();
364
365 /**
366 * @brief Prepare CCD temperature checks
367 */
368 void prepareTemperatureCheck(bool enforceCCDTemp);
369
370 /**
371 * @brief prepareRotatorCheck Check if the rotator is at the expected
372 * target angle.
373 */
374 void prepareRotatorCheck();
375
376 /**
377 * @brief prepareTargetFilter Initiate changing the filter to the target position
378 * {@see #targetFilterID}
379 * @param frameType frame type to be captured
380 * @param isPreview is the captured frame only a preview?
381 */
382 void prepareTargetFilter(CCDFrameType frameType, bool isPreview);
383
384 /**
385 * @brief Before capturing light frames check, if the scope cover is open.
386 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
387 * process should be aborted.
388 */
389 IPState checkLightFrameScopeCoverOpen();
390
391 /**
392 * @brief Check if a certain action has already been initialized
393 */
394 bool isInitialized(CaptureWorkflowActionType action);
395 /**
396 * @brief Set a certain action as initialized
397 */
398 void setInitialized(CaptureWorkflowActionType action, bool init);
399
400 // ////////////////////////////////////////////////////////////////////
401 // flats preparation state
402 // ////////////////////////////////////////////////////////////////////
403
404 /**
405 * @brief checkCalibrationPreActionsReady Check if we completed all the required pre-calibration actions
406 * @return IPS_OK if completed, IPS_BUSY if in progress, and IPS_ALERT if trouble.
407 */
408 IPState checkCalibrationPreActionsReady();
409
410 /**
411 * @brief Check if the cover and light for flats is ready
412 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
413 * process should be aborted.
414 */
415 IPState checkFlatsCoverReady();
416
417 /**
418 * @brief Check if the selected dark covers is ready.
419 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
420 * process should be aborted.
421 */
422 IPState checkDarksCoverReady();
423
424 /**
425 * @brief Ask the user to place a flat screen onto the telescope if a light source is required.
426 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
427 * process should be aborted.
428 */
429 IPState checkManualCoverReady(bool lightSourceRequired);
430
431 /**
432 * @brief Check if the telescope dust cap is ready for capturing flats or darks.
433 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
434 * process should be aborted.
435 */
436 IPState checkDustCapReady(CCDFrameType frameType);
437
438 /**
439 * @brief Check if the telescope is pointing to the desired position on the wall
440 * for capturing flats.
441 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
442 * process should be aborted.
443 */
444 IPState checkWallPositionReady(CCDFrameType frametype);
445
446 /**
447 * @brief Check mount parking before capturing flats.
448 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
449 * process should be aborted.
450 */
451 IPState checkPreMountParkReady();
452
453 /**
454 * @brief Check dome parking before capturing flats.
455 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
456 * process should be aborted.
457 */
458 IPState checkPreDomeParkReady();
459
460 /**
461 * @brief Check if the focuser needs to be moved to the focus position.
462 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
463 * process should be aborted.
464 */
465 IPState checkFlatSyncFocus();
466
467 // ////////////////////////////////////////////////////////////////////
468 // darks preparation state
469 // ////////////////////////////////////////////////////////////////////
470
471 /**
472 * @brief Check if the CCD has a shutter or not.
473 * @return IPS_OK if ready, IPS_BUSY if running and IPS_ALERT if the
474 * process should be aborted.
475 */
476 IPState checkHasShutter();
477
478 // ////////////////////////////////////////////////////////////////////
479 // Attributes shared across all sequence jobs
480 // ////////////////////////////////////////////////////////////////////
481 QSharedPointer<CameraState> m_CameraState;
482
483 // ////////////////////////////////////////////////////////////////////
484 // sequence job specific states
485 // ////////////////////////////////////////////////////////////////////
486 // target filter ID
487 int targetFilterID { Ekos::INVALID_VALUE };
488 FilterManager::FilterPolicy m_filterPolicy { FilterManager::ALL_POLICIES };
489 // target temperature
490 double targetTemperature { Ekos::INVALID_VALUE };
491 // target rotation in absolute ticks, NOT angle
492 double targetPositionAngle { Ekos::INVALID_VALUE };
493 // calibration state
494 CalibrationStage calibrationStage { CAL_NONE };
495 // query state for (un)covering the scope
496 CalibrationCheckType coverQueryState { CAL_CHECK_TASK };
497};
498
499}; // namespace
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
CaptureState
Capture states.
Definition ekos.h:92
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:54:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.