Skip to content

Commit

Permalink
Skip daytime check for dome opening if PLC overrides are active
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 7, 2025
1 parent bcdc254 commit 71a8daf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* Added PLC engineering mode status bits to the configuration file.
* If the dome is moving when commanded to open/close, the movement will be stopped before actually open or close.
* Daytime check for dome opening will be ignored if the PLC hardware or software overrides are active.

### 🔧 Fixed

Expand Down
12 changes: 5 additions & 7 deletions python/lvmecp/dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def open(self, force: bool = False):

self._open_attempt_times.append(time())

if not self.is_allowed():
if not await self.is_allowed():
raise DomeError("Dome is not allowed to open.")

await self._move(True, force=force)
Expand Down Expand Up @@ -238,14 +238,12 @@ async def reset(self):
await self.modbus["dome_error_reset"].write(True)
await asyncio.sleep(0.5)

def is_allowed(self):
async def is_allowed(self):
"""Returns whether the dome is allowed to move."""

if self.plc._actor and self.plc._actor._engineering_mode:
self.plc._actor.write(
"w",
text="Skipping dome checks due to engineering mode.",
)
if await self.plc.safety.engineering_mode_active():
if actor := self.plc._actor:
actor.write("w", text="Engineering mode active.")
return True

if not config["dome.daytime_allowed"] and self.is_daytime():
Expand Down
24 changes: 24 additions & 0 deletions python/lvmecp/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ async def is_remote(self):

return not (self.status & self.flag.LOCAL)

async def engineering_mode_active(self, include_plc_overrides: bool = True):
"""Returns :obj:`True` if engineering mode is active.
With ``include_plc_overrides=True``, the function will return
:obj:`True` if the lvmecp engineering mode is active or the PLC
software or hardware overrides are active.
"""

if self.plc._actor is not None and self.plc._actor._engineering_mode:
return True

if include_plc_overrides is False:
return False

await self.update(use_cache=False)

plc_hw = await self.plc.modbus.read_register("engineering_mode_hardware_status")
plc_sw = await self.plc.modbus.read_register("engineering_mode_software_status")

if plc_hw or plc_sw:
return True

return False

async def emergency_stop(self):
"""Triggers an emergency stop."""

Expand Down
18 changes: 18 additions & 0 deletions tests/test_command_dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,21 @@ async def test_dome_open_with_safety_alerts(

assert cmd.status.did_fail
assert "E-stops are pressed" in cmd.replies.get("error")


async def test_dome_open_during_daytime_plc_override(
actor: ECPActor, context: ModbusSlaveContext, mocker: MockerFixture
):
mocker.patch.object(actor.plc.dome, "is_daytime", return_value=True)
move_patch = mocker.patch.object(actor.plc.dome, "_move")

context.setValues(
1,
actor.plc.modbus["engineering_mode_hardware_status"].address,
[1],
)

cmd = await actor.invoke_mock_command("dome open")
await cmd

move_patch.assert_called()

0 comments on commit 71a8daf

Please sign in to comment.