Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gnthibault committed Aug 18, 2023
1 parent 5dccce0 commit e5616df
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
44 changes: 31 additions & 13 deletions Manager/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,24 +562,42 @@ def power_down(self):

def park(self):
try:
#close running guider server and client
if self.guider is not None:
self.guider.disconnect_profile()
self.guider.disconnect_server()
def call_subroutine_with_event(subroutine, event):
subroutine()
event.set()
def run_park_subroutine(subroutine, timeout_s=60):
try:
event = Event()
thread = Thread(target=call_subroutine_with_event, args=(subroutine, event))
thread.start()
assert event.wait(timeout=timeout_s), f"Timeout while waiting for subroutine {subroutine}"
except Exception as e:
self.logger.error(f"There has been an error while trying to park with routine {subroutine}:{e}")

# parking cameras
def park_guider():
# close running guider server and client
if self.guider is not None:
self.guider.disconnect_profile()
self.guider.disconnect_server()
run_park_subroutine(park_guider, timeout_s=60)

def park_camera(camera):
return lambda: camera.park()
for camera_name, camera in self.cameras.items():
camera.park()
run_park_subroutine(park_camera(camera), timeout_s=60)

# Mount and observatory will be shut down
if self.vizualization_service:
self.vizualization_service.stop()
def park_vizualization():
if self.vizualization_service:
self.vizualization_service.stop()
run_park_subroutine(park_vizualization, timeout_s=60)

# park the mount
self.mount.park()
def park_mount():
self.mount.park()
run_park_subroutine(park_mount, timeout_s=200)

# park the observatory
self.observatory.park()
def park_observatory():
self.observatory.park()
run_park_subroutine(park_observatory, timeout_s=200)

return True
except Exception as e:
Expand Down
7 changes: 6 additions & 1 deletion Service/SceneVizualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ def run(self):
if self.mount_device is None and self.observatory_device is None:
time.sleep(shortest_update)

def start(self):
self.do_run = True
super().start()

def stop(self):
self.stop_requested = True
self.do_run = False
try:
self.join()
self.logger.debug(f"Vizualization thread successfully stopped")
except RuntimeError as e: # cannot join thread before it is started
self.logger.debug(f"Most likely thread was not started: {e}")
18 changes: 9 additions & 9 deletions Spectro/DummySpectroController.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import logging

# Local utilities
from Base import Base
from Base.Base import Base

class DummySpectroController:
class DummySpectroController(Base):
"""
"""
Expand All @@ -21,7 +21,7 @@ def __init__(self,
)

super().__init__()

self.device_name = config["device_name"]

# Finished configuring
self.logger.debug('Indi Spectro controller configured successfully')
Expand All @@ -38,24 +38,24 @@ def on_emergency(self):
"finished")

def switch_on_spectro_light(self):
self.logger("Switching-on spectro light")
self.logger.debug("Switching-on spectro light")

def switch_off_spectro_light(self):
self.logger("Switching-off spectro light")
self.logger.debug("Switching-off spectro light")
self.open_optical_path()

def switch_on_flat_light(self):
self.logger("Switching-on flat light")
self.logger.debug("Switching-on flat light")

def switch_off_flat_light(self):
self.logger("Switching-off flat light")
self.logger.debug("Switching-off flat light")
self.open_optical_path()

def close_optical_path_for_dark(self):
self.logger("Close optical path for dark")
self.logger.debug("Close optical path for dark")

def open_optical_path(self):
self.logger("Open optical path")
self.logger.debug("Open optical path")

def __str__(self):
return f"Spectro controller: {self.device_name}"
Expand Down
7 changes: 3 additions & 4 deletions calibration/SpectralCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def __init__(self,
cfg = config['controller']
controller_name = cfg['module']
controller = load_module('Spectro.'+controller_name)
self.controller = getattr(controller,
controller_name)(cfg)
self.controller = getattr(controller, controller_name)(config=cfg)
except Exception as e:
self.controller = None
msg = f"Cannot instantiate controller properly: {e}"
Expand All @@ -71,7 +70,7 @@ def take_flat(self, observed_list):
temperature=self.flat_temperature,
gain=self.flat_gain,
offset=self.flat_offset,
exp_time_sec=self.flat_exp_sec,
exp_time=self.flat_exp_sec,
calibration_name="flat",
observations=observed_list.values())
#yield event
Expand All @@ -85,7 +84,7 @@ def take_spectral_calib(self, observed_list):
temperature=self.spectral_calib_temperature,
gain=self.spectral_calib_gain,
offset=self.spectral_calib_offset,
exp_time_sec=self.spectral_calib_exp_sec,
exp_time=self.spectral_calib_exp_sec,
calibration_name="spectral_calib",
observations=observed_list.values())
# yield event
Expand Down
2 changes: 0 additions & 2 deletions conf_files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ scheduler:
module: SpectroScheduler
#target_file: targets.yaml
target_file: spectral_targets.yaml
spectroscope_controller:
module: IndiSpectroController
calibration:
#module: ImagingCalibration
module: SpectralCalibration
Expand Down
2 changes: 0 additions & 2 deletions conf_files/config_backyard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ scheduler:
module: SpectroScheduler
# target_file: targets.yaml
target_file: spectral_targets.yaml
spectroscope_controller:
module: IndiSpectroController
calibration:
#module: ImagingCalibration
module: SpectralCalibration
Expand Down

0 comments on commit e5616df

Please sign in to comment.