-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
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
Significant path deviation using arc interpolation with large R and small theta #21856
Comments
Hi. I quickly looked at the code. I don't have a full understanding of G2/G3 (yet), but these lines look mighty suspicious if we are talking about errors adding up for small theta: Marlin/Marlin/src/gcode/motion/G2_G3.cpp Lines 184 to 185 in cb4e388
Did you also try to replace the approximation in those two lines with a precise solution? In the end, only calculating with higher precision for very small angles (like your did in your code snippet) might be enough to fix the problem. But for diagnostics, it would be good to know where it originates. |
Yes, I buried that nugget in the Additional information & file uploads, but should have probably included it at the top. The resulting path using sin instead of the small angle approximation above is indistinguishable from the path using the approximation. The approximation of sin above is, for example, approximately 99.9999883 percent accurate. It's the actual interpolation step that is causing the issue here from what I can tell. Turning off interpolation (setting N_ARC_CORRECTION = 0) is the only thing that seems to work. |
Sorry, didn't see that. Yes, looks like an accumulated numerical error due to the repeated application of the rotation matrix, specifically in the case where One possible fix would certainly be your suggestion to ignore the subdivision for very small Extending that idea: Looking at the code, the |
Yes, definitely. If we could very quickly calculate the error involved, corrections could be applied whenever a deviation threshold is met, but I'm not sure how to estimate the drift of this operation. I'm guessing that calculation will be rather slow, but I could be mistaken. This kind of math is above my pay grade. |
This issue has had no activity in the last 60 days. Please add a reply if you want to keep this issue active, otherwise it will be automatically closed within 10 days. |
It might be good to keep this open a bit longer. I have not figured out a good solution yet, but am still working on it |
I've noticed the deviations in my machine. I attached a pen to the head and made the following Gcode test:
and as you can see in the following images the paths deviate in diagonals and the circles are not ended in the exact position. Is this expected or normal? What can I do for the paths to be overlapped in the diagonal directions? |
This issue has had no activity in the last 60 days. Please add a reply if you want to keep this issue active, otherwise it will be automatically closed within 10 days. |
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. |
Did you test the latest
bugfix-2.0.x
code?Yes, and the problem still exists.
Bug Description
The arc interpolation algorithm produces paths that vary from the G2/G3 command significantly if theta_per_segment is very small (less than 0.001 radians). Here is a sample gcode sequence that can be used to replicate the issue:
This gcode was taken from an issue on my ArcWelderLib repository, which includes pictures of a benchy showing the artifacts I was able to discover from the interpolated gcode.
Here is an overlay of the interpolated path (which I generated from my arc straightener project, which uses the Marlin 2.0 interpolation algorithm to produce G1 commands from G2/G3 commands) and the original G2/G3 path:
The path towards the bottom is the G2/G3, and I've zoomed into the bit where the issue is occurring, and have circled the endpoint of the deviation:
Here is an overlay of the original path from Cura and the path that was generated from arcwelder:
As you can see, there is no significant deviation.
I also experimented with adding a check to this line of G2_G#.cpp:
Which fixed the issues I was seeing. Note that theta_per_segment = -0.0000146 in the example, which is quite small. The arc has a very large radius, and I think the combination of a large radius and a small theta_per_segment is causing the issue.
I'm not sure how exactly to check theta_per_segment for these kinds of deviations, but my initial thoughts would be to find a way to compare the arc radius and theta_per_segment to approximate the deviation, and bypass the small angle approximation if it would create substantial deviation. I will continue to think about this, and will test some solutions if I come up with any. I mostly wanted to post this issue here to generate some ideas for a resolution, since this is quite tricky.
I also know that disabling n_arc_correction would do the trick, but that seems like overkill. As long as r is not huge and theta_per_segment is not terribly small, the interpolation works well. This seems to be an edge case, but since it seems to affect the outside of benchy, an important edge case. You might also be interested to know that MANY other firmwares have this same issue, so it's not just Marlin, and it's not a bug that was introduced recently.
Please let me know if I can provide ANY additional useful data, like test cases, photos, more detailed explanations, etc, and THANK YOU SO MUCH for your hard work on this amazing project!
Bug Timeline
This has been around in every version that included arc interpolation, so probably all of them.
Expected behavior
Hopefully there would be no noticeable (visible) deviation. Something on the order of 0.025mm would NOT have been noticed, but this deviation was off by approximately 0.086MM, which is plainly seen on the outer shell.
Actual behavior
The interpolated arc (starting from point X122.404 Y139.732 and using G2 X148.247 Y136.998 I-7179.760 J-67989.836 E1129.15389) should have matched the requested arc to an accuracy that can't be seen with the naked eye.
Steps to Reproduce
You could also use the ArcStraightener.exe to see the results, though it doesn't match the current G2_G3.cpp code exactly. I'm working to add this to the project. Let me know if that's useful enough that I should expedite it.
Version of Marlin Firmware
Latest Bugfix
Printer model
NA
Electronics
NA
Add-ons
NA
Your Slicer
Other (explain below)
Host Software
SD Card (headless)
Additional information & file uploads
Since this issue is related to the interpolation algorithm itself, there should be no difference what slicer or printer is used. Also, I've verified that using true sin and cos (not the small angle approximation) at the beginning of the algorithm, and this made no difference. If N_ARC_CORRECTIONS = 0, however, and only this code is used to calculate X and Y, then the path is true to the original.
The text was updated successfully, but these errors were encountered: