Skip to content

Commit 8a33c74

Browse files
thinkyheaddbuezas
andauthored
✨ M493/M493 FT_MOTION (V2) (#608)
Co-authored-by: David Buezas <dbuezas@users.noreply.github.com>
1 parent a07b7d1 commit 8a33c74

File tree

4 files changed

+247
-72
lines changed

4 files changed

+247
-72
lines changed

_configuration/configuration.md

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,66 +2738,91 @@ The Fixed-Time-based Motion Control (FTM) feature provides an alternative motion
27382738
```cpp
27392739
/**
27402740
* Fixed-time-based Motion Control -- BETA FEATURE
2741-
* Enable/disable and set parameters with G-code M493.
2741+
* Enable/disable and set parameters with G-code M493 and M494.
27422742
* See ft_types.h for named values used by FTM options.
27432743
*/
27442744
//#define FT_MOTION
27452745
#if ENABLED(FT_MOTION)
2746-
//#define FTM_IS_DEFAULT_MOTION // Use FT Motion as the factory default?
2746+
//#define FTM_IS_DEFAULT_MOTION // Use FT Motion as the factory default?
2747+
//#define FT_MOTION_MENU // Provide a MarlinUI menu to set M493 and M494 parameters
2748+
//#define FTM_HOME_AND_PROBE // Use FT Motion for homing / probing. Disable if FT Motion breaks these functions.
2749+
27472750
#define FTM_DEFAULT_DYNFREQ_MODE dynFreqMode_DISABLED // Default mode of dynamic frequency calculation. (DISABLED, Z_BASED, MASS_BASED)
2751+
2752+
#define FTM_LINEAR_ADV_DEFAULT_ENA false // Default linear advance enable (true) or disable (false)
2753+
#define FTM_LINEAR_ADV_DEFAULT_K 0.0f // Default linear advance gain. (Acceleration-based scaling factor.)
2754+
27482755
#define FTM_DEFAULT_SHAPER_X ftMotionShaper_NONE // Default shaper mode on X axis (NONE, ZV, ZVD, ZVDD, ZVDDD, EI, 2HEI, 3HEI, MZV)
2756+
#define FTM_SHAPING_DEFAULT_FREQ_X 37.0f // (Hz) Default peak frequency used by input shapers
2757+
#define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis
2758+
#define FTM_SHAPING_V_TOL_X 0.05f // Vibration tolerance used by EI input shapers for X axis
2759+
27492760
#define FTM_DEFAULT_SHAPER_Y ftMotionShaper_NONE // Default shaper mode on Y axis
2750-
#define FTM_SHAPING_DEFAULT_FREQ_X 37.0f // (Hz) Default peak frequency used by input shapers
2751-
#define FTM_SHAPING_DEFAULT_FREQ_Y 37.0f // (Hz) Default peak frequency used by input shapers
2752-
#define FTM_LINEAR_ADV_DEFAULT_ENA false // Default linear advance enable (true) or disable (false)
2753-
#define FTM_LINEAR_ADV_DEFAULT_K 0.0f // Default linear advance gain. (Acceleration-based scaling factor.)
2754-
#define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis
2755-
#define FTM_SHAPING_ZETA_Y 0.1f // Zeta used by input shapers for Y axis
2761+
#define FTM_SHAPING_DEFAULT_FREQ_Y 37.0f // (Hz) Default peak frequency used by input shapers
2762+
#define FTM_SHAPING_ZETA_Y 0.1f // Zeta used by input shapers for Y axis
2763+
#define FTM_SHAPING_V_TOL_Y 0.05f // Vibration tolerance used by EI input shapers for Y axis
2764+
2765+
//#define FTM_SHAPER_Z // Include Z shaping support
2766+
#define FTM_DEFAULT_SHAPER_Z ftMotionShaper_NONE // Default shaper mode on Z axis
2767+
#define FTM_SHAPING_DEFAULT_FREQ_Z 21.0f // (Hz) Default peak frequency used by input shapers
2768+
#define FTM_SHAPING_ZETA_Z 0.03f // Zeta used by input shapers for Z axis
2769+
#define FTM_SHAPING_V_TOL_Z 0.05f // Vibration tolerance used by EI input shapers for Z axis
2770+
2771+
//#define FTM_SHAPER_E // Include E shaping support
2772+
// Required to synchronize extruder with XYZ (better quality)
2773+
#define FTM_DEFAULT_SHAPER_E ftMotionShaper_NONE // Default shaper mode on Extruder axis
2774+
#define FTM_SHAPING_DEFAULT_FREQ_E 21.0f // (Hz) Default peak frequency used by input shapers
2775+
#define FTM_SHAPING_ZETA_E 0.03f // Zeta used by input shapers for E axis
2776+
#define FTM_SHAPING_V_TOL_E 0.05f // Vibration tolerance used by EI input shapers for E axis
2777+
2778+
//#define FTM_SMOOTHING // Smoothing can reduce artifacts and make steppers quieter
2779+
// on sharp corners, but too much will round corners.
2780+
#if ENABLED(FTM_SMOOTHING)
2781+
#define FTM_MAX_SMOOTHING_TIME 0.10f // (s) Maximum smoothing time. Higher values consume more RAM.
2782+
// Increase smoothing time to reduce jerky motion, ghosting and noises.
2783+
#define FTM_SMOOTHING_TIME_X 0.00f // (s) Smoothing time for X axis. Zero means disabled.
2784+
#define FTM_SMOOTHING_TIME_Y 0.00f // (s) Smoothing time for Y axis
2785+
#define FTM_SMOOTHING_TIME_Z 0.00f // (s) Smoothing time for Z axis
2786+
#define FTM_SMOOTHING_TIME_E 0.02f // (s) Smoothing time for E axis. Prevents noise/skipping from LA by
2787+
// smoothing acceleration peaks, which may also smooth curved surfaces.
2788+
#endif
27562789

2757-
#define FTM_SHAPING_V_TOL_X 0.05f // Vibration tolerance used by EI input shapers for X axis
2758-
#define FTM_SHAPING_V_TOL_Y 0.05f // Vibration tolerance used by EI input shapers for Y axis
2790+
#define FTM_TRAJECTORY_TYPE TRAPEZOIDAL // Block acceleration profile (TRAPEZOIDAL, POLY5, POLY6)
2791+
// TRAPEZOIDAL: Continuous Velocity. Max acceleration is respected.
2792+
// POLY5: Like POLY6 with 1.5x but cpu cheaper.
2793+
// POLY6: Continuous Acceleration (aka S_CURVE).
2794+
// POLY trajectories not only reduce resonances without rounding corners, but also
2795+
// reduce extruder strain due to linear advance.
27592796

2760-
//#define FT_MOTION_MENU // Provide a MarlinUI menu to set M493 parameters
2797+
#define FTM_POLY6_ACCELERATION_OVERSHOOT 1.875f // Max acceleration overshoot factor for POLY6 (1.25 to 1.875)
27612798

27622799
/**
27632800
* Advanced configuration
27642801
*/
2765-
#define FTM_UNIFIED_BWS // DON'T DISABLE unless you use Ulendo FBS (not implemented)
2802+
#define FTM_UNIFIED_BWS // DON'T DISABLE unless you use Ulendo FBS (not implemented)
27662803
#if ENABLED(FTM_UNIFIED_BWS)
2767-
#define FTM_BW_SIZE 100 // Unified Window and Batch size with a ratio of 2
2804+
#define FTM_BW_SIZE 100 // Unified Window and Batch size with a ratio of 2
27682805
#else
2769-
#define FTM_WINDOW_SIZE 200 // Custom Window size for trajectory generation needed by Ulendo FBS
2770-
#define FTM_BATCH_SIZE 100 // Custom Batch size for trajectory generation needed by Ulendo FBS
2806+
#define FTM_WINDOW_SIZE 200 // Custom Window size for trajectory generation needed by Ulendo FBS
2807+
#define FTM_BATCH_SIZE 100 // Custom Batch size for trajectory generation needed by Ulendo FBS
27712808
#endif
27722809

2773-
#define FTM_FS 1000 // (Hz) Frequency for trajectory generation. (Reciprocal of FTM_TS)
2774-
#define FTM_TS 0.001f // (s) Time step for trajectory generation. (Reciprocal of FTM_FS)
2810+
#define FTM_FS 1000 // (Hz) Frequency for trajectory generation
27752811

27762812
#if DISABLED(COREXY)
2777-
#define FTM_STEPPER_FS 20000 // (Hz) Frequency for stepper I/O update
2813+
#define FTM_STEPPER_FS 20000 // (Hz) Frequency for stepper I/O update
27782814

27792815
// Use this to adjust the time required to consume the command buffer.
27802816
// Try increasing this value if stepper motion is choppy.
2781-
#define FTM_STEPPERCMD_BUFF_SIZE 3000 // Size of the stepper command buffers
2817+
#define FTM_STEPPERCMD_BUFF_SIZE 3000 // Size of the stepper command buffers
27822818

27832819
#else
27842820
// CoreXY motion needs a larger buffer size. These values are based on our testing.
27852821
#define FTM_STEPPER_FS 30000
27862822
#define FTM_STEPPERCMD_BUFF_SIZE 6000
27872823
#endif
27882824

2789-
#define FTM_STEPS_PER_UNIT_TIME (FTM_STEPPER_FS / FTM_FS) // Interpolated stepper commands per unit time
2790-
#define FTM_CTS_COMPARE_VAL (FTM_STEPS_PER_UNIT_TIME / 2) // Comparison value used in interpolation algorithm
2791-
#define FTM_MIN_TICKS ((STEPPER_TIMER_RATE) / (FTM_STEPPER_FS)) // Minimum stepper ticks between steps
2792-
2793-
#define FTM_MIN_SHAPE_FREQ 10 // Minimum shaping frequency
2794-
#define FTM_RATIO (FTM_FS / FTM_MIN_SHAPE_FREQ) // Factor for use in FTM_ZMAX. DON'T CHANGE.
2795-
#define FTM_ZMAX (FTM_RATIO * 2) // Maximum delays for shaping functions (even numbers only!)
2796-
// Calculate as:
2797-
// ZV : FTM_RATIO / 2
2798-
// ZVD, MZV : FTM_RATIO
2799-
// 2HEI : FTM_RATIO * 3 / 2
2800-
// 3HEI : FTM_RATIO * 2
2825+
#define FTM_MIN_SHAPE_FREQ 10 // (Hz) Minimum shaping frequency, lower consumes more RAM
28012826
#endif // FT_MOTION
28022827
```
28032828

_development/code_structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ See [the Input Shaping page](/docs/features/input_shaping.html) for details on t
225225
### Fixed-Time Motion
226226
Marlin 2.1.3 introduces Fixed-Time Motion as an alternative method to get more precise step and direction timing along with its own Linear Advance and Input Shaping handlers. Fixed-Time Motion also uses the Stepper ISR to do regular stepping, but it also has a periodic `idle` task to handle state changes.
227227

228-
Since Fixed-Time motion requires significantly more resources than the standard motion system to pre-calculate its precise pulse timings, it requires a faster processor and more RAM.
228+
Since Fixed-Time Motion requires significantly more resources than the standard motion system to pre-calculate its precise pulse timings, it requires a faster processor and more RAM. However, FTM is also very optimized, so it requires fewer resources than you might expect, and should run well on leaner ARM boards.
229229

230230
As this system matures it will likely become default for fast 32-bit boards, but the original motion system will be preserved for slower processors and for simpler motion systems that don't need the most precise timing.
231231

_gcode/M493.md

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,50 @@ requires: FT_MOTION
1010
eeprom: true
1111

1212
codes: [ M493 ]
13-
related: [ M593 ]
13+
related: [ M494, M593 ]
1414

1515
parameters:
1616

1717
- tag: S
1818
optional: true
19-
description: Set Fixed-Time motion mode OFF (0) / ON (1).
19+
description: Set Fixed-Time Motion mode enabled / disabled.
2020
values:
21-
- tag: bool
21+
- tag: 0
22+
description: Disabled
23+
- tag: 1
24+
description: Enabled
25+
26+
- tag: T
27+
optional: true
28+
description: Set the state for Axis Synchronization.
29+
values:
30+
- tag: 0
31+
description: Disabled
32+
- tag: 1
33+
description: Enabled
34+
35+
- tag: P
36+
optional: true
37+
description: Enable/disable Linear Advance aka Pressure Advance.
38+
values:
39+
- type: bool
40+
tag: state
2241

23-
- tag: X|Y
42+
- tag: K
2443
optional: true
25-
description: Set the vibration compensator [input shaper] mode for X / Y axis. Note.
26-
Users and slicers must remember to set the mode for both axes!
44+
description: Set the gain for Linear Advance aka Pressure Advance.
45+
values:
46+
- type: float
47+
tag: gain
48+
49+
- tag: C
50+
optional: true
51+
description: |
52+
Set the vibration compensator [input shaper] mode for the specified axes.<br/>
53+
NOTE: Users and slicers must remember to set the mode for both X and Y!
2754
values:
2855
- tag: 0
29-
description: NONE (No input shaper)
56+
description: No Input Shaper
3057
- tag: 1
3158
description: ZV (Zero Vibration)
3259
- tag: 2
@@ -44,23 +71,9 @@ parameters:
4471
- tag: 8
4572
description: MZV (Mass-based Zero Vibration)
4673

47-
- tag: P
48-
optional: true
49-
description: Enable/disable Linear Advance.
50-
values:
51-
- type: bool
52-
tag: state
53-
54-
- tag: K
55-
optional: true
56-
description: Set the gain for Linear Advance.
57-
values:
58-
- type: float
59-
tag: gain
60-
6174
- tag: D
6275
optional: true
63-
description: Set the Dynamic Frequency mode.
76+
description: Set the Dynamic Frequency mode. (Available when there is a Z axis and/or Extruder to follow.)
6477
values:
6578
- tag: 0
6679
description: Disabled
@@ -71,39 +84,67 @@ parameters:
7184

7285
- tag: A
7386
optional: true
74-
description: Set the Base Frequency for Input Shaping on the X axis.
87+
description: Set the Base Frequency for Input Shaping on the specified axes.
7588
values:
7689
- type: float
7790
tag: Hz
7891

79-
- tag: B
92+
- tag: F
8093
optional: true
81-
description: Set the Base Frequency for Input Shaping on the Y axis.
94+
description: |
95+
Set the Frequency Scaling factor for Input Shaping on the specified axes.<br/>
96+
(Available when there is a Z axis and/or Extruder to follow.)
8297
values:
8398
- type: float
84-
tag: Hz
99+
tag: scale
85100

86-
- tag: F
101+
- tag: I
87102
optional: true
88-
description: Set the Frequency Scaling factor for Input Shaping on the X axis.
103+
description: Set the Zeta for Input Shaping on the specified axes.
89104
values:
90105
- type: float
91-
tag: scale
106+
tag: zeta
107+
range: [ 0.01, 1.0 ]
92108

93-
- tag: H
109+
- tag: Q
94110
optional: true
95-
description: Set the Frequency Scaling factor for Input Shaping on the Y axis.
111+
description: Set the Vibration Tolerance for Input Shaping on the specified axes.
96112
values:
97113
- type: float
98-
tag: scale
114+
tag: vtol
115+
range: [ 0.0, 1.0 ]
116+
117+
- tag: X
118+
optional: true
119+
description: Flag to apply `A`,`C`,`F`,`I`,`Q` to the X axis. (If no axis parameters are given then XY is assumed.)
120+
values:
121+
- type: flag
122+
123+
- tag: Y
124+
optional: true
125+
description: Flag to apply `A`,`C`,`F`,`I`,`Q` to the Y axis. (If no axis parameters are given then XY is assumed.)
126+
values:
127+
- type: flag
128+
129+
- tag: Z
130+
optional: true
131+
description: Flag to apply `A`,`C`,`F`,`I`,`Q` to the Z axis. (If no axis parameters are given then XY is assumed.)
132+
values:
133+
- type: flag
134+
135+
- tag: E
136+
optional: true
137+
description: Flag to apply `A`,`C`,`F`,`I`,`Q` to the E axis. (If no axis parameters are given then XY is assumed.)
138+
values:
139+
- type: flag
99140

100141
example:
101142

102-
- pre: Enable Fixed-Time motion with Linear Advance gain 0.22
143+
- pre: Enable Fixed-Time Motion with Linear Advance gain 0.22
103144
code: M493 S1 P1 K0.22
104145

105-
- pre: Enable Fixed-Time motion with ZVD Input Shaping
106-
code: M493 S1 X2 Y2 A37 B37 D0 P1 K0.18
146+
- pre: Enable Fixed-Time Motion with ZVD Input Shaping on X and Y
147+
code: M493 S1 XY C2 A37 D0 P1 K0.18
107148
post: This also sets the IS Frequency to 37Hz for X and Y, disables Dynamic Frequency mode, and enables Linear Advance with a gain of 0.18.
108149

109150
---
@@ -124,21 +165,19 @@ Use a slicer that provides custom G-code macros for layer change. For example yo
124165

125166
- In the the Starting G-code enable Fixed-Time Motion with something like:
126167
```
127-
M493 S1 X2 Y2 D0 ; Enable ZVD Input Shaping
168+
M493 S1 XY C2 D0 ; Enable ZVD Input Shaping
128169
```
129170

130171
- In *Kiri:Moto* enable **Infill > Fill Type > Vase**. Then add the following under **Setup > Machine > Gcode Macros > Layer** to run a test range of 15Hz to 60Hz:
131172

132173
```
133-
M493 A{(layer < 2 ? 0 : 15 + 45.0 * (layer - 2) / 297)} ; (Hz) X Input Shaping Test
134-
M493 B{(layer < 2 ? 0 : 15 + 45.0 * (layer - 2) / 297)} ; (Hz) Y Input Shaping Test
174+
M493 XY A{(layer < 2 ? 0 : 15 + 45.0 * (layer - 2) / 297)} ; (Hz) XY Input Shaping Test
135175
```
136176

137177
- In *Prusa Slicer* you'll enable **Spiral vase**. Then add the following to your **Printer Settings > After layer change G-code** to run a test range of 15Hz to 60Hz:
138178

139179
```
140-
M493 A{(layer_num < 2 ? 0 : 15 + 45.0 * (layer_num - 2) / 297)} ; (Hz) X Input Shaping Test
141-
M493 B{(layer_num < 2 ? 0 : 15 + 45.0 * (layer_num - 2) / 297)} ; (Hz) Y Input Shaping Test
180+
M493 XY A{(layer_num < 2 ? 0 : 15 + 45.0 * (layer_num - 2) / 297)} ; (Hz) XY Input Shaping Test
142181
```
143182

144183
- In *Cura*, you'll first need to add the .py file in [this repository](//www.github.com/dsdanielko/cura-ringing-tower-script/) to your Cura "scripts" folder. Reopen Cura, enable **Spiralize Outer Contour** and set **Minimum Layer Time** to 0. Then go to **Extensions > Post Processing > Modify G-Code**. Click **Add a script** in the window that opens and use the dropdown menu to find **Input Shaping**. Make sure the **Motion planning type** dropdown is set to **M493**. The default frequency settings will let you test a range of 15Hz to 60Hz.

0 commit comments

Comments
 (0)