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

Alignment safety #1271

Merged
merged 3 commits into from
May 18, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/panoptes/pocs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def status(self) -> dict:
self.logger.warning(f"Can't get status: {e!r}")
return {}

def update_status(self) -> dict:
"""Thin-wrapper around status property.

This method will update the status of the system in the database.
"""
return self.status

################################################################################################
# Methods
################################################################################################
Expand Down Expand Up @@ -394,6 +401,7 @@ def is_safe(self, no_warning=False, horizon='observe', ignore=None, park_if_not_
self.logger.warning(f'Safety failed, setting {self.next_state=} to "parking"')
self.next_state = 'parking'

self.update_status()
return safe

def _in_simulator(self, key):
Expand Down
40 changes: 26 additions & 14 deletions src/panoptes/pocs/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import List

import typer
from panoptes.utils.error import PanError
from panoptes.utils.time import current_time
from panoptes.utils.utils import altaz_to_radec, listify
from rich import print
Expand All @@ -22,9 +23,9 @@

@app.callback()
def common(
context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
):
context.obj = [simulator, cloud_logging]

Expand Down Expand Up @@ -90,17 +91,17 @@ def run_auto(context: typer.Context) -> None:

@app.command(name='alignment')
def run_alignment(
context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
) -> None:
"""Runs POCS in alignment mode.

Expand All @@ -109,6 +110,8 @@ def run_alignment(
-c 70,60 -c 70,120 -c 70,240 -c 70,300
"""
pocs = get_pocs(context)
print(f'[bold yellow]Starting POCS in alignment mode.[/bold yellow]')
pocs.update_status()

alts = [55, 70]
azs = [60, 120, 240, 300]
Expand Down Expand Up @@ -140,6 +143,11 @@ def get_altaz_observation(coords, seq_time) -> Observation:

procs = list()
for i, altaz_coord in enumerate(altaz_coords):
# Check safety (parking happens below if unsafe).
if pocs.is_safe(park_if_not_safe=False) is False:
print('[red]POCS is not safe, shutting down.[/red]')
raise PanError('POCS is not safe.')

print(f'{field_name} #{i:02d}/{len(altaz_coords):02d} {altaz_coord=}')

# Create an observation and set it as current.
Expand All @@ -166,6 +174,7 @@ def get_altaz_observation(coords, seq_time) -> Observation:
for j in range(num_exposures):
print(f'\tStarting {exptime}s exposure #{j + 1:02d}/{num_exposures:02d}')
pocs.observatory.take_observation(blocking=True)
pocs.update_status()

# Do processing in background (if exposure time is long enough).
if exptime > 10:
Expand All @@ -180,6 +189,9 @@ def get_altaz_observation(coords, seq_time) -> Observation:
except Exception as e:
print('[bold red]POCS encountered an error.[/bold red]')
print(e)
except PanError as e:
print('[bold red]POCS encountered an error.[/bold red]')
print(e)
else:
print('[green]POCS alignment finished, shutting down.[/green]')
finally:
Expand Down
Loading