Skip to content

Commit

Permalink
* Ability to specify horizon (although it doesn't change the mount se…
Browse files Browse the repository at this point in the history
…tting)

* Confirm after showing target info.
* Loop while tracking and show status (needs to be improved).
  • Loading branch information
wtgee committed Oct 14, 2024
1 parent 983ccc8 commit 75b9ea1
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/panoptes/pocs/utils/cli/mount.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import time
from pathlib import Path

import serial
Expand Down Expand Up @@ -137,24 +138,19 @@ def slew_to_home(
def slew_to_target(
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to slew to the target position?',
help='Confirm slew to target.'
)] = False,
target: Annotated[str, typer.Option(
..., '--target', '-t',
prompt='The name of the target to slew the mount to.',
help='The name of the target to slew the mount to.'
)] = None,
dry_run: Annotated[bool, typer.Option(
..., '--dry-run',
help="Show target info but don't actually initialize or move the mount."
)] = False,
horizon: Annotated[float, typer.Option(
..., '--horizon', '-h',
help='The horizon of the target to slew the mount to.'
)] = 30,
):
"""Slews the mount target position."""
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

print(f'Looking for coordinates for {target}.')
coords = None
try:
Expand All @@ -175,23 +171,27 @@ def slew_to_target(
print(f'Using {coords=} from {location.observer.name}')

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#L171

Added line #L171 was not covered by tests

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

Check warning on line 174 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

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

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

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L176-L177

Added lines #L176 - L177 were not covered by tests

# Show target info for observatory.
target_set_time = location.observer.target_set_time(current_time(), coords, horizon=30. * u.deg, which='next')
target_set_time = location.observer.target_set_time(current_time(), coords, horizon=horizon * u.deg, which='next')
print(

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

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L180-L181

Added lines #L180 - L181 were not covered by tests
f'Target will be above 30° for '
f'Target will be above {horizon}° for '
f'{friendly_time_delta(current_time().to_datetime(), target_set_time.to_datetime())}'
)

# 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}')

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

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L187-L188

Added lines #L187 - L188 were not covered by tests

if dry_run:
# If not specified on the command line, ask for confirmation.
if not confirm:
confirm = typer.confirm('Are you sure you want to slew to the target position?')

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#L192

Added line #L192 was not covered by tests

if not confirm:
print(f'[red]Dry run, will not move the mount.[/red]')
return typer.Abort()

Check warning on line 196 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-L196

Added lines #L195 - L196 were not covered by tests

Expand All @@ -200,9 +200,17 @@ def slew_to_target(
mount.set_target_coordinates(coords)
mount.slew_to_target(blocking=True)

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#L198-L201

Added lines #L198 - L201 were not covered by tests

# TODO create a watchdog for park/safety?

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

Check warning on line 204 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-L204

Added lines #L203 - L204 were not covered by tests
while mount.is_tracking:
print(mount.status)
time.sleep(1)
except KeyboardInterrupt:
print('[red]Tracking interrupted.[/red]')

Check warning on line 209 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-L209

Added lines #L206 - L209 were not covered by tests
finally:
print("[green]Moving mount to the home position (don't forget to park!)[/green]")
mount.slew_to_home(blocking=True)
mount.disconnect()

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

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/mount.py#L211-L213

Added lines #L211 - L213 were not covered by tests


@app.command(name='search-home')
Expand Down

0 comments on commit 75b9ea1

Please sign in to comment.