From 6e8c1b50a418c4e5da5162dd8b70c9f2c671f120 Mon Sep 17 00:00:00 2001 From: gmegh Date: Sat, 7 Oct 2023 14:47:30 +0900 Subject: [PATCH] Add apply_dof script --- .../ts/standardscripts/maintel/apply_dof.py | 430 ++++++++++++++++++ 1 file changed, 430 insertions(+) create mode 100644 python/lsst/ts/standardscripts/maintel/apply_dof.py diff --git a/python/lsst/ts/standardscripts/maintel/apply_dof.py b/python/lsst/ts/standardscripts/maintel/apply_dof.py new file mode 100644 index 000000000..364303b23 --- /dev/null +++ b/python/lsst/ts/standardscripts/maintel/apply_dof.py @@ -0,0 +1,430 @@ +# This file is part of ts_standardscripts +# +# Developed for the LSST Telescope and Site Systems. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__all__ = ["ApplyDOF"] + +import typing + +import numpy as np +import yaml +from lsst.ts import salobj +from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages +from lsst.ts.observatory.control.utils.enums import DOFName + + +class ApplyDOF(salobj.BaseScript): + """Apply a DOF to the main telescope, either bending + mode or hexapod offset. + + Parameters + ---------- + index : `int` + Index of Script SAL component. + + Notes + ----- + **Checkpoints** + "Applying DOF offset..." - The DOF offset is being applied. + + """ + + def __init__(self, index, add_remotes: bool = True) -> None: + super().__init__( + index=index, + descr="Apply an offset to the degrees of freedom of the main telescope.", + ) + + # Create the MTCS object + self.mtcs = None + + # Set the add_remotes flag + self.add_remotes = add_remotes + + # Create the DOF vector + self.dofs = np.zeros(50) + + async def configure_tcs(self) -> None: + """Handle creating MTCS object and waiting for remote to start.""" + if self.mtcs is None: + self.log.debug("Creating MTCS.") + mtcs_usage = None if self.add_remotes else MTCSUsages.DryTest + self.mtcs = MTCS( + domain=self.domain, + intended_usage=mtcs_usage, + log=self.log, + ) + await self.mtcs.start_task + else: + self.log.debug("MTCS already defined, skipping.") + + @classmethod + def get_schema(cls) -> typing.Dict[str, typing.Any]: + schema_yaml = """ + $schema: http://json-schema.org/draft-07/schema# + $id: https://github.com/lsst-ts/ts_standardscripts/maintel/ApplyDOF.yaml + title: ApplyDOF v1 + description: Configuration for ApplyDOF Script. + type: object + properties: + M2_dz: + type: number + description: >- + Defines the offset applied to the M2 hexapod in the z direction. + Units in um. + default: 0.0 + M2_dx: + type: number + description: >- + Defines the offset applied to the M2 hexapod in the x direction. + Units in um. + default: 0.0 + M2_dy: + type: number + description: >- + Defines the offset applied to the M2 hexapod in the y direction. + Units in um. + default: 0.0 + M2_rx: + type: number + description: >- + Defines the offset applied to the M2 hexapod in rx. + Units in arcsec. + default: 0.0 + M2_ry: + type: number + description: >- + Defines the offset applied to the M2 hexapod in ry. + Units in arcsec. + default: 0.0 + Cam_dz: + type: number + description: >- + Defines the offset applied to the Camera hexapod in + the z direction. Units in um. + default: 0.0 + Cam_dx: + type: number + description: >- + Defines the offset applied to the Camera hexapod + in the x direction. Units in um. + default: 0.0 + Cam_dy: + type: number + description: >- + Defines the offset applied to the Camera hexapod in + the y direction. Units in um. + default: 0.0 + Cam_rx: + type: number + description: >- + Defines the offset applied to the Camera hexapod in rx. + Units in arcsec. + default: 0.0 + Cam_ry: + type: number + description: >- + Defines the offset applied to the Camera hexapod in ry. + Units in arcsec. + default: 0.0 + M1M3_B1: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 1. + Units in um. + default: 0.0 + M1M3_B2: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 2. + Units in um. + default: 0.0 + M1M3_B3: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 3. + Units in um. + default: 0.0 + M1M3_B4: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 4. + Units in um. + default: 0.0 + M1M3_B5: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 5. + Units in um. + default: 0.0 + M1M3_B6: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 6. + Units in um. + default: 0.0 + M1M3_B7: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 7. + Units in um. + default: 0.0 + M1M3_B8: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 8. + Units in um. + default: 0.0 + M1M3_B9: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 9. + Units in um. + default: 0.0 + M1M3_B10: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 10. + Units in um. + default: 0.0 + M1M3_B11: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 11. + Units in um. + default: 0.0 + M1M3_B12: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 12. + Units in um. + default: 0.0 + M1M3_B13: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 13. + Units in um. + default: 0.0 + M1M3_B14: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 14. + Units in um. + default: 0.0 + M1M3_B15: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 15. + Units in um. + default: 0.0 + M1M3_B16: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 16. + Units in um. + default: 0.0 + M1M3_B17: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 17. + Units in um. + default: 0.0 + M1M3_B18: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 18. + Units in um. + default: 0.0 + M1M3_B19: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 19. + Units in um. + default: 0.0 + M1M3_B20: + type: number + description: >- + Defines the offset applied to the M1M3 bending mode 20. + Units in um. + default: 0.0 + M2_B1: + type: number + description: >- + Defines the offset applied to the M2 bending mode 1. + Units in um. + default: 0.0 + M2_B2: + type: number + description: >- + Defines the offset applied to the M2 bending mode 2. + Units in um. + default: 0.0 + M2_B3: + type: number + description: >- + Defines the offset applied to the M2 bending mode 3. + Units in um. + default: 0.0 + M2_B4: + type: number + description: >- + Defines the offset applied to the M2 bending mode 4. + Units in um. + default: 0.0 + M2_B5: + type: number + description: >- + Defines the offset applied to the M2 bending mode 5. + Units in um. + default: 0.0 + M2_B6: + type: number + description: >- + Defines the offset applied to the M2 bending mode 6. + Units in um. + default: 0.0 + M2_B7: + type: number + description: >- + Defines the offset applied to the M2 bending mode 7. + Units in um. + default: 0.0 + M2_B8: + type: number + description: >- + Defines the offset applied to the M2 bending mode 8. + Units in um. + default: 0.0 + M2_B9: + type: number + description: >- + Defines the offset applied to the M2 bending mode 9. + Units in um. + default: 0.0 + M2_B10: + type: number + description: >- + Defines the offset applied to the M2 bending mode 10. + Units in um. + default: 0.0 + M2_B11: + type: number + description: >- + Defines the offset applied to the M2 bending mode 11. + Units in um. + default: 0.0 + M2_B12: + type: number + description: >- + Defines the offset applied to the M2 bending mode 12. + Units in um. + default: 0.0 + M2_B13: + type: number + description: >- + Defines the offset applied to the M2 bending mode 13. + Units in um. + default: 0.0 + M2_B14: + type: number + description: >- + Defines the offset applied to the M2 bending mode 14. + Units in um. + default: 0.0 + M2_B15: + type: number + description: >- + Defines the offset applied to the M2 bending mode 15. + Units in um. + default: 0.0 + M2_B16: + type: number + description: >- + Defines the offset applied to the M2 bending mode 16. + Units in um. + default: 0.0 + M2_B17: + type: number + description: >- + Defines the offset applied to the M2 bending mode 17. + Units in um. + default: 0.0 + M2_B18: + type: number + description: >- + Defines the offset applied to the M2 bending mode 18. + Units in um. + default: 0.0 + M2_B19: + type: number + description: >- + Defines the offset applied to the M2 bending mode 19. + Units in um. + default: 0.0 + M2_B20: + type: number + description: >- + Defines the offset applied to the M2 bending mode 20. + Units in um. + default: 0.0 + additionalProperties: false + """ + return yaml.safe_load(schema_yaml) + + async def configure(self, config) -> None: + """Configure script. + + Parameters + ---------- + config : `types.SimpleNamespace` + Script configuration, as defined by `schema`. + """ + + # Configure tcs and camera + await self.configure_tcs() + + # Loop through properties and assign their values to the vector + for key, value in vars(config).items(): + self.dofs[getattr(DOFName, key)] = value + + def set_metadata(self, metadata) -> None: + """Set script metadata. + + Parameters + ---------- + metadata : `lsst.ts.salobj.base.ScriptMetadata` + Script metadata. + """ + metadata.duration = 10 + + async def assert_feasibility(self) -> None: + """Verify that the telescope is in a feasible state to + execute the script. + """ + + await self.mtcs.assert_all_enabled() + + async def run(self) -> None: + """Run script.""" + # Assert feasibility + await self.assert_feasibility() + + await self.checkpoint("Applying DOF offset...") + await self.mtcs.mtaos.cmd_offsetDOF(self.dofs)