Skip to content

Commit

Permalink
Merge pull request #504 from gemini-hlsw/guider-gains
Browse files Browse the repository at this point in the history
Guider gains
  • Loading branch information
cquiroz authored Jan 16, 2024
2 parents 1775caf + 2f4ca14 commit cb0c45a
Show file tree
Hide file tree
Showing 11 changed files with 590 additions and 152 deletions.
12 changes: 11 additions & 1 deletion modules/epics/src/main/scala/navigate/epics/EpicsService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package navigate.epics
import cats.effect.Async
import cats.effect.Resource
import cats.syntax.option.*
import eu.timepit.refined.types.string.NonEmptyString
import org.epics.ca.Context
import org.epics.ca.impl.LibraryConfiguration.PropertyNames.CA_REPEATER_DISABLE
import org.epics.ca.impl.ProtocolConfiguration.PropertyNames.EPICS_CA_ADDR_LIST
Expand All @@ -21,19 +22,28 @@ 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: NonEmptyString, 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: NonEmptyString, name: String)(using
tjt: ToJavaType[T]
): Resource[F, Channel[F, T]] =
getChannel(s"${top.value}$name")

}

case class Builder(
Expand Down
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
(gains >>> m1)(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
(gains >>> m1)(tcsEpics.startCommand(timeout)).m2GuideCommand
.state(true)
.m2GuideModeCommand
.coma(coma)
Expand Down
Loading

0 comments on commit cb0c45a

Please sign in to comment.