Skip to content

Commit

Permalink
Reset pmac triggers and wait for completion on Pause and Abort
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Dec 9, 2016
1 parent 9d2d507 commit 1f68701
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/P45-MALC01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#/dls_sw/prod/common/python/RHEL6-x86_64/pymalcolm/2-0a6/malcolm/imalcolm.py
# This sample is intended for use with the test lab setup LAB-MO-IOC-01

- blocks.ADCore.SimDetectorManager:
- blocks.ADCore.DetectorManager:
pvPrefix: BL45P-EA-MAP-01:MIC
mriPrefix: P45-MIC

Expand Down
31 changes: 31 additions & 0 deletions malcolm/blocks/ADCore/DetectorManager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- parameters.string:
name: mriPrefix
description: Malcolm resource id of the Block and prefix for children

- parameters.string:
name: pvPrefix
description: PV prefix for driver and all plugins

- controllers.RunnableController:
mri: $(mriPrefix)

- blocks.ADCore.SimDetectorDriver:
mri: $(mriPrefix)-DRV
prefix: $(pvPrefix):DET

- parts.ADCore.DetectorDriverPart:
name: DRV
mri: $(mriPrefix)-DRV
readoutTime: 40e-6

- blocks.ADCore.StatsPlugin:
mri: $(mriPrefix)-STAT
prefix: $(pvPrefix):STAT

- parts.ADCore.StatsPluginPart:
name: STAT
mri: $(mriPrefix)-STAT

- includes.ADCore.filewriting_collection:
pvPrefix: $(pvPrefix)
mriPrefix: $(mriPrefix)
16 changes: 8 additions & 8 deletions malcolm/controllers/runnablecontroller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from malcolm.controllers.managercontroller import ManagerController
from malcolm.core import RunnableStateMachine, REQUIRED, method_also_takes, \
method_writeable_in, method_takes, MethodMeta, Task, Hook, method_returns, \
Info, AbortedError
Info, AbortedError, BadValueError
from malcolm.core.vmetas import PointGeneratorMeta, NumberMeta, StringArrayMeta


Expand Down Expand Up @@ -202,7 +202,7 @@ def do_reset(self):

def go_to_error_state(self, exception):
if isinstance(exception, AbortedError):
self.log_info("Got StopIteration in %s" % self.state.value)
self.log_info("Got AbortedError in %s" % self.state.value)
else:
super(RunnableController, self).go_to_error_state(exception)

Expand Down Expand Up @@ -322,12 +322,16 @@ def _call_do_run(self):
except AbortedError:
# Work out if it was an abort or pause
state = self.state.value
self.log_error("Do run got AbortedError from %s", state)
self.log_debug("Do run got AbortedError from %s", state)
if state in (sm.SEEKING, sm.PAUSED):
# Wait to be restarted
task = Task("StateWaiter", self.process)
bad_states = [sm.DISABLING, sm.ABORTING, sm.FAULT]
task.when_matches(self.state, sm.RUNNING, bad_states)
try:
task.when_matches(self.state, sm.RUNNING, bad_states)
except BadValueError:
# raise AbortedError so we don't try to transition
raise AbortedError()
# Restart it
hook = self.Resume
self.status.set_value("Run resumed")
Expand Down Expand Up @@ -367,15 +371,11 @@ def abort(self):
sm.ABORTING, sm.ABORTED, self.do_abort, self.Abort)

def do_abort(self, hook):
self.log_warning("Stopping tasks")
for task in self.part_tasks.values():
task.stop()
self.log_warning("Running hook")
self.run_hook(hook, self.create_part_tasks())
self.log_warning("Waiting on tasks")
for task in self.part_tasks.values():
task.wait()
self.log_warning("do_abort done")

def set_completed_steps(self, completed_steps):
params = self.pause.MethodMeta.prepare_input_map(
Expand Down
4 changes: 2 additions & 2 deletions malcolm/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def _set_block_children(self):
def call_writeable_function(self, function, child, *args):
with self.lock:
if not child.writeable:
child.log_info("I'm not writeable")
raise ValueError("Child %r is not writeable" % (child,))
raise ValueError(
"Child %r is not writeable" % (child.process_path,))
result = function(*args)
return result

Expand Down
5 changes: 4 additions & 1 deletion malcolm/parts/builtin/runnablechildpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ def post_run(self, task, completed_steps=None, steps_to_do=None,

@RunnableController.Seek
def seek(self, task, completed_steps, steps_to_do, part_info):
# Clear out the update_completed_steps and match_future subscriptions
task.unsubscribe_all()
params = self.child["pause"].prepare_input_map(
completedSteps=completed_steps)
task.post(self.child["pause"], params)

@RunnableController.Resume
def resume(self, task, update_completed_steps):
# The update_completed_steps subscription from run() is still valid here
task.subscribe(
self.child["completedSteps"], update_completed_steps, self)
match_future = self._wait_for_postrun(task)
task.post(self.child["resume"])
task.wait_all(match_future)
Expand Down
13 changes: 13 additions & 0 deletions malcolm/parts/pmac/pmactrajectorypart.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class PMACTrajectoryPart(ChildPart):
def reset(self, task):
super(PMACTrajectoryPart, self).reset(task)
self.abort(task)
self.reset_triggers(task)

@RunnableController.Validate
@method_takes(*configure_args)
Expand Down Expand Up @@ -333,6 +334,18 @@ def write_profile_points(self, task, time_array, velocity_mode, trajectory,
attr_dict["positions%s" % cs_axis] = trajectory[axis_name]
task.put_many(self.child, attr_dict)

def reset_triggers(self, task):
"""Just call a Move to the run up position ready to start the scan"""
task.put(self.child["numPoints"], 10)
time_array = [0.1]
velocity_mode = [ZERO_VELOCITY]
user_programs = [TRIG_ZERO]
trajectory = {}
self.write_profile_points(task, time_array, velocity_mode, trajectory,
user_programs)
task.post(self.child["buildProfile"])
task.post(self.child["executeProfile"])

def build_generator_profile(self, start_index, do_run_up=True):
acceleration_time = self.calculate_acceleration_time()
trajectory = {axis_name: [] for axis_name in self.axis_mapping}
Expand Down
7 changes: 7 additions & 0 deletions malcolm/parts/pmac/rawmotorpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ def report_cs_info(self, _):
scannable=self.child.scannable
)
return [motor_info]

@RunnableController.Abort
@RunnableController.Pause
def abort(self, task):
self.log_warning("Waiting for motor to stop moving")
# Wait for the motor to stop moving
task.when_matches(self.child["doneMoving"], 1)

0 comments on commit 1f68701

Please sign in to comment.