Added stealthchop lag compensation code#7258
Conversation
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This integration eliminates one subtraction of very close values, improving numerical stability of integration, and it is also faster, requiring 16 multiplications and 9 additions per move rather than 20 multiplications and 11 additions in the previous implementation. Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
|
Thank you for your contribution to Klipper. Unfortunately, a reviewer has not assigned themselves to this GitHub Pull Request. All Pull Requests are reviewed before merging, and a reviewer will need to volunteer. Further information is available at: https://www.klipper3d.org/CONTRIBUTING.html There are some steps that you can take now:
Unfortunately, if a reviewer does not assign themselves to this GitHub Pull Request then it will be automatically closed. If this happens, then it is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available. Best regards, PS: I'm just an automated script, not a human being. |
|
@MRX8024 thanks for testing!
So, based on these values, a good-guess value for a compensation parameter is 0.001 * 0.6 / 0.5 = 1.2e-3. I guess this also roughly matches your tests, with 1e-3 showing good (about 2x) reduction in the positional lag, and 1e-2 showing already a large overshoot. So, I suppose an optimal value would be somewhere in the range of 1.2e-3 - 3e-3.
I'm sorry to hear that. To be honest, I am not familiar with any software or hardware defect of TMC5160 that could lead to such outcome, though that possibility cannot be ruled out completely, of course. But generally, there are few 'prevention' mechanisms that, even if accidental, should prevent a TMC driver from damage:
So, alas, I'm not sure how this PR, even if misconfigured, could have fried the TMC5160. I'm only aware of a TMC2208 bug that on quick direction change (which could have happened with PA) in stealthchop mode would trigger over-current protection error (but AFAIR it was a 'false triggering' bug). So again, I'm not sure if TMC5160 could have some hardware bug that would make it short the phases at very high steps in stealthchop mode, I'm just not aware of anything like that. But if some issue like that exist, I wonder if extremely low resistance and inductance of the motor contributed to this unfortunate outcome (and also whether you are using higher-voltage PSU)? Separately, it would indeed be a good idea to make safety limits more tight, it's just for now they were set how they are to allow more permissive testing as for now we do not exactly know what the reasonable limits for each parameter are (and FWIW, one could trigger somewhat similar behavior with PA by setting high PA constant and small pressure_advance_smooth_time). |
For what it is worth, my reading "between the lines" of the tmc specifications is that stealthchop mode doesn't actually measure current (it's not a "current chopper") - it just makes guesses about how long to apply power. (See: https://klipper.discourse.group/t/spreadcycle-and-stealthchop-an-advanced-guide/23938/1 ) So, as I understand it, it is not necessary for the mcu to send lots of steps to the tmc driver to get it to fully power a coil for an extended period of time. It is only necessary for the driver to make poor guesses. So, as a random example, if the driver guesses it needs 10x more power to move 1mm/s faster and the mcu jumps velocity from 20mm/s to 100mm/s, then I'd expect the driver could enable power to a coil for 800x longer. Thus, in this random example, it doesn't need lots of mcu generated steps for things to go awry. I know the tmc2209s (and similar) have an over-current check even when in stealthchop mode. I'm not sure about the tmc5160. Since the tmc5160 has external mosfets, I'd guess a close read of the spec would be needed to see what kind of over-current checks there are. If it was me, I'd probably avoid any kind of abrupt pulsing movements (high bursts of acceleration) while in stealthchop mode. I am not an expert on TMC drivers - this is just my general understanding - so take what I say here "with a grain of salt". Cheers, |
|
AFAIU. So, normally, it is simpler than the SpreadCycle. And it should normally be covered by the S2G/S2VS. So, I guess, the question is, why has protection not been triggered? |
|
For future testing, we basically want to ensure that documented stealth lag is visible on the real print in the first place. To do so, the suggested procedure is:
Suggested models: So one can print the model samples in the Spread, then in the stealth (without compensation) It is advisable to have more than one sample at each mode. Then, one can enable StealthChop lag compensation, based on the motor datasheet, for example. And define it in the configuration: And try to reprint the test samples. Alas, for example, I cannot reproduce distinguishable results on my machine in the first place. Btw, Right now, I'm not sure why it happens with the probe, my pure guess, because we compare the trapq position with the stepcompress position, where step compress can be shifted based on the compensated lag. And for whatever reason: Regards, |
Hmmm, I think that trigger happens at the position which is obviously behind the commanded one. It looks pretty similar to how FOC works. FOC adjusts the voltage phase, so the current phase would be 90 degrees ahead of the rotor. We adjust the step position/voltage phase, so the toolhead position would be where the current actually is. Upon halt, the toolhead would reach the commanded position, and lag would be subtracted. I guess that Regards, |
FYI, this warning appears if all the steppers on a multi-stepper axis (eg, So, for example, if all the stepper_z motors start at mcu position 101 and stepper_z/stepper_z1 halt at position 4099 while stepper_z2 halts at mcu position 4105 then a warning is produced. The code is not expecting the steppers controlling a single axis to move different amounts during homing/probing. If they do move different amounts, there is no correction for it, and the motors will be skewed for the remainder of the print (until the next z_tilt_adjust, quad_gantry_level, or the next home/probe that skews them further). Ideally, the code could detect a skew during homing/probing and restore the proper axis alignment. (Restoring alignment would allow support multi-mcu multi-stepper axes.) However, this has not been implemented, and due to the complexity of the current homing/probing code it's likely not easy to implement. Cheers, |
Omg, you are right. Sorry for the above nonsense, I simply enabled compensation only for the stepper_z After the configuration fix, I no longer see those messages. Thanks, |
|
Some comments on the current code by a LLM review, even if it's still a draft PR: Things that are correct / well done
Findings1. (High)
|
|
at request over discord, I have tested my platform consisting of LDO-42STH48-2804AH + BTT TMC5160T on my AB motors. When enabled my config was |





























It is often reported that enabling StealthChop mode in TMC drivers results in positional errors of the stepper motors, which can lead to geometrical distortions of the printed models, especially on more complicated kinematics such as CoreXY. This is a proof-of-concept PR that adds runtime compensation for stepper position lag in StealthChop mode. I opened this PR as a draft to facilitate further testing following the discussions in this discourse threads (and original proposal from here). @nefelim4ag FYI