Skip to content

Commit a18952e

Browse files
committed
Fix abort freeze: bypass handoff margin for stop requests in computeBranch
1 parent d35cbe5 commit a18952e

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/emc/motion_planning/motion_planning_9d.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,9 +2458,12 @@ bool computeBranch(TP_STRUCT *tp, TC_STRUCT *tc, double new_feed_scale)
24582458

24592459
// Clamp handoff to before segment end
24602460
if (handoff_time >= profile_duration - min_handoff_margin) {
2461-
if (tp->aborting) {
2462-
// Abort: bypass margin — we must stop no matter where we are
2463-
// in the profile. Place handoff at current time for immediate takeover.
2461+
if (tp->aborting || new_feed_scale < 0.001) {
2462+
// Stop request (abort or feed hold): bypass margin — we must
2463+
// decelerate no matter where we are in the profile. Place handoff
2464+
// at current time for immediate takeover.
2465+
// Note: tpRequestAbortBranch_9D calls us BEFORE tp->aborting is
2466+
// set by RT, so we also check new_feed_scale to catch abort.
24642467
handoff_time = elapsed;
24652468
window_end_time = handoff_time + window_sec + 1.0;
24662469
} else {

src/emc/tp/tp.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,12 +3736,6 @@ STATIC tp_err_t tpHandleAbort(TP_STRUCT * const tp, TC_STRUCT * const tc,
37363736
return TP_ERR_NO_ACTION;
37373737
}
37383738

3739-
// REMOVED: Workaround for late abort no longer needed.
3740-
// The abort-before-mode-change fix in emctask.cc (switching order of
3741-
// emcTaskAbort() and emcTrajSetMode()) ensures aborts arrive before
3742-
// fresh segments are queued, eliminating the race condition this was
3743-
// trying to detect.
3744-
37453739
//If the motion has stopped, then it's safe to reset the TP struct.
37463740
if( MOTION_ID_VALID(tp->spindle.waiting_for_index) ||
37473741
MOTION_ID_VALID(tp->spindle.waiting_for_atspeed) ||
@@ -5115,6 +5109,10 @@ int tpRunCycle(TP_STRUCT * const tp, long period)
51155109
* This prevents trapezoidal→Ruckig switch mid-execution which causes
51165110
* position discontinuity in cycles 2-8 after motion start. */
51175111
if (!__atomic_load_n(&tc->shared_9d.profile.valid, __ATOMIC_ACQUIRE) && tc->progress < TP_POS_EPSILON) {
5112+
/* Abort bypass: don't block abort behind profile wait */
5113+
if (tp->aborting) {
5114+
goto past_gates;
5115+
}
51185116
static int profile_wait_count = 0;
51195117
profile_wait_count++;
51205118

@@ -5140,6 +5138,10 @@ int tpRunCycle(TP_STRUCT * const tp, long period)
51405138
* their v_exit=0 is always correct, no correction needed. */
51415139
if (tc->progress < TP_POS_EPSILON && queue_len < 2 && nexttc == NULL
51425140
&& tc->term_cond != TC_TERM_COND_EXACT) {
5141+
/* Abort bypass: don't block abort behind queue gate */
5142+
if (tp->aborting) {
5143+
goto past_gates;
5144+
}
51435145
static int gate_seg_id = -1;
51445146
static int gate_wait_count = 0;
51455147
/* Reset counter for each new segment */
@@ -5155,6 +5157,7 @@ int tpRunCycle(TP_STRUCT * const tp, long period)
51555157
}
51565158
gate_wait_count = 0;
51575159
}
5160+
past_gates:
51585161
}
51595162

51605163
tc_debug_print("-------------------\n");

0 commit comments

Comments
 (0)