Skip to content
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

[FR] Input Shaping - Marlin 2.1.2 #402

Closed
St-Aris opened this issue Dec 21, 2022 · 8 comments
Closed

[FR] Input Shaping - Marlin 2.1.2 #402

St-Aris opened this issue Dec 21, 2022 · 8 comments

Comments

@St-Aris
Copy link

St-Aris commented Dec 21, 2022

Description

Marlin 2.1.2 has a new Klipper like input shaping feature:

https://marlinfw.org/docs/gcode/M593.html

Any chance on working on a port of this - looks soooo interesting. Perhaps in the next major release - i'm sure it will be getting a fair bit of tweaking.

Feature Workflow

(https://marlinfw.org/docs/gcode/M593.html)

Additional Information

@stklcode
Copy link
Contributor

stklcode commented Dec 22, 2022

With the fix #405 is merged into master, the full 2.1.2 upstream sources are available.

The (experimental) feature can be enabled adding something like this to the configuration:

/**
 * Input Shaping -- EXPERIMENTAL
 *
 * Zero Vibration (ZV) Input Shaping for X and/or Y movements.
 *
 * This option uses a lot of SRAM for the step buffer. The buffer size is
 * calculated automatically from SHAPING_FREQ_[XY], DEFAULT_AXIS_STEPS_PER_UNIT,
 * DEFAULT_MAX_FEEDRATE and ADAPTIVE_STEP_SMOOTHING. The default calculation can
 * be overridden by setting SHAPING_MIN_FREQ and/or SHAPING_MAX_FEEDRATE.
 * The higher the frequency and the lower the feedrate, the smaller the buffer.
 * If the buffer is too small at runtime, input shaping will have reduced
 * effectiveness during high speed movements.
 *
 * Tune with M593 D<factor> F<frequency>:
 *
 *  D<factor>    Set the zeta/damping factor. If axes (X, Y, etc.) are not specified, set for all axes.
 *  F<frequency> Set the frequency. If axes (X, Y, etc.) are not specified, set for all axes.
 *  T[map]       Input Shaping type, 0:ZV, 1:EI, 2:2H EI (not implemented yet)
 *  X<1>         Set the given parameters only for the X axis.
 *  Y<1>         Set the given parameters only for the Y axis.
 */
//#define INPUT_SHAPING_X
//#define INPUT_SHAPING_Y
#if EITHER(INPUT_SHAPING_X, INPUT_SHAPING_Y)
  #if ENABLED(INPUT_SHAPING_X)
    #define SHAPING_FREQ_X  40          // (Hz) The default dominant resonant frequency on the X axis.
    #define SHAPING_ZETA_X  0.15f       // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping).
  #endif
  #if ENABLED(INPUT_SHAPING_Y)
    #define SHAPING_FREQ_Y  40          // (Hz) The default dominant resonant frequency on the Y axis.
    #define SHAPING_ZETA_Y  0.15f       // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping).
  #endif
  //#define SHAPING_MIN_FREQ  20        // By default the minimum of the shaping frequencies. Override to affect SRAM usage.
  //#define SHAPING_MAX_STEPRATE 10000  // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage.
  //#define SHAPING_MENU                // Add a menu to the LCD to set shaping parameters.
#endif

I don't have any idea which parameter values might be appropriate for our printers, so somebody has to figure them out...

@St-Aris
Copy link
Author

St-Aris commented Jan 1, 2023

Can anyone confirm if this is enabled in the latest beta hext file?

@St-Aris St-Aris closed this as completed Jan 1, 2023
@St-Aris St-Aris reopened this Jan 1, 2023
@dtylerb
Copy link

dtylerb commented Jan 28, 2023

With the fix #405 is merged into master, the full 2.1.2 upstream sources are available.

The (experimental) feature can be enabled adding something like this to the configuration:

/**
 * Input Shaping -- EXPERIMENTAL
 *
 * Zero Vibration (ZV) Input Shaping for X and/or Y movements.
 *
 * This option uses a lot of SRAM for the step buffer. The buffer size is
 * calculated automatically from SHAPING_FREQ_[XY], DEFAULT_AXIS_STEPS_PER_UNIT,
 * DEFAULT_MAX_FEEDRATE and ADAPTIVE_STEP_SMOOTHING. The default calculation can
 * be overridden by setting SHAPING_MIN_FREQ and/or SHAPING_MAX_FEEDRATE.
 * The higher the frequency and the lower the feedrate, the smaller the buffer.
 * If the buffer is too small at runtime, input shaping will have reduced
 * effectiveness during high speed movements.
 *
 * Tune with M593 D<factor> F<frequency>:
 *
 *  D<factor>    Set the zeta/damping factor. If axes (X, Y, etc.) are not specified, set for all axes.
 *  F<frequency> Set the frequency. If axes (X, Y, etc.) are not specified, set for all axes.
 *  T[map]       Input Shaping type, 0:ZV, 1:EI, 2:2H EI (not implemented yet)
 *  X<1>         Set the given parameters only for the X axis.
 *  Y<1>         Set the given parameters only for the Y axis.
 */
//#define INPUT_SHAPING_X
//#define INPUT_SHAPING_Y
#if EITHER(INPUT_SHAPING_X, INPUT_SHAPING_Y)
  #if ENABLED(INPUT_SHAPING_X)
    #define SHAPING_FREQ_X  40          // (Hz) The default dominant resonant frequency on the X axis.
    #define SHAPING_ZETA_X  0.15f       // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping).
  #endif
  #if ENABLED(INPUT_SHAPING_Y)
    #define SHAPING_FREQ_Y  40          // (Hz) The default dominant resonant frequency on the Y axis.
    #define SHAPING_ZETA_Y  0.15f       // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping).
  #endif
  //#define SHAPING_MIN_FREQ  20        // By default the minimum of the shaping frequencies. Override to affect SRAM usage.
  //#define SHAPING_MAX_STEPRATE 10000  // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage.
  //#define SHAPING_MENU                // Add a menu to the LCD to set shaping parameters.
#endif

I don't have any idea which parameter values might be appropriate for our printers, so somebody has to figure them out...

I downloaded the latest Knutwurst firmware (1.5.0 beta 3) thinking it would have input shaping because it is listed in the changelog on marlinfw.org as being part of version 2.1.2, and the changelog for the knutwurst firmware says that as of version 1.5.0 beta 3 the codebase has been updated to Marlin 2.1.2. Unfortunately I found that the section on input shaping was missing from configuration_adv.h. I then ran across this post and pasted the section above in to my configuration_adv.h, but was unable to compile due to some errors. I then downloaded the stock Marlin 2.1.2 so that I could see exactly where in the file it belongs (in case that makes a difference) and copied and pasted it from the stock Marlin configuration_adv.h in to exactly the same spot, but it made no difference. Oh, and of course in all cases I uncommented the lines for #define INPUT_SHAPING_X and Y. Obviously there's more to it than that. Here are the errors:

Compiling .pio\build\MEGA_S_TMC\src\src\feature\bedlevel\bedlevel.cpp.o
In file included from Marlin\src\MarlinCore.cpp:47:0:
Marlin\src\module/stepper.h:348:56: in constexpr expansion of 'max_isr_rate<>()'
Marlin\src\module/stepper.h:348:75: error: array subscript value '4' is outside the bounds of array type 'const feedRate_t [4] {aka const float [4]}'
constexpr float max_step_rate = _MIN(max_isr_rate(), max_shaped_rate);
^
Marlin\src\module/stepper.h:370:55: error: size of array 'times' is not an integral constant-expression
static shaping_time_t times[shaping_echoes];
^
Marlin\src\module/stepper.h:371:59: error: size of array 'echo_axes' is not an integral constant-expression
static shaping_echo_axis_t echo_axes[shaping_echoes];
^
Compiling .pio\build\MEGA_S_TMC\src\src\feature\bedlevel\hilbert_curve.cpp.o
*** [.pio\build\MEGA_S_TMC\src\src\MarlinCore.cpp.o] Error 1
In file included from Marlin\src\feature\babystep.cpp:31:0:
Marlin\src\feature../module/stepper.h:348:56: in constexpr expansion of 'max_isr_rate<>()'
Marlin\src\feature../module/stepper.h:348:75: error: array subscript value '4' is outside the bounds of array type 'const feedRate_t [4] {aka const float [4]}'
constexpr float max_step_rate = _MIN(max_isr_rate(), max_shaped_rate);
^
Marlin\src\feature../module/stepper.h:370:55: error: size of array 'times' is not an integral constant-expression
static shaping_time_t times[shaping_echoes];
^
Marlin\src\feature../module/stepper.h:371:59: error: size of array 'echo_axes' is not an integral constant-expression
static shaping_echo_axis_t echo_axes[shaping_echoes];
^
*** [.pio\build\MEGA_S_TMC\src\src\feature\babystep.cpp.o] Error 1
====================================================================================== [FAILED] Took 10.86 seconds ======================================================================================

@stklcode
Copy link
Contributor

stklcode commented Jan 28, 2023

Obviously there's more to it than that.

At the very least you have to comment out the source exclusion from the platformio.ini:

-<src/gcode/feature/input_shaping>

I.e. make this line
# -<src/gcode/feature/input_shaping>

@St-Aris
Copy link
Author

St-Aris commented Jan 28, 2023

Could we get a beta image with this enabled? Do the original early trigorilla boards have enough ram to handle it?

@dtylerb
Copy link

dtylerb commented Jan 28, 2023

Obviously there's more to it than that.

At the very least you have to comment out the source exclusion from the platformio.ini:

-<src/gcode/feature/input_shaping>

I.e. make this line # -<src/gcode/feature/input_shaping>

Well, that didn't fix it. I haven't done any serious coding in many years and when I did it wasn't using Visual Studio/platform.io, so it may be a simple issue but I have limited ability to troubleshoot. Anyhow, if it's not a simple thing to tell me how to get it enabled, I just wanted those who do have the ability to know that it's either not working or there aren't clear instructions that work (or at least not that I've been able to find). I'm still getting the same errors.

I appreciate the help so far.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants