Skip to content

Commit

Permalink
Add check to confirm telescope reached position
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jul 7, 2023
1 parent 255d4b0 commit f2be9d5
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 2 deletions.
102 changes: 101 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typing-extensions = "^4.5.0"
httpx = "^0.24.1"
tqdm = "^4.65.0"
kubernetes = "^26.1.0"
astropy = "^5.3.1"

[tool.poetry.group.dev.dependencies]
ipython = ">=8.0.0"
Expand Down
21 changes: 20 additions & 1 deletion src/gort/telescope.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
from __future__ import annotations

import asyncio
import inspect
from inspect import currentframe, getouterframes

from typing import TYPE_CHECKING

from gort import config
from gort.exceptions import GortTelescopeError
from gort.gort import GortDevice, GortDeviceSet
from gort.tools import get_calibrators, get_next_tile_id
from gort.tools import angular_separation, get_calibrators, get_next_tile_id


if TYPE_CHECKING:
Expand Down Expand Up @@ -367,6 +369,19 @@ async def goto_coordinates(
self.write_to_log(f"Moving to ra={ra:.6f} dec={dec:.6f}.", level="info")
await self.pwi.commands.gotoRaDecJ2000(ra / 15.0, dec)

# Check that we reached the position.
status = await self.status()
ra_status = status["ra_j2000_hours"] * 15
dec_status = status["dec_j2000_degs"]
separation = angular_separation(ra, dec, ra_status, dec_status)
if separation > 0.1:
await self.actor.commands.setEnabled(False)
raise GortTelescopeError(
"Telescope failed to reach desired position. "
"The axes have been disabled for safety. "
"Try re-homing the telescope."
)

elif alt is not None and az is not None:
is_altaz = alt is not None and az is not None and not ra and not dec
assert is_altaz, "Invalid input parameters"
Expand All @@ -378,6 +393,10 @@ async def goto_coordinates(
if altaz_tracking:
await self.pwi.commands.setTracking(enable=True)

status = await self.status()
ra_status = status["altitude_degs"] * 15
dec_status = status["azimuth_degs"] * 15

if kmirror_task is not None and not kmirror_task.done():
await kmirror_task

Expand Down
21 changes: 21 additions & 0 deletions src/gort/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from typing import TYPE_CHECKING, Callable, Coroutine

import httpx
from astropy import units as uu
from astropy.coordinates import angular_separation as astropy_angular_separation

from gort import config

Expand All @@ -40,6 +42,7 @@
"get_ccd_frame_path",
"move_mask_interval",
"radec_sexagesimal_to_decimal",
"angular_separation",
]

CAMERAS = [
Expand Down Expand Up @@ -443,3 +446,21 @@ def radec_sexagesimal_to_decimal(ra: str, dec: str, ra_is_hours: bool = True):
dec_deg -= float(dec_groups[1]) / 60 - float(dec_groups[2]) / 3600

return ra_deg, dec_deg


def angular_separation(lon1: float, lat1: float, lon2: float, lat2: float):
"""A wrapper around astropy's ``angular_separation``.
Returns the separation between two sets of coordinates. All units must
be degrees and the returned values is also the separation in degrees.
"""

separation = astropy_angular_separation(
lon1 * uu.degree, # type: ignore
lat1 * uu.degree, # type: ignore
lon2 * uu.degree, # type: ignore
lat2 * uu.degree, # type: ignore
)

return separation.to("deg").value
3 changes: 3 additions & 0 deletions typings/astropy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
3 changes: 3 additions & 0 deletions typings/astropy/coordinates/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
3 changes: 3 additions & 0 deletions typings/astropy/io/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
3 changes: 3 additions & 0 deletions typings/astropy/io/fits/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
3 changes: 3 additions & 0 deletions typings/astropy/units/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
3 changes: 3 additions & 0 deletions typings/astropy/wcs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...

0 comments on commit f2be9d5

Please sign in to comment.