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

KDE's Doxygen guidelines are available online.