Skip to content

Feed hold in the last ~100 ms of the last planned block: resume does nothing, the remaining motion runs together with the next block #1024

Open

Description

@yiivon

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:

  1. state_await_hold() clears the whole sys.step_control (including end_motion) when the hold completes (state_machine.c:514).
  2. st_prep_buffer() therefore keeps running during the hold (its guard at stepper.c:878 is end_motion only) 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).
  3. On cycle start, state_set(STATE_CYCLE) finds plan_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.
  4. The segments are still in the buffer. The next motion — in a program typically after M5/M3/M8/G4 or 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, then G53 G0 Z-5: the recorded status stream shows X/Y moving to -90.000,-96.666 first, at the old feed, then Z lifting.
  • Trace of st_prep_buffer during the hold: execute_hold, end_motion both 0 after the hold completed, mm_remaining running 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions