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 67ca737
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ 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 +387,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 +404,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 +413,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 +432,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,29 @@ 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)
)
)

override def defaultGains: TcsCommands[F] = addParam(
tcsEpics.p1GuiderGainsCmd.setParam1(0.0)
)

}
}

class TcsEpicsSystemImpl[F[_]: Monad: Parallel](epics: TcsEpics[F], st: TcsStatus[F])
Expand Down Expand Up @@ -993,6 +1019,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 +1435,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 +1530,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
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,89 @@ class TcsBaseControllerEpicsSpec extends CatsEffectSuite {
}
}

test("Enable and disable guiding day mode") {
val guideCfg = TelescopeGuideConfig(
mountGuide = true,
m1Guide = M1GuideConfig.M1GuideOn(M1Source.Oiwfs),
m2Guide = M2GuideOn(true, Set(TipTiltSource.Oiwfs)),
true
)

for {
x <- createController
(st, ctr) = x
_ <- ctr.enableGuide(guideCfg)
r1 <- st.get
_ <- ctr.disableGuide
r2 <- st.get
} yield {
assert(r1.m1Guide.connected)
assert(r1.m1GuideConfig.source.connected)
assert(r1.m1GuideConfig.frames.connected)
assert(r1.m1GuideConfig.weighting.connected)
assert(r1.m1GuideConfig.filename.connected)
assert(r1.m2Guide.connected)
assert(r1.m2GuideConfig.source.connected)
assert(r1.m2GuideConfig.beam.connected)
assert(r1.m2GuideConfig.filter.connected)
assert(r1.m2GuideConfig.samplefreq.connected)
assert(r1.m2GuideConfig.reset.connected)
assert(r1.m2GuideMode.connected)
assert(r1.m2GuideReset.connected)
assert(r1.mountGuide.mode.connected)
assert(r1.mountGuide.source.connected)
assert(r1.guiderGains.p1TipGain.connected)

assertEquals(r1.m1Guide.value.flatMap(Enumerated[BinaryOnOff].fromTag), BinaryOnOff.On.some)
assertEquals(r1.m1GuideConfig.source.value.flatMap(Enumerated[M1Source].fromTag),
M1Source.Oiwfs.some
)
assertEquals(r1.m1GuideConfig.frames.value.flatMap(_.toIntOption), 1.some)
assertEquals(r1.m1GuideConfig.weighting.value, "none".some)
assertEquals(r1.m1GuideConfig.filename.value, "".some)
assertEquals(r1.m2Guide.value.flatMap(Enumerated[BinaryOnOff].fromTag), BinaryOnOff.On.some)
assertEquals(r1.m2GuideConfig.source.value.flatMap(Enumerated[TipTiltSource].fromTag),
TipTiltSource.Oiwfs.some
)
assertEquals(r1.m2GuideConfig.beam.value, "B".some)
assertEquals(r1.m2GuideConfig.filter.value, "raw".some)
assertEquals(r1.m2GuideConfig.samplefreq.value.flatMap(_.toDoubleOption), 200.0.some)
assertEquals(r1.m2GuideConfig.reset.value.flatMap(Enumerated[BinaryOnOff].fromTag),
BinaryOnOff.Off.some
)
assertEquals(r1.m2GuideMode.value.flatMap(Enumerated[BinaryOnOff].fromTag),
BinaryOnOff.On.some
)
assertEquals(r1.m2GuideReset.value, CadDirective.MARK.some)
assertEquals(r1.mountGuide.mode.value.flatMap(Enumerated[BinaryOnOff].fromTag),
BinaryOnOff.On.some
)
assertEquals(r1.mountGuide.source.value, "SCS".some)

assertEquals(r2.m1Guide.value.flatMap(Enumerated[BinaryOnOff].fromTag), BinaryOnOff.Off.some)
assertEquals(r2.m2Guide.value.flatMap(Enumerated[BinaryOnOff].fromTag), BinaryOnOff.Off.some)
assertEquals(r2.mountGuide.mode.value.flatMap(Enumerated[BinaryOnOff].fromTag),
BinaryOnOff.Off.some
)
assertEquals(r1.guiderGains.p1TipGain.value, "0.0".some)
assertEquals(r1.guiderGains.p1TiltGain.value, "0.0".some)
assertEquals(r1.guiderGains.p1FocusGain.value, "0.0".some)

assertEquals(r1.guiderGains.p2TipGain.value, "0.0".some)
assertEquals(r1.guiderGains.p2TiltGain.value, "0.0".some)
assertEquals(r1.guiderGains.p2FocusGain.value, "0.0".some)

assertEquals(r1.guiderGains.oiTipGain.value, "0.0".some)
assertEquals(r1.guiderGains.oiTiltGain.value, "0.0".some)
assertEquals(r1.guiderGains.oiFocusGain.value, "0.0".some)
}
}
test("Enable and disable guiding") {
val guideCfg = TelescopeGuideConfig(
mountGuide = true,
m1Guide = M1GuideConfig.M1GuideOn(M1Source.Oiwfs),
m2Guide = M2GuideOn(true, Set(TipTiltSource.Oiwfs))
m2Guide = M2GuideOn(true, Set(TipTiltSource.Oiwfs)),
false
)

for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package navigate.server.tcs

import cats.Applicative
import cats.Monad
import cats.Parallel
Expand Down Expand Up @@ -174,17 +175,17 @@ object TestTcsEpicsSystem {
}

case class GuiderGainsState(
p1tipGain: TestChannel.State[Double],
p1tiltGain: TestChannel.State[Double],
p1FocusGain: TestChannel.State[Double],
p1TipGain: TestChannel.State[String],
p1TiltGain: TestChannel.State[String],
p1FocusGain: TestChannel.State[String],
p1Reset: TestChannel.State[BinaryYesNo],
p2tipGain: TestChannel.State[Double],
p2tiltGain: TestChannel.State[Double],
p2FocusGain: TestChannel.State[Double],
p2TipGain: TestChannel.State[String],
p2TiltGain: TestChannel.State[String],
p2FocusGain: TestChannel.State[String],
p2Reset: TestChannel.State[BinaryYesNo],
oitipGain: TestChannel.State[Double],
oitiltGain: TestChannel.State[Double],
oiFocusGain: TestChannel.State[Double],
oiTipGain: TestChannel.State[String],
oiTiltGain: TestChannel.State[String],
oiFocusGain: TestChannel.State[String],
oiReset: TestChannel.State[BinaryYesNo]
)

Expand Down Expand Up @@ -671,17 +672,17 @@ object TestTcsEpicsSystem {
s: Ref[F, State],
l: Lens[State, GuiderGainsState]
): GuiderGainsChannels[F] = GuiderGainsChannels(
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p1tipGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p1tiltGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p1FocusGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p1TipGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p1TiltGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p1FocusGain))),
new TestChannel[F, State, BinaryYesNo](s, l.andThen(Focus[GuiderGainsState](_.p1Reset))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p2tipGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p2tiltGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.p2FocusGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p2TipGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p2TiltGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.p2FocusGain))),
new TestChannel[F, State, BinaryYesNo](s, l.andThen(Focus[GuiderGainsState](_.p2Reset))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.oitipGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.oitiltGain))),
new TestChannel[F, State, Double](s, l.andThen(Focus[GuiderGainsState](_.oiFocusGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.oiTipGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.oiTiltGain))),
new TestChannel[F, State, String](s, l.andThen(Focus[GuiderGainsState](_.oiFocusGain))),
new TestChannel[F, State, BinaryYesNo](s, l.andThen(Focus[GuiderGainsState](_.oiReset)))
)
def buildChannels[F[_]: Applicative](s: Ref[F, State]): TcsChannels[F] =
Expand Down
4 changes: 2 additions & 2 deletions modules/web/server/src/main/resources/NewTCC.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ input GuideConfigurationInput {
m1Input: M1CorrectionSource
"""Tip-tilt offload to the mount enabled"""
mountOffload: Boolean!
#"""Flag for day time tests. It sets all gains to 0"""
#daytimeMode: Boolean!
"""Flag for day time tests. It sets all gains to 0"""
daytimeMode: Boolean!
}

enum LogLevel {
Expand Down
Loading

0 comments on commit 67ca737

Please sign in to comment.