Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-46165: Removed optical configuration from enums #56

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/lsst/ts/tunablelaser/canbus_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"MidiOPG",
"E5DCB",
]

import logging

from . import interfaces
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ts/tunablelaser/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def set_optical_configuration(self, optical_configuration):

Parameters
----------
optical_configuration: `str`, {straight-through,F1,F2}
optical_configuration: `str`, OpticalConfiguration(enum.StrEnum)
The optical alignment to switch to.
"""
self.maxi_opg.optical_alignment = optical_configuration
Expand Down
6 changes: 4 additions & 2 deletions python/lsst/ts/tunablelaser/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

import yaml

from .enums import OpticalConfiguration

CONFIG_SCHEMA = yaml.safe_load(
"""
f"""
$schema: http://json-schema.org/draft-07/schema#
$id: https://github.com/lsst-ts/ts_TunableLaser/blob/master/schema/TunableLaser.yaml
title: TunableLaser v4
Expand All @@ -46,7 +48,7 @@
type: number
optical_configuration:
description: The mirror alignment configuration for the laser
enum: ["SCU","No SCU","F1 SCU","F1 No SCU","F2 SCU","F2 No SCU"]
enum: {[e.value for e in OpticalConfiguration]}
wavelength:
description: The min and max wavelengths for the laser
type: object
Expand Down
54 changes: 31 additions & 23 deletions python/lsst/ts/tunablelaser/csc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import asyncio

from lsst.ts import salobj, utils
from lsst.ts.xml.enums import TunableLaser
from lsst.ts.xml.enums.TunableLaser import LaserDetailedState, LaserErrorCode

from . import __version__, component, mock_server
from .config_schema import CONFIG_SCHEMA
from .enums import OpticalConfiguration


def run_tunablelaser():
Expand Down Expand Up @@ -119,7 +120,7 @@ async def telemetry(self):
or self.model.m_cpu800.power_register_2.register_value == "FAULT"
):
await self.fault(
code=TunableLaser.LaserErrorCode.HW_CPU_ERROR,
code=LaserErrorCode.HW_CPU_ERROR,
report=(
f"cpu8000 fault:{self.model.cpu8000.fault_register.register_value}"
f"m_cpu800 fault:{self.model.m_cpu800.fault_register.register_value}"
Expand Down Expand Up @@ -166,7 +167,7 @@ def assert_substate(self, substates, action):

"""
if self.evt_detailedState.data.detailedState not in [
TunableLaser.LaserDetailedState(substate) for substate in substates
LaserDetailedState(substate) for substate in substates
]:
raise salobj.ExpectedError(
f"{action} not allowed in state {self.evt_detailedState.data.detailedState!r}"
Expand Down Expand Up @@ -195,7 +196,7 @@ async def handle_summary_state(self):

if not self.connected and self.model is not None:
await self.evt_detailedState.set_write(
detailedState=TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
detailedState=LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
)
try:
await self.model.connect()
Expand All @@ -212,7 +213,7 @@ async def handle_summary_state(self):
):
await self.model.stop_propagating()
await self.publish_new_detailed_state(
TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
)
if self.telemetry_task.done():
self.telemetry_task = asyncio.create_task(self.telemetry())
Expand Down Expand Up @@ -245,18 +246,18 @@ async def do_setBurstMode(self, data):
await self.model.set_burst_mode(data.count)
await self.evt_burstModeSet.set_write()
if self.evt_detailedState.data.detailedState in [
TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE,
TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE,
LaserDetailedState.PROPAGATING_BURST_MODE,
LaserDetailedState.PROPAGATING_CONTINUOUS_MODE,
]:
await self.publish_new_detailed_state(
TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE
LaserDetailedState.PROPAGATING_BURST_MODE
)
if self.evt_detailedState.data.detailedState in [
TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE,
TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE,
LaserDetailedState.NONPROPAGATING_BURST_MODE,
LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE,
]:
await self.publish_new_detailed_state(
TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE
LaserDetailedState.NONPROPAGATING_BURST_MODE
)
else:
raise salobj.ExpectedError("Not connected.")
Expand Down Expand Up @@ -303,8 +304,8 @@ async def do_startPropagateLaser(self, data):
self.assert_enabled()
self.assert_substate(
[
TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE,
TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE,
LaserDetailedState.NONPROPAGATING_BURST_MODE,
LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE,
],
"startPropagateLaser",
)
Expand All @@ -324,26 +325,26 @@ async def do_stopPropagateLaser(self, data):
self.assert_enabled()
self.assert_substate(
[
TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE,
TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE,
LaserDetailedState.PROPAGATING_BURST_MODE,
LaserDetailedState.PROPAGATING_CONTINUOUS_MODE,
],
"stopPropagateLaser",
)
if self.connected:
await self.model.stop_propagating()
if (
self.evt_detailedState.data.detailedState
== TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE
== LaserDetailedState.PROPAGATING_BURST_MODE
):
await self.publish_new_detailed_state(
TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE
LaserDetailedState.NONPROPAGATING_BURST_MODE
)
elif (
self.evt_detailedState.data.detailedState
== TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE
== LaserDetailedState.PROPAGATING_CONTINUOUS_MODE
):
await self.publish_new_detailed_state(
TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE
)
else:
raise salobj.ExpectedError("Not connected.")
Expand All @@ -366,7 +367,7 @@ async def do_triggerBurst(self, data):
"""Trigger a burst."""
self.assert_enabled()
self.assert_substate(
[TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE],
[LaserDetailedState.PROPAGATING_BURST_MODE],
"Trigger",
)
await self.model.trigger_burst()
Expand Down Expand Up @@ -403,11 +404,18 @@ async def do_setOpticalConfiguration(self, data):
alignment of the laser.
"""
self.assert_enabled()
try:
configuration = OpticalConfiguration(data.configuration)
except Exception:
raise salobj.ExpectedError(
f"Optical Configuration {data.configuration} not included in allowable options"
)

if self.connected:
if self.laser_type == "Main": # only main laser can do this
await self.model.set_optical_configuration(data.configuration)
await self.model.set_optical_configuration(configuration)
await self.evt_opticalConfiguration.set_write(
configuration=data.configuration
configuration=configuration
)
else:
raise salobj.ExpectedError("Not connected")
Expand All @@ -420,7 +428,7 @@ async def publish_new_detailed_state(self, new_sub_state):
new_sub_state : `LaserDetailedState`
The new sub state to publish.
"""
new_sub_state = TunableLaser.LaserDetailedState(new_sub_state)
new_sub_state = LaserDetailedState(new_sub_state)
await self.evt_detailedState.set_write(detailedState=new_sub_state)

async def configure(self, config):
Expand Down
39 changes: 24 additions & 15 deletions python/lsst/ts/tunablelaser/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__all__ = ["Power", "Mode", "Output", "OpticalConfiguration"]

import enum
import warnings


class Power(enum.StrEnum):
Expand Down Expand Up @@ -33,18 +34,26 @@ class Output(enum.StrEnum):
"""Maximum energy level for the laser."""


class OpticalConfiguration(enum.StrEnum):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you leave this alone for now and just add a note here to remove this enum and use the one from ts-xml once that is available. The way you are going about this is a bit awkward.

If you want to automatically switch the ts-xml once it is available, you can re-export it from here adding the try/except you included in the other files here and leaving the OpticalConfiguration entry in the __all__ list above.

"""Configuration of the optical output"""

SCU = "SCU"
"""Pass the beam straight-through the SCU."""
F1_SCU = "F1 SCU"
"""Direct the beam through the F1 after passing through the SCU."""
F2_SCU = "F2 SCU"
"""Direct the beam through the F2 after passing through the SCU."""
NO_SCU = "No SCU"
"""Pass the beam straight-through."""
F1_NO_SCU = "F1 No SCU"
"""Pass the beam to F1 output."""
F2_NO_SCU = "F2 No SCU"
"""Pass the beam to F2 output."""
# TODO: (DM-46168) Revert workaround for TunableLaser XML changes
try:
from lsst.ts.xml.enums.TunableLaser import OpticalConfiguration
except ImportError:
warnings.warn(
"OpticalConfiguration enumeration not availble in ts-xml. Using local version."
)

class OpticalConfiguration(enum.StrEnum):
"""Configuration of the optical output"""

SCU = "SCU"
"""Pass the beam straight-through the SCU."""
F1_SCU = "F1 SCU"
"""Direct the beam through the F1 after passing through the SCU."""
F2_SCU = "F2 SCU"
"""Direct the beam through the F2 after passing through the SCU."""
NO_SCU = "No SCU"
"""Pass the beam straight-through."""
F1_NO_SCU = "F1 No SCU"
"""Pass the beam to F1 output."""
F2_NO_SCU = "F2 No SCU"
"""Pass the beam to F2 output."""