Skip to content

Commit

Permalink
Merge pull request #435 from jluhrs/oiwfs_probe_tracking
Browse files Browse the repository at this point in the history
Oiwfs probe tracking configuration
  • Loading branch information
jluhrs authored Oct 19, 2023
2 parents 9f243d3 + a437875 commit 40bcb96
Show file tree
Hide file tree
Showing 32 changed files with 392 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object EpicsService {
.map(x => Channel.build[F, T, tjt.javaType](x)(Async[F], tjt.convert))
}

final case class Builder(
case class Builder(
addrList: Option[List[InetAddress]],
autoAddrList: Option[Boolean],
connectionTimeout: Option[FiniteDuration],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import scala.concurrent.duration.FiniteDuration
* @param ldap
* URL of the ldap servers
*/
final case class AuthenticationConfig(
case class AuthenticationConfig(
sessionLifeHrs: FiniteDuration,
cookieName: String,
secretKey: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait GpiSettings
* @param ioTimeout
* Timeout to listen for EPICS events
*/
final case class NavigateEngineConfiguration(
case class NavigateEngineConfiguration(
odb: Uri,
systemControl: SystemsControlConfiguration,
odbNotifications: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cats._
/**
* Indicates how each subsystems is treated, e.g. full connection or simulated
*/
final case class SystemsControlConfiguration(
case class SystemsControlConfiguration(
altair: ControlStrategy,
gems: ControlStrategy,
gcal: ControlStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import cats.syntax.all._
import mouse.all._

object FixedLengthBuffer {
private final case class FixedLengthBufferImpl[A](maxLength: Int, data: Chain[A])
private case class FixedLengthBufferImpl[A](maxLength: Int, data: Chain[A])
extends FixedLengthBuffer[A] {
// Sanity check
require(maxLength >= data.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object NavigateCommand {
case object Slew extends NavigateCommand
case object InstSpecifics extends NavigateCommand
case object OiwfsTarget extends NavigateCommand
case object OiwfsProbeTracking extends NavigateCommand

given Eq[NavigateCommand] = Eq.fromUniversalEquals

Expand Down Expand Up @@ -96,6 +97,7 @@ object NavigateCommand {
case Slew => "Slew"
case InstSpecifics => "Instrument Specifics"
case OiwfsTarget => "OIWFS"
case OiwfsProbeTracking => "OIWFS Probe Tracking"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.time.Instant
sealed trait NavigateEvent

object NavigateEvent {
final case class ServerLogMessage(level: ServerLogLevel, timestamp: Instant, msg: String)
case class ServerLogMessage(level: ServerLogLevel, timestamp: Instant, msg: String)
extends NavigateEvent
object ServerLogMessage {
private given Order[Instant] =
Expand All @@ -25,7 +25,7 @@ object NavigateEvent {

case object NullEvent extends NavigateEvent

final case class ConnectionOpenEvent(
case class ConnectionOpenEvent(
userDetails: Option[UserDetails],
clientId: ClientId,
serverVersion: String
Expand All @@ -36,22 +36,22 @@ object NavigateEvent {
Eq.by(x => (x.userDetails, x.clientId, x.serverVersion))
}

final case class CommandStart(cmd: NavigateCommand) extends NavigateEvent
case class CommandStart(cmd: NavigateCommand) extends NavigateEvent
object CommandStart {
given Eq[CommandStart] = Eq.by(_.cmd)
}

final case class CommandSuccess(cmd: NavigateCommand) extends NavigateEvent
case class CommandSuccess(cmd: NavigateCommand) extends NavigateEvent
object CommandSuccess {
given Eq[CommandSuccess] = Eq.by(_.cmd)
}

final case class CommandPaused(cmd: NavigateCommand) extends NavigateEvent
case class CommandPaused(cmd: NavigateCommand) extends NavigateEvent
object CommandPaused {
given Eq[CommandPaused] = Eq.by(_.cmd)
}

final case class CommandFailure(cmd: NavigateCommand, msg: String) extends NavigateEvent
case class CommandFailure(cmd: NavigateCommand, msg: String) extends NavigateEvent
object CommandFailure {
given Eq[CommandFailure] = Eq.by(x => (x.cmd, x.msg))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cats.Eq
import java.util.UUID

package model {
final case class ClientId(self: UUID) extends AnyVal
case class ClientId(self: UUID) extends AnyVal
}
package object model {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object SchemaStitcher {

sealed trait Elements
case object AllElements extends Elements
final case class ElementList(l: NonEmptySet[NonEmptyString]) extends Elements
case class ElementList(l: NonEmptySet[NonEmptyString]) extends Elements

extension (el: Elements) {
def union(other: Elements): Elements = (el, other) match {
Expand Down
33 changes: 16 additions & 17 deletions modules/server/src/main/scala/navigate/server/NavigateEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ import cats.effect.{Async, Concurrent, Ref, Temporal}
import cats.effect.kernel.Sync
import cats.syntax.all.*
import org.typelevel.log4cats.Logger
import navigate.model.NavigateCommand.{
CrcsFollow,
CrcsMove,
CrcsPark,
CrcsStop,
EcsCarouselMode,
InstSpecifics,
McsFollow,
McsPark,
OiwfsTarget,
Slew
}
import navigate.model.NavigateCommand.{CrcsFollow, CrcsMove, CrcsPark, CrcsStop, EcsCarouselMode, InstSpecifics, McsFollow, McsPark, OiwfsProbeTracking, OiwfsTarget, Slew}
import navigate.model.{NavigateCommand, NavigateEvent}
import navigate.model.NavigateEvent.{CommandFailure, CommandPaused, CommandStart, CommandSuccess}
import navigate.model.config.NavigateEngineConfiguration
import navigate.model.enums.{DomeMode, ShutterMode}
import navigate.server.tcs.{SlewConfig, Target}
import navigate.server.tcs.{InstrumentSpecifics, SlewConfig, Target, TrackingConfig}
import navigate.stateengine.StateEngine
import NavigateEvent.NullEvent
import fs2.{Pipe, Stream}
Expand All @@ -33,7 +22,6 @@ import lucuma.core.math.Angle
import monocle.{Focus, Lens}

import scala.concurrent.duration.{DurationInt, FiniteDuration}
import navigate.server.tcs.InstrumentSpecifics

trait NavigateEngine[F[_]] {
val systems: Systems[F]
Expand All @@ -55,6 +43,7 @@ trait NavigateEngine[F[_]] {
def slew(slewConfig: SlewConfig): F[Unit]
def instrumentSpecifics(instrumentSpecificsParams: InstrumentSpecifics): F[Unit]
def oiwfsTarget(target: Target): F[Unit]
def oiwfsProbeTracking(config: TrackingConfig): F[Unit]
}

object NavigateEngine {
Expand Down Expand Up @@ -169,6 +158,13 @@ object NavigateEngine {
systems.tcsSouth.oiwfsTarget(target),
Focus[State](_.oiwfsInProgress)
)

override def oiwfsProbeTracking(config: TrackingConfig): F[Unit] = command(
engine,
OiwfsProbeTracking,
systems.tcsSouth.oiwfsProbeTracking(config),
Focus[State](_.oiwfsProbeTrackingInProgress)
)
}

def build[F[_]: Concurrent: Logger](
Expand All @@ -191,7 +187,8 @@ object NavigateEngine {
slewInProgress: Boolean,
oiwfsInProgress: Boolean,
instrumentSpecificsInProgress: Boolean,
rotIaaInProgress: Boolean
rotIaaInProgress: Boolean,
oiwfsProbeTrackingInProgress: Boolean
) {
lazy val tcsActionInProgress: Boolean =
mcsParkInProgress ||
Expand All @@ -205,7 +202,8 @@ object NavigateEngine {
slewInProgress ||
oiwfsInProgress ||
instrumentSpecificsInProgress ||
rotIaaInProgress
rotIaaInProgress ||
oiwfsProbeTrackingInProgress
}

val startState: State = State(
Expand All @@ -220,7 +218,8 @@ object NavigateEngine {
slewInProgress = false,
oiwfsInProgress = false,
instrumentSpecificsInProgress = false,
rotIaaInProgress = false
rotIaaInProgress = false,
oiwfsProbeTrackingInProgress = false
)

private def command[F[_]: MonadThrow: Logger](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ sealed trait NavigateFailure extends Exception with Product with Serializable
object NavigateFailure {

/** Something went wrong while applying a configuration. * */
final case class Execution(errMsg: String) extends NavigateFailure
case class Execution(errMsg: String) extends NavigateFailure

final case class Unexpected(msg: String) extends NavigateFailure
case class Unexpected(msg: String) extends NavigateFailure

final case class Timeout(msg: String) extends NavigateFailure
case class Timeout(msg: String) extends NavigateFailure

final case class NullEpicsError(channel: String) extends NavigateFailure
case class NullEpicsError(channel: String) extends NavigateFailure

def explain(f: NavigateFailure): String = f match {
case Execution(errMsg) => s"Configuration action failed with error: $errMsg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import lucuma.core.enums.Site

import scala.annotation.nowarn

final case class Systems[F[_]](
case class Systems[F[_]](
odb: OdbProxy[F],
tcsSouth: TcsSouthController[F],
tcsNorth: TcsNorthController[F]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package navigate.server.tcs

case class GuiderConfig (
target: Target,
tracking: TrackingConfig
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package navigate.server.tcs
import lucuma.core.math.Angle
import navigate.model.Distance

final case class InstrumentSpecifics(
case class InstrumentSpecifics(
iaa: Angle,
focusOffset: Distance,
agName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package navigate.server.tcs
import navigate.model.Distance

final case class Origin(
case class Origin(
x: Distance,
y: Distance
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

package navigate.server.tcs

import lucuma.core.math.Angle

case class SlewConfig(
slewOptions: SlewOptions,
baseTarget: Target,
instrumentSpecifics: InstrumentSpecifics,
oiwfsTarget: Option[Target]
oiwfs: Option[GuiderConfig]
)
12 changes: 6 additions & 6 deletions modules/server/src/main/scala/navigate/server/tcs/Target.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sealed trait Target extends Product with Serializable {
}

object Target {
final case class SiderealTarget(
case class SiderealTarget(
override val objectName: String,
override val wavelength: Wavelength,
coordinates: Coordinates,
Expand All @@ -30,19 +30,19 @@ object Target {
parallax: Option[Parallax]
) extends Target

final case class Azimuth(toAngle: Angle)
case class Azimuth(toAngle: Angle)

final case class Elevation(toAngle: Angle)
case class Elevation(toAngle: Angle)

final case class AzElCoordinates(azimuth: Azimuth, elevation: Elevation)
case class AzElCoordinates(azimuth: Azimuth, elevation: Elevation)

final case class AzElTarget(
case class AzElTarget(
override val objectName: String,
override val wavelength: Wavelength,
coordinates: AzElCoordinates
) extends Target

final case class EphemerisTarget(
case class EphemerisTarget(
override val objectName: String,
override val wavelength: Wavelength,
ephemerisFile: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

package navigate.server.tcs

import lucuma.core.math.Angle
import navigate.model.enums.{DomeMode, ShutterMode}
import navigate.server.ApplyCommandResult
import lucuma.core.math.{Angle, Coordinates, Epoch, Parallax, ProperMotion, RadialVelocity}

trait TcsBaseController[F[_]] {
import TcsBaseController._
import TcsBaseController.*
def mcsPark: F[ApplyCommandResult]
def mcsFollow(enable: Boolean): F[ApplyCommandResult]
def rotStop(useBrakes: Boolean): F[ApplyCommandResult]
Expand All @@ -28,11 +28,12 @@ trait TcsBaseController[F[_]] {
def instrumentSpecifics(config: InstrumentSpecifics): F[ApplyCommandResult]
def oiwfsTarget(target: Target): F[ApplyCommandResult]
def rotIaa(angle: Angle): F[ApplyCommandResult]
def oiwfsProbeTracking(config: TrackingConfig): F[ApplyCommandResult]
}

object TcsBaseController {

final case class TcsConfig(
case class TcsConfig(
sourceATarget: Target
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import cats.effect.Async
import navigate.server.{ApplyCommandResult, ConnectionTimeout}

import scala.concurrent.duration.FiniteDuration
import navigate.epics.VerifiedEpics._
import navigate.epics.VerifiedEpics.*
import navigate.model.Distance
import navigate.model.enums.{DomeMode, ShutterMode}
import navigate.server.tcs.Target._
import navigate.server.tcs.TcsEpicsSystem.{TargetCommand, TcsCommands}
import navigate.server.tcs.Target.*
import navigate.server.tcs.TcsEpicsSystem.{ProbeTrackingCommand, TargetCommand, TcsCommands}
import lucuma.core.math.{Angle, Parallax, ProperMotion, RadialVelocity, Wavelength}
import monocle.Getter

Expand Down Expand Up @@ -226,9 +226,10 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
.compose(setFocusOffset(config.instrumentSpecifics.focusOffset))
.compose(setOrigin(config.instrumentSpecifics.origin))
.compose(
config.oiwfsTarget
.map(
setTarget(Getter[TcsCommands[F], TargetCommand[F, TcsCommands[F]]](_.oiwfsTargetCmd), _)
config.oiwfs
.map( o =>
setTarget(Getter[TcsCommands[F], TargetCommand[F, TcsCommands[F]]](_.oiwfsTargetCmd), o.target)
.compose(setProbeTracking(Getter[TcsCommands[F], ProbeTrackingCommand[F, TcsCommands[F]]](_.oiwfsProbeTrackingCommand), o.tracking))
)
.getOrElse(identity[TcsCommands[F]])
)(
Expand Down Expand Up @@ -257,4 +258,18 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
tcsEpics.startCommand(timeout)
).post
.verifiedRun(ConnectionTimeout)


def setProbeTracking(l: Getter[TcsCommands[F], ProbeTrackingCommand[F, TcsCommands[F]]], config: TrackingConfig): TcsCommands[F] => TcsCommands[F] =
{ (x: TcsCommands[F]) => l.get(x).nodAchopA(config.nodAchopA) }
.compose[TcsCommands[F]](l.get(_).nodAchopB(config.nodAchopB))
.compose[TcsCommands[F]](l.get(_).nodBchopA(config.nodBchopA))
.compose[TcsCommands[F]](l.get(_).nodBchopB(config.nodBchopB))

override def oiwfsProbeTracking(config: TrackingConfig): F[ApplyCommandResult] =
setProbeTracking(Getter[TcsCommands[F], ProbeTrackingCommand[F, TcsCommands[F]]](_.oiwfsProbeTrackingCommand), config)(
tcsEpics.startCommand(timeout)
).post
.verifiedRun(ConnectionTimeout)

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ class TcsBaseControllerSim[F[_]: Applicative] extends TcsBaseController[F] {

override def rotIaa(angle: Angle): F[ApplyCommandResult] =
Applicative[F].pure(ApplyCommandResult.Completed)

override def oiwfsProbeTracking(config: TrackingConfig): F[ApplyCommandResult] =
Applicative[F].pure(ApplyCommandResult.Completed)
}
Loading

0 comments on commit 40bcb96

Please sign in to comment.