Repository navigation
tp: S-curve (PLANNER_TYPE 1) fixes for feed override changes - #4974
Open
MetalMusings wants to merge 3 commits into
Open
MetalMusings wants to merge 3 commits into
MetalMusings wants to merge 3 commits into
Conversation
With PLANNER_TYPE = 1, tpCalculateSCurveAccel reported DECEL whenever Ruckig slowed down, and that becomes tc->on_final_decel, which lets tcIsBlending start the parabolic blend into the next segment. Slowing down for a lower feed override in the middle of a segment then started the blend there: the next segment ran while this one still had its whole length to go, and the commanded path was offset by the next segment's displacement for the rest of it. Seen on a 3 turn G3 helix (P4) followed by a 10 mm G1, with the feed override changed every 0.25 s: after about a turn the path left the helix and ran a helix shifted by -10 mm in X to the end, 10 mm off the programmed path. With 5 random override sequences this happened in 2. DECEL is now only reported within the distance it takes to stop (with 20 % and one cycle to spare), as the trapezoidal planner's final deceleration test does in effect. Without override changes the motion is unchanged; with them the helix stays on its path in all 5. Reproduce with tests/trajectory-bench of the scurve branch: run.py -p tp1 -g helix -s 0.25:0.2:1.8:1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With PLANNER_TYPE = 1, a segment that ends within a servo cycle hands the rest of the cycle to the next segment. Two things in that hand-over assumed the trapezoidal planner: - tpCheckEndCondition estimated when in the cycle the segment ends from a speed going straight to the final velocity. Under the S-curve the speed changes over many cycles; after a feed override change the segment ends at a speed far from the new final velocity, the split time is wrong, and the position steps by the difference. - The next segment started from the speed and acceleration at the start of the cycle, losing the speed change of the split time. Both show as a one cycle dip or bump in the speed, a jerk far above the limit: up to 70x MAX_JERK at a 0.5 ms servo period on a spiral of short segments with the feed override changed every 0.25 s. The split time is now where the current velocity, acceleration and jerk reach the end of the segment (bisection within the cycle), and the next segment takes over the velocity and acceleration at that time. Motion without override changes is unchanged in the trajectory bench. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With PLANNER_TYPE = 1, Ruckig position control could not replan in two cases that feed override changes bring about. The replan failed, and the segment either ran its old trajectory on to its end or, right after a switch from velocity control, fell back to a trapezoidal profile with a step in the acceleration (50x MAX_JERK). - Above the max velocity after the override was lowered: Ruckig brakes into the velocity limit at full jerk and arrives still decelerating, so it has to undershoot and come back up, which on a short segment takes going backwards; min velocity 0 forbids that. Velocity control now slows to the max velocity with zero acceleration, where slowing to the final velocity fits in the distance left, and position control takes over from there; where it does not fit, velocity control slows to the final velocity as fast as it can. Past the end of a velocity profile the motion goes on at the speed reached, where the clamped Ruckig time used to stop it for the rest of the cycle. - Below a final velocity the segment has no room to reach after the override was raised: plan again to the highest final velocity there is room for. Checked in the trajectory bench at 0.5 and 1 ms servo periods with random override steps (20-180 % every 0.25 s, 10-200 % every 50 ms, 0-150 % every 0.1 s): no replan fails, and the axis jerk stays within 1.5x MAX_JERK, the rest being from stops ending within a cycle and curvature steps at arc joins, which are there without override changes too. Without override changes the motion is unchanged. tests/motion, tests/tp, tests/trajectory-planner, tests/abort pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tp: S-curve (PLANNER_TYPE 1) fixes for feed override changes
With
[TRAJ]PLANNER_TYPE = 1, changing the feed override while a programruns can take the tool off the programmed path, by up to the length of the
next segment, and can give jerk spikes of up to 70×
MAX_JERK. This PRfixes three causes, one commit each. All changes are in
src/emc/tp/tp.c(+157 −8 lines) and only affect
PLANNER_TYPE = 1. Without feed overridechanges, the motion is the same as before.
b9377e5a11): the toolleaves the path.
ea28c2870c): one-cyclespeed dips.
2ddbfca578): the old speed is kept,or the segment falls back to a trapezoidal profile.
Test setup
The machine used 200 mm/s, 2000 mm/s² and 50000 mm/s³ on X, Y and Z. The
servo period was 1 ms or 0.5 ms. The commanded axis positions were sampled
every servo cycle. They were compared with the programmed path, and with
the axis velocity, acceleration and jerk limits computed from position
differences. The feed override was stepped to random values while the
programs ran:
There were 10 programs: lines, arcs, chords, a spiral of short segments, a
helix, rapids, exact stop and G95.
1. Final deceleration only near the end of the segment
Problem
Lowering the feed override in the middle of a segment can start the
parabolic blend into the next segment far too early. The next segment then
runs to its end while the current one still has most of its length to go.
For the rest of the current segment, the commanded path is offset by the
next segment's whole displacement.
Example: a 3-turn G3 helix followed by a 10 mm G1, with the feed override
changed while the helix runs:
About one turn into the helix, the commanded position leaves it. It then
follows the same helix shifted by −10 mm in X (centre at X−10 instead of
X0) down to Z−10, and ends at X0 Y0 Z−10. That is up to 10 mm off the
programmed path, while the reported velocity looks normal.
This happened in 2 of 5 random override sequences of 20–180 % every 0.25 s
at 1 ms. It needs the override to drop, and the speed to fall below the
blend velocity, while the segment is still slowing down.
Cause
tpCalculateSCurveAccel()returnsTP_SCURVE_ACCEL_DECELwhenever Ruckigslows down:
tpUpdateCycle()stores that astc->on_final_decel.tcIsBlending()starts the parabolic blend when
on_final_decelis set and the speed isbelow
blend_vel, and keeps it set until the blend is complete. So anydeceleration counts as the final one, including one for a lower feed
override in the middle of a long segment.
The trapezoidal planner sets
on_final_decelonly when the distance leftis what slows the segment down, that is, near its end. The S-curve path has
no such condition.
Fix
Report
DECELonly within the jerk-limited distance needed to stop. Thecheck uses
stoppingDist()fromsp_scurve, with 20 % and one cycle ofmargin:
The final deceleration towards the blend happens within that distance.
Slowing to the final velocity takes about as much distance as stopping, or
less, and the margin covers the difference in profile shape. Normal blends
therefore start as before. Only decelerations far from the end, which come
from the feed override, no longer start a blend.
2. Segment changes within a servo cycle, from the motion actually made
Problem
A segment that ends within a servo cycle hands the rest of that cycle to
the next segment. With override changes, this gives single-cycle dips or
bumps in the speed, for example 14.3 → 13.5 → 14.2 mm/s. Their jerk is far
above the limit: up to 30×
MAX_JERKat 1 ms, and up to 70× at 0.5 ms onthe spiral of short segments.
Cause
Two parts of that hand-over assume the trapezoidal planner:
tpCheckEndCondition()estimates when in the cycle the segment ends. Itassumes the speed goes straight to the final velocity. Under the S-curve
planner the speed changes over many cycles. After an override change the
segment ends at a speed far from the new final velocity. The estimated
time is then wrong, and the position steps by the difference.
tpHandleSplitCycle()starts the next segment from the speed andacceleration at the start of the cycle. That loses the speed change up to
the split time.
Fix
For
PLANNER_TYPE = 1, a newtpCheckEndConditionSCurve()finds the splittime. It is the first time in the cycle where the current velocity,
acceleration and jerk reach the end of the segment, found by bisection. The
final velocity is the speed at that time. The next segment takes over that
speed and the acceleration the current jerk has reached by then.
3. Ruckig replans that fail after override changes
Problem
Ruckig position control finds no trajectory in two cases that override
changes create. When the replan fails, the segment either runs its old
trajectory on at the old speed to its end, or, right after velocity
control, falls back to a trapezoidal profile. That fallback has a step in
the acceleration, up to 53×
MAX_JERK.Cause and fix
into the velocity limit at full jerk and arrives still decelerating. It
then has to go below the limit and come back up. On a short segment that
takes going backwards, which a min velocity of 0 forbids.
zero acceleration, and position control takes over from there. This
applies where there is still room to slow to the final velocity after
that.
final velocity as fast as it can.
reached. Before, the clamped Ruckig time stopped the motion for the
rest of the cycle.
override was raised. Ruckig is now asked again with the highest final
velocity there is room for, found by bisection. The next segment does
the rest of the speed-up.
Testing
Highest axis jerk, as a multiple of
MAX_JERK, over all programs andoverride sequences:
The remaining excess, up to about 1.5×, also occurs without override
changes and is not touched by this PR. It comes from stops that end within
a cycle, and from the curvature step where a G2 joins a G3.
At 0.5 ms on PREEMPT_RT, the longest cycles were 35 µs for
motion-controllerand 16 µs formotion-command-handler.On master c21c442 these tests pass:
tests/motion,tests/tp,tests/trajectory-planner,tests/abort,jog-speed-change,stale-motion-statusandspindle-sync-scurve.Reproducing without the sampling setup
PLANNER_TYPE = 1andMAX_LINEAR_JERKset.the feed override slider down and up a few times.
🤖 Generated with Claude Code