def focuser(self): if not hasattr(self, '_focuser'): try: self._focuser = focuser.driver.Driver( host=self.config['focuser']['host']) except socket.timeout as e: raise ttypes.LesediException('Connection timed out.') except socket.error as e: raise ttypes.LesediException(str(e)) return self._focuser
def rotator_left(self): if not hasattr(self, '_rotator_left'): try: self._rotator_left = rotator.driver.LeftRotatorDriver( host=self.config['rotator']['host']) except socket.timeout as e: raise ttypes.LesediException('Connection timed out.') except socket.error as e: raise ttypes.LesediException(str(e)) return self._rotator_left
def telescope(self): if not hasattr(self, '_telescope'): try: self._telescope = telescope.driver.Driver( host=self.config['telescope']['host']) except socket.timeout as e: raise ttypes.LesediException('Connection timed out.') except socket.error as e: raise ttypes.LesediException(str(e)) return self._telescope
def goto_radec(self, ra, dec): telescope = self.telescope.get_status() if telescope.parked: raise ttypes.LesediException( 'Telescope cannot be slewed while parked.') if telescope.manual: raise ttypes.LesediException( 'Cannot move telescope. Motors are in manual mode.') self.telescope.goto_radec(ra, dec)
def wrapper(self, *args, **kwargs): if self._stop.is_set(): raise ttypes.LesediException( 'Emergency stop has been triggered. Please reset to continue.') dome = self.dome.get_status() if dome.tcs_locked_out: raise ttypes.LesediException( 'Lockout engaged. Command not allowed.') return f(self, *args, **kwargs)
def _write(self, value): builder = BinaryPayloadBuilder(byteorder='>', wordorder='<') builder.add_16bit_uint(value) payload = builder.to_registers() try: with ModbusTcpClient(self.host, self.port) as client: result = client.write_registers(self.COMMAND_ADDRESS, payload) except ConnectionException as e: raise ttypes.LesediException(str(e)) if result.isError(): raise ttypes.LesediException(str(result))
def unpark(self): response = Response(self.execute('UnParkRotator')) if response.message == 'UnParkRotatorAccepted': return response raise ttypes.LesediException('Unpark command failed.')
def get_status(self): try: with ModbusTcpClient(self.host, self.port) as client: result = client.read_holding_registers( self.COVERS_STATUS_ADDRESS, self.COVERS_STATUS_LENGTH) except ConnectionException as e: raise ttypes.LesediException(str(e)) if result.isError(): raise ttypes.LesediException(str(result)) status = BinaryPayloadDecoder.fromRegisters( result.registers, byteorder='>', wordorder='<').decode_16bit_uint() return Status(status)
def close_dome(self): dome = self.dome.get_status() if not dome.remote: raise ttypes.LesediException( 'Dome cannot be closed while not in remote mode.') self.dome.close()
def tertiary_go_right(self): response = Response(self.execute('GoRightTertiary')) if response.message == 'GoRightTertiaryAccepted': return response raise ttypes.LesediException('Tertiary go command failed.')
def rotate_dome(self, az): dome = self.dome.get_status() if not dome.remote: raise ttypes.LesediException( 'Dome cannot be rotated while not in remote mode.') self.dome.rotate(az)
def secondary_to_manual(self): response = Response(self.execute('ToBlinkyFocuser')) if response.message == 'ToBlinkyFocuserAccepted': return response raise ttypes.LesediException('Manual command failed.')
def select_instrument(self, instrument): """Tertiary mirror is is position 1 (i.e. directing the beam to the SHOC port) or position 2 (for WiNCam). """ if instrument == ttypes.Instrument.WINCAM: response = Response(self.execute('GoLeftTertiary')) elif instrument == ttypes.Instrument.SHOC: response = Response(self.execute('GoRightTertiary')) else: raise ttypes.LesediException('Unknown instrument') if response.message in ('GoLeftTertiaryAccepted', 'GoRightTertiaryAccepted'): return response raise ttypes.LesediException('Select instrument command failed.')
def aux(self): if not hasattr(self, '_aux'): try: self._aux = aux.driver.Driver(host=self.config['aux']['host']) except Exception as e: # TODO: Handle more specific types of exceptions. raise ttypes.LesediException(str(e)) return self._aux
def open_dome(self): dome = self.dome.get_status() if not dome.remote: raise ttypes.LesediException( 'Dome cannot be opened while not in remote mode.') self.dome.open()
def set_focus(self, inches): focuser = self.focuser.get_status() if not focuser.secondary_mirror_auto: raise ttypes.LesediException( 'Cannot set focus. Secondary mirror is in manual mode.') self.focuser.secondary_move_to(inches)
def park_dome(self): dome = self.dome.get_status() if not dome.remote: raise ttypes.LesediException( 'Dome cannot be parked while not in remote mode.') self.dome.park()
def cancel_autofocus(self): response = Response(self.execute('CancelAutoFocus')) if response.message == 'CancelAutoFocusAccepted': return response raise ttypes.LesediException('Cancel command failed.')
def secondary_to_auto(self): response = Response(self.execute('ToAutoFocuser')) if response.message == 'ToAutoFocuserAccepted': return response raise ttypes.LesediException('Auto command failed.')
def tracking_off(self): response = Response(self.execute('RotatorTrackingOff')) if response.message == 'TrackingOffAccepted': return response raise ttypes.LesediException('Tracking off command failed.')
def do_autofocus(self): response = Response(self.execute('DoAutoFocus')) if response.message == 'FocuserToAutoAccepted': return response raise ttypes.LesediException('Autofocus command failed.')
def move_to_parallactic_angle(self): """Move the rotator to the parallactic angle (North Up) (or will move to the limit).""" response = Response(self.execute('MoveRotatorToParallacticAngle')) if response.message == '': return response raise ttypes.LesediException('Move to parallactic angle command failed.')
def to_manual(self): """Put it in "Manual" (blinky) mode.""" response = Response(self.execute('RotatorToBlinky')) if response.message == 'RotatorToBlinkyAccepted': return response raise ttypes.LesediException('Manual command failed.')
def to_auto(self): """Put it in "Auto" mode.""" response = Response(self.execute('RotatorToAuto')) if response.message == 'RotatorToAutoAccepted': return response raise ttypes.LesediException('Auto command failed.')
def secondary_move_to(self, inches): """Move the focuser to nn.nn inches (or will move to the limit).""" response = Response(self.execute('MoveFocuserTo {}'.format(inches))) if response.message == 'MoveFocuserAccepted': return response raise ttypes.LesediException('Move command failed.')
def secondary_stop(self): """Stop the focuser movement.""" response = Response(self.execute('StopFocuser')) if response.message == 'StopFocuserAccepted': return response raise ttypes.LesediException('Stop command failed.')
def tertiary_to_manual(self): """Puts the tertiary servo motor into the "Manual" (or blinky) mode.""" response = Response(self.execute('ToBlinkyTertiary')) if response.message == 'ToBlinkyTertiaryAccepted': return response raise ttypes.LesediException('Tertiary manual command failed.')
def restart_comms(self): """Try to reconnect to ServoCommunicator if there is no communications.""" response = Response(self.execute('RestartCommunicatorComms')) if response.message == 'RestartCommunicatorCommsAccepted': return response raise ttypes.LesediException('Restart command failed.')
def tertiary_to_auto(self): """Puts the tertiary servo motor into the "Auto" mode.""" response = Response(self.execute('ToAutoTertiary')) if response.message == 'ToAutoTertiaryAccepted': return response raise ttypes.LesediException('Tertiary auto command failed.')
def tertiary_jog_by(self, angle): """Jog the Tertiary mirror by nn.nn angle (or will move to the limit).""" response = Response(self.execute('JogTertiary {:.2f}'.format(angle))) if response.message == '': return response raise ttypes.LesediException('Tertiary jog command failed.')