From ba5e62bb40abaf2e221bdd9f513080862de98da0 Mon Sep 17 00:00:00 2001 From: tiagohm Date: Thu, 2 May 2024 09:16:01 -0300 Subject: [PATCH] [api][desktop]: Refactor tasks --- .../polar/PolarAlignmentController.kt | 18 +++++------ .../alignment/polar/PolarAlignmentService.kt | 12 ++++---- .../api/alignment/polar/darv/DARVEvent.kt | 3 +- .../api/alignment/polar/darv/DARVExecutor.kt | 9 +++--- .../api/alignment/polar/darv/DARVJob.kt | 2 +- .../api/alignment/polar/darv/DARVTask.kt | 10 +++++++ .../api/alignment/polar/tppa/TPPAExecutor.kt | 30 +++++++------------ .../api/alignment/polar/tppa/TPPAJob.kt | 2 +- .../api/alignment/polar/tppa/TPPATask.kt | 16 +++++++--- .../nebulosa/api/cameras/CameraCaptureTask.kt | 5 ++-- .../api/guiding/DitherAfterExposureTask.kt | 6 +++- .../nebulosa/api/guiding/GuidePulseTask.kt | 4 ++- .../api/guiding/WaitForSettleEvent.kt | 8 ----- .../nebulosa/api/guiding/WaitForSettleTask.kt | 12 +++----- .../kotlin/nebulosa/api/image/ImageService.kt | 4 +-- .../nebulosa/api/mounts/MountMoveTask.kt | 6 ++-- .../api/sequencer/SequencerExecutor.kt | 15 ++-------- .../nebulosa/api/sequencer/SequencerTask.kt | 14 +++++++++ api/src/main/kotlin/nebulosa/api/tasks/Job.kt | 4 ++- .../nebulosa/api/tasks/delay/DelayTask.kt | 2 +- .../nebulosa/api/wheels/WheelMoveTask.kt | 3 ++ .../api/wizard/flat/FlatWizardExecutor.kt | 13 ++------ .../api/wizard/flat/FlatWizardTask.kt | 10 +++++-- .../src/app/alignment/alignment.component.ts | 17 +++++------ desktop/src/shared/services/api.service.ts | 20 ++++++------- desktop/src/shared/types/alignment.types.ts | 6 ++-- .../watney/plate/solving/WatneyPlateSolver.kt | 2 +- 27 files changed, 130 insertions(+), 123 deletions(-) delete mode 100644 api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleEvent.kt diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentController.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentController.kt index 3b0516a81..4d1341341 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentController.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentController.kt @@ -33,18 +33,18 @@ class PolarAlignmentController( @RequestBody body: TPPAStartRequest, ) = polarAlignmentService.tppaStart(camera, mount, body) - @PutMapping("tppa/{camera}/{mount}/stop") - fun tppaStop(camera: Camera, mount: Mount) { - polarAlignmentService.tppaStop(camera, mount) + @PutMapping("tppa/{camera}/stop") + fun tppaStop(camera: Camera) { + polarAlignmentService.tppaStop(camera) } - @PutMapping("tppa/{camera}/{mount}/pause") - fun tppaPause(camera: Camera, mount: Mount) { - polarAlignmentService.tppaPause(camera, mount) + @PutMapping("tppa/{camera}/pause") + fun tppaPause(camera: Camera) { + polarAlignmentService.tppaPause(camera) } - @PutMapping("tppa/{camera}/{mount}/unpause") - fun tppaUnpause(camera: Camera, mount: Mount) { - polarAlignmentService.tppaUnpause(camera, mount) + @PutMapping("tppa/{camera}/unpause") + fun tppaUnpause(camera: Camera) { + polarAlignmentService.tppaUnpause(camera) } } diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentService.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentService.kt index f3247f059..9c6111d3c 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentService.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentService.kt @@ -27,15 +27,15 @@ class PolarAlignmentService( tppaExecutor.execute(camera, mount, tppaStartRequest) } - fun tppaStop(camera: Camera, mount: Mount) { - tppaExecutor.stop(camera, mount) + fun tppaStop(camera: Camera) { + tppaExecutor.stop(camera) } - fun tppaPause(camera: Camera, mount: Mount) { - tppaExecutor.pause(camera, mount) + fun tppaPause(camera: Camera) { + tppaExecutor.pause(camera) } - fun tppaUnpause(camera: Camera, mount: Mount) { - tppaExecutor.unpause(camera, mount) + fun tppaUnpause(camera: Camera) { + tppaExecutor.unpause(camera) } } diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVEvent.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVEvent.kt index db0d83b89..a494b8c24 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVEvent.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVEvent.kt @@ -2,10 +2,11 @@ package nebulosa.api.alignment.polar.darv import nebulosa.api.messages.MessageEvent import nebulosa.guiding.GuideDirection +import nebulosa.indi.device.camera.Camera import java.time.Duration data class DARVEvent( - @JvmField val id: String, + @JvmField val camera: Camera, @JvmField val remainingTime: Duration = Duration.ZERO, @JvmField val direction: GuideDirection = GuideDirection.NORTH, @JvmField val progress: Double = 0.0, diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVExecutor.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVExecutor.kt index 7a728eb84..7c6771183 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVExecutor.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVExecutor.kt @@ -20,7 +20,7 @@ class DARVExecutor( private val messageService: MessageService, ) : Consumer { - private val jobs = ConcurrentHashMap.newKeySet(2) + private val jobs = ConcurrentHashMap.newKeySet(1) override fun accept(event: DARVEvent) { messageService.sendMessage(event) @@ -35,7 +35,8 @@ class DARVExecutor( fun execute(camera: Camera, guideOutput: GuideOutput, request: DARVStartRequest) { check(camera.connected) { "${camera.name} Camera is not connected" } check(guideOutput.connected) { "${guideOutput.name} Guide Output is not connected" } - check(jobs.any { it.task.camera === camera }) { "${camera.name} DARV Job in progress" } + check(jobs.any { it.task.camera === camera }) { "${camera.name} DARV Job is already in progress" } + check(jobs.any { it.task.guideOutput === guideOutput }) { "${camera.name} DARV Job is already in progress" } val task = DARVTask(camera, guideOutput, request) task.subscribe(this) @@ -48,8 +49,6 @@ class DARVExecutor( } fun stop(camera: Camera) { - jobs.find { it.task.camera === camera } - ?.also(jobs::remove) - ?.stop() + jobs.find { it.task.camera === camera }?.stop() } } diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVJob.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVJob.kt index eef57fce8..5889a5907 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVJob.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVJob.kt @@ -5,7 +5,7 @@ import nebulosa.indi.device.camera.CameraEvent data class DARVJob(override val task: DARVTask) : Job() { - override val name = "DARV Job" + override val name = "${task.camera.name} DARV Job" fun handleCameraEvent(event: CameraEvent) { task.handleCameraEvent(event) diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVTask.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVTask.kt index 0a83fd649..f93072675 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVTask.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVTask.kt @@ -15,6 +15,7 @@ import nebulosa.indi.device.camera.Camera import nebulosa.indi.device.camera.CameraEvent import nebulosa.indi.device.camera.FrameType import nebulosa.indi.device.guide.GuideOutput +import nebulosa.log.loggerFor import java.nio.file.Files import java.time.Duration import java.util.concurrent.CompletableFuture @@ -55,6 +56,8 @@ data class DARVTask( } override fun execute(cancellationToken: CancellationToken) { + LOG.info("DARV started. camera={}, guideOutput={}, request={}", camera, guideOutput, request) + val a = CompletableFuture.runAsync { // CAPTURE. cameraExposureTask.execute(cancellationToken) @@ -72,6 +75,8 @@ data class DARVTask( } CompletableFuture.allOf(a, b).join() + + LOG.info("DARV finished. camera={}, guideOutput={}, request={}", camera, guideOutput, request) } override fun accept(event: Any) { @@ -89,4 +94,9 @@ data class DARVTask( backwardGuidePulseTask.close() super.close() } + + companion object { + + @JvmStatic private val LOG = loggerFor() + } } diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAExecutor.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAExecutor.kt index 5cf71edc1..30abd7a14 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAExecutor.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAExecutor.kt @@ -8,8 +8,6 @@ import nebulosa.indi.device.camera.Camera import nebulosa.indi.device.camera.CameraEvent import nebulosa.indi.device.mount.Mount import nebulosa.indi.device.mount.MountEvent -import nebulosa.log.info -import nebulosa.log.loggerFor import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.springframework.stereotype.Component @@ -22,7 +20,7 @@ class TPPAExecutor( private val plateSolverService: PlateSolverService, ) : Consumer { - private val jobs = ConcurrentHashMap.newKeySet() + private val jobs = ConcurrentHashMap.newKeySet(1) override fun accept(event: TPPAEvent) { messageService.sendMessage(event) @@ -41,10 +39,9 @@ class TPPAExecutor( @Synchronized fun execute(camera: Camera, mount: Mount, request: TPPAStartRequest) { check(camera.connected) { "${camera.name} Camera is not connected" } - check(mount.connected) { "${mount.name} Guide Output is not connected" } - check(jobs.any { it.task.camera === camera || it.task.mount === mount }) { "${camera.name}/${mount.name} TPPA Job in progress" } - - LOG.info { "starting TPPA. camera=$camera, mount=$mount, request=$request" } + check(mount.connected) { "${mount.name} Mount is not connected" } + check(jobs.any { it.task.camera === camera }) { "${camera.name} TPPA Job is already in progress" } + check(jobs.any { it.task.mount === mount }) { "${camera.name} TPPA Job is already in progress" } val solver = plateSolverService.solverFor(request.plateSolver) val task = TPPATask(camera, solver, request, mount) @@ -57,22 +54,15 @@ class TPPAExecutor( } } - fun stop(camera: Camera, mount: Mount) { - jobs.find { it.task.camera === camera && it.task.mount === mount } - ?.also(jobs::remove) - ?.stop() - } - - fun pause(camera: Camera, mount: Mount) { - jobs.find { it.task.camera === camera && it.task.mount === mount }?.pause() + fun stop(camera: Camera) { + jobs.find { it.task.camera === camera }?.stop() } - fun unpause(camera: Camera, mount: Mount) { - jobs.find { it.task.camera === camera && it.task.mount === mount }?.unpause() + fun pause(camera: Camera) { + jobs.find { it.task.camera === camera }?.pause() } - companion object { - - @JvmStatic private val LOG = loggerFor() + fun unpause(camera: Camera) { + jobs.find { it.task.camera === camera }?.unpause() } } diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAJob.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAJob.kt index e7fe825f6..f44f877cf 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAJob.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAJob.kt @@ -6,7 +6,7 @@ import nebulosa.indi.device.mount.MountEvent data class TPPAJob(override val task: TPPATask) : Job() { - override val name = "Three-Point Polar Alignment Job" + override val name = "${task.camera.name} TPPA Job" fun handleCameraEvent(event: CameraEvent) { task.handleCameraEvent(event) diff --git a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPATask.kt b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPATask.kt index 618067451..6b3f8a064 100644 --- a/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPATask.kt +++ b/api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPATask.kt @@ -14,10 +14,11 @@ import nebulosa.indi.device.camera.CameraEvent import nebulosa.indi.device.camera.FrameType import nebulosa.indi.device.mount.Mount import nebulosa.indi.device.mount.MountEvent -import nebulosa.log.debug import nebulosa.log.loggerFor import nebulosa.math.Angle import nebulosa.math.deg +import nebulosa.math.formatHMS +import nebulosa.math.formatSignedDMS import nebulosa.plate.solving.PlateSolver import java.nio.file.Files import java.nio.file.Path @@ -81,9 +82,9 @@ data class TPPATask( } override fun execute(cancellationToken: CancellationToken) { - while (!cancellationToken.isDone) { - LOG.debug { "executing TPPA. camera=$camera, mount=$mount, request=$request" } + LOG.info("TPPA started. camera={}, mount={}, request={}", camera, mount, request) + while (!cancellationToken.isDone) { mount?.tracking(true) if (cancellationToken.isPaused) { @@ -124,7 +125,7 @@ data class TPPATask( request.compensateRefraction, cancellationToken ) - LOG.info("alignment completed. result=$result") + LOG.info("TPPA alignment completed. result=$result") if (cancellationToken.isDone) return @@ -167,6 +168,11 @@ data class TPPATask( else -> "" } + LOG.info( + "TPPA alignment computed. rightAscension={}, declination={}, azimuthError={}, altitudeError={}", + rightAscension.formatHMS(), declination.formatSignedDMS(), azimuthError.formatSignedDMS(), altitudeError.formatSignedDMS(), + ) + sendEvent(TPPAState.COMPUTED) continue @@ -179,6 +185,8 @@ data class TPPATask( } sendEvent(TPPAState.FINISHED) + + LOG.info("TPPA finished. camera={}, mount={}, request={}", camera, mount, request) } private fun sendEvent(state: TPPAState) { diff --git a/api/src/main/kotlin/nebulosa/api/cameras/CameraCaptureTask.kt b/api/src/main/kotlin/nebulosa/api/cameras/CameraCaptureTask.kt index 4d1dd9a2b..2695e84dc 100644 --- a/api/src/main/kotlin/nebulosa/api/cameras/CameraCaptureTask.kt +++ b/api/src/main/kotlin/nebulosa/api/cameras/CameraCaptureTask.kt @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore import io.reactivex.rxjava3.functions.Consumer import nebulosa.api.guiding.DitherAfterExposureEvent import nebulosa.api.guiding.DitherAfterExposureTask -import nebulosa.api.guiding.WaitForSettleEvent import nebulosa.api.guiding.WaitForSettleTask import nebulosa.api.tasks.Task import nebulosa.api.tasks.delay.DelayEvent @@ -93,6 +92,8 @@ data class CameraCaptureTask( ditherAfterExposureTask.execute(cancellationToken) } } + + LOG.info("camera capture finished. camera={}, request={}, exposureCount={}", camera, request, exposureCount) } @Synchronized @@ -105,8 +106,6 @@ data class CameraCaptureTask( stepRemainingTime = event.remainingTime stepProgress = event.progress } - is WaitForSettleEvent -> { - } is CameraExposureEvent -> { when (event.state) { CameraExposureState.STARTED -> { diff --git a/api/src/main/kotlin/nebulosa/api/guiding/DitherAfterExposureTask.kt b/api/src/main/kotlin/nebulosa/api/guiding/DitherAfterExposureTask.kt index a3bb9d9f6..00b80ca76 100644 --- a/api/src/main/kotlin/nebulosa/api/guiding/DitherAfterExposureTask.kt +++ b/api/src/main/kotlin/nebulosa/api/guiding/DitherAfterExposureTask.kt @@ -29,7 +29,7 @@ data class DitherAfterExposureTask( && guider.state == GuideState.GUIDING && !cancellationToken.isDone ) { - LOG.info("dithering. request={}", request) + LOG.info("Dither started. request={}", request) try { cancellationToken.listen(this) @@ -49,6 +49,8 @@ data class DitherAfterExposureTask( guider.unregisterGuiderListener(this) cancellationToken.unlisten(this) + + LOG.info("Dither finished. request={}", request) } } } @@ -58,6 +60,8 @@ data class DitherAfterExposureTask( this.dy = dy state = DitherAfterExposureState.DITHERED + LOG.info("dithered. dx={}, dy={}", dx, dy) + ditherLatch.reset() } diff --git a/api/src/main/kotlin/nebulosa/api/guiding/GuidePulseTask.kt b/api/src/main/kotlin/nebulosa/api/guiding/GuidePulseTask.kt index 7090c8241..05f571fac 100644 --- a/api/src/main/kotlin/nebulosa/api/guiding/GuidePulseTask.kt +++ b/api/src/main/kotlin/nebulosa/api/guiding/GuidePulseTask.kt @@ -25,7 +25,7 @@ data class GuidePulseTask( override fun execute(cancellationToken: CancellationToken) { if (guideOutput.pulseGuide(request.duration, request.direction)) { - LOG.info("guide pulsing for {} ms at {} direction", request.duration.toMillis(), request.direction) + LOG.info("Guide Pulse started. duration={}, direction={}", request.duration.toMillis(), request.direction) try { cancellationToken.listen(this) @@ -33,6 +33,8 @@ data class GuidePulseTask( } finally { cancellationToken.unlisten(this) } + + LOG.info("Guide Pulse finished. duration={}, direction={}", request.duration.toMillis(), request.direction) } } diff --git a/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleEvent.kt b/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleEvent.kt deleted file mode 100644 index ead677497..000000000 --- a/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleEvent.kt +++ /dev/null @@ -1,8 +0,0 @@ -package nebulosa.api.guiding - -import java.time.Duration - -data class WaitForSettleEvent( - @JvmField val task: WaitForSettleTask, - @JvmField val elapsedTime: Duration = Duration.ZERO, -) diff --git a/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleTask.kt b/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleTask.kt index 982ee445c..f0da6ca64 100644 --- a/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleTask.kt +++ b/api/src/main/kotlin/nebulosa/api/guiding/WaitForSettleTask.kt @@ -4,20 +4,16 @@ import nebulosa.api.tasks.Task import nebulosa.common.concurrency.cancel.CancellationToken import nebulosa.guiding.Guider import nebulosa.log.loggerFor -import java.time.Duration -import kotlin.system.measureTimeMillis data class WaitForSettleTask( @JvmField val guider: Guider?, -) : Task() { +) : Task() { override fun execute(cancellationToken: CancellationToken) { if (guider != null && guider.isSettling && !cancellationToken.isDone) { - LOG.info("waiting for guiding to settle") - - onNext(WaitForSettleEvent(this)) - val elapsedTime = measureTimeMillis { guider.waitForSettle(cancellationToken) } - onNext(WaitForSettleEvent(this, Duration.ofMillis(elapsedTime))) + LOG.info("Wait For Settle started") + guider.waitForSettle(cancellationToken) + LOG.info("Wait For Settle finished") } } diff --git a/api/src/main/kotlin/nebulosa/api/image/ImageService.kt b/api/src/main/kotlin/nebulosa/api/image/ImageService.kt index a5be3ad60..bde370b9c 100644 --- a/api/src/main/kotlin/nebulosa/api/image/ImageService.kt +++ b/api/src/main/kotlin/nebulosa/api/image/ImageService.kt @@ -221,7 +221,7 @@ class ImageService( } } - LOG.info("Found {} minor planets", count) + LOG.info("found {} minor planets", count) }.whenComplete { _, e -> e?.printStackTrace() } .also(tasks::add) } @@ -256,7 +256,7 @@ class ImageService( count++ } - LOG.info("Found {} stars/DSOs", count) + LOG.info("found {} stars/DSOs", count) }.whenComplete { _, e -> e?.printStackTrace() } .also(tasks::add) } diff --git a/api/src/main/kotlin/nebulosa/api/mounts/MountMoveTask.kt b/api/src/main/kotlin/nebulosa/api/mounts/MountMoveTask.kt index accd311af..31f5f803c 100644 --- a/api/src/main/kotlin/nebulosa/api/mounts/MountMoveTask.kt +++ b/api/src/main/kotlin/nebulosa/api/mounts/MountMoveTask.kt @@ -49,7 +49,7 @@ data class MountMoveTask( ) { latch.countUp() - LOG.info("moving mount. mount={}, ra={}, dec={}", mount, rightAscension.formatHMS(), declination.formatSignedDMS()) + LOG.info("Mount Move started. mount={}, ra={}, dec={}", mount, rightAscension.formatHMS(), declination.formatSignedDMS()) initialRA = mount.rightAscension initialDEC = mount.declination @@ -70,11 +70,11 @@ data class MountMoveTask( cancellationToken.unlisten(this) } - LOG.info("mount moved. mount={}", mount) + LOG.info("Mount Move finished. mount={}, ra={}, dec={}", mount, rightAscension.formatHMS(), declination.formatSignedDMS()) delayTask.execute(cancellationToken) } else { - LOG.warn("cannot move mount. mount={}", mount) + LOG.warn("cannot move mount. mount={}, ra={}, dec={}", mount, rightAscension.formatHMS(), declination.formatSignedDMS()) } } diff --git a/api/src/main/kotlin/nebulosa/api/sequencer/SequencerExecutor.kt b/api/src/main/kotlin/nebulosa/api/sequencer/SequencerExecutor.kt index 5e4ed1508..86afc0e7b 100644 --- a/api/src/main/kotlin/nebulosa/api/sequencer/SequencerExecutor.kt +++ b/api/src/main/kotlin/nebulosa/api/sequencer/SequencerExecutor.kt @@ -10,8 +10,6 @@ import nebulosa.indi.device.filterwheel.FilterWheel import nebulosa.indi.device.filterwheel.FilterWheelEvent import nebulosa.indi.device.focuser.Focuser import nebulosa.indi.device.focuser.FocuserEvent -import nebulosa.log.info -import nebulosa.log.loggerFor import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.springframework.stereotype.Component @@ -50,20 +48,18 @@ class SequencerExecutor( wheel: FilterWheel? = null, focuser: Focuser? = null, ) { check(camera.connected) { "${camera.name} Camera is not connected" } - check(jobs.any { it.task.camera === camera }) { "${camera.name} Camera Capture is already in progress" } + check(jobs.any { it.task.camera === camera }) { "${camera.name} Sequencer Job is already in progress" } if (wheel != null) { check(wheel.connected) { "${wheel.name} Wheel is not connected" } - check(jobs.any { it.task.wheel === wheel }) { "${wheel.name} Wheel Capture is already in progress" } + check(jobs.any { it.task.wheel === wheel }) { "${camera.name} Sequencer Job is already in progress" } } if (focuser != null) { check(focuser.connected) { "${focuser.name} Focuser is not connected" } - check(jobs.any { it.task.focuser === focuser }) { "${focuser.name} Focuser Capture is already in progress" } + check(jobs.any { it.task.focuser === focuser }) { "${camera.name} Sequencer Job is already in progress" } } - LOG.info { "starting sequencer. camera=$camera, wheel=$wheel, focuser=$focuser, request=$request" } - val task = SequencerTask(camera, request, guider) task.subscribe(this) @@ -77,9 +73,4 @@ class SequencerExecutor( fun stop(camera: Camera) { jobs.find { it.task.camera === camera }?.stop() } - - companion object { - - @JvmStatic private val LOG = loggerFor() - } } diff --git a/api/src/main/kotlin/nebulosa/api/sequencer/SequencerTask.kt b/api/src/main/kotlin/nebulosa/api/sequencer/SequencerTask.kt index 5ea021e11..494af1b99 100644 --- a/api/src/main/kotlin/nebulosa/api/sequencer/SequencerTask.kt +++ b/api/src/main/kotlin/nebulosa/api/sequencer/SequencerTask.kt @@ -15,6 +15,8 @@ import nebulosa.indi.device.camera.FrameType import nebulosa.indi.device.filterwheel.FilterWheel import nebulosa.indi.device.filterwheel.FilterWheelEvent import nebulosa.indi.device.focuser.Focuser +import nebulosa.indi.device.mount.Mount +import nebulosa.log.loggerFor import java.util.* import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicReference @@ -27,6 +29,7 @@ data class SequencerTask( @JvmField val camera: Camera, @JvmField val plan: SequencePlanRequest, @JvmField val guider: Guider? = null, + @JvmField val mount: Mount? = null, @JvmField val wheel: FilterWheel? = null, @JvmField val focuser: Focuser? = null, ) : Task(), Consumer { @@ -112,12 +115,18 @@ data class SequencerTask( } override fun execute(cancellationToken: CancellationToken) { + LOG.info("Sequencer started. camera={}, mount={}, wheel={}, focuser={}, plan={}", camera, mount, wheel, focuser, plan) + + camera.snoop(listOf(mount, wheel, focuser)) + for (task in tasks) { if (cancellationToken.isDone) break currentTask.set(task) task.execute(cancellationToken) currentTask.set(null) } + + LOG.info("Sequencer finished. camera={}, mount={}, wheel={}, focuser={}, plan={}", camera, mount, wheel, focuser, plan) } private fun CameraStartCaptureRequest.wheelMoveTask(): WheelMoveTask? { @@ -152,4 +161,9 @@ data class SequencerTask( sequencerId.set(id) } } + + companion object { + + @JvmStatic private val LOG = loggerFor() + } } diff --git a/api/src/main/kotlin/nebulosa/api/tasks/Job.kt b/api/src/main/kotlin/nebulosa/api/tasks/Job.kt index 3192dee87..0665c9426 100644 --- a/api/src/main/kotlin/nebulosa/api/tasks/Job.kt +++ b/api/src/main/kotlin/nebulosa/api/tasks/Job.kt @@ -10,9 +10,10 @@ abstract class Job : CompletableFuture(), Runnable { abstract val name: String - @Volatile private var thread: Thread? = null private val cancellationToken = CancellationToken() + @Volatile private var thread: Thread? = null + final override fun run() { try { task.execute(cancellationToken) @@ -20,6 +21,7 @@ abstract class Job : CompletableFuture(), Runnable { thread = null cancellationToken.close() complete(Unit) + task.close() } } diff --git a/api/src/main/kotlin/nebulosa/api/tasks/delay/DelayTask.kt b/api/src/main/kotlin/nebulosa/api/tasks/delay/DelayTask.kt index ee8a45ba5..3c9c5639e 100644 --- a/api/src/main/kotlin/nebulosa/api/tasks/delay/DelayTask.kt +++ b/api/src/main/kotlin/nebulosa/api/tasks/delay/DelayTask.kt @@ -18,7 +18,7 @@ data class DelayTask( var remainingTime = durationTime if (!cancellationToken.isDone && remainingTime > 0L) { - LOG.info("delaying for {} ms", remainingTime) + LOG.info("Delay started. duration={}", remainingTime) while (!cancellationToken.isDone && remainingTime > 0L) { val waitTime = minOf(remainingTime, DELAY_INTERVAL) diff --git a/api/src/main/kotlin/nebulosa/api/wheels/WheelMoveTask.kt b/api/src/main/kotlin/nebulosa/api/wheels/WheelMoveTask.kt index 6f2bdf0e0..eab47e043 100644 --- a/api/src/main/kotlin/nebulosa/api/wheels/WheelMoveTask.kt +++ b/api/src/main/kotlin/nebulosa/api/wheels/WheelMoveTask.kt @@ -33,6 +33,8 @@ data class WheelMoveTask( if (wheel.connected && position in 1..wheel.count && wheel.position != position) { initialPosition = wheel.position + LOG.info("Filter Wheel Move started. wheel={}, position={}", wheel, position) + try { cancellationToken.listen(latch) latch.countUp() @@ -40,6 +42,7 @@ data class WheelMoveTask( latch.await() } finally { cancellationToken.unlisten(latch) + LOG.info("Filter Wheel Move finished. wheel={}, position={}", wheel, position) } } else { LOG.warn("filter wheel not connected or invalid position. position={}, wheel={}", position, wheel) diff --git a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardExecutor.kt b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardExecutor.kt index 0be829da4..fb06044f6 100644 --- a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardExecutor.kt +++ b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardExecutor.kt @@ -5,8 +5,6 @@ import nebulosa.api.beans.annotations.Subscriber import nebulosa.api.messages.MessageService import nebulosa.indi.device.camera.Camera import nebulosa.indi.device.camera.CameraEvent -import nebulosa.log.info -import nebulosa.log.loggerFor import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.springframework.stereotype.Component @@ -18,7 +16,7 @@ class FlatWizardExecutor( private val messageService: MessageService, ) : Consumer { - private val jobs = ConcurrentHashMap.newKeySet(2) + private val jobs = ConcurrentHashMap.newKeySet(1) @Subscribe(threadMode = ThreadMode.ASYNC) fun onCameraEvent(event: CameraEvent) { @@ -31,9 +29,7 @@ class FlatWizardExecutor( fun execute(camera: Camera, request: FlatWizardRequest) { check(camera.connected) { "camera is not connected" } - check(jobs.any { it.task.camera === camera }) { "${camera.name} Camera Flat Wizard is already in progress" } - - LOG.info { "starting flat wizard capture. camera=$camera, request=$request" } + check(jobs.any { it.task.camera === camera }) { "${camera.name} Flat Wizard is already in progress" } val task = FlatWizardTask(camera, request) task.subscribe(this) @@ -48,9 +44,4 @@ class FlatWizardExecutor( fun stop(camera: Camera) { jobs.find { it.task.camera === camera }?.stop() } - - companion object { - - @JvmStatic private val LOG = loggerFor() - } } diff --git a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardTask.kt b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardTask.kt index 7787fa637..b5d47072e 100644 --- a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardTask.kt +++ b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardTask.kt @@ -48,6 +48,8 @@ data class FlatWizardTask( exposureTime = (exposureMax + exposureMin).dividedBy(2L) + LOG.info("Flat Wizard started. camera={}, request={}, exposureTime={}", camera, request, exposureTime) + val cameraRequest = request.captureRequest.copy( exposureTime = exposureTime, frameType = FrameType.LIGHT, autoSave = false, autoSubFolderMode = AutoSubFolderMode.OFF, @@ -74,16 +76,18 @@ data class FlatWizardTask( val image = savedPath!!.fits().use { Image.open(it, false) } val statistics = STATISTICS.compute(image) - LOG.info("flat frame captured. duration={}, statistics={}", exposureTime, statistics) + LOG.info("flat frame captured. exposureTime={}, statistics={}", exposureTime, statistics) if (statistics.mean in meanRange) { state = FlatWizardState.CAPTURED - LOG.info("Found an optimal exposure time. exposure={}, path={}", exposureTime, savedPath) + LOG.info("found an optimal exposure time. exposureTime={}, path={}", exposureTime, savedPath) break } else if (statistics.mean < meanRange.start) { exposureMin = exposureTime + LOG.info("captured frame is below mean range. exposureTime={}, path={}", exposureTime, savedPath) } else { exposureMax = exposureTime + LOG.info("captured frame is above mean range. exposureTime={}, path={}", exposureTime, savedPath) } } @@ -92,6 +96,8 @@ data class FlatWizardTask( } sendEvent() + + LOG.info("Flat Wizard finished. camera={}, request={}, exposureTime={}", camera, request, exposureTime) } private fun sendEvent() { diff --git a/desktop/src/app/alignment/alignment.component.ts b/desktop/src/app/alignment/alignment.component.ts index d94fe13cb..e94147f39 100644 --- a/desktop/src/app/alignment/alignment.component.ts +++ b/desktop/src/app/alignment/alignment.component.ts @@ -37,7 +37,6 @@ export class AlignmentComponent implements AfterViewInit, OnDestroy { elapsedTime = 0 remainingTime = 0 progress = 0 - private id = '' readonly tppaRequest: TPPAStart = { capture: structuredClone(EMPTY_CAMERA_START_CAPTURE), @@ -172,7 +171,7 @@ export class AlignmentComponent implements AfterViewInit, OnDestroy { }) electron.on('TPPA.ELAPSED', event => { - if (event.id === this.id) { + if (event.camera === this.camera) { ngZone.run(() => { if (this.status !== 'PAUSING' || event.state === 'PAUSED') { this.status = event.state @@ -200,7 +199,7 @@ export class AlignmentComponent implements AfterViewInit, OnDestroy { }) electron.on('DARV.ELAPSED', event => { - if (event.id === this.id) { + if (event.camera === this.camera) { ngZone.run(() => { this.status = event.state this.remainingTime = event.remainingTime @@ -316,30 +315,30 @@ export class AlignmentComponent implements AfterViewInit, OnDestroy { this.darvRequest.capture.exposureTime = this.darvRequest.exposureTime * 1000000 this.darvRequest.capture.exposureDelay = this.darvRequest.initialPause await this.openCameraImage() - this.id = await this.api.darvStart(this.camera, this.guideOutput, this.darvRequest) + await this.api.darvStart(this.camera, this.guideOutput, this.darvRequest) } darvStop() { - this.api.darvStop(this.id) + this.api.darvStop(this.camera) } async tppaStart() { this.alignmentMethod = 'TPPA' await this.openCameraImage() - this.id = await this.api.tppaStart(this.camera, this.mount, this.tppaRequest) + await this.api.tppaStart(this.camera, this.mount, this.tppaRequest) } tppaPause() { this.status = 'PAUSING' - this.api.tppaPause(this.id) + this.api.tppaPause(this.camera) } tppaUnpause() { - this.api.tppaUnpause(this.id) + this.api.tppaUnpause(this.camera) } tppaStop() { - this.api.tppaStop(this.id) + this.api.tppaStop(this.camera) } openCameraImage() { diff --git a/desktop/src/shared/services/api.service.ts b/desktop/src/shared/services/api.service.ts index 54d4a708a..ca10fa34b 100644 --- a/desktop/src/shared/services/api.service.ts +++ b/desktop/src/shared/services/api.service.ts @@ -525,29 +525,29 @@ export class ApiService { // DARV darvStart(camera: Camera, guideOutput: GuideOutput, data: DARVStart) { - return this.http.put(`polar-alignment/darv/${camera.id}/${guideOutput.id}/start`, data) + return this.http.put(`polar-alignment/darv/${camera.id}/${guideOutput.id}/start`, data) } - darvStop(id: string) { - return this.http.put(`polar-alignment/darv/${id}/stop`) + darvStop(camera: Camera) { + return this.http.put(`polar-alignment/darv/${camera.id}/stop`) } // TPPA tppaStart(camera: Camera, mount: Mount, data: TPPAStart) { - return this.http.put(`polar-alignment/tppa/${camera.id}/${mount.id}/start`, data) + return this.http.put(`polar-alignment/tppa/${camera.id}/${mount.id}/start`, data) } - tppaStop(id: string) { - return this.http.put(`polar-alignment/tppa/${id}/stop`) + tppaStop(camera: Camera) { + return this.http.put(`polar-alignment/tppa/${camera.id}/stop`) } - tppaPause(id: string) { - return this.http.put(`polar-alignment/tppa/${id}/pause`) + tppaPause(camera: Camera) { + return this.http.put(`polar-alignment/tppa/${camera.id}/pause`) } - tppaUnpause(id: string) { - return this.http.put(`polar-alignment/tppa/${id}/unpause`) + tppaUnpause(camera: Camera) { + return this.http.put(`polar-alignment/tppa/${camera.id}/unpause`) } // SEQUENCER diff --git a/desktop/src/shared/types/alignment.types.ts b/desktop/src/shared/types/alignment.types.ts index 0473c2a2d..65855fc7a 100644 --- a/desktop/src/shared/types/alignment.types.ts +++ b/desktop/src/shared/types/alignment.types.ts @@ -1,5 +1,5 @@ import { Angle } from './atlas.types' -import { CameraStartCapture } from './camera.types' +import { Camera, CameraStartCapture } from './camera.types' import { GuideDirection } from './guider.types' import { PlateSolverPreference, PlateSolverType } from './settings.types' @@ -44,7 +44,7 @@ export interface DARVStart { } export interface DARVElapsed extends MessageEvent { - id: string + camera: Camera remainingTime: number progress: number state: DARVState @@ -62,7 +62,7 @@ export interface TPPAStart { } export interface TPPAElapsed extends MessageEvent { - id: string + camera: Camera elapsedTime: number stepCount: number state: TPPAState diff --git a/nebulosa-watney/src/main/kotlin/nebulosa/watney/plate/solving/WatneyPlateSolver.kt b/nebulosa-watney/src/main/kotlin/nebulosa/watney/plate/solving/WatneyPlateSolver.kt index 46d2c6524..249aec548 100644 --- a/nebulosa-watney/src/main/kotlin/nebulosa/watney/plate/solving/WatneyPlateSolver.kt +++ b/nebulosa-watney/src/main/kotlin/nebulosa/watney/plate/solving/WatneyPlateSolver.kt @@ -654,7 +654,7 @@ data class WatneyPlateSolver( return if (filtered.size >= 8) { filtered } else { - LOG.info("Not enough matches to perform filtering, with so few matches assuming they're good") + LOG.info("not enough matches to perform filtering, with so few matches assuming they're good") matches } }