Repository navigation
Description
Core: master d7aaee3 (build 20260923); stepper.c and state_machine.c on master today are identical.
What happens
If a feed hold is issued while the last (or last-but-few-short) block in the planner is running and the remaining distance of the interrupted block fits into the segment buffer (about 90 ms of motion from standstill: 9 segments of 10 ms), then:
state_await_hold()clears the wholesys.step_control(includingend_motion) when the hold completes (state_machine.c:514).st_prep_buffer()therefore keeps running during the hold (its guard atstepper.c:878isend_motiononly) and preps the rest of the interrupted block into the segment buffer. When the block is fully checked out,plan_discard_current_block()removes it from the planner (stepper.c:1429).- On cycle start,
state_set(STATE_CYCLE)findsplan_get_current_block() == NULL(state_machine.c:261) and does not start the steppers. The state goes back to Idle with the machine short of the block's end. - The segments are still in the buffer. The next motion — in a program typically after
M5/M3/M8/G4or a tool change, i.e. a Z-only retract — starts the stepper ISR, which first executes the leftover segments, then the new block.
Consequence: after a pause taken as a cut finishes (a very ordinary moment to pause), the operator sees the machine stop short and Idle; the program continues with M5; the following Z retract first drags the stopped tool along the remaining path at cutting depth, then lifts. MPos is correct throughout, which makes it hard to notice before the tool moves.
grbl 1.1 kept END_MOTION set until the cycle restarted, so its segment prep stayed blocked during the hold.
Reproduction
Deterministic, in a simulator running the unmodified core (16 MHz emulated MCU, 800 steps/mm):
G53 G1 X-90 Y-96.6667 F600 ; from X-100 Y-100 (10.54 mm, ~1.05 s)
! ; ~0.16 s before the end
~ ; once the status shows Hold:0
- Status after the resume:
<Idle|MPos:-90.419,-96.806,...>— 0.44 mm short, no motion. - Then
M5, thenG53 G0 Z-5: the recorded status stream shows X/Y moving to-90.000,-96.666first, at the old feed, then Z lifting. - Trace of
st_prep_bufferduring the hold:execute_hold,end_motionboth 0 after the hold completed,mm_remainingrunning to 0 and the planner block discarded while in Hold. - Random-program property (one move, hold 0.02–0.35 s before its end, resume at Hold:0, then a Z-only move): about 1 case in 7 shows it; the others either finish the block on resume (hold early enough that the rest does not fit the buffer) or stop with more than one block left.
Proposed fix
Keep the segment prep blocked while the hold is complete:
void st_prep_buffer (void)
{
// Block step prep buffer, while in a suspend state and there is no suspend motion to execute.
if (sys.step_control.end_motion || sys.holding_state == Hold_Complete)
return;Verified in the simulator: the case above finishes the block on resume (the planner still holds it, state Run), the property passes 30 of 30, all other regression tests unchanged (including parking/safety-door paths as far as the simulator exercises them — it has no door). I have not run it on hardware and have not checked the interaction with settings.parking (the hold_partial_block path), which may need the same guard or a different one.
Patch against master (stepper.c):
--- a/stepper.c
+++ b/stepper.c
@@ -875,7 +875,9 @@
void st_prep_buffer (void)
{
// Block step prep buffer, while in a suspend state and there is no suspend motion to execute.
- if (sys.step_control.end_motion)
+ // Also while a feed hold is complete: prepping on could check out the rest of the block and
+ // discard it from the planner, and the resume would then find nothing to restart.
+ if (sys.step_control.end_motion || sys.holding_state == Hold_Complete)
return;
while (segment_buffer.head->next != segment_buffer.tail) { // Check if we need to fill the buffer.
Activity
Fix for potential loss of position after a feed hold due to incorrect…