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

Input Shaping improvements #24951

Merged
merged 35 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
34fe801
Frequency = 0 now disables input shaping
tombrazier Oct 25, 2022
518a43e
Adjusted ADAPTIVE_STEP_SMOOTHING calculation to take input shaping in…
tombrazier Oct 28, 2022
aaacf79
Fixed synchronisation error between echo steps and changes in dividends
tombrazier Oct 29, 2022
58797c8
Laser seems to work okay with input shaping, so allow it
tombrazier Oct 29, 2022
2023140
Ensure the double pulse generated on direction change is slow enough …
tombrazier Oct 29, 2022
60966e2
Spread the tiny rounding errors caused by scaling over subsequent seg…
tombrazier Oct 29, 2022
c87be2e
Remember steps that have not yet happened because of echoes when proc…
tombrazier Oct 31, 2022
c5865da
Fixed some errors around IS being disabled for specific axes
tombrazier Nov 3, 2022
c9458cd
Handle multi-stepping in input shaping
tombrazier Nov 3, 2022
1c67a61
Allow disabling input shaping from the menu and make it clear in conf…
tombrazier Nov 5, 2022
8e6aae5
Cache the values for peek_x and peek_y which saves a lot of cycles in…
tombrazier Nov 9, 2022
b76a8df
Testing a bool for shaping being enabled is a lot cheaper than testin…
tombrazier Nov 9, 2022
3d094f1
shaping_isr() gets called a lot, so optimised it
tombrazier Nov 9, 2022
5d10dc5
Updated ASS calculations
tombrazier Nov 9, 2022
312b4c2
Fix DelayQueue
thinkyhead Nov 11, 2022
d8f5e26
misc. cleanup
thinkyhead Nov 11, 2022
e570e1c
Modify configuration
thinkyhead Nov 12, 2022
9ea21dd
Minor fixes
tombrazier Nov 12, 2022
9d6f98e
Cleaned up oversampling_factor vs oversampling
tombrazier Nov 14, 2022
c2a9c5f
Refined step frequency calculations for multi-stepping
tombrazier Nov 14, 2022
24b589b
Add a sufficient delay when changing direction to prevent confusing t…
tombrazier Nov 14, 2022
a1546cb
Take extra step rate from ADAPTIVE_STEP_SMOOTHING into account when s…
tombrazier Nov 16, 2022
24a1b4d
Remove remaining small hysteresis on direction change
tombrazier Nov 19, 2022
35904b3
Instead of changing existing bresenham logic, do IS with a secondary …
tombrazier Nov 19, 2022
62eb0c5
Cleanup
tombrazier Nov 20, 2022
badaab2
Alternative method of preventing buffer overflows: reduce shaping del…
tombrazier Nov 20, 2022
cca1b8e
Optimised free_count_[xy]() functions and updated cycle calculations
tombrazier Nov 20, 2022
d54efc1
Merge branch 'bugfix-2.1.x' into is_improvements
tombrazier Nov 20, 2022
d273909
More realistic default zetas
tombrazier Nov 20, 2022
8fe8a4f
shaping_isr() must now happen before pulse_phase_isr() to prevent buf…
tombrazier Nov 21, 2022
52664a0
Simpler, cleaner alternative buffer overflow logic
tombrazier Nov 21, 2022
35725a7
Updated timings
tombrazier Nov 21, 2022
583f249
Prevent TMC2208/TMC2225 bug using hysteresis
tombrazier Nov 23, 2022
c8c0f3a
Merge branch 'bugfix-2.1.x' into pr/24951
thinkyhead Nov 27, 2022
f2c06af
cleanup
thinkyhead Nov 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,8 @@
*/
//#define INPUT_SHAPING
#if ENABLED(INPUT_SHAPING)
#define SHAPING_FREQ_X 40 // (Hz) The dominant resonant frequency of the X axis.
#define SHAPING_FREQ_Y 40 // (Hz) The dominant resonant frequency of the Y axis.
#define SHAPING_FREQ_X 40 // (Hz) The dominant resonant frequency of the X axis. Comment to disable shaping for X.
#define SHAPING_FREQ_Y 40 // (Hz) The dominant resonant frequency of the Y axis. Comment to disable shaping for Y.
#define SHAPING_ZETA_X 0.3f // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping).
#define SHAPING_ZETA_Y 0.3f // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping).
//#define SHAPING_MENU // Add a menu to the LCD to set shaping parameters.
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/gcode/feature/input_shaping/M593.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ void GcodeSuite::M593() {

if (parser.seen('F')) {
const float freq = parser.value_float();
if (freq > 0) {
constexpr float max_freq = float(uint32_t(STEPPER_TIMER_RATE) / 2) / shaping_time_t(-2);
if (freq == 0.0f || freq > max_freq) {
if (for_X) stepper.set_shaping_frequency(X_AXIS, freq);
if (for_Y) stepper.set_shaping_frequency(Y_AXIS, freq);
}
else
SERIAL_ECHO_MSG("?Frequency (F) must be greater than 0");
SERIAL_ECHOLNPGM("?Frequency (F) must be greater than ", max_freq, " or 0 to disable");
}
}

Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4277,8 +4277,6 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#if ENABLED(INPUT_SHAPING)
#if ENABLED(DIRECT_STEPPING)
#error "INPUT_SHAPING cannot currently be used with DIRECT_STEPPING."
#elif ENABLED(LASER_FEATURE)
#error "INPUT_SHAPING cannot currently be used with LASER_FEATURE."
#endif
#endif

Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ namespace Language_en {
LSTR MSG_A_RETRACT = _UxGT("Retract Accel");
LSTR MSG_A_TRAVEL = _UxGT("Travel Accel");
LSTR MSG_INPUT_SHAPING = _UxGT("Input Shaping");
LSTR MSG_SHAPING_X_FREQ = STR_X _UxGT(" frequency");
LSTR MSG_SHAPING_Y_FREQ = STR_Y _UxGT(" frequency");
LSTR MSG_SHAPING_X_ZETA = STR_X _UxGT(" damping");
LSTR MSG_SHAPING_Y_ZETA = STR_Y _UxGT(" damping");
LSTR MSG_SHAPING_ENABLE = _UxGT("Enable @ shaping");
LSTR MSG_SHAPING_DISABLE = _UxGT("Disable @ shaping");
LSTR MSG_SHAPING_FREQ = _UxGT("@ frequency");
LSTR MSG_SHAPING_ZETA = _UxGT("@ damping");
LSTR MSG_XY_FREQUENCY_LIMIT = _UxGT("XY Freq Limit");
LSTR MSG_XY_FREQUENCY_FEEDRATE = _UxGT("Min FR Factor");
LSTR MSG_STEPS_PER_MM = _UxGT("Steps/mm");
Expand Down
30 changes: 17 additions & 13 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,24 +545,28 @@ void menu_backlash();
START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS);

// M593 F Frequency
// M593 F Frequency and D Damping ratio
#if HAS_SHAPING_X
editable.decimal = stepper.get_shaping_frequency(X_AXIS);
EDIT_ITEM_FAST(float61, MSG_SHAPING_X_FREQ, &editable.decimal, min_frequency, 200.0f, []{ stepper.set_shaping_frequency(X_AXIS, editable.decimal); });
if (editable.decimal) {
ACTION_ITEM_N(X_AXIS, MSG_SHAPING_DISABLE, []{ stepper.set_shaping_frequency(X_AXIS, 0.0f); });
EDIT_ITEM_FAST_N(float61, X_AXIS, MSG_SHAPING_FREQ, &editable.decimal, min_frequency, 200.0f, []{ stepper.set_shaping_frequency(X_AXIS, editable.decimal); });
editable.decimal = stepper.get_shaping_damping_ratio(X_AXIS);
EDIT_ITEM_FAST_N(float42_52, X_AXIS, MSG_SHAPING_ZETA, &editable.decimal, 0.0f, 1.0f, []{ stepper.set_shaping_damping_ratio(X_AXIS, editable.decimal); });
}
else
ACTION_ITEM_N(X_AXIS, MSG_SHAPING_ENABLE, []{ stepper.set_shaping_frequency(X_AXIS, SHAPING_FREQ_X); });
#endif
#if HAS_SHAPING_Y
editable.decimal = stepper.get_shaping_frequency(Y_AXIS);
EDIT_ITEM_FAST(float61, MSG_SHAPING_Y_FREQ, &editable.decimal, min_frequency, 200.0f, []{ stepper.set_shaping_frequency(Y_AXIS, editable.decimal); });
#endif

// M593 D Damping ratio
#if HAS_SHAPING_X
editable.decimal = stepper.get_shaping_damping_ratio(X_AXIS);
EDIT_ITEM_FAST(float42_52, MSG_SHAPING_X_ZETA, &editable.decimal, 0.0f, 1.0f, []{ stepper.set_shaping_damping_ratio(X_AXIS, editable.decimal); });
#endif
#if HAS_SHAPING_Y
editable.decimal = stepper.get_shaping_damping_ratio(Y_AXIS);
EDIT_ITEM_FAST(float42_52, MSG_SHAPING_Y_ZETA, &editable.decimal, 0.0f, 1.0f, []{ stepper.set_shaping_damping_ratio(Y_AXIS, editable.decimal); });
if (editable.decimal) {
ACTION_ITEM_N(Y_AXIS, MSG_SHAPING_DISABLE, []{ stepper.set_shaping_frequency(Y_AXIS, 0.0f); });
EDIT_ITEM_FAST_N(float61, Y_AXIS, MSG_SHAPING_FREQ, &editable.decimal, min_frequency, 200.0f, []{ stepper.set_shaping_frequency(Y_AXIS, editable.decimal); });
editable.decimal = stepper.get_shaping_damping_ratio(Y_AXIS);
EDIT_ITEM_FAST_N(float42_52, Y_AXIS, MSG_SHAPING_ZETA, &editable.decimal, 0.0f, 1.0f, []{ stepper.set_shaping_damping_ratio(Y_AXIS, editable.decimal); });
}
else
ACTION_ITEM_N(Y_AXIS, MSG_SHAPING_ENABLE, []{ stepper.set_shaping_frequency(Y_AXIS, SHAPING_FREQ_Y); });
#endif

END_MENU();
Expand Down
17 changes: 13 additions & 4 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,13 @@ float Planner::triggered_position_mm(const AxisEnum axis) {
return result * mm_per_step[axis];
}

bool Planner::busy() {
return (has_blocks_queued() || cleaning_buffer_counter
|| TERN0(EXTERNAL_CLOSED_LOOP_CONTROLLER, CLOSED_LOOP_WAITING())
|| TERN0(INPUT_SHAPING, stepper.input_shaping_busy())
);
}

void Planner::finish_and_disable() {
while (has_blocks_queued() || cleaning_buffer_counter) idle();
stepper.disable_all_steppers();
Expand Down Expand Up @@ -2484,10 +2491,12 @@ bool Planner::_populate_block(
#endif // XY_FREQUENCY_LIMIT

#if ENABLED(INPUT_SHAPING)
const float top_freq = _MIN(float(0x7FFFFFFFL)
OPTARG(HAS_SHAPING_X, stepper.get_shaping_frequency(X_AXIS))
OPTARG(HAS_SHAPING_Y, stepper.get_shaping_frequency(Y_AXIS))),
max_factor = (top_freq * float(shaping_dividends - 3) * 2.0f) / block->nominal_rate;
float bottom_freq = float(0x7FFFFFFFL);
if (TERN0(HAS_SHAPING_X, stepper.get_shaping_frequency(X_AXIS)))
NOMORE(bottom_freq, stepper.get_shaping_frequency(X_AXIS));
if (TERN0(HAS_SHAPING_Y, stepper.get_shaping_frequency(Y_AXIS)))
NOMORE(bottom_freq, stepper.get_shaping_frequency(Y_AXIS));
const float max_factor = (bottom_freq * (float(shaping_dividends - 3) * 2.0f)) / block->nominal_rate;
NOMORE(speed_factor, max_factor);
#endif

Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/module/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,7 @@ class Planner {
static float triggered_position_mm(const AxisEnum axis);

// Blocks are queued, or we're running out moves, or the closed loop controller is waiting
static bool busy() {
return (has_blocks_queued() || cleaning_buffer_counter
|| TERN0(EXTERNAL_CLOSED_LOOP_CONTROLLER, CLOSED_LOOP_WAITING())
);
}
static bool busy();

// Block until all buffered steps are executed / cleaned
static void synchronize();
Expand Down
Loading