Skip to content

Commit

Permalink
Prevent race conditins dome open vs drive disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jul 26, 2024
1 parent a9cd0cb commit 4d42ee7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions python/lvmecp/dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import asyncio
import warnings
from time import time
from types import SimpleNamespace

from lvmecp import log
Expand Down Expand Up @@ -118,21 +119,26 @@ async def _move(self, open: bool, force: bool = False):
await self.modbus["drive_enabled"].set(True)

await asyncio.sleep(0.5)

last_enabled: float = 0.0
while True:
# Still moving.
await asyncio.sleep(2)

drive_enabled = await self.modbus["drive_enabled"].get()
move_done = await self.modbus["dome_open" if open else "dome_closed"].get()

if drive_enabled:
last_enabled = time()

if not drive_enabled and move_done:
break

if not drive_enabled:
# This usually means the movement has been stopped.
raise DomeError(
"Dome drive has been disabled. Was the dome was stopped."
)
# Check if the drive is not enabled for more than 5 seconds without the
# movement being done. This usually means the dome has been manually
# stopped.
if not drive_enabled and (time() - last_enabled) > 5:
raise DomeError("Dome drive has been disabled.")

await self.update(use_cache=False)

Expand Down

0 comments on commit 4d42ee7

Please sign in to comment.