Skip to content

Commit

Permalink
* Better shutdown timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgee committed Oct 14, 2024
1 parent 75b9ea1 commit e0f009e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/panoptes/pocs/utils/cli/mount.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import time
from pathlib import Path

import serial
Expand All @@ -11,7 +10,7 @@
from panoptes.utils.config.client import set_config
from panoptes.utils.rs232 import SerialData
from panoptes.utils.serial.device import get_serial_port_info
from panoptes.utils.time import current_time
from panoptes.utils.time import CountdownTimer, current_time
from rich import print
from typing_extensions import Annotated

Expand Down Expand Up @@ -145,10 +144,6 @@ def slew_to_target(
prompt='The name of the target to slew the mount to.',
help='The name of the target to slew the mount to.'
)] = None,
horizon: Annotated[float, typer.Option(
..., '--horizon', '-h',
help='The horizon of the target to slew the mount to.'
)] = 30,
):
"""Slews the mount target position."""
print(f'Looking for coordinates for {target}.')
Expand All @@ -167,25 +162,26 @@ def slew_to_target(

# Get the observer location
location = create_location_from_config()

print(f'Using {coords=} from {location.observer.name}')
observe_horizon = location.location.get('horizon', 30 * u.deg)

Check warning on line 165 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L164-L165

Added lines #L164 - L165 were not covered by tests

# Check that the target is observable.
is_observable = location.observer.target_is_up(current_time(), coords, horizon=horizon * u.deg)
is_observable = location.observer.target_is_up(current_time(), coords, horizon=observe_horizon)

Check warning on line 168 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L168

Added line #L168 was not covered by tests
if not is_observable:
print(f'[red]Target is not observable[/red]')
return typer.Abort()

Check warning on line 171 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L170-L171

Added lines #L170 - L171 were not covered by tests

# Show target info for observatory.
target_set_time = location.observer.target_set_time(current_time(), coords, horizon=horizon * u.deg, which='next')
# Get AltAz for coordinates.
alt_az = coords.transform_to(AltAz(location=location.earth_location, obstime=current_time()))
print(

Check warning on line 175 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L174-L175

Added lines #L174 - L175 were not covered by tests
f'Target will be above {horizon}° for '
f'{friendly_time_delta(current_time().to_datetime(), target_set_time.to_datetime())}'
f'Current position: '
f'\n\tRA/Dec: {coords.ra:.02f} {coords.dec:.02f}'
f'\n\t AltAz: {alt_az.alt:.02f} {alt_az.az:.02f}'
)

# Get AltAz for coordinates.
alt_az = coords.transform_to(AltAz(location=location.earth_location, obstime=current_time()))
print(f'Current position: Alt={alt_az.alt:.02f} Az={alt_az.az:.02f}')
# Show target info for observatory.
target_set_time = location.observer.target_set_time(current_time(), coords, horizon=observe_horizon, which='next')
set_delta = (target_set_time - current_time()).to_datetime()
print(f'Target will be above {observe_horizon}° for {friendly_time_delta(set_delta)}')

Check warning on line 184 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L182-L184

Added lines #L182 - L184 were not covered by tests

# If not specified on the command line, ask for confirmation.
if not confirm:
Expand All @@ -195,16 +191,21 @@ def slew_to_target(
print(f'[red]Dry run, will not move the mount.[/red]')
return typer.Abort()

Check warning on line 192 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L191-L192

Added lines #L191 - L192 were not covered by tests

# Initialize the mount and slew to the target.
mount = create_mount_from_config()
mount.initialize()
mount.set_target_coordinates(coords)
mount.slew_to_target(blocking=True)

Check warning on line 198 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L195-L198

Added lines #L195 - L198 were not covered by tests

print('[green]Starting to track target, press Ctrl-C to cancel[/green]')
try:

Check warning on line 201 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L200-L201

Added lines #L200 - L201 were not covered by tests
# Show the status every 5 seconds.
timer = CountdownTimer(5)

Check warning on line 203 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L203

Added line #L203 was not covered by tests
while mount.is_tracking:
print(mount.status)
time.sleep(1)
if timer.expired():
print(mount.status)
timer.restart()
timer.sleep(1)
except KeyboardInterrupt:
print('[red]Tracking interrupted.[/red]')

Check warning on line 210 in src/panoptes/pocs/utils/cli/mount.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L206-L210

Added lines #L206 - L210 were not covered by tests
finally:
Expand Down

0 comments on commit e0f009e

Please sign in to comment.