Skip to content

Commit

Permalink
Add guider gain channels
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Jan 12, 2024
1 parent 3174d1d commit ae3e0b6
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ import scala.concurrent.duration.FiniteDuration

trait EpicsService[F[_]] {
def getChannel[T](name: String)(using tjt: ToJavaType[T]): Resource[F, Channel[F, T]]
def getChannel[T](top: String, name: String)(using tjt: ToJavaType[T]): Resource[F, Channel[F, T]]
}

object EpicsService {

final class EpicsServiceImpl[F[_]: Async](ctx: Context) extends EpicsService[F] {
override def getChannel[T](
def getChannel[T](
name: String
)(using tjt: ToJavaType[T]): Resource[F, Channel[F, T]] = Resource
.make(
Async[F]
.delay(ctx.createChannel[tjt.javaType](name, tjt.clazz))
)(c => Async[F].delay(c.close()))
.map(x => Channel.build[F, T, tjt.javaType](x)(Async[F], tjt.convert))

def getChannel[T](top: String, name: String)(using
tjt: ToJavaType[T]
): Resource[F, Channel[F, T]] =
getChannel(s"$top$name")

}

case class Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ case class TcsChannels[F[_]](
m2GuideReset: Channel[F, CadDirective],
mountGuide: MountGuideChannels[F],
oiwfs: WfsChannels[F],
guide: GuideConfigStatusChannels[F]
guide: GuideConfigStatusChannels[F],
guiderGains: GuiderGainsChannels[F]
)

object TcsChannels {
Expand Down Expand Up @@ -190,6 +191,21 @@ object TcsChannels {
follow: Channel[F, String]
)

case class GuiderGainsChannels[F[_]](
p1tipGain: Channel[F, Double],
p1tiltGain: Channel[F, Double],
p1FocusGain: Channel[F, Double],
p1Reset: Channel[F, BinaryYesNo],
p2tipGain: Channel[F, Double],
p2tiltGain: Channel[F, Double],
p2FocusGain: Channel[F, Double],
p2Reset: Channel[F, BinaryYesNo],
oitipGain: Channel[F, Double],
oitiltGain: Channel[F, Double],
oiFocusGain: Channel[F, Double],
oiReset: Channel[F, BinaryYesNo]
)

// Build functions to construct each epics channel for each
// channels group
def buildEnclosureChannels[F[_]](
Expand Down Expand Up @@ -493,6 +509,40 @@ object TcsChannels {
)
}

object GuiderGains {
def build[F[_]](
service: EpicsService[F],
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")
} yield GuiderGainsChannels(
p1tipGain,
p1tiltGain,
p1FocusGain,
p1Reset,
p2tipGain,
p2tiltGain,
p2FocusGain,
p2Reset,
oitipGain,
oitiltGain,
oiFocusGain,
oiReset
)
}

/**
* Build all TcsChannels It will construct the desired raw channel or call the build function for
* channels group
Expand Down Expand Up @@ -531,6 +581,7 @@ object TcsChannels {
mng <- MountGuideChannels.build(service, top)
oi <- WfsChannels.build(service, top, "oiwfs", "oi")
gd <- GuideConfigStatusChannels.build(service, top)
gg <- GuiderGains.build(service, top)
} yield TcsChannels[F](
tt,
tpd,
Expand All @@ -557,6 +608,7 @@ object TcsChannels {
m2gr,
mng,
oi,
gd
gd,
gg
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import navigate.server.epicsdata.BinaryOnOff
import navigate.server.epicsdata.BinaryYesNo
import navigate.server.tcs.TcsChannels.EnclosureChannels
import navigate.server.tcs.TcsChannels.GuideConfigStatusChannels
import navigate.server.tcs.TcsChannels.GuiderGainsChannels
import navigate.server.tcs.TcsChannels.M1GuideConfigChannels
import navigate.server.tcs.TcsChannels.M2GuideConfigChannels
import navigate.server.tcs.TcsChannels.MountGuideChannels
Expand Down Expand Up @@ -172,6 +173,38 @@ object TestTcsEpicsSystem {
)
}

case class GuiderGainsState(
p1tipGain: TestChannel.State[Double],
p1tiltGain: TestChannel.State[Double],
p1FocusGain: TestChannel.State[Double],
p1Reset: TestChannel.State[BinaryYesNo],
p2tipGain: TestChannel.State[Double],
p2tiltGain: TestChannel.State[Double],
p2FocusGain: TestChannel.State[Double],
p2Reset: TestChannel.State[BinaryYesNo],
oitipGain: TestChannel.State[Double],
oitiltGain: TestChannel.State[Double],
oiFocusGain: TestChannel.State[Double],
oiReset: TestChannel.State[BinaryYesNo]
)

object GuiderGainsState {
val default: GuiderGainsState = GuiderGainsState(
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default,
TestChannel.State.default
)
}

case class State(
telltale: TestChannel.State[String],
telescopeParkDir: TestChannel.State[CadDirective],
Expand All @@ -198,7 +231,8 @@ object TestTcsEpicsSystem {
m2GuideConfig: M2GuideConfigState,
m2GuideReset: TestChannel.State[CadDirective],
mountGuide: MountGuideState,
guideStatus: GuideConfigState
guideStatus: GuideConfigState,
guiderGains: GuiderGainsState
)

val defaultState: State = State(
Expand Down Expand Up @@ -299,7 +333,8 @@ object TestTcsEpicsSystem {
m2GuideConfig = M2GuideConfigState.default,
m2GuideReset = TestChannel.State.default,
mountGuide = MountGuideState.default,
guideStatus = GuideConfigState.default
guideStatus = GuideConfigState.default,
guiderGains = GuiderGainsState.default
)

def buildEnclosureChannels[F[_]: Applicative](s: Ref[F, State]): EnclosureChannels[F] =
Expand Down Expand Up @@ -632,6 +667,23 @@ object TestTcsEpicsSystem {
)
)

def buildGuiderGainsChannels[F[_]: Applicative](
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, 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, 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, BinaryYesNo](s, l.andThen(Focus[GuiderGainsState](_.oiReset)))
)
def buildChannels[F[_]: Applicative](s: Ref[F, State]): TcsChannels[F] =
TcsChannels(
telltale =
Expand Down Expand Up @@ -661,7 +713,8 @@ object TestTcsEpicsSystem {
m2GuideReset = new TestChannel[F, State, CadDirective](s, Focus[State](_.m2GuideReset)),
mountGuide = buildMountGuideChannels(s, Focus[State](_.mountGuide)),
oiwfs = buildWfsChannels(s, Focus[State](_.oiWfs)),
guide = buildGuideStateChannels(s, Focus[State](_.guideStatus))
guide = buildGuideStateChannels(s, Focus[State](_.guideStatus)),
guiderGains = buildGuiderGainsChannels(s, Focus[State](_.guiderGains))
)

def build[F[_]: Monad: Parallel](s: Ref[F, State]): TcsEpicsSystem[F] =
Expand Down
4 changes: 3 additions & 1 deletion modules/web/server/src/main/resources/NewTCC.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +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!
}

enum LogLevel {
Expand Down Expand Up @@ -208,4 +210,4 @@ type Mutation {
type Subscription {
logMessage: LogMessage!
guideState: GuideConfigurationState!
}
}

0 comments on commit ae3e0b6

Please sign in to comment.