-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
333 changed files
with
6,149 additions
and
3,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
api/src/main/kotlin/nebulosa/api/alignment/polar/PolarAlignmentService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package nebulosa.api.alignment.polar | ||
|
||
import nebulosa.api.alignment.polar.darv.DARVPolarAlignmentExecutor | ||
import nebulosa.api.alignment.polar.darv.DARVStart | ||
import nebulosa.api.alignment.polar.darv.DARVExecutor | ||
import nebulosa.api.alignment.polar.darv.DARVStartRequest | ||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class PolarAlignmentService( | ||
private val darvPolarAlignmentExecutor: DARVPolarAlignmentExecutor, | ||
private val darvExecutor: DARVExecutor, | ||
) { | ||
|
||
fun darvStart(camera: Camera, guideOutput: GuideOutput, darvStart: DARVStart) { | ||
fun darvStart(camera: Camera, guideOutput: GuideOutput, darvStartRequest: DARVStartRequest) { | ||
check(camera.connected) { "camera not connected" } | ||
check(guideOutput.connected) { "guide output not connected" } | ||
darvPolarAlignmentExecutor.execute(darvStart.copy(camera = camera, guideOutput = guideOutput)) | ||
darvExecutor.execute(darvStartRequest.copy(camera = camera, guideOutput = guideOutput)) | ||
} | ||
|
||
fun darvStop(camera: Camera, guideOutput: GuideOutput) { | ||
darvPolarAlignmentExecutor.stop(camera, guideOutput) | ||
darvExecutor.stop(camera, guideOutput) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import nebulosa.api.messages.MessageEvent | ||
import nebulosa.guiding.GuideDirection | ||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import java.time.Duration | ||
|
||
sealed interface DARVEvent : MessageEvent { | ||
|
||
val camera: Camera | ||
|
||
val guideOutput: GuideOutput | ||
|
||
val remainingTime: Duration | ||
|
||
val progress: Double | ||
|
||
val direction: GuideDirection? | ||
|
||
val state: DARVState | ||
|
||
override val eventName | ||
get() = "DARV_POLAR_ALIGNMENT_ELAPSED" | ||
} |
73 changes: 73 additions & 0 deletions
73
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVExecutor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import io.reactivex.rxjava3.functions.Consumer | ||
import nebulosa.api.messages.MessageEvent | ||
import nebulosa.api.messages.MessageService | ||
import nebulosa.batch.processing.JobExecution | ||
import nebulosa.batch.processing.JobLauncher | ||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import nebulosa.log.debug | ||
import nebulosa.log.loggerFor | ||
import org.springframework.stereotype.Component | ||
import java.util.* | ||
|
||
/** | ||
* @see <a href="https://www.cloudynights.com/articles/cat/articles/darv-drift-alignment-by-robert-vice-r2760">Reference</a> | ||
*/ | ||
@Component | ||
class DARVExecutor( | ||
private val jobLauncher: JobLauncher, | ||
private val messageService: MessageService, | ||
) : Consumer<MessageEvent> { | ||
|
||
private val jobExecutions = LinkedList<JobExecution>() | ||
|
||
@Synchronized | ||
fun execute(request: DARVStartRequest) { | ||
val camera = requireNotNull(request.camera) | ||
val guideOutput = requireNotNull(request.guideOutput) | ||
|
||
check(!isRunning(camera, guideOutput)) { "DARV job is already running" } | ||
|
||
LOG.debug { "starting DARV. request=%s".format(request) } | ||
|
||
with(DARVJob(request)) { | ||
subscribe(this@DARVExecutor) | ||
val jobExecution = jobLauncher.launch(this) | ||
jobExecutions.add(jobExecution) | ||
} | ||
} | ||
|
||
fun findJobExecution(camera: Camera, guideOutput: GuideOutput): JobExecution? { | ||
for (i in jobExecutions.indices.reversed()) { | ||
val jobExecution = jobExecutions[i] | ||
val job = jobExecution.job as DARVJob | ||
|
||
if (!jobExecution.isDone && job.camera === camera && job.guideOutput === guideOutput) { | ||
return jobExecution | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
@Synchronized | ||
fun stop(camera: Camera, guideOutput: GuideOutput) { | ||
val jobExecution = findJobExecution(camera, guideOutput) ?: return | ||
jobLauncher.stop(jobExecution) | ||
} | ||
|
||
fun isRunning(camera: Camera, guideOutput: GuideOutput): Boolean { | ||
return findJobExecution(camera, guideOutput) != null | ||
} | ||
|
||
override fun accept(event: MessageEvent) { | ||
messageService.sendMessage(event) | ||
} | ||
|
||
companion object { | ||
|
||
@JvmStatic private val LOG = loggerFor<DARVExecutor>() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVFinished.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import java.time.Duration | ||
|
||
data class DARVFinished( | ||
override val camera: Camera, | ||
override val guideOutput: GuideOutput, | ||
) : DARVEvent { | ||
|
||
override val remainingTime = Duration.ZERO!! | ||
override val progress = 0.0 | ||
override val state = DARVState.IDLE | ||
override val direction = null | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVGuidePulseElapsed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import nebulosa.api.messages.MessageEvent | ||
import nebulosa.guiding.GuideDirection | ||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import java.time.Duration | ||
|
||
data class DARVGuidePulseElapsed( | ||
override val camera: Camera, | ||
override val guideOutput: GuideOutput, | ||
override val remainingTime: Duration, | ||
override val progress: Double, | ||
override val direction: GuideDirection, | ||
override val state: DARVState, | ||
) : MessageEvent, DARVEvent |
16 changes: 16 additions & 0 deletions
16
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVInitialPauseElapsed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import nebulosa.indi.device.camera.Camera | ||
import nebulosa.indi.device.guide.GuideOutput | ||
import java.time.Duration | ||
|
||
data class DARVInitialPauseElapsed( | ||
override val camera: Camera, | ||
override val guideOutput: GuideOutput, | ||
override val remainingTime: Duration, | ||
override val progress: Double, | ||
) : DARVEvent { | ||
|
||
override val state = DARVState.INITIAL_PAUSE | ||
override val direction = null | ||
} |
83 changes: 83 additions & 0 deletions
83
api/src/main/kotlin/nebulosa/api/alignment/polar/darv/DARVJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package nebulosa.api.alignment.polar.darv | ||
|
||
import io.reactivex.rxjava3.subjects.PublishSubject | ||
import nebulosa.api.cameras.* | ||
import nebulosa.api.guiding.GuidePulseListener | ||
import nebulosa.api.guiding.GuidePulseRequest | ||
import nebulosa.api.guiding.GuidePulseStep | ||
import nebulosa.api.messages.MessageEvent | ||
import nebulosa.batch.processing.* | ||
import nebulosa.batch.processing.ExecutionContext.Companion.getDouble | ||
import nebulosa.batch.processing.ExecutionContext.Companion.getDuration | ||
import nebulosa.batch.processing.ExecutionContext.Companion.getPath | ||
import nebulosa.batch.processing.delay.DelayStep | ||
import nebulosa.batch.processing.delay.DelayStepListener | ||
import nebulosa.indi.device.camera.FrameType | ||
import java.nio.file.Files | ||
import java.time.Duration | ||
|
||
data class DARVJob( | ||
val request: DARVStartRequest, | ||
) : SimpleJob(), PublishSubscribe<MessageEvent>, CameraCaptureListener, GuidePulseListener, DelayStepListener { | ||
|
||
@JvmField val camera = requireNotNull(request.camera) | ||
@JvmField val guideOutput = requireNotNull(request.guideOutput) | ||
@JvmField val direction = if (request.reversed) request.direction.reversed else request.direction | ||
|
||
@JvmField val cameraRequest = (request.capture ?: CameraStartCaptureRequest()).copy( | ||
camera = camera, | ||
exposureTime = request.exposureTime + request.initialPause, | ||
savePath = Files.createTempDirectory("darv"), | ||
exposureAmount = 1, exposureDelay = Duration.ZERO, | ||
frameType = FrameType.LIGHT, autoSave = false, autoSubFolderMode = AutoSubFolderMode.OFF | ||
) | ||
|
||
override val subject = PublishSubject.create<MessageEvent>() | ||
|
||
init { | ||
val cameraExposureStep = CameraExposureStep(cameraRequest) | ||
cameraExposureStep.registerCameraCaptureListener(this) | ||
|
||
val initialPauseDelayStep = DelayStep(request.initialPause) | ||
initialPauseDelayStep.registerDelayStepListener(this) | ||
|
||
val guidePulseDuration = request.exposureTime.dividedBy(2L) | ||
val forwardGuidePulseRequest = GuidePulseRequest(guideOutput, direction, guidePulseDuration) | ||
val forwardGuidePulseStep = GuidePulseStep(forwardGuidePulseRequest) | ||
forwardGuidePulseStep.registerGuidePulseListener(this) | ||
|
||
val backwardGuidePulseRequest = GuidePulseRequest(guideOutput, direction.reversed, guidePulseDuration) | ||
val backwardGuidePulseStep = GuidePulseStep(backwardGuidePulseRequest) | ||
backwardGuidePulseStep.registerGuidePulseListener(this) | ||
|
||
val guideFlow = SimpleFlowStep(initialPauseDelayStep, forwardGuidePulseStep, backwardGuidePulseStep) | ||
add(SimpleSplitStep(cameraExposureStep, guideFlow)) | ||
} | ||
|
||
override fun beforeJob(jobExecution: JobExecution) { | ||
onNext(DARVStarted(camera, guideOutput, request.initialPause, direction)) | ||
} | ||
|
||
override fun afterJob(jobExecution: JobExecution) { | ||
onNext(DARVFinished(camera, guideOutput)) | ||
} | ||
|
||
override fun onExposureFinished(step: CameraExposureStep, stepExecution: StepExecution) { | ||
val savePath = stepExecution.context.getPath(CameraExposureStep.SAVE_PATH)!! | ||
onNext(CameraExposureFinished(stepExecution.jobExecution, step.camera, 1, 1, Duration.ZERO, 1.0, Duration.ZERO, savePath)) | ||
} | ||
|
||
override fun onGuidePulseElapsed(step: GuidePulseStep, stepExecution: StepExecution) { | ||
val direction = step.request.direction | ||
val remainingTime = stepExecution.context.getDuration(DelayStep.REMAINING_TIME) | ||
val progress = stepExecution.context.getDouble(DelayStep.PROGRESS) | ||
val state = if (direction == this.direction) DARVState.FORWARD else DARVState.BACKWARD | ||
onNext(DARVGuidePulseElapsed(camera, guideOutput, remainingTime, progress, direction, state)) | ||
} | ||
|
||
override fun onDelayElapsed(step: DelayStep, stepExecution: StepExecution) { | ||
val remainingTime = stepExecution.context.getDuration(DelayStep.REMAINING_TIME) | ||
val progress = stepExecution.context.getDouble(DelayStep.PROGRESS) | ||
onNext(DARVInitialPauseElapsed(camera, guideOutput, remainingTime, progress)) | ||
} | ||
} |
Oops, something went wrong.