Skip to content

Commit 387800e

Browse files
authored
v0.16.4
version 0.16.4
2 parents 3b9c793 + c049b7c commit 387800e

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

pyobs_alpaca/telescope.py

+45-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pyobs.modules import timeout
1010
from pyobs.modules.telescope.basetelescope import BaseTelescope
1111
from pyobs.utils.enums import MotionStatus
12-
from pyobs.utils.parallel import event_wait
12+
from pyobs.utils.parallel import event_wait, acquire_lock
1313
from pyobs.utils.threads import LockWithAbort
1414
from pyobs.utils import exceptions as exc
1515
from .device import AlpacaDevice
@@ -20,11 +20,12 @@
2020
class AlpacaTelescope(BaseTelescope, FitsNamespaceMixin, IFitsHeaderBefore, IOffsetsRaDec, ISyncTarget):
2121
__module__ = "pyobs_alpaca"
2222

23-
def __init__(self, settle_time: float = 3.0, **kwargs: Any):
23+
def __init__(self, settle_time: float = 3.0, park_position: Tuple[float, float] = (180.0, 15.0), **kwargs: Any):
2424
"""Initializes a new ASCOM Alpaca telescope.
2525
2626
Args:
2727
settle_time: Time in seconds to wait after slew before finishing.
28+
park_position: Alt/Az park position
2829
"""
2930
BaseTelescope.__init__(self, **kwargs, motion_status_interfaces=["ITelescope"])
3031

@@ -33,6 +34,7 @@ def __init__(self, settle_time: float = 3.0, **kwargs: Any):
3334

3435
# variables
3536
self._settle_time = settle_time
37+
self._park_position = park_position
3638

3739
# offsets in ra/dec
3840
self._offset_ra = 0.0
@@ -114,6 +116,9 @@ async def init(self, **kwargs: Any) -> None:
114116
await self._change_motion_status(MotionStatus.UNKNOWN)
115117
raise exc.InitError("Could not init telescope.")
116118

119+
except InterruptedError:
120+
await self._change_motion_status(MotionStatus.UNKNOWN)
121+
117122
@timeout(60000)
118123
async def park(self, **kwargs: Any) -> None:
119124
"""Park telescope.
@@ -138,7 +143,10 @@ async def park(self, **kwargs: Any) -> None:
138143

139144
# park telescope
140145
try:
141-
# TODO: add abort event
146+
# first move the telescope to its park position, which can be aborted
147+
await self._move_altaz(self._park_position[1], self._park_position[0], self._abort_move)
148+
149+
# then actually park
142150
await self._device.put("Park", timeout=60)
143151
await self._change_motion_status(MotionStatus.PARKED)
144152
log.info("Telescope parked.")
@@ -147,6 +155,9 @@ async def park(self, **kwargs: Any) -> None:
147155
await self._change_motion_status(MotionStatus.UNKNOWN)
148156
raise exc.ParkError("Could not park telescope.")
149157

158+
except InterruptedError:
159+
await self._change_motion_status(MotionStatus.UNKNOWN)
160+
150161
async def _move_altaz(self, alt: float, az: float, abort_event: asyncio.Event) -> None:
151162
"""Actually moves to given coordinates. Must be implemented by derived classes.
152163
@@ -228,8 +239,17 @@ async def set_offsets_radec(self, dra: float, ddec: float, **kwargs: Any) -> Non
228239
pyobs.utils.exceptions.MoveError: If offset could not be set.
229240
"""
230241

231-
# acquire lock
232-
async with LockWithAbort(self._lock_moving, self._abort_move):
242+
# need to be tracking to set offset
243+
if await self.get_motion_status() != MotionStatus.TRACKING:
244+
log.warning("Can only set offset when tracking.")
245+
return
246+
247+
# try to acquire lock
248+
if not await acquire_lock(self._lock_moving, 5):
249+
log.warning("Could not acquire lock for setting offset.")
250+
return
251+
252+
try:
233253
# not connected
234254
if not self._device.connected:
235255
raise exc.MoveError("Not connected to ASCOM.")
@@ -250,33 +270,34 @@ async def set_offsets_radec(self, dra: float, ddec: float, **kwargs: Any) -> Non
250270
ra += float(self._offset_ra / np.cos(np.radians(dec)))
251271
dec += float(self._offset_dec)
252272

253-
try:
254-
# start slewing
255-
await self._device.put("Tracking", Tracking=True)
256-
await self._device.put("SlewToCoordinatesAsync", RightAscension=ra / 15.0, Declination=dec)
273+
# start slewing
274+
await self._device.put("Tracking", Tracking=True)
275+
await self._device.put("SlewToCoordinatesAsync", RightAscension=ra / 15.0, Declination=dec)
257276

258-
# wait for it
259-
while await self._device.get("Slewing"):
260-
if await event_wait(self._abort_move, 1):
261-
log.info("RA/Dec offset movement aborted.")
262-
return
277+
# wait for it
278+
while await self._device.get("Slewing"):
279+
if await event_wait(self._abort_move, 1):
280+
log.info("RA/Dec offset movement aborted.")
281+
return
263282

264-
await self._device.put("Tracking", Tracking=True)
283+
await self._device.put("Tracking", Tracking=True)
265284

266-
# wait settle time
267-
await event_wait(self._abort_move, self._settle_time)
285+
# wait settle time
286+
await event_wait(self._abort_move, self._settle_time)
268287

269-
# finish slewing
270-
await self._change_motion_status(MotionStatus.TRACKING)
271-
log.info("Reached destination.")
288+
# finish slewing
289+
await self._change_motion_status(MotionStatus.TRACKING)
290+
log.info("Reached destination.")
272291

273-
except ConnectionError:
274-
await self._change_motion_status(MotionStatus.UNKNOWN)
275-
raise exc.MoveError("Could not move telescope to RA/Dec offset.")
292+
except ConnectionError:
293+
await self._change_motion_status(MotionStatus.UNKNOWN)
294+
raise exc.MoveError("Could not move telescope to RA/Dec offset.")
295+
296+
finally:
297+
self._lock_moving.release()
276298

277299
async def get_offsets_radec(self, **kwargs: Any) -> Tuple[float, float]:
278300
"""Get RA/Dec offset.
279-
280301
Returns:
281302
Tuple with RA and Dec offsets.
282303
"""

pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
[tool.poetry]
22
name = "pyobs-alpaca"
3-
version = "0.16.3"
3+
version = "0.16.4"
44
description = "pyobs module for ASCOM Alpaca"
55
authors = ["Tim-Oliver Husser <[email protected]>"]
66
license = "MIT"
77

88
[tool.poetry.dependencies]
99
python = ">=3.9,<3.11"
10-
requests = "^2.26"
1110
numpy = "^1.22.1"
1211
single-source = "^0.2.0"
1312
pyobs-core="^0.16"

0 commit comments

Comments
 (0)