Skip to content

Feature/shift anti lag#225

Open
kferjaoui wants to merge 6 commits into
developerfrom
feature/shift_anti_lag
Open

Feature/shift anti lag#225
kferjaoui wants to merge 6 commits into
developerfrom
feature/shift_anti_lag

Conversation

@kferjaoui

Copy link
Copy Markdown
Collaborator
  • Add single TEM I/O dispatcher and route fast stage moves through it
  • Execute preload/overshoot + correction as an atomic sequence (no interleaving with other TEM calls)
  • Keep existing UI signal wiring and TEMClient dependency unchanged

- Add single TEM I/O dispatcher and route fast stage moves through it
- Execute preload/overshoot + correction as an atomic sequence (no interleaving with other TEM calls)
- Keep existing UI signal wiring and TEMClient dependency unchanged
@kferjaoui kferjaoui linked an issue Dec 14, 2025 that may be closed by this pull request
…correction

- Define globals.preload (e.g. +1 µm / +1°) for two-step overshoot+return moves
- Wire stage jog buttons and move_with_backlash() calls to use preload consistently

- Note: current backlash/overshoot behavior is only applied on negative moves
@tgruene tgruene marked this pull request as ready for review December 18, 2025 12:06

@tgruene tgruene 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.

As far as I can tell, this code replaces 'backlash' with 'preload'. The backlash in task_manager.py (line 803) seems to correct for inaccuracies of the instrument, i.e. if 10um are send to pyJEM, the stage would actually only move e.g. 9.9um, and this is corrected by the backlash. This is very different from the lag-correction. in line 786 in task_manager.py sets backlash to 0 in case the stage is already in moving direction, also this seems to lead to undesired behaviour. If the user came the the crystal from the same direction, lag-correction would still be required in order to move back to the crystal after alignment 10um off the crystal, right?

@kferjaoui kferjaoui self-assigned this Jan 19, 2026
- implement “parking” movements to reduce backlash: move past target by a preload margin, then step back by preload so gears are loaded in the return direction. For e.g; pushing [+10µm] moves +12µm then −2µm; [−10µm] -> −12µm then +2µm; same idea for ±TX degrees
- track a per-axis net “away” displacement (accumulator) so repeated parking movements stack; Back returns in one straight move by −net_away (no preload) and then resets the accumulator.
- serialize all TEM ZMQ commands through a single dispatcher lane to avoid overlapping REQ/REP calls and reduce timeouts under polling + user actions

TODO: tie "back buttons" status control (enable/disable) + accumulator reset to dispatcher success via Qt queued signal/callback (currently toggled from main thread)
@kferjaoui

kferjaoui commented Jan 20, 2026

Copy link
Copy Markdown
Collaborator Author

Hi Tim,
I have updated the logic of the lag-corrected moves in the latest commit dda021c. I have tested the routines behavior using a dummy TEM server, so actual testing at the instrument remains necessary.

To implement the “move away -> align -> move back to crystal” workflow, the new code:

  1. renames the parameter to preload
  2. and in move_parking_with_preload() it always does the two-step sequence via _two_step_sequence()
    (overshoot then step back), regardless of previous direction.

So the old logic that could zero the correction:

# (old idea)
if direction == 0 and last_diff_sign >= 0: preload = 0
...

has been discarded.

Because for this use case it causes the exact undesired behavior you mention: even if you approached from the same direction, you still want the “park away” move to preload the gears so the later Back is repeatable.

Finally, the return is handled by the added back buttons (Back X for translation in the x direction, Back TX for rotation) through the move_back_no_preload() function which sends one straight move by -away (no preload), then clears the stored away value.

Situation: The GUI allows to accumulate multiple fast movements hence the Back button will compensate for the accumulated distance i.e. if you click twice on the button [+10µm], then you will perform 2 lag-corrected moves i.e. +12µm → -2µm then 12µm → -2µm with a final state at +20µm but cogs set in the direction of (-x) and by using the button Back X you'd perform a straight shot of -20µm without backlash. After completion, the Back X button is disabled (as there is nothing to go back to).

N.B: I kept the old routine move_with_backlash() as it is still used in some of the operations implemented by KT such as in subimageMouseClickEvent() or the CenteringTask (stage_centering_task.py). I can update the functionalities to incorporate the logic of the new fct move_parking_with_preload if you are satisfied with the current lag-corrected fast movements.

@kferjaoui kferjaoui requested a review from tgruene January 20, 2026 15:33
@kferjaoui kferjaoui mentioned this pull request Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

+/-10um shifts with anti-lag

2 participants