StallGuard Tuning : autotune stallguard sensitivity#28483
Open
narno2202 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This updated pull request supersedes #28455 after a huge refactoring. This PR adds
STALLGUARD_TUNINGoption inConfiguration_adv.h, enabling automatic tuning of TMC stallguard thresholds for X/Y sensorless homing in Marlin.Both StallGuard2 and StallGuard4 drivers are supported for Cartesian and CoreXY printers. For axis with 2 stepper drivers or a CoreXY printer, StallGuard version must be the same or in case of a mismatch, one driver must be a
TMC2240.STALLGUARD_TUNINGoffers separate tuning results for standard motion andFT_MOTIONwhen both are enabled.STALLGUARD_TUNINGadds:M921for tuning X or Y axis:M921 XorM921 YandM921 S0orM921 S1to save from Fixed Time Motion tuning or Standard motion tuningEDITABLE_HOMING_CURRENTmust be enabled if you want to save the used tuning currentThe tuning routine reports:
FT_MOTIONRemeber that the results are only valid for the current and the speed used in the tuning routine.
If both
FT_MOTIONand standard motion are enabled, the system runs:FT_MOTIONtuning firstCommon flow
SGTHRSis the threshold value (sensitivity),SG_RESULTrepresents "the motor load".X_CURRENT,Y_CURRENT) with a minimum of 400 mA to optimize back-EMF behavior.HOMING_FEEDRATE_MM_M/ 60 for velocity and the same value for motion distanceStallGuard2 tuning
SGTHRS = 0for a free move:SG_RESULTin a histogram while moving then computes the median of theSG_RESULTsample.SGTHRSprogressively untilSG_RESULTis in the target window of80..120The range
80-120matches StallGuard2 datasheet behavior whereSG_RESULTindicates proximity to stall.SGTHRSis tuned automatically for the printer motion systems: standard motion and/orFT_MOTION. As the 2 values should be in the good range, either one or another can be chosen.StallGuard4 tuning
SGTHRS = 0for a free move:SG_RESULTin a histogram while moving then computes the median of theSG_RESULTsample.SGTHRSto one sixth of the medianSG_RESULTto avoid false triggers during accelerationSGTHRS, do a move, check the endstop. Stop when the endstop is triggered (the endstop is triggered during the acceleration phase)For StallGuard4,
SG_RESULTis tested againstSGTHRS * 2to detect a stall:SG_RESULT < 2 * SGTHRS. If both standard motion and FT_MOTION are present, the preferred finalSGTHRSis the lowest value.Tested with TMC2226 stepper drivers (equivalent to TMC2209, StallGuard4), 1 driver on X, 2 drivers on Y. Tuning done with standard and FTM motion system. The refactoring improves reliability and repeatability as zombie values are eliminated. The returned values for the 2 motion systems were different but not enough to have a sensorless homing failure.
Please test the function for SG2, SG4 and CoreXY, the menu. Waiting for feedback and suggestions
Requirements
Both
SENSORLESS_HOMINGandSTALLGUARD_TUNINGenabled,Sanitycheck.hwill do the rest.Benefits
Configurations
Related Issues