Skip to content

Commit 08207a8

Browse files
authored
v1.4.0
version 1.4.0
2 parents 15ba5c9 + 4a6fec2 commit 08207a8

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

pyobs_pilar/pilartelescope.py

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
self._temperatures = temperatures if temperatures else {}
6565
self._fix_telescope_time_error = fix_telescope_time_error
6666
self._has_filterwheel = has_filterwheel
67+
self._block_status_change = asyncio.Lock()
6768

6869
# pilar
6970
self._pilar_connect = host, port, username, password
@@ -215,25 +216,26 @@ async def _pilar_update(self) -> None:
215216
else:
216217
await self.set_state(ModuleState.READY)
217218

218-
# we always set PARKED, INITIALIZING, ERROR, the others only on init
219-
if float(self._status["TELESCOPE.READY_STATE"]) == 0.0:
220-
await self._change_motion_status(MotionStatus.PARKED)
221-
elif 0.0 < float(self._status["TELESCOPE.READY_STATE"]) < 1.0:
222-
await self._change_motion_status(MotionStatus.INITIALIZING)
223-
else:
224-
# only check motion state, if currently in an undefined state, error or initializing
225-
if await self.get_motion_status() in [MotionStatus.UNKNOWN, MotionStatus.ERROR, MotionStatus.INITIALIZING]:
226-
# telescope is initialized, check motion state
227-
ms = int(self._status["TELESCOPE.MOTION_STATE"])
228-
if ms & (1 << 1):
229-
# second bit indicates tracking
230-
await self._change_motion_status(MotionStatus.TRACKING)
231-
elif ms & (1 << 0):
232-
# first bit indicates moving
233-
await self._change_motion_status(MotionStatus.SLEWING)
234-
else:
235-
# otherwise we're idle
236-
await self._change_motion_status(MotionStatus.IDLE)
219+
if not self._block_status_change.locked():
220+
# we always set PARKED, INITIALIZING, ERROR, the others only on init
221+
if float(self._status["TELESCOPE.READY_STATE"]) == 0.0:
222+
await self._change_motion_status(MotionStatus.PARKED)
223+
elif 0.0 < float(self._status["TELESCOPE.READY_STATE"]) < 1.0:
224+
await self._change_motion_status(MotionStatus.INITIALIZING)
225+
else:
226+
# only check motion state, if currently in an undefined state, error or initializing
227+
if await self.get_motion_status() in [MotionStatus.UNKNOWN, MotionStatus.ERROR, MotionStatus.INITIALIZING]:
228+
# telescope is initialized, check motion state
229+
ms = int(self._status["TELESCOPE.MOTION_STATE"])
230+
if ms & (1 << 1):
231+
# second bit indicates tracking
232+
await self._change_motion_status(MotionStatus.TRACKING)
233+
elif ms & (1 << 0):
234+
# first bit indicates moving
235+
await self._change_motion_status(MotionStatus.SLEWING)
236+
else:
237+
# otherwise we're idle
238+
await self._change_motion_status(MotionStatus.IDLE)
237239

238240
# sleep a second
239241
await asyncio.sleep(1)
@@ -668,21 +670,22 @@ async def init(self, **kwargs: Any) -> None:
668670

669671
# acquire lock
670672
async with LockWithAbort(self._lock_moving, self._abort_move):
671-
# init telescope
672-
log.info("Initializing telescope...")
673-
await self._change_motion_status(MotionStatus.INITIALIZING)
674-
if not await self._pilar.init():
675-
await self._change_motion_status(MotionStatus.ERROR)
676-
raise ValueError("Could not initialize telescope.")
677-
678-
# init filter wheel
679-
if self._has_filterwheel:
680-
log.info("Initializing filter wheel...")
681-
await self.set_filter(self._filters[-1])
682-
await self.set_filter("clear")
683-
684-
# finished, send event
685-
await self._change_motion_status(MotionStatus.IDLE)
673+
async with self._block_status_change:
674+
# init telescope
675+
log.info("Initializing telescope...")
676+
await self._change_motion_status(MotionStatus.INITIALIZING)
677+
if not await self._pilar.init():
678+
await self._change_motion_status(MotionStatus.ERROR)
679+
raise ValueError("Could not initialize telescope.")
680+
681+
# init filter wheel
682+
if self._has_filterwheel:
683+
log.info("Initializing filter wheel...")
684+
await self.set_filter(self._filters[-1])
685+
await self.set_filter("clear")
686+
687+
# finished, send event
688+
await self._change_motion_status(MotionStatus.IDLE)
686689

687690
@timeout(300000)
688691
async def park(self, **kwargs: Any) -> None:
@@ -702,16 +705,17 @@ async def park(self, **kwargs: Any) -> None:
702705

703706
# acquire lock
704707
async with LockWithAbort(self._lock_moving, self._abort_move):
705-
# reset all offsets
706-
await self._reset_offsets()
707-
708-
# park telescope
709-
log.info("Parking telescope...")
710-
await self._change_motion_status(MotionStatus.PARKING)
711-
if not await self._pilar.park():
712-
await self._change_motion_status(MotionStatus.ERROR)
713-
raise ValueError("Could not park telescope.")
714-
await self._change_motion_status(MotionStatus.PARKED)
708+
async with self._block_status_change:
709+
# reset all offsets
710+
await self._reset_offsets()
711+
712+
# park telescope
713+
log.info("Parking telescope...")
714+
await self._change_motion_status(MotionStatus.PARKING)
715+
if not await self._pilar.park():
716+
await self._change_motion_status(MotionStatus.ERROR)
717+
raise ValueError("Could not park telescope.")
718+
await self._change_motion_status(MotionStatus.PARKED)
715719

716720
async def get_temperatures(self, **kwargs: Any) -> Dict[str, float]:
717721
"""Returns all temperatures measured by this module.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyobs-pilar"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
description = "pyobs module for Pilar TCS"
55
authors = ["Tim-Oliver Husser <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)