How is stepper position determined during homing

I am trying to understand a certain aspect of the homing process.

When homing/probing, Klipper waits for the trigger from the endstop_state response. After that trigger has been received, it queries the position of the axis stepper(s).

From what I can understand, Klipper uses two values to calculate the axis position - the stepper trigger position and the stepper halt position.

The halt position is the position of the stepper as reported by stepper_get_position. The trigger position is a computed position based on the next_clock value returned by the endstop_state response.

I am confused on how the triggered position is computed. For a printer with 4 Z steppers, the is what Klipper uses to compute the Z axis position when doing QUAD_GANTRY_LEVEL:

halt = {'stepper_z': -4002, 'stepper_z1': -4002, 'stepper_z2': -4003, 'stepper_z3': -4004}, trigger = {'stepper_z': -4298, 'stepper_z1': -4298, 'stepper_z2': -4298, 'stepper_z3': -4298}

What I don’t understand is how can the halt position be a smaller value than the trigger position (the Z axis homes towards 0, so lower position means closer to 0)?

The difference between the halt position and the trigger position seems to be any extra steps that the stepper might have done before it was stopped by the TRSync. So, the absolute value of the halt position should always be >= than the absolute value of the trigger position (abs(halt) >= abs(trigger)).

What you’ve described is a good overview of how homing/probing works - the trigger position is calculated based on the time of the probe/endstop event, and it is separate from where the position the steppers end movement at. (They can be different due to timing of the probe/endstop signal if that signal is produced on an mcu other than the mcus controlling the stepper motors.)

I’m not sure how you produced that debugging data, so I can’t say why you’ve got results that seem odd.

Cheers,
-Kevin