Skip to content

Commit

Permalink
Set guider gains depending on dayMode
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Jan 12, 2024
1 parent ae3e0b6 commit 4091d5b
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
.verifiedRun(ConnectionTimeout)

override def enableGuide(config: TelescopeGuideConfig): F[ApplyCommandResult] = {
val gains = (x: TcsCommands[F]) =>
if (config.dayTimeMode)
x.guiderGainsCommands.dayTimeGains
else
x.guiderGainsCommands.defaultGains

val m1 = (x: TcsCommands[F]) =>
config.m1Guide match {
case M1GuideConfig.M1GuideOff => x.m1GuideCommand.state(false)
Expand All @@ -382,7 +388,7 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](

config.m2Guide match {
case M2GuideConfig.M2GuideOff =>
m1(tcsEpics.startCommand(timeout)).m2GuideCommand
m1(gains(tcsEpics.startCommand(timeout))).m2GuideCommand
.state(false)
.m2GuideModeCommand
.coma(false)
Expand All @@ -399,11 +405,7 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
.flatMap(x => beams.map(y => (x, y)))
.foldLeft(
requireReset.fold(
tcsEpics
.startCommand(timeout)
.m2GuideResetCommand
.mark
.post
gains(tcsEpics.startCommand(timeout)).m2GuideResetCommand.mark.post
.verifiedRun(ConnectionTimeout),
ApplyCommandResult.Completed.pure[F]
)
Expand All @@ -412,9 +414,10 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
// Set tip-tilt guide for each source on each beam
// TCC adds a delay between each call. Is it necessary?
(r === ApplyCommandResult.Completed).fold(
tcsEpics
.startCommand(timeout)
.m2GuideConfigCommand
gains(
tcsEpics
.startCommand(timeout)
).m2GuideConfigCommand
.source(src.tag)
.m2GuideConfigCommand
.sampleFreq(200.0)
Expand All @@ -430,7 +433,7 @@ class TcsBaseControllerEpics[F[_]: Async: Parallel](
)
}.flatMap { r =>
(r === ApplyCommandResult.Completed).fold(
m1(tcsEpics.startCommand(timeout)).m2GuideCommand
m1(gains(tcsEpics.startCommand(timeout))).m2GuideCommand
.state(true)
.m2GuideModeCommand
.coma(coma)
Expand Down
42 changes: 21 additions & 21 deletions modules/server/src/main/scala/navigate/server/tcs/TcsChannels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ object TcsChannels {
)

case class GuiderGainsChannels[F[_]](
p1tipGain: Channel[F, Double],
p1tiltGain: Channel[F, Double],
p1FocusGain: Channel[F, Double],
p1TipGain: Channel[F, String],
p1TiltGain: Channel[F, String],
p1FocusGain: Channel[F, String],
p1Reset: Channel[F, BinaryYesNo],
p2tipGain: Channel[F, Double],
p2tiltGain: Channel[F, Double],
p2FocusGain: Channel[F, Double],
p2TipGain: Channel[F, String],
p2TiltGain: Channel[F, String],
p2FocusGain: Channel[F, String],
p2Reset: Channel[F, BinaryYesNo],
oitipGain: Channel[F, Double],
oitiltGain: Channel[F, Double],
oiFocusGain: Channel[F, Double],
oiTipGain: Channel[F, String],
oiTiltGain: Channel[F, String],
oiFocusGain: Channel[F, String],
oiReset: Channel[F, BinaryYesNo]
)

Expand Down Expand Up @@ -515,18 +515,18 @@ object TcsChannels {
top: String
): Resource[F, GuiderGainsChannels[F]] =
for {
p1tipGain <- service.getChannel[Double](top, "pwfs1:dc:detSigInitFgGain.A")
p1tiltGain <- service.getChannel[Double](top, "pwfs1:dc:detSigInitFgGain.B")
p1FocusGain <- service.getChannel[Double](top, "pwfs1:dc:detSigInitFgGain.C")
p1Reset <- service.getChannel[BinaryYesNo](top, "pwfs1:dc:initSigInit.J")
p2tipGain <- service.getChannel[Double](top, "pwfs2:dc:detSigInitFgGain.A")
p2tiltGain <- service.getChannel[Double](top, "pwfs2:dc:detSigInitFgGain.B")
p2FocusGain <- service.getChannel[Double](top, "pwfs2:dc:detSigInitFgGain.C")
p2Reset <- service.getChannel[BinaryYesNo](top, "pwfs2:dc:initSigInit.J")
oitipGain <- service.getChannel[Double](top, "oiwfs:dc:detSigInitFgGain.A")
oitiltGain <- service.getChannel[Double](top, "oiwfs:dc:detSigInitFgGain.B")
oiFocusGain <- service.getChannel[Double](top, "oiwfs:dc:detSigInitFgGain.C")
oiReset <- service.getChannel[BinaryYesNo](top, "oiwfs:dc:initSigInit.J")
p1tipGain <- service.getChannel[String]("pwfs1:dc:detSigInitFgGain.A")
p1tiltGain <- service.getChannel[String]("pwfs1:dc:detSigInitFgGain.B")
p1FocusGain <- service.getChannel[String]("pwfs1:dc:detSigInitFgGain.C")
p1Reset <- service.getChannel[BinaryYesNo]("pwfs1:dc:initSigInit.J")
p2tipGain <- service.getChannel[String]("pwfs2:dc:detSigInitFgGain.A")
p2tiltGain <- service.getChannel[String]("pwfs2:dc:detSigInitFgGain.B")
p2FocusGain <- service.getChannel[String]("pwfs2:dc:detSigInitFgGain.C")
p2Reset <- service.getChannel[BinaryYesNo]("pwfs2:dc:initSigInit.J")
oitipGain <- service.getChannel[String]("oiwfs:dc:detSigInitFgGain.A")
oitiltGain <- service.getChannel[String]("oiwfs:dc:detSigInitFgGain.B")
oiFocusGain <- service.getChannel[String]("oiwfs:dc:detSigInitFgGain.C")
oiReset <- service.getChannel[BinaryYesNo]("oiwfs:dc:initSigInit.J")
} yield GuiderGainsChannels(
p1tipGain,
p1tiltGain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ object TcsEpicsSystem {
]
val m2GuideResetCmd: ParameterlessCommandChannels[F]
val mountGuideCmd: Command4Channels[F, BinaryOnOff, String, Double, Double]
val p1GuiderGainsCmd: Command3Channels[F, Double, Double, Double]
val p2GuiderGainsCmd: Command3Channels[F, Double, Double, Double]
val oiGuiderGainsCmd: Command3Channels[F, Double, Double, Double]

// val offsetACmd: OffsetCmd[F]
// val offsetBCmd: OffsetCmd[F]
Expand Down Expand Up @@ -841,6 +844,41 @@ object TcsEpicsSystem {
)
}
}

override val guiderGainsCommands: GuiderGainsCommand[F, TcsCommands[F]] =
new GuiderGainsCommand[F, TcsCommands[F]] {
override def dayTimeGains: TcsCommands[F] =
addMultipleParams(
List(
tcsEpics.p1GuiderGainsCmd.setParam1(0.0),
tcsEpics.p1GuiderGainsCmd.setParam2(0.0),
tcsEpics.p1GuiderGainsCmd.setParam3(0.0),
tcsEpics.p2GuiderGainsCmd.setParam1(0.0),
tcsEpics.p2GuiderGainsCmd.setParam2(0.0),
tcsEpics.p2GuiderGainsCmd.setParam3(0.0),
tcsEpics.oiGuiderGainsCmd.setParam1(0.0),
tcsEpics.oiGuiderGainsCmd.setParam2(0.0),
tcsEpics.oiGuiderGainsCmd.setParam3(0.0)
)
)

// TODO These hardcoded value should be configurable
override def defaultGains: TcsCommands[F] =
addMultipleParams(
List(
tcsEpics.p1GuiderGainsCmd.setParam1(0.03),
tcsEpics.p1GuiderGainsCmd.setParam2(0.03),
tcsEpics.p1GuiderGainsCmd.setParam3(0.00002),
tcsEpics.p2GuiderGainsCmd.setParam1(0.05),
tcsEpics.p2GuiderGainsCmd.setParam2(0.05),
tcsEpics.p2GuiderGainsCmd.setParam3(0.0001),
tcsEpics.oiGuiderGainsCmd.setParam1(0.08),
tcsEpics.oiGuiderGainsCmd.setParam2(0.08),
tcsEpics.oiGuiderGainsCmd.setParam3(0.00015)
)
)

}
}

class TcsEpicsSystemImpl[F[_]: Monad: Parallel](epics: TcsEpics[F], st: TcsStatus[F])
Expand Down Expand Up @@ -993,6 +1031,30 @@ object TcsEpicsSystem {
)
override val oiWfsCmds: WfsCommandsChannels[F] =
WfsCommandsChannels.build(channels.telltale, channels.oiwfs)

override val p1GuiderGainsCmd: Command3Channels[F, Double, Double, Double] =
Command3Channels(
channels.telltale,
channels.guiderGains.p1TipGain,
channels.guiderGains.p1TiltGain,
channels.guiderGains.p1FocusGain
)

override val p2GuiderGainsCmd: Command3Channels[F, Double, Double, Double] =
Command3Channels(
channels.telltale,
channels.guiderGains.p2TipGain,
channels.guiderGains.p2TiltGain,
channels.guiderGains.p2FocusGain
)

override val oiGuiderGainsCmd: Command3Channels[F, Double, Double, Double] =
Command3Channels(
channels.telltale,
channels.guiderGains.oiTipGain,
channels.guiderGains.oiTiltGain,
channels.guiderGains.oiFocusGain
)
}

case class ParameterlessCommandChannels[F[_]: Monad](
Expand Down Expand Up @@ -1385,6 +1447,11 @@ object TcsEpicsSystem {
def state(v: Boolean): S
}

trait GuiderGainsCommand[F[_], +S] {
def dayTimeGains: S
def defaultGains: S
}

trait M1GuideConfigCommand[F[_], +S] {
def weighting(v: String): S
def source(v: String): S
Expand Down Expand Up @@ -1475,6 +1542,7 @@ object TcsEpicsSystem {
val m2GuideResetCommand: BaseCommand[F, TcsCommands[F]]
val mountGuideCommand: MountGuideCommand[F, TcsCommands[F]]
val oiWfsCommands: WfsCommands[F, TcsCommands[F]]
val guiderGainsCommands: GuiderGainsCommand[F, TcsCommands[F]]
}
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import cats.derived.*

/** Data type for guide config. */
case class TelescopeGuideConfig(
mountGuide: Boolean,
m1Guide: M1GuideConfig,
m2Guide: M2GuideConfig
mountGuide: Boolean,
m1Guide: M1GuideConfig,
m2Guide: M2GuideConfig,
dayTimeMode: Boolean
) derives Eq,
Show
Loading

0 comments on commit 4091d5b

Please sign in to comment.