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 { ACTION_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 Clear all actions required for preparation
348 */
349 void setAllActionsReady();
350
351 /**
352 * @brief Prepare CCD temperature checks
353 */
354 void prepareTemperatureCheck(bool enforceCCDTemp);
355
356 /**
357 * @brief prepareRotatorCheck Check if the rotator is at the expected
358 * target angle.
359 */
360 void prepareRotatorCheck();
361
362 /**
363 * @brief prepareTargetFilter Initiate changing the filter to the target position
364 * {@see #targetFilterID}
365 * @param frameType frame type to be captured
366 * @param isPreview is the captured frame only a preview?
367 */
368 void prepareTargetFilter(CCDFrameType frameType, bool isPreview);
369
370 /**
371 * @brief Before capturing light frames check, if the scope cover is open.
372 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
373 * process should be aborted.
374 */
375 IPState checkLightFrameScopeCoverOpen();
376
377 /**
378 * @brief Check if a certain action has already been initialized
379 */
380 bool isInitialized(CameraState::PrepareActions action);
381 /**
382 * @brief Set a certain action as initialized
383 */
384 void setInitialized(CameraState::PrepareActions action, bool init);
385
386 // ////////////////////////////////////////////////////////////////////
387 // flats preparation state
388 // ////////////////////////////////////////////////////////////////////
389
390 /**
391 * @brief checkCalibrationPreActionsReady Check if we completed all the required pre-calibration actions
392 * @return IPS_OK if completed, IPS_BUSY if in progress, and IPS_ALERT if trouble.
393 */
394 IPState checkCalibrationPreActionsReady();
395
396 /**
397 * @brief Check if the cover and light for flats is ready
398 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
399 * process should be aborted.
400 */
401 IPState checkFlatsCoverReady();
402
403 /**
404 * @brief Check if the selected dark covers is ready.
405 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
406 * process should be aborted.
407 */
408 IPState checkDarksCoverReady();
409
410 /**
411 * @brief Ask the user to place a flat screen onto the telescope if a light source is required.
412 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
413 * process should be aborted.
414 */
415 IPState checkManualCoverReady(bool lightSourceRequired);
416
417 /**
418 * @brief Check if the telescope dust cap is ready for capturing flats or darks.
419 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
420 * process should be aborted.
421 */
422 IPState checkDustCapReady(CCDFrameType frameType);
423
424 /**
425 * @brief Check if the telescope is pointing to the desired position on the wall
426 * for capturing flats.
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 checkWallPositionReady(CCDFrameType frametype);
431
432 /**
433 * @brief Check mount parking before capturing flats.
434 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
435 * process should be aborted.
436 */
437 IPState checkPreMountParkReady();
438
439 /**
440 * @brief Check dome parking before 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 checkPreDomeParkReady();
445
446 /**
447 * @brief Check if the focuser needs to be moved to the focus position.
448 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
449 * process should be aborted.
450 */
451 IPState checkFlatSyncFocus();
452
453 // ////////////////////////////////////////////////////////////////////
454 // darks preparation state
455 // ////////////////////////////////////////////////////////////////////
456
457 /**
458 * @brief Check if the CCD has a shutter or not.
459 * @return IPS_OK if ready, IPS_BUSY if running and IPS_ALERT if the
460 * process should be aborted.
461 */
462 IPState checkHasShutter();
463
464 // ////////////////////////////////////////////////////////////////////
465 // Attributes shared across all sequence jobs
466 // ////////////////////////////////////////////////////////////////////
467 QSharedPointer<CameraState> m_CameraState;
468
469 // ////////////////////////////////////////////////////////////////////
470 // sequence job specific states
471 // ////////////////////////////////////////////////////////////////////
472 // target filter ID
473 int targetFilterID { Ekos::INVALID_VALUE };
474 FilterManager::FilterPolicy m_filterPolicy { FilterManager::ALL_POLICIES };
475 // target temperature
476 double targetTemperature { Ekos::INVALID_VALUE };
477 // target rotation in absolute ticks, NOT angle
478 double targetPositionAngle { Ekos::INVALID_VALUE };
479 // calibration state
480 CalibrationStage calibrationStage { CAL_NONE };
481 // query state for (un)covering the scope
482 CalibrationCheckType coverQueryState { CAL_CHECK_TASK };
483};
484
485}; // 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:79
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 Fri Jul 26 2024 11:59:51 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.