9
9
from pyobs .modules import timeout
10
10
from pyobs .modules .telescope .basetelescope import BaseTelescope
11
11
from pyobs .utils .enums import MotionStatus
12
- from pyobs .utils .parallel import event_wait
12
+ from pyobs .utils .parallel import event_wait , acquire_lock
13
13
from pyobs .utils .threads import LockWithAbort
14
14
from pyobs .utils import exceptions as exc
15
15
from .device import AlpacaDevice
20
20
class AlpacaTelescope (BaseTelescope , FitsNamespaceMixin , IFitsHeaderBefore , IOffsetsRaDec , ISyncTarget ):
21
21
__module__ = "pyobs_alpaca"
22
22
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 ):
24
24
"""Initializes a new ASCOM Alpaca telescope.
25
25
26
26
Args:
27
27
settle_time: Time in seconds to wait after slew before finishing.
28
+ park_position: Alt/Az park position
28
29
"""
29
30
BaseTelescope .__init__ (self , ** kwargs , motion_status_interfaces = ["ITelescope" ])
30
31
@@ -33,6 +34,7 @@ def __init__(self, settle_time: float = 3.0, **kwargs: Any):
33
34
34
35
# variables
35
36
self ._settle_time = settle_time
37
+ self ._park_position = park_position
36
38
37
39
# offsets in ra/dec
38
40
self ._offset_ra = 0.0
@@ -114,6 +116,9 @@ async def init(self, **kwargs: Any) -> None:
114
116
await self ._change_motion_status (MotionStatus .UNKNOWN )
115
117
raise exc .InitError ("Could not init telescope." )
116
118
119
+ except InterruptedError :
120
+ await self ._change_motion_status (MotionStatus .UNKNOWN )
121
+
117
122
@timeout (60000 )
118
123
async def park (self , ** kwargs : Any ) -> None :
119
124
"""Park telescope.
@@ -138,7 +143,10 @@ async def park(self, **kwargs: Any) -> None:
138
143
139
144
# park telescope
140
145
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
142
150
await self ._device .put ("Park" , timeout = 60 )
143
151
await self ._change_motion_status (MotionStatus .PARKED )
144
152
log .info ("Telescope parked." )
@@ -147,6 +155,9 @@ async def park(self, **kwargs: Any) -> None:
147
155
await self ._change_motion_status (MotionStatus .UNKNOWN )
148
156
raise exc .ParkError ("Could not park telescope." )
149
157
158
+ except InterruptedError :
159
+ await self ._change_motion_status (MotionStatus .UNKNOWN )
160
+
150
161
async def _move_altaz (self , alt : float , az : float , abort_event : asyncio .Event ) -> None :
151
162
"""Actually moves to given coordinates. Must be implemented by derived classes.
152
163
@@ -228,8 +239,17 @@ async def set_offsets_radec(self, dra: float, ddec: float, **kwargs: Any) -> Non
228
239
pyobs.utils.exceptions.MoveError: If offset could not be set.
229
240
"""
230
241
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 :
233
253
# not connected
234
254
if not self ._device .connected :
235
255
raise exc .MoveError ("Not connected to ASCOM." )
@@ -250,33 +270,34 @@ async def set_offsets_radec(self, dra: float, ddec: float, **kwargs: Any) -> Non
250
270
ra += float (self ._offset_ra / np .cos (np .radians (dec )))
251
271
dec += float (self ._offset_dec )
252
272
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 )
257
276
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
263
282
264
- await self ._device .put ("Tracking" , Tracking = True )
283
+ await self ._device .put ("Tracking" , Tracking = True )
265
284
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 )
268
287
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." )
272
291
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 ()
276
298
277
299
async def get_offsets_radec (self , ** kwargs : Any ) -> Tuple [float , float ]:
278
300
"""Get RA/Dec offset.
279
-
280
301
Returns:
281
302
Tuple with RA and Dec offsets.
282
303
"""
0 commit comments