Fix e jerk calculations for linear advance and junction deviation#11118
Fix e jerk calculations for linear advance and junction deviation#11118thinkyhead merged 1 commit intoMarlinFirmware:bugfix-2.0.xfrom
Conversation
|
Cleaned up version of previous PR. Code is the same but hopefully the git state is better. |
bc31872 to
4a68b7b
Compare
thinkyhead
left a comment
There was a problem hiding this comment.
Consider my comment about _EINDEX and if there's still an issue here then make the appropriate changes.
Marlin/src/module/planner.cpp
Outdated
There was a problem hiding this comment.
This cannot be changed, because _EINDEX relies on the extruder parameter passed to _populate_block. We cannot use active_extruder, which could very well have been changed before this function was called.
There was a problem hiding this comment.
The problem is that for the calculation to be correct the max_acceleration_mm_per_s2 term needs to be SQRT(max_acceleration_mm_per_sz[_EINDEX]), but I assume that it is not ideal to be calling SQRT here? Is this the case?
If it is undesirable to call SQRT in this context would it be acceptable to create an array of pre-computed SQRT values for max_acceleration_mm_per_s2 (updated if the underlying values is changed), one for each extruder? I'm not that familiar with the Marlin space/time trade offs but this would add (in the worst case) a second static array of floats with one entry per extruder. If you think this is OK I'll go ahead and modify the PR to do things that way.
There was a problem hiding this comment.
In my opinion the best thing is to use an array for max_e_jerk [EXTRUDERS], so calculate the value for each extruder with its corresponding acceleration and use the macro #define MAX_E_JERK max_e_jerk [active_extruder]
There was a problem hiding this comment.
@gloomyandy — A pre-computed array would do the trick. The array will only be needed when DISTINCT_E_FACTORS (and LIN_ADVANCE) is set. Otherwise a single computed value will do.
There was a problem hiding this comment.
I've just pushed a change that should handle multiple extruders correctly. I did not special case the single extruder case though. Is the compiler smart enough to optimize a single element array accessed via constant value indices into just a single value?
There was a problem hiding this comment.
When DISTINCT_E_FACTORS is disabled, no array is required, and max_acceleration_mm_per_s2 only has a single E entry. So I've patched the code to properly handle this case.
Marlin/src/module/planner.cpp
Outdated
There was a problem hiding this comment.
That's the same as this:
#define MAX_E_JERK max_e_jerk[extruder]7a206da to
a7678ef
Compare
a7678ef to
12bf2a9
Compare
Description
This PR fixes errors in the calculation of the max e jerk setting used when linear advance is active along with junction deviation. The previous implementation was based on an incorrect definition. This version has replaced the previous split calculation to avoid calling SQRT (required by the corrected version) repeatedly. Instead it computes the full e jerk value whenever the contributing factors change.
Benefits
E jerk is now correctly calculated
Related Issues
See issue: #9917