From ac4c92faba7f1c94f101a0e7d6c0a7beef6610fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Sat, 12 Aug 2023 05:06:26 +0000 Subject: [PATCH] Add timeouts for TAN devices --- src/gort/devices/telescope.py | 54 ++++++++++++++++++++++++++--------- src/gort/etc/lvmgort.yml | 14 +++++++++ 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/gort/devices/telescope.py b/src/gort/devices/telescope.py index 7dcabb8..986fe5c 100644 --- a/src/gort/devices/telescope.py +++ b/src/gort/devices/telescope.py @@ -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"] @@ -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.""" @@ -58,7 +68,7 @@ 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): @@ -66,7 +76,7 @@ async def park(self): 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): @@ -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. @@ -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() @@ -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): @@ -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): @@ -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): @@ -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]: @@ -211,7 +233,10 @@ 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.""" @@ -219,7 +244,10 @@ async def move_relative(self, steps: float): 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): diff --git a/src/gort/etc/lvmgort.yml b/src/gort/etc/lvmgort.yml index 486ae24..0c83c94 100644 --- a/src/gort/etc/lvmgort.yml +++ b/src/gort/etc/lvmgort.yml @@ -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]