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 // light source for flat capturing
326 uint32_t m_CalibrationPreAction { CAPTURE_PREACTION_NONE };
327 // wall coordinates for capturing flats with the wall as light source
328 SkyPoint wallCoord;
329 // telescope status for flats using the wall position
330 ScopeWallPositionStatus wpScopeStatus { WP_NONE };
331
332 // ////////////////////////////////////////////////////////////////////
333 // capture preparation state
334 // ////////////////////////////////////////////////////////////////////
335 /**
336 * @brief Check if all actions are ready and emit {@see prepareComplete()} if all are ready.
337 */
338 void checkAllActionsReady();
339
340 /**
341 * @brief Check if all preparation actions are completed
342 * @return true if all preparation actions are completed
343 */
344 bool areActionsReady();
345
346 /**
347 * @brief preparationCompleted helper function for checking, if the preparation has been completed
348 */
349 bool preparationCompleted()
350 {
351 return m_PreparationState == PREP_COMPLETED;
352 }
353
354 /**
355 * @brief Clear all actions required for preparation
356 */
357 void setAllActionsReady();
358
359 /**
360 * @brief Prepare CCD temperature checks
361 */
362 void prepareTemperatureCheck(bool enforceCCDTemp);
363
364 /**
365 * @brief prepareRotatorCheck Check if the rotator is at the expected
366 * target angle.
367 */
368 void prepareRotatorCheck();
369
370 /**
371 * @brief prepareTargetFilter Initiate changing the filter to the target position
372 * {@see #targetFilterID}
373 * @param frameType frame type to be captured
374 * @param isPreview is the captured frame only a preview?
375 */
376 void prepareTargetFilter(CCDFrameType frameType, bool isPreview);
377
378 /**
379 * @brief Before capturing light frames check, if the scope cover is open.
380 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
381 * process should be aborted.
382 */
383 IPState checkLightFrameScopeCoverOpen();
384
385 /**
386 * @brief Check if a certain action has already been initialized
387 */
388 bool isInitialized(CaptureWorkflowActionType action);
389 /**
390 * @brief Set a certain action as initialized
391 */
392 void setInitialized(CaptureWorkflowActionType action, bool init);
393
394 // ////////////////////////////////////////////////////////////////////
395 // flats preparation state
396 // ////////////////////////////////////////////////////////////////////
397
398 /**
399 * @brief checkCalibrationPreActionsReady Check if we completed all the required pre-calibration actions
400 * @return IPS_OK if completed, IPS_BUSY if in progress, and IPS_ALERT if trouble.
401 */
402 IPState checkCalibrationPreActionsReady();
403
404 /**
405 * @brief Check if the cover and light for flats is ready
406 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
407 * process should be aborted.
408 */
409 IPState checkFlatsCoverReady();
410
411 /**
412 * @brief Check if the selected dark covers is ready.
413 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
414 * process should be aborted.
415 */
416 IPState checkDarksCoverReady();
417
418 /**
419 * @brief Ask the user to place a flat screen onto the telescope if a light source is required.
420 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
421 * process should be aborted.
422 */
423 IPState checkManualCoverReady(bool lightSourceRequired);
424
425 /**
426 * @brief Check if the telescope dust cap is ready for capturing flats or darks.
427 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
428 * process should be aborted.
429 */
430 IPState checkDustCapReady(CCDFrameType frameType);
431
432 /**
433 * @brief Check if the telescope is pointing to the desired position on the wall
434 * for capturing flats.
435 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
436 * process should be aborted.
437 */
438 IPState checkWallPositionReady(CCDFrameType frametype);
439
440 /**
441 * @brief Check mount parking before capturing flats.
442 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
443 * process should be aborted.
444 */
445 IPState checkPreMountParkReady();
446
447 /**
448 * @brief Check dome parking before capturing flats.
449 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
450 * process should be aborted.
451 */
452 IPState checkPreDomeParkReady();
453
454 /**
455 * @brief Check if the focuser needs to be moved to the focus position.
456 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
457 * process should be aborted.
458 */
459 IPState checkFlatSyncFocus();
460
461 // ////////////////////////////////////////////////////////////////////
462 // darks preparation state
463 // ////////////////////////////////////////////////////////////////////
464
465 /**
466 * @brief Check if the CCD has a shutter or not.
467 * @return IPS_OK if ready, IPS_BUSY if running and IPS_ALERT if the
468 * process should be aborted.
469 */
470 IPState checkHasShutter();
471
472 // ////////////////////////////////////////////////////////////////////
473 // Attributes shared across all sequence jobs
474 // ////////////////////////////////////////////////////////////////////
475 QSharedPointer<CameraState> m_CameraState;
476
477 // ////////////////////////////////////////////////////////////////////
478 // sequence job specific states
479 // ////////////////////////////////////////////////////////////////////
480 // target filter ID
481 int targetFilterID { Ekos::INVALID_VALUE };
482 FilterManager::FilterPolicy m_filterPolicy { FilterManager::ALL_POLICIES };
483 // target temperature
484 double targetTemperature { Ekos::INVALID_VALUE };
485 // target rotation in absolute ticks, NOT angle
486 double targetPositionAngle { Ekos::INVALID_VALUE };
487 // calibration state
488 CalibrationStage calibrationStage { CAL_NONE };
489 // query state for (un)covering the scope
490 CalibrationCheckType coverQueryState { CAL_CHECK_TASK };
491};
492
493}; // 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 Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.