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 "capturemodulestate.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<CaptureModuleState> &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 // Capture preparation complete(d)
250 void prepareComplete(bool success = true);
251 // Capture initialization complete(d)
252 void initCaptureComplete(FITSMode mode);
253 // change the rotator angle
254 void setRotatorAngle(double rawAngle);
255 // ask for the current filter position
256 void readFilterPosition();
257 // Change the filter to the given position and the filter change policy
258 void changeFilterPosition(int targetFilterPosition, FilterManager::FilterPolicy policy);
259 // set the CCD target temperature
260 void setCCDTemperature(double temp);
261 // set CCD to preview mode
262 void setCCDBatchMode(bool m_preview);
263 // ask for manually covering the scope with a flat light source or dark cover
264 void askManualScopeCover(QString question, QString title, bool light);
265 // ask for manually opening the scope cover
266 void askManualScopeOpen(bool light);
267 // turn light on in the light box
268 void setLightBoxLight(bool on);
269 // turn light on in the dust cap
270 void setDustCapLight(bool on);
271 // park the dust cap
272 void parkDustCap(bool park);
273 // slew the telescope to a target
274 void slewTelescope(SkyPoint &target);
275 // turn scope tracking on and off
276 void setScopeTracking(bool on);
277 // park / unpark telescope
278 void setScopeParked(bool parked);
279 // park / unpark dome
280 void setDomeParked(bool parked);
281 // check if the focuser needs to be moved to the focus position.
282 void flatSyncFocus(int targetFilterID);
283 // ask whether the CCD has a shutter
284 void queryHasShutter();
285 // abort capturing
286 void abortCapture();
287 // log entry
288 void newLog(QString);
289
290 private:
291 // current status of the capture sequence job
292 JOBStatus m_status { JOB_IDLE };
293
294 // Is the capture preparation ready?
295 PreparationState m_PreparationState { PREP_NONE };
296
297 // ////////////////////////////////////////////////////////////////////
298 // capture preparation relevant flags
299 // ////////////////////////////////////////////////////////////////////
300
301 // Mapping PrepareActions --> bool marks whether a certain action is completed (=true) or not (=false)
303 // This is a workaround for a specific INDI behaviour. If a INDI property is set, it sends this value
304 // back to the clients. If the value does not immediately change to the target value (like e.g. the CCD
305 // temperature), the first value after setting a property must be ignored.
307
308 // capture frame type (light, flat, dark, bias)
309 CCDFrameType m_frameType { FRAME_NONE };
310 // do we shoot a preview?
311 bool m_isPreview { false };
312 // should a certain temperature should be enforced?
313 bool m_enforceTemperature { false };
314 // flag if auto focus has been completed for the selected filter
315 bool autoFocusReady;
316 // Capturing mode, necessary for the display in the FITS viewer
317 FITSMode m_fitsMode;
318 // ////////////////////////////////////////////////////////////////////
319 // flat preparation attributes
320 // ////////////////////////////////////////////////////////////////////
321 // status of the focuser synchronisation
322 FlatSyncStatus flatSyncStatus { FS_NONE };
323 // light source for flat capturing
324 uint32_t m_CalibrationPreAction { ACTION_NONE };
325 // wall coordinates for capturing flats with the wall as light source
326 SkyPoint wallCoord;
327 // telescope status for flats using the wall position
328 ScopeWallPositionStatus wpScopeStatus { WP_NONE };
329
330 // ////////////////////////////////////////////////////////////////////
331 // capture preparation state
332 // ////////////////////////////////////////////////////////////////////
333 /**
334 * @brief Check if all actions are ready and emit {@see prepareComplete()} if all are ready.
335 */
336 void checkAllActionsReady();
337
338 /**
339 * @brief Check if all preparation actions are completed
340 * @return true if all preparation actions are completed
341 */
342 bool areActionsReady();
343
344 /**
345 * @brief Clear all actions required for preparation
346 */
347 void setAllActionsReady();
348
349 /**
350 * @brief Prepare CCD temperature checks
351 */
352 void prepareTemperatureCheck(bool enforceCCDTemp);
353
354 /**
355 * @brief prepareRotatorCheck Check if the rotator is at the expected
356 * target angle.
357 */
358 void prepareRotatorCheck();
359
360 /**
361 * @brief prepareTargetFilter Initiate changing the filter to the target position
362 * {@see #targetFilterID}
363 * @param frameType frame type to be captured
364 * @param isPreview is the captured frame only a preview?
365 */
366 void prepareTargetFilter(CCDFrameType frameType, bool isPreview);
367
368 /**
369 * @brief Before capturing light frames check, if the scope cover is open.
370 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
371 * process should be aborted.
372 */
373 IPState checkLightFrameScopeCoverOpen();
374
375 /**
376 * @brief Check if a certain action has already been initialized
377 */
378 bool isInitialized(CaptureModuleState::PrepareActions action);
379 /**
380 * @brief Set a certain action as initialized
381 */
382 void setInitialized(CaptureModuleState::PrepareActions action, bool init);
383
384 // ////////////////////////////////////////////////////////////////////
385 // flats preparation state
386 // ////////////////////////////////////////////////////////////////////
387
388 /**
389 * @brief checkCalibrationPreActionsReady Check if we completed all the required pre-calibration actions
390 * @return IPS_OK if completed, IPS_BUSY if in progress, and IPS_ALERT if trouble.
391 */
392 IPState checkCalibrationPreActionsReady();
393
394 /**
395 * @brief Check if the cover and light for flats is ready
396 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
397 * process should be aborted.
398 */
399 IPState checkFlatsCoverReady();
400
401 /**
402 * @brief Check if the selected dark covers is ready.
403 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
404 * process should be aborted.
405 */
406 IPState checkDarksCoverReady();
407
408 /**
409 * @brief Ask the user to place a flat screen onto the telescope if a light source is required.
410 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
411 * process should be aborted.
412 */
413 IPState checkManualCoverReady(bool lightSourceRequired);
414
415 /**
416 * @brief Check if the telescope dust cap is ready for capturing flats or darks.
417 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
418 * process should be aborted.
419 */
420 IPState checkDustCapReady(CCDFrameType frameType);
421
422 /**
423 * @brief Check if the telescope is pointing to the desired position on the wall
424 * for capturing flats.
425 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
426 * process should be aborted.
427 */
428 IPState checkWallPositionReady(CCDFrameType frametype);
429
430 /**
431 * @brief Check mount parking before capturing flats.
432 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
433 * process should be aborted.
434 */
435 IPState checkPreMountParkReady();
436
437 /**
438 * @brief Check dome parking before capturing flats.
439 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
440 * process should be aborted.
441 */
442 IPState checkPreDomeParkReady();
443
444 /**
445 * @brief Check if the focuser needs to be moved to the focus position.
446 * @return IPS_OK if cover closed, IPS_BUSY if not and IPS_ALERT if the
447 * process should be aborted.
448 */
449 IPState checkFlatSyncFocus();
450
451 // ////////////////////////////////////////////////////////////////////
452 // darks preparation state
453 // ////////////////////////////////////////////////////////////////////
454
455 /**
456 * @brief Check if the CCD has a shutter or not.
457 * @return IPS_OK if ready, IPS_BUSY if running and IPS_ALERT if the
458 * process should be aborted.
459 */
460 IPState checkHasShutter();
461
462 // ////////////////////////////////////////////////////////////////////
463 // Attributes shared across all sequence jobs
464 // ////////////////////////////////////////////////////////////////////
465 QSharedPointer<CaptureModuleState> m_CaptureModuleState;
466
467 // ////////////////////////////////////////////////////////////////////
468 // sequence job specific states
469 // ////////////////////////////////////////////////////////////////////
470 // target filter ID
471 int targetFilterID { Ekos::INVALID_VALUE };
472 FilterManager::FilterPolicy m_filterPolicy { FilterManager::ALL_POLICIES };
473 // target temperature
474 double targetTemperature { Ekos::INVALID_VALUE };
475 // target rotation in absolute ticks, NOT angle
476 double targetPositionAngle { Ekos::INVALID_VALUE };
477 // calibration state
478 CalibrationStage calibrationStage { CAL_NONE };
479 // query state for (un)covering the scope
480 CalibrationCheckType coverQueryState { CAL_CHECK_TASK };
481};
482
483}; // 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 May 17 2024 11:48:25 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.