Skip to content

Move the beam centre to target position by nudging the piezos - #186

Merged
noemifrisina merged 43 commits into
mainfrom
166-ad-plugin-chain
Oct 20, 2026
Merged

noemifrisina merged 43 commits into
mainfrom
166-ad-plugin-chain

Conversation

@noemifrisina

@noemifrisina noemifrisina commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #166
Closes #180

Needs dodal#2227

Add plans to move the beam centre by nudging the piezos in a loop.

Tested on the beamline and gave promising results even with the vfm not in a closed loop. Will need to retest next occasion with beam as vfm is now in a closed loop, but I think it would be better to get this bit merged and make any fixes in a separate branch/issue, as the PR is getting quite big.

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (8f698bb) to head (3a2a76b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
+ Coverage   98.90%   99.11%   +0.20%     
==========================================
  Files          36       38       +2     
  Lines         733      901     +168     
==========================================
+ Hits          725      893     +168     
  Misses          8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@noemifrisina
noemifrisina marked this pull request as ready for review October 7, 2026 11:47

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, generally looks good, I'm glad it worked! Some comments in code but no real showstoppers

return (x, y)


# TODO Create model in daq-config-server

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: Can you add an issue for it in the config server?

return lut.columns


def _get_lut_path_and_column_from_name(device_name: str) -> tuple[Path, int]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: It feels like this info should live in the device?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a separate issue for this, as eh2 will also want to use this code but they need their own lookup tables first - and I don't much like the idea of temporarily having the device just use the eh1 lut for both hutches. Issues in code.

def _get_lut_path_and_column_from_name(device_name: str) -> tuple[Path, int]:
match device_name:
case "hfm_piezo":
return (HFM_LUT, 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: If we're only using the one column then I think we should just have the one in the file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like the idea of not having both columns, mainly because it's a good indication of the fact that even if slightly each piezo does shift the beam in the other direction too (iirc the vfm more than the hfm)
That being said, I admit I don't like this function just couldn't think of anything else for now...

return nudge_size


def _check_position_reached(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Does it make more sense to do the pythagorian distance here? In practice probably makes very little difference

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yeah, even if it doesn't change things that much.

Comment on lines +198 to +200
# NOTE. The following plans should in the future become just one (if even needed), but
# until further testing can be done it would be easier to have two separare entry points
# for the two piezos.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: I think we should decide now whether to remove them or make them into one and do it in this PR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least I would keep one, considering we're going to need to run the test again now that the work on the vfm is done and its lookup table has been updated - it was much easier to debug things one piezo at a time then when running both. And we'll also need it to do the same on eh2 at a later point anyway...

Comment on lines +102 to +109
"""Stops the stats plugin at the end of the loop"""
yield from bps.abs_set(
beam_centre.stats.enable_callbacks, EnableDisable.DISABLE, group=group
)
yield from bps.abs_set(beam_centre.stats.compute_statistics, False, group=group)
yield from bps.abs_set(beam_centre.stats.compute_centroid, False, group=group)
yield from bps.abs_set(beam_centre.stats.compute_profiles, False, group=group)
yield from bps.abs_set(beam_centre.stats.compute_histogram, False, group=group)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: The setup for this is in the device itself so it feels like the teardown should be too. I think the most logical way to do this would be to replace what you're doing in trigger with a stage and then put this stuff into unstage?

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@noemifrisina
noemifrisina merged commit d83e0c4 into main Oct 20, 2026
12 checks passed
@noemifrisina
noemifrisina deleted the 166-ad-plugin-chain branch October 20, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write an algorithm to move the beam centre to a given pixel value Measure the relationship between mirror voltage and beam position

2 participants