Skip to content

Commit

Permalink
Also ignore the ioptron.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgee committed May 11, 2024
1 parent 04c1094 commit 1681616
Showing 1 changed file with 60 additions and 44 deletions.
104 changes: 60 additions & 44 deletions src/panoptes/pocs/utils/cli/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import serial
import typer
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 rich import print
from typing_extensions import Annotated

from panoptes.utils.serial.device import get_serial_port_info
from panoptes.utils.rs232 import SerialData
from panoptes.pocs.mount import create_mount_from_config
from panoptes.pocs.mount.ioptron import MountInfo

Expand All @@ -17,9 +17,12 @@

@app.command(name='park')
def park_mount(
confirm: Annotated[bool, typer.Option(..., '--confirm',
prompt='Are you sure you want to park the mount?',
help='Confirm mount parking.')] = False):
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to park the mount?',
help='Confirm mount parking.'
)] = False
):
"""Parks the mount.
Warning: This will move the mount to the park position but will not do any safety
Expand All @@ -28,7 +31,7 @@ def park_mount(
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

mount = create_mount_from_config()
mount.initialize()
mount.unpark()
Expand All @@ -37,9 +40,12 @@ def park_mount(

@app.command(name='set-park')
def set_park_position(
confirm: Annotated[bool, typer.Option(..., '--confirm',
prompt='Are you sure you want to set the park position?',
help='Confirm setting the park position.')] = False):
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to set the park position?',
help='Confirm setting the park position.'
)] = False
):
"""Sets the park position.
Warning: This will move the mount to the park position but will not do any safety
Expand All @@ -48,19 +54,19 @@ def set_park_position(
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

mount = create_mount_from_config()
mount.initialize()

# Confirm that they have previously set the home position.
if not typer.confirm('Have you previously set the home position?'):
print('Please set the home position before setting the park position by running "pocs mount search-home".')
return typer.Exit()

print(f'The mount will first park at the default position and then ask you to confirm the new park position.')
mount.unpark()
mount.park()

# Check if correct side of the pier (i.e. RA axis).
if not typer.confirm('Is the mount on the correct side of the pier?'):
# Switch the RA axis.
Expand All @@ -72,7 +78,7 @@ def set_park_position(
mount.unpark()
mount.slew_to_home(blocking=True)
mount.park()

# Check to make sure cameras are facing down (i.e. Dec axis).
if not typer.confirm('Are the cameras facing down?'):
# Switch the DEC axis.
Expand All @@ -84,22 +90,27 @@ def set_park_position(
mount.unpark()
mount.slew_to_home(blocking=True)
mount.park()

# Double-check the park position.
if not typer.confirm('Is the mount parked in the correct position?'):
# Give warning and bail out.
print('[red]Sorry! Please try again or ask the PANOPTES team.[/red]')
else:
print('Park position set. If the directions are correct but the mount is not parked in the correct position, '
'then you may need to adjust the number of seconds the mount moves in each direction. If you are unsure, '
'please ask the PANOPTES team for help.')
print(
'Park position set. If the directions are correct but the mount is not parked in the correct position, '
'then you may need to adjust the number of seconds the mount moves in each direction. If you are unsure, '
'please ask the PANOPTES team for help.'
)


@app.command(name='slew-home')
def search_for_home(
confirm: Annotated[bool, typer.Option(..., '--confirm',
prompt='Are you sure you want to slew to the home position?',
help='Confirm slew to home.')] = False):
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to slew to the home position?',
help='Confirm slew to home.'
)] = False
):
"""Slews the mount home position.
Warning: This will move the mount to the home position but will not do any safety
Expand All @@ -108,7 +119,7 @@ def search_for_home(
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

mount = create_mount_from_config()
mount.initialize()
mount.unpark()
Expand All @@ -118,9 +129,12 @@ def search_for_home(

@app.command(name='search-home')
def search_for_home(
confirm: Annotated[bool, typer.Option(..., '--confirm',
prompt='Are you sure you want to search for home?',
help='Confirm mount searching for home.')] = False):
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to search for home?',
help='Confirm mount searching for home.'
)] = False
):
"""Searches for the mount home position.
Warning: This will move the mount to the home position but will not do any safety
Expand All @@ -129,7 +143,7 @@ def search_for_home(
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

mount = create_mount_from_config()
mount.initialize()
mount.search_for_home()
Expand All @@ -138,45 +152,47 @@ def search_for_home(

@app.command(name='setup')
def setup_mount(
confirm: Annotated[bool, typer.Option(..., '--confirm',
prompt='Are you sure you want to setup the mount?',
help='Confirm mount setup.')] = False,
confirm: Annotated[bool, typer.Option(
..., '--confirm',
prompt='Are you sure you want to setup the mount?',
help='Confirm mount setup.'
)] = False,
):
"""Sets up the mount port, type, and firmware."""
if not confirm:
print('[red]Cancelled.[/red]')
return typer.Abort()

# Baudrates to check.
baudrates = [9600, 115200]

# Ports to ignore
ignore_ports = ['/dev/serial', '/dev/aag', '/dev/ttyACM0']

ignore_ports = ['/dev/ioptron', '/dev/aag', '/dev/ttyACM0', '/dev/serial']
# Get all the serial ports.
ports = get_serial_port_info()

# Loop through all the ports and baudrates.
for port in ports:
for baudrate in baudrates:
if port.device in ignore_ports:
continue
print(f"Trying {port.device=} at {baudrate=}...")
device = SerialData(port=port.device, baudrate=baudrate, timeout=1)

try:
device.write(':MountInfo#')
try:
response = device.read()
except serial.SerialException:
print('\tDevice potentially being accessed by another process.')
continue

if re.match(r'\d{4}', response): # iOptron specific
mount_type = MountInfo(int(response[0:4]))
print(f'Found mount at {port.device=} at {baudrate=} with {response=}.')
print(f'It looks like an iOptron {mount_type.name}.')

# Get the mainboard and handcontroller firmware version.
device.write(':FW1#')
response = device.read()
Expand All @@ -185,18 +201,18 @@ def setup_mount(
print('Firmware:')
print(f'\tMainboard: {mainboard_fw}')
print(f'\tHandcontroller: {handcontroller_fw}')

# Get the RA and DEC firmware version.
device.write(':FW2#')
response = device.read()
ra_fw = int(response[:6])
dec_fw = int(response[6:-1])
print(f'\tRA: {ra_fw}')
print(f'\tDEC: {dec_fw}')

command_set = 'v310' if ra_fw >= 210101 and dec_fw >= 210101 else 'v250'
print(f'Suggested command set: {command_set}')

# Get info for writing udev entry.
try:
udev_str = (
Expand All @@ -207,20 +223,20 @@ def setup_mount(
)
if port.serial_number is not None:
udev_str += f'ATTRS{{serial}}=="{port.serial_number}", '

# The name we want it known by.
udev_str += f'SYMLINK+="ioptron"'

udev_fn = Path('91-panoptes.rules')
with udev_fn.open('w') as f:
f.write(udev_str)

print(f'Wrote udev entry to [green]{udev_fn}[/green].')
print('Run the following command and then reboot for changes to take effect:')
print(f'\t[green]cat {udev_fn} | sudo tee /etc/udev/rules.d/{udev_fn}[/green]')
except Exception:
pass

# Confirm the user wants to update the config.
if typer.confirm('Do you want to update the config?'):
print('Updating config.')
Expand All @@ -230,7 +246,7 @@ def setup_mount(
set_config('mount.model', mount_type.name.lower())
set_config('mount.driver', f'panoptes.pocs.mount.ioptron.{mount_type.name.lower()}')
set_config('mount.commands_file', f'ioptron/{command_set}')

return typer.Exit()
except serial.SerialTimeoutException:
pass

0 comments on commit 1681616

Please sign in to comment.