Skip to content

Commit

Permalink
Add timeouts for TAN devices
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 12, 2023
1 parent e9cd88b commit ac4c92f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/gort/devices/telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
from __future__ import annotations

import asyncio
from collections import defaultdict

from typing import TYPE_CHECKING, ClassVar

import numpy

from gort.exceptions import GortTelescopeError
from gort.gort import GortDevice, GortDeviceSet
from gort.gort import GortClient, GortDevice, GortDeviceSet
from gort.tools import angular_separation


if TYPE_CHECKING:
from gort.core import ActorReply
from gort.gort import GortClient


__all__ = ["Telescope", "TelescopeSet", "KMirror", "FibSel", "Focuser", "MoTanDevice"]
Expand All @@ -33,6 +33,16 @@ class MoTanDevice(GortDevice):
#: Artificial delay introduced to prevent all motors to slew at the same time.
SLEW_DELAY: ClassVar[float | dict[str, float]] = 0

def __init__(self, gort: GortClient, name: str, actor: str):
super().__init__(gort, name, actor)

class_name = self.__class__.__name__

timeouts = self.gort.config["telescopes"]["timeouts"].get(class_name.lower())

self.timeouts: defaultdict[str, float | None]
self.timeouts = defaultdict(lambda: None, timeouts)

async def slew_delay(self):
"""Sleeps the :obj:`.SLEW_DELAY` amount."""

Expand All @@ -58,15 +68,15 @@ async def home(self):
await self.slew_delay()

self.write_to_log("Homing k-mirror.", level="info")
await self.actor.commands.moveToHome()
await self.actor.commands.moveToHome(timeout=self.timeouts["moveToHome"])
self.write_to_log("k-mirror homing complete.")

async def park(self):
"""Park the k-mirror at 90 degrees."""

await self.slew_delay()

await self.actor.commands.slewStop()
await self.actor.commands.slewStop(timeout=self.timeouts["slewStop"])
await self.move(90)

async def move(self, degs: float):
Expand All @@ -84,10 +94,14 @@ async def move(self, degs: float):
self.write_to_log(f"Moving k-mirror to {degs:.3f} degrees.", level="info")

self.write_to_log("Stopping slew.")
await self.actor.commands.slewStop()
await self.actor.commands.slewStop(timeout=self.timeouts["slewStop"])

self.write_to_log("Moving k-mirror to absolute position.")
await self.actor.commands.moveAbsolute(degs, "deg")
await self.actor.commands.moveAbsolute(
degs,
"deg",
timeout=self.timeouts["moveAbsolute"],
)

async def slew(self, ra: float, dec: float):
"""Moves the mirror to the position for ``ra, dec`` and starts slewing.
Expand All @@ -102,7 +116,7 @@ async def slew(self, ra: float, dec: float):
"""

self.write_to_log("Stopping slew.")
await self.actor.commands.slewStop()
await self.actor.commands.slewStop(timeout=self.timeouts["slewStop"])

await self.slew_delay()

Expand All @@ -111,7 +125,11 @@ async def slew(self, ra: float, dec: float):
level="info",
)

await self.actor.commands.slewStart(ra / 15.0, dec)
await self.actor.commands.slewStart(
ra / 15.0,
dec,
timeout=self.timeouts["slewStart"],
)


class Focuser(MoTanDevice):
Expand Down Expand Up @@ -141,7 +159,7 @@ async def home(self, restore_position: bool = True):
await self.slew_delay()

self.write_to_log("Homing focuser.", level="info")
await self.actor.commands.moveToHome()
await self.actor.commands.moveToHome(timeout=self.timeouts["moveToHome"])
self.write_to_log("Focuser homing complete.")

if current_position is not None and not numpy.isnan(current_position):
Expand All @@ -154,7 +172,11 @@ async def move(self, dts: float):
await self.slew_delay()

self.write_to_log(f"Moving focuser to {dts:.3f} DT.", level="info")
await self.actor.commands.moveAbsolute(dts, "DT")
await self.actor.commands.moveAbsolute(
dts,
"DT",
timeout=self.timeouts["moveAbsolute"],
)


class FibSel(MoTanDevice):
Expand All @@ -175,7 +197,7 @@ async def home(self):
await self.slew_delay()

self.write_to_log("Homing fibsel.", level="info")
await self.actor.commands.moveToHome()
await self.actor.commands.moveToHome(timeout=self.timeouts["moveToHome"])
self.write_to_log("Fibsel homing complete.")

def list_positions(self) -> list[str]:
Expand Down Expand Up @@ -211,15 +233,21 @@ async def move_to_position(self, position: str | int):
self.write_to_log(f"Moving mask to {steps} DT.", level="info")

await self.slew_delay()
await self.actor.commands.moveAbsolute(steps)
await self.actor.commands.moveAbsolute(
steps,
timeout=self.timeouts["moveAbsolute"],
)

async def move_relative(self, steps: float):
"""Move the mask a number of motor steps relative to the current position."""

self.write_to_log(f"Moving fibre mask {steps} steps.")

await self.slew_delay()
await self.actor.commands.moveRelative(steps)
await self.actor.commands.moveRelative(
steps,
timeout=self.timeouts["moveRelative"],
)


class Telescope(GortDevice):
Expand Down
14 changes: 14 additions & 0 deletions src/gort/etc/lvmgort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ telescopes:
actor: lvm.skyw.pwi
kmirror: lvm.skyw.km
focuser: lvm.skyw.foc
timeouts:
kmirror:
slewStart: 60
slewStop: 5
moveAbsolute: 60
moveToHome: 60
focuser:
moveAbsolute: 60
moveToHome: 60
fibsel:
moveAbsolute: 60
moveRelative: 30
moveToHome: 60

pointing_offsets:
sci: [-1618, -848]
skye: [-251, -15]
Expand Down

0 comments on commit ac4c92f

Please sign in to comment.