Skip to content

Commit 8b3434a

Browse files
author
Luca Toniolo
committed
Fix split-cycle elapsed_time advance: prevent velocity dip on short segments
In Phase B of a split cycle, cycle_time was still set to remain_time when tpUpdateCycle advanced elapsed_time. This made elapsed = 2*remain instead of remain+cycleTime, causing tpCheckEndCondition to compute a negative last_sample_time when remain < 0.5*cycleTime. Short segments that should have been detected for split-cycle handling were missed, completing mid-cycle on the next regular cycle with progress clamped to target — producing a 20-33% velocity dip and ~30M mm/s³ jerk spike. Reset cycle_time to cycleTime after saving remain_time but before tpUpdateCycle, so the elapsed advance gives the correct value and tpCheckEndCondition can properly detect short segments during Phase B.
1 parent 1b31859 commit 8b3434a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/emc/tp/tp.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4252,7 +4252,6 @@ STATIC int tpUpdateCycle(TP_STRUCT * const tp,
42524252
__atomic_store_n(&tc->shared_9d.branch.taken, 1, __ATOMIC_RELEASE);
42534253
// Clear brake_done flag for fresh two-stage execution
42544254
__atomic_store_n(&tc->shared_9d.branch.brake_done, 0, __ATOMIC_RELEASE);
4255-
42564255
}
42574256
}
42584257

@@ -4920,6 +4919,17 @@ STATIC int tpHandleSplitCycle(TP_STRUCT * const tp, TC_STRUCT * const tc,
49204919
// tpUpdateCycle will overwrite nexttc->cycle_time to tp->cycleTime.
49214920
double nexttc_remain_time = nexttc->cycle_time;
49224921

4922+
// Reset cycle_time to full cycleTime BEFORE tpUpdateCycle.
4923+
// elapsed_time was pre-advanced to remain_time for correct Ruckig
4924+
// sampling. Inside tpUpdateCycle, elapsed_time advances by cycle_time
4925+
// (line 4367). If cycle_time is still remain_time, elapsed becomes
4926+
// 2*remain_time, and tpCheckEndCondition computes a negative
4927+
// last_sample_time when remain < 0.5*cycleTime, preventing detection
4928+
// of short segments that complete within one cycle.
4929+
if (GET_TRAJ_PLANNER_TYPE() == 2) {
4930+
nexttc->cycle_time = tp->cycleTime;
4931+
}
4932+
49234933
// Run split cycle update with remaining time in nexttc
49244934
// KLUDGE: use next cycle after nextc to prevent velocity dip (functions fail gracefully w/ NULL)
49254935
int queue_dir_step = tp->reverse_run ? -1 : 1;

0 commit comments

Comments
 (0)