Skip to content

Commit

Permalink
Add a 'dome' attribute to Observatory. (#231)
Browse files Browse the repository at this point in the history
Add a 'dome' attribute to Observatory.

Add logger kwarg to create_dome_from_config, enabling caller to provide logger to be used.

Remove obsolete comment from observatory.py. Add TODO about non-bisque mounts, which assumes all are serial.
  • Loading branch information
jamessynge authored Dec 23, 2017
1 parent 9890d1f commit 160f3f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
18 changes: 7 additions & 11 deletions pocs/dome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
import pocs.utils
import pocs.utils.logger as logger_module

# A dome needs a config. We assume that there is at most one dome in the config,
# i.e. we don't support two different dome devices, such as might be the case
# if there are multiple independent actuators, for example slit, rotation and
# vents.


def create_dome_from_config(config):
def create_dome_from_config(config, logger=None):
"""If there is a dome specified in the config, create a driver for it.
A dome needs a config. We assume that there is at most one dome in the config, i.e. we don't
support two different dome devices, such as might be the case if there are multiple
independent actuators, for example slit, rotation and vents. Those would need to be handled
by a single dome class.
by a single dome driver class.
"""
root_logger = logger_module.get_root_logger()
if not logger:
logger = logger_module.get_root_logger()
if 'dome' not in config:
root_logger.debug('No dome in config.')
logger.info('No dome in config.')
return None
dome_config = config['dome']
if 'dome' in config.get('simulator', []):
Expand All @@ -30,10 +26,10 @@ def create_dome_from_config(config):
else:
brand = dome_config.get('brand')
driver = dome_config['driver']
root_logger.debug('Creating dome: brand={}, driver={}'.format(brand, driver))
logger.debug('Creating dome: brand={}, driver={}'.format(brand, driver))
module = pocs.utils.load_module('pocs.dome.{}'.format(driver))
dome = module.Dome(config=config)
root_logger.debug('Created dome.')
logger.info('Created dome driver: brand={}, driver={}'.format(brand, driver))
return dome


Expand Down
18 changes: 14 additions & 4 deletions pocs/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from astropy.coordinates import get_sun

from . import PanBase
import pocs.dome
from .images import Image
from .scheduler.constraint import Duration
from .scheduler.constraint import MoonAvoidance
Expand Down Expand Up @@ -49,6 +50,10 @@ def __init__(self, *args, **kwargs):
self._primary_camera = None
self._create_cameras(**kwargs)

# TODO(jamessynge): Discuss with Wilfred the serial port validation behavior
# here compared to that for the mount.
self.dome = pocs.dome.create_dome_from_config(self.config, logger=self.logger)

self.logger.info('\tSetting up scheduler')
self.scheduler = None
self._create_scheduler()
Expand Down Expand Up @@ -111,6 +116,8 @@ def power_down(self):
"""
self.logger.debug("Shutting down observatory")
self.mount.disconnect()
if self.dome:
self.dome.disconnect()

def status(self):
"""Get status information for various parts of the observatory
Expand All @@ -128,6 +135,9 @@ def status(self):
status['mount']['mount_target_ha'] = self.observer.target_hour_angle(
t, self.mount.get_target_coordinates())

if self.dome:
status['dome'] = self.dome.status

if self.current_observation:
status['observation'] = self.current_observation.status()
status['observation']['field_ha'] = self.observer.target_hour_angle(
Expand Down Expand Up @@ -485,10 +495,6 @@ def _create_mount(self, mount_info=None):
This method ensures that the proper mount type is loaded.
Note:
This does not actually make a serial connection to the mount. To do so,
call the 'mount.connect()' explicitly.
Args:
mount_info (dict): Configuration items for the mount.
Expand All @@ -509,6 +515,10 @@ def _create_mount(self, mount_info=None):
model = mount_info.get('brand')
driver = mount_info.get('driver')

# TODO(jamessynge): We should move the driver specific validation into the driver
# module (e.g. module.create_mount_from_config). This means we have to adjust the
# definition of this method to return a validated but not fully initialized mount
# driver.
if model != 'bisque':
port = mount_info.get('port')
if port is None or len(glob(port)) == 0:
Expand Down

0 comments on commit 160f3f2

Please sign in to comment.