Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/chimera/controllers/scheduler/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Scheduler(ChimeraObject):
"point_verify": "/PointVerify/0",
"operator": "/Operator/0",
"algorithm": SchedulingAlgorithm.SEQUENTIAL,
# left tracking, an unattended mount walks into a limit
"stop_tracking_on_program_end": True,
}

def __init__(self):
Expand Down
75 changes: 43 additions & 32 deletions src/chimera/controllers/scheduler/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,54 @@ def __start__(self):
def execute(self, program):
self.must_stop.clear()

for action in program.actions:
# aborted?
if self.must_stop.is_set():
raise ProgramExecutionAborted()

t0 = time.time()

try:
self.current_action = action
self.current_handler = self.action_handlers[type(action)]

log_msg = str(self.current_handler.log(action))
log.debug(f"[start] {log_msg} ")
self.controller.action_begin(action.id, log_msg)

self.current_handler.process(action)

# instruments just returns in case of abort, so we need to check handler
# returned 'cause of abort or not
try:
for action in program.actions:
# aborted?
if self.must_stop.is_set():
self.controller.action_complete(action.id, SchedulerStatus.ABORTED)
raise ProgramExecutionAborted()
else:
self.controller.action_complete(action.id, SchedulerStatus.OK)

except ProgramExecutionException:
self.controller.action_complete(action.id, SchedulerStatus.ERROR)
raise
except KeyError:
log.debug(f"No handler to {action} action. Skipping it")
finally:
log.debug("[finish] took: %f s" % (time.time() - t0))
t0 = time.time()

try:
self.current_action = action
self.current_handler = self.action_handlers[type(action)]

log_msg = str(self.current_handler.log(action))
log.debug(f"[start] {log_msg} ")
self.controller.action_begin(action.id, log_msg)

self.current_handler.process(action)

# instruments just returns in case of abort, so we need to check handler
# returned 'cause of abort or not
if self.must_stop.is_set():
self.controller.action_complete(
action.id, SchedulerStatus.ABORTED
)
raise ProgramExecutionAborted()
else:
self.controller.action_complete(action.id, SchedulerStatus.OK)

except ProgramExecutionException:
self.controller.action_complete(action.id, SchedulerStatus.ERROR)
raise
except KeyError:
log.debug(f"No handler to {action} action. Skipping it")
finally:
log.debug("[finish] took: %f s" % (time.time() - t0))
finally:
# a later stop() must not abort an action of a finished program
self.current_action = None
self.current_handler = None

def stop(self):
if self.current_handler:
self.must_stop.set()
self.current_handler.abort(self.current_action)
# flag first: a worker between actions must see the stop even when
# there is no action in flight to abort
self.must_stop.set()

handler, action = self.current_handler, self.current_action
if handler:
handler.abort(action)

def _inject_instrument(self, handler):
if not issubclass(handler, ActionHandler):
Expand Down
8 changes: 6 additions & 2 deletions src/chimera/controllers/scheduler/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ def process(action):
float(ra_dec.ra.to_h()), float(ra_dec.dec.to_d()), 2000.0
) # epoch is always 2000.0 for pointing
elif action.target_alt_az is not None:
# Position.alt/az are plain float degrees, unlike .ra/.dec
# which are Coords; accept either
alt = action.target_alt_az.alt
az = action.target_alt_az.az
telescope.slew_to_alt_az(
float(action.target_alt_az.alt.to_d()),
float(action.target_alt_az.az.to_d()),
float(alt.to_d() if hasattr(alt, "to_d") else alt),
float(az.to_d() if hasattr(az, "to_d") else az),
)
elif action.target_name is not None:
telescope.slew_to_object(action.target_name)
Expand Down
Loading
Loading