Skip to content

Smooth_linear_advance WITH s_curve_acceleration [experimental] #27827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

dbuezas
Copy link
Contributor

@dbuezas dbuezas commented Apr 30, 2025

Description

Adds s-curve support to the lookahead function.
Note that smooth linear advance can actually track the acceleration profile, this is different than classic/rough advance, which always managed nozzle pressure as if the profile was trapezoidal.

NOTE: this PR is based upon the not-yet-merged PR #27818 (merged)

NOTE: this PR is based upon the not-yet-merged PR #27862, so all of those changes are included. The actual changes of this PR are inside the "Experimental s-curve" commit only. (merged)

Requirements

Benefits

Configurations

Related Issues

@dbuezas dbuezas marked this pull request as draft April 30, 2025 19:48
@dbuezas dbuezas changed the title Smooth_linear_advance WITH s_curve_acceleration Smooth_linear_advance WITH s_curve_acceleration [experimental] Apr 30, 2025
@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from 32148c4 to 0b0a29e Compare April 30, 2025 20:07
@rq3
Copy link

rq3 commented May 1, 2025

Strange. I have s curves enabled in configuration.h, AND smooth linear enabled in configuration_adv.h, yet I have never gotten a compile error or warning. And yes, the error line is there in the sanity check. It is just never invoked.

I also have all three axes enabled in input shaping, with the frequencies determined by an IPhone accelerometer app.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 1, 2025

@rq3 maybe you had an older version. @thinkyhead added that sanity check at some point.

@rq3
Copy link

rq3 commented May 1, 2025

@rq3 maybe you had an older version. @thinkyhead added that sanity check at some point.

Nope. I get no compiler errors or warnings whether or not that line is in sanity check. Weird. Oh well, I'm off to install the latest compiled firmware.bin with your s-curve mods.

@grizzleeadam
Copy link

Is this intended to be used alongside Input Shaping, or as an alternative? Additionally, does it matter if class jerk or JD is used?

@vovodroid
Copy link
Contributor

@grizzleeadam

Is this intended to be used alongside Input Shaping

Yes, it's different functions with different purposes.

does it matter if class jerk or JD is used?

Doesn't matter.

@rq3

I get no compiler errors or warnings whether or not that line is in sanity check.

Do you have line #error "SMOOTH_LIN_ADVANCE doesn't currently support NONLINEAR_EXTRUSION." in SanityCheck.h?

@dbuezas
Copy link
Contributor Author

dbuezas commented May 10, 2025

@grizzleeadam you may have to recalibrate input shaping and the idea is to combine all together (smooth linear advance + input shaping + s curve)

Please do post your results

@grizzleeadam
Copy link

@grizzleeadam you may have to recalibrate input shaping and the idea is to combine all together (smooth linear advance + input shaping + s curve)

Please do post your results

It looks like PR27818 was just merged. Could you possibly rebase to the latest bugfix?

@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from 0b0a29e to e37cd31 Compare May 15, 2025 07:20
@dbuezas
Copy link
Contributor Author

dbuezas commented May 15, 2025

@grizzleeadam Done, I couldn't test it yet, but the changes are rebased and conflicts resolved

@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from e37cd31 to 0365f43 Compare May 15, 2025 07:34
@dbuezas
Copy link
Contributor Author

dbuezas commented May 15, 2025

Just gave it a test. It works.
I noted the machine crashes if i disable input shaping and try to move an axis. It's probably e-synch accessing broken input shaping delays and factors (so probably not related to this PR)

@dbuezas
Copy link
Contributor Author

dbuezas commented May 15, 2025

@thinkyhead, I took a quick and dirty approach in this PR to avoid interfering with motion. Do you have any ideas how to do this a bit more cleanly?
The issue are the precomputations done once per trapezoid phase, which don't save much time anyway so wondering if we could make the bezier computation not depend on the precomputed factors.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 15, 2025

4k acceleration, 5mm/s jerk, 132mm/s .

image image

@grizzleeadam
Copy link

It seems you're getting a bit more corner over-extrusion with S-curve enabled. I haven't had a chance to try this out yet - have you tried tweaking any other parameters to clean up the corners more? Does look like a significant reduction in ringing.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 17, 2025

Yes, just increased k from 0.04 to 0.05 and it's fine. I think it's just that the head stays a bit longer bear the corner and the low k just depressurized there

@dbuezas
Copy link
Contributor Author

dbuezas commented May 17, 2025

I just remembered I had lowered jerk a lot because i was calibrating input shaping and the Klipper docs say so.

@grizzleeadam
Copy link

IMG_1767

here’s my sample. Top is without S-Curve, bottom is with it enabled. Quality changes with height as I was calibrating JD. It seems the detail inside the triangle is much smoother with S-Curve! Speed is 100mm/s, 3000 acceleration, 0.4K with Bowden.

It seems we may need to have a branch with S-Curve and your other e-sync fix combined together - as of now I’m unable to test re-calibrating IS with S-Curve together.

@vovodroid
Copy link
Contributor

vovodroid commented May 18, 2025 via email

@grizzleeadam
Copy link

grizzleeadam commented May 18, 2025 via email

@vovodroid
Copy link
Contributor

vovodroid commented May 18, 2025 via email

@grizzleeadam
Copy link

That’s not really ringing, more likely banding from my v-rollers. I get that no matter what speed I print at on that axis.

Here’s the other side of those same two prints. The Y’s look much more crisp on the bottom print.

IMG_1768

@vovodroid
Copy link
Contributor

vovodroid commented May 18, 2025 via email

@dbuezas
Copy link
Contributor Author

dbuezas commented May 18, 2025

They're no the same layer height, are they?

It seems we may need to have a branch with S-Curve and your other e-sync fix combined together

Ill rebase this one on top of the fixes today and ping you

@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from 0365f43 to 4864f04 Compare May 18, 2025 08:19
@dbuezas
Copy link
Contributor Author

dbuezas commented May 18, 2025

@grizzleeadam This draft pr now includes the fixes from #27862

@dbuezas
Copy link
Contributor Author

dbuezas commented May 20, 2025

Is this always true?

Same as @robherc, I don't really know for sure. You may be right that the duration of each phase is not the exact same as the trapezoidal profile. In this PR I just piggy back on the existing calculations to compute the appropriate advance for each instant where the smooth linear advance ISR runs.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 20, 2025

Actually, you are right! my prints are taking a less than what the slicer says. And I get less ringing.
I don't know if that wasn't the case already without s-curve. If it wasn't... NOT BAD! 😮

@vovodroid
Copy link
Contributor

I've tried this PR (before conflicts appeared) and got X axis layer shift. Does S-CURVE in this PR also applied to non-printing moves, or it's just coincident?

@dbuezas
Copy link
Contributor Author

dbuezas commented May 21, 2025

S-CURVE in this PR also applied to non-printing moves

Yes, all moves. It could be the case that it is related. S curve reaches I think twice the acceleration in its steepest point, so if you were too close to your max accel it would be best to reduce slightly.

Btw, did you combine it with input shaping? I'm getting very clean prints with everything combined. The cleanest I've ever had

@vovodroid
Copy link
Contributor

I again took a look on print - actually layer shift could happen by short (about 5 millimeters) move (whether printing or travel).

S curve reaches I think twice the acceleration in its steepest point

In this PR or always? I didn't have layer shift with S-CURVE before.

did you combine it with input shaping?

Yes.

The cleanest I've ever had

It's difficult to say on this model, also material I used (PETG) is not the best quality.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 22, 2025

In this PR or always?

Always. This pr only changes extrusion, motion is untouched. Congrats on the non linear extrusion PR merge btw.

The layer shift must be a coincidence, smooth linear advance does not change anything motion related, only extrusion

@vovodroid
Copy link
Contributor

The layer shift must be a coincidence,

Ok, I'll try again

@vovodroid
Copy link
Contributor

Could you resolve conflicts to test on latest version?

@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from f9b787e to c6bc380 Compare May 22, 2025 08:14
@dbuezas
Copy link
Contributor Author

dbuezas commented May 22, 2025

resolved

@vovodroid
Copy link
Contributor

S curve reaches I think twice the acceleration in its steepest point,

I was sure that it reduces vibration and frame load by gradually increasing acceleration, but not exceeds defined limit anyway.

@dbuezas
Copy link
Contributor Author

dbuezas commented May 22, 2025

If that were the case, acceleration would be lower on average. Here @mh-dm has very intuitive visualizations of real data: #27101

@vovodroid
Copy link
Contributor

If that were the case, acceleration would be lower on average.

You bet I thought it was!

@vovodroid
Copy link
Contributor

I printed with this PR - looks good, though I don't have the same object printed before to compare.
Don't you think it's ready for merging?

@dbuezas
Copy link
Contributor Author

dbuezas commented May 30, 2025

Don't you think it's ready for merging?

The code is crappy, need to rebase and reorganize it a bit, but functionally it is done.

I need a better way to make it coexist with the normal usage of the s curve coefficients

(cherry picked from commit 5348de1)

# Conflicts:
#	Marlin/src/inc/SanityCheck.h
#	Marlin/src/module/stepper.cpp
(cherry picked from commit 4e698f1)
@dbuezas dbuezas force-pushed the dbuezas/s-curve-tracking-smooth-advance branch from c6bc380 to 002a7bf Compare May 31, 2025 20:09
@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 3 times, most recently from 3791e7d to 6ea4a16 Compare June 2, 2025 21:51
@dbuezas
Copy link
Contributor Author

dbuezas commented Jun 3, 2025

@thinkyhead any advice on how to reuse the bezier code without backing up variables and whatnot?

@dbuezas dbuezas marked this pull request as ready for review June 5, 2025 19:48
@thinkyhead
Copy link
Member

@thinkyhead any advice on how to reuse the bezier code without backing up variables … ?

These are written in hand-coded assembler for performance, particularly vital on AVR. These routines use the hardcoded RAM addresses of the variables to bypass stack passing. If the functions were re-built around the function calling ABI with a structure pointer and member offsets that would allow them to work on more than just the one set of values. It wouldn't necessarily be faster due to the added stack manipulation. We'd have to get a profiler on that.

@dbuezas
Copy link
Contributor Author

dbuezas commented Jun 9, 2025

Ok, sounds like it wouldn't make much more sense since smooth LA most likely only works on 32 bit machines.

@thinkyhead thinkyhead merged commit fbee2a2 into MarlinFirmware:bugfix-2.1.x Jun 9, 2025
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants