From f53c96eb5303f4cc0b0bcb2734fd7f20050485fa Mon Sep 17 00:00:00 2001 From: James Synge Date: Mon, 25 Dec 2017 09:19:30 -0500 Subject: [PATCH] Add minimal support for domes into POCS. (#248) * Add minimal support for domes into POCS. * Close dome when entering the parking state and when powering down. * Tests TBS. --- pocs/core.py | 7 ++++-- pocs/observatory.py | 33 ++++++++++++++++++++++++++++ pocs/state/states/default/parking.py | 6 +++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pocs/core.py b/pocs/core.py index 0f7c60a7e..b2a310f31 100644 --- a/pocs/core.py +++ b/pocs/core.py @@ -40,7 +40,6 @@ class POCS(PanStateMachine, PanBase): Attributes: name (str): Name of PANOPTES unit - next_state (str): The next state for the state machine observatory (`pocs.observatory.Observatory`): The `~pocs.observatory.Observatory` object """ @@ -223,8 +222,13 @@ def power_down(self): "Shutting down {}, please be patient and allow for exit.".format( self.name)) + if not self.observatory.close_dome(): + self.logger.critical('Unable to close dome!') + # Park if needed if self.state not in ['parking', 'parked', 'sleeping', 'housekeeping']: + # TODO(jamessynge): Figure out how to handle the situation where we have both + # mount and dome, but this code is only checking for a mount. if self.observatory.mount.is_connected: if not self.observatory.mount.is_parked: self.logger.info("Parking mount") @@ -295,7 +299,6 @@ def is_safe(self, no_warning=False): if no_warning is False: self.logger.warning('Unsafe conditions: {}'.format(is_safe_values)) - # Not safe so park unless we are not active if self.state not in ['sleeping', 'parked', 'parking', 'housekeeping', 'ready']: self.logger.warning('Safety failed so sending to park') self.park() diff --git a/pocs/observatory.py b/pocs/observatory.py index aeefaf844..bfa41de60 100644 --- a/pocs/observatory.py +++ b/pocs/observatory.py @@ -101,6 +101,9 @@ def current_observation(self): def current_observation(self, new_observation): self.scheduler.current_observation = new_observation + @property + def has_dome(self): + return self.dome is not None ########################################################################## # Methods @@ -110,6 +113,8 @@ def initialize(self): """Initialize the observatory and connected hardware """ self.logger.debug("Initializing mount") self.mount.initialize() + if self.dome: + self.dome.connect() def power_down(self): """Power down the observatory. Currently does nothing @@ -428,6 +433,34 @@ def autofocus_cameras(self, camera_list=None, coarse=False): return autofocus_events + def open_dome(self): + """Open the dome, if there is one. + + Returns: False if there is a problem opening the dome, + else True if open (or if not exists). + """ + if not self.dome: + return True + if not self.dome.connect(): + return False + if not self.dome.is_open: + self.logger.info('Opening dome') + return self.dome.open() + + def close_dome(self): + """Close the dome, if there is one. + + Returns: False if there is a problem closing the dome, + else True if closed (or if not exists). + """ + if not self.dome: + return True + if not self.dome.connect(): + return False + if not self.dome.is_closed: + self.logger.info('Closed dome') + return self.dome.close() + ########################################################################## # Private Methods ########################################################################## diff --git a/pocs/state/states/default/parking.py b/pocs/state/states/default/parking.py index d542c41f2..a90b9ac71 100644 --- a/pocs/state/states/default/parking.py +++ b/pocs/state/states/default/parking.py @@ -7,5 +7,11 @@ def on_enter(event_data): pocs.next_state = 'parked' + if pocs.observatory.has_dome: + pocs.say('Closing dome') + if not pocs.observatory.close_dome(): + self.logger.critical('Unable to close dome!') + pocs.say('Unable to close dome!') + pocs.say("I'm takin' it on home and then parking.") pocs.observatory.mount.home_and_park()