-
-
Notifications
You must be signed in to change notification settings - Fork 194
Description
A surprising property of the non-linear PA models from Dmitry (in BEv2 branch) is that the nonlinear function is only applied to the final smoothed velocity after integrating extruder velocity over the smooth time window. This has two very negative consequences:
- Smoothing cannot be applied to the nonlinearity to reduce the severity of the motions it imposes on the extruder. This requires using a higher linearization velocity, and/or lower linear offset, than what might be physically ideal.
- Because the integral of a nonlinear function is not equal to the nonlinear function of the integral (integration only commutes with linear functions), the amount of advance is not actually accurate.
Problem 2 is big, I think. The nonlinear PA response will only pull back on advance when it sees a very low speed (roughly, under the linearization velocity). We want this to happen especially at corners at reasonable SCV values for high quality, where the SCV is well under the linearization velocity. However, with high kinematic acceleration, unless the PA smooth time is extremely low, the average, smoothed-out extruder velocity around a corner will remain well above the linearization velocity, so that only the linear PA term has any effect. This in turn makes it necessary to configure a linear PA constant much higher than ideal to get good corners. And moreover, the magnitude of the excess depends in a complicated way on speed and acceleration. As such, this is probably one of the remaining root causes for the "you need different PA settings at different speeds and accelerations" problem.
The reason the nonlinear model was implemented as applying post-integration is clear: there's no easy and cheap analytic way to integrate tanh(mx+b) times a window function, so we'd be stuck with a lot of expensive math per move in the integrator or doing an (also expensive) discretized numerical integration instead of antiderivatives.
What I'd like to propose is simplifying the nonlinear model to an exponential function of the form A(1-exp(-x/B)). This is relatively easy to integrate in closed form even with a window function, and the parameters can be chosen to fit the tanh curve almost exactly for x≥0. Then, when nonlinear PA is enabled, the integrator can process the exponential part alongside the linear part in computing the smoothed PA integral. If my math is correct, should amount to two calls to exp (or likely an optimized approximation for the limited domain) for each move in the integration interval.
Moreover, I'd like to consider implementing this first for mainline Kalico branch rather than BEv2. IMO the changes Dmitry made to PA in the advanced features branch make it harder to implement new functionality like this, especially with good performance, because the factoring of the code makes for more internal interfaces that the parameters and results need to be marshalled across. But perhaps more importantly, I think this would open the door to getting nonlinear PA to a wider audience, and maybe even getting it in Klipper too someday. The big blocker to doing this, however, is lack of extruder sync-to-IS in mainline. Without that, the results will certainly be worse than anything in BEv2 right now. So, if I'm going to do this in mineline, I think a prerequisite is adapting sync-to-IS or comparable functionality to mainline. I have some ideas for that too, which I'll probably put forth in a separate ticket.