Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Do not move lower gonio until the robot is safely away (#1526)
Browse files Browse the repository at this point in the history
* Do not move lower gonio until the robot is safely away

* Added group to thawing
  • Loading branch information
DominicOram committed Aug 15, 2024
1 parent 010dd7d commit 2d47e50
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/hyperion/experiment_plans/robot_load_then_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ def prepare_for_robot_load(composite: RobotLoadThenCentreComposite):
yield from bps.wait("prepare_robot_load")


def robot_load_and_energy_change(
def do_robot_load(
composite: RobotLoadThenCentreComposite,
sample_location: SampleLocation,
demand_energy_ev: float | None,
thawing_time: float,
):
yield from bps.abs_set(
composite.robot,
Expand All @@ -168,6 +169,11 @@ def robot_load_and_energy_change(

yield from bps.wait("robot_load")

yield from bps.abs_set(
composite.thawer.thaw_for_time_s, thawing_time, group="thawing_finished"
)
yield from wait_for_smargon_not_disabled(composite.smargon)


def raise_exception_if_moved_out_of_cryojet(exception):
yield from bps.null()
Expand Down Expand Up @@ -204,10 +210,11 @@ def robot_load_and_snapshots():
assert params.sample_puck is not None
assert params.sample_pin is not None

robot_load_plan = robot_load_and_energy_change(
robot_load_plan = do_robot_load(
composite,
SampleLocation(params.sample_puck, params.sample_pin),
params.demand_energy_ev,
params.thawing_time,
)

# The lower gonio must be in the correct position for the robot load and we
Expand All @@ -226,9 +233,6 @@ def robot_load_and_snapshots():
except_plan=raise_exception_if_moved_out_of_cryojet,
)

yield from bps.abs_set(composite.thawer.thaw_for_time_s, params.thawing_time)
yield from wait_for_smargon_not_disabled(composite.smargon)

yield from take_robot_snapshots(
composite.oav, composite.webcam, params.snapshot_directory
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,62 @@ def get_read(axis, msg):
)


@patch(
"hyperion.experiment_plans.robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
@patch(
"hyperion.experiment_plans.robot_load_then_centre_plan.set_energy_plan",
MagicMock(return_value=iter([])),
)
def test_when_plan_run_then_lower_gonio_moved_before_robot_loads_and_back_after_smargon_enabled(
mock_centring_plan: MagicMock,
robot_load_composite: RobotLoadThenCentreComposite,
robot_load_then_centre_params_no_energy: RobotLoadThenCentre,
sim_run_engine: RunEngineSimulator,
):
initial_values = {"x": 0.11, "y": 0.12, "z": 0.13}

def get_read(axis, msg):
return {f"lower_gonio-{axis}": {"value": initial_values[axis]}}

for axis in initial_values.keys():
sim_run_engine.add_handler(
"read", partial(get_read, axis), f"lower_gonio-{axis}"
)

messages = sim_run_engine.simulate_plan(
robot_load_then_centre(
robot_load_composite,
robot_load_then_centre_params_no_energy,
)
)

assert_message_and_return_remaining(
messages, lambda msg: msg.command == "set" and msg.obj.name == "robot"
)

for axis in initial_values.keys():
messages = assert_message_and_return_remaining(
messages,
lambda msg: msg.command == "set"
and msg.obj.name == f"lower_gonio-{axis}"
and msg.args == (0,),
)

assert_message_and_return_remaining(
messages,
lambda msg: msg.command == "read" and msg.obj.name == "smargon-disabled",
)

for axis, initial in initial_values.items():
messages = assert_message_and_return_remaining(
messages,
lambda msg: msg.command == "set"
and msg.obj.name == f"lower_gonio-{axis}"
and msg.args == (initial,),
)


@patch(
"hyperion.experiment_plans.robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
Expand Down

0 comments on commit 2d47e50

Please sign in to comment.