Skip to content

Commit

Permalink
Update MoveRotator and tests with new design for MTCS creation
Browse files Browse the repository at this point in the history
  • Loading branch information
b1quint committed Oct 20, 2023
1 parent 3622dde commit 056c5f4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
42 changes: 29 additions & 13 deletions python/lsst/ts/standardscripts/maintel/mtrotator/move_rotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__all__ = ["MoveRotator"]

import yaml
from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages
from lsst.ts.observatory.control.maintel.mtcs import MTCS

from ...base_block_script import BaseBlockScript

Expand All @@ -49,15 +49,7 @@ class MoveRotator(BaseBlockScript):
def __init__(self, index: int, add_remotes: bool = True) -> None:
super().__init__(index=index, descr="Move Rotator")

self.mtcs = MTCS(
domain=self.domain,
intended_usage=None if add_remotes else MTCSUsages.DryTest,
log=self.log,
)

for comp in self.mtcs.components_attr:
if comp not in ["mtrotator", "mtmount"]:
setattr(self.mtcs.check, comp, False)
self.mtcs = None

self.rotator_velocity = 3.5 # degrees per second
self.short_timeout = 10 # seconds
Expand Down Expand Up @@ -105,22 +97,46 @@ def get_schema(cls):
return schema_dict

async def configure(self, config):
"""
Configure the script.
Parameters
----------
config : `dict`
Dictionary containing the configuration parameters.
"""
await self.configure_tcs()

self.target_angle = config.angle
self.wait_for_complete = config.wait_for_complete

await super().configure(config=config)

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.")
self.mtcs = MTCS(
domain=self.domain,
log=self.log,
)
await self.mtcs.start_task
else:
self.log.debug("MTCS already defined, skipping.")

def set_metadata(self, metadata):
"""Set the metadata for the script."""
metadata.duration = self.long_timeout

async def run_block(self):
"""Run the script."""
await self.checkpoint(f"Start moving rotator to {self.target_angle} degrees.")
await self.mtcs.move_rotator(
angle=self.target_angle, wait_for_complete=self.wait_for_complete
)
if self.wait_for_complete:
await self.checkpoint_message(
f"Rotator reached {self.target_angle} degrees."
)
await self.checkpoint(f"Rotator reached {self.target_angle} degrees.")
else:
await self.checkpoint("Stop script and keep rotator moving.")
33 changes: 20 additions & 13 deletions tests/test_maintel_mtrotator_move_rotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import asyncio
import unittest

from lsst.ts import standardscripts
from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages
from lsst.ts.standardscripts.maintel.mtrotator import MoveRotator


Expand All @@ -32,23 +32,18 @@ class TestMoveRotator(
async def basic_make_script(self, index):
self.script = MoveRotator(index=index, add_remotes=False)

self.script.mtcs = MTCS(
domain=self.script.domain,
intended_usage=MTCSUsages.DryTest,
log=self.script.log,
)

self.start_angle = 0.0 # degrees
self.very_short_sleep = 0.1 # seconds
self.script.mtcs.move_rotator = unittest.mock.AsyncMock(
side_effect=self.mock_move_rotator
)
self.script.mtcs.move_rotator = unittest.mock.AsyncMock()

return (self.script,)

async def mock_move_rotator(self, angle, wait_for_complete):
if wait_for_complete is False:
await asyncio.sleep(self.very_short_sleep)
else:
current_angle = self.start_angle
while current_angle < angle:
await asyncio.sleep(self.very_short_sleep)
current_angle += self.script.rotator_velocity * self.very_short_sleep

async def test_configure_default(self):
"""Test the default configuration"""

Expand Down Expand Up @@ -100,6 +95,18 @@ async def test_configure_with_program_reason(self):
== "MoveRotator BLOCK-123 202306060001 SITCOM-321"
)

async def test_run_with_default_config(self):
async with self.make_script():
target_angle = 45.0

await self.configure_script(angle=target_angle)

await self.run_script()

self.script.mtcs.move_rotator.assert_called_once_with(
angle=target_angle, wait_for_complete=True
)

async def test_executable(self):
scripts_dir = standardscripts.get_scripts_dir()
script_path = scripts_dir / "maintel" / "mtrotator" / "move_rotator.py"
Expand Down

0 comments on commit 056c5f4

Please sign in to comment.