-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
add_y_axis_support and automatic_compensation to axis_twist_compensation #6624
add_y_axis_support and automatic_compensation to axis_twist_compensation #6624
Conversation
2c39e55
to
29fc0ac
Compare
Thank you for submitting a PR, pleas refer to point 3 in "What to expect in a review" in https://github.com/Klipper3d/klipper/blob/master/docs/CONTRIBUTING.md and provide a signed off by line. Thanks |
c2fe44d
to
1fd8443
Compare
29fc0ac
to
bdf6ea1
Compare
cabc5b4
to
4585e73
Compare
Thank you for your feedback. I have reviewed point 3 in "What to Expect in a Review" and have now included a signed-off-by line in my commits. Thanks! |
Thanks. @koonweee, @blastrock - do you have any comments? On a quick glance through this PR, it seems some of the config options change ( -Kevin |
Hi Kevin, Thanks for the feedback. I've updated docs/Config_Changes.md to document the change from z_compensations to zx_compensations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I have reviewed only the first commit for the moment, I'll try to read the rest asap.
default=[], parser=float) | ||
self.compensation_start_x = config.getfloat('compensation_start_x', | ||
default=None) | ||
self.compensation_end_x = config.getfloat('compensation_start_y', | ||
self.compensation_end_x = config.getfloat('compensation_end_x', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that was my bad. The variable seemed unused so it shouldn't have caused issues. Thanks for the fix.
if not all([ | ||
self.y_start_point[0], | ||
self.y_end_point[0], | ||
self.y_start_point[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't there a similar check for the X axis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think cause they are already required for the basic cofig:
self.calibrate_start_x = config.getfloat('calibrate_start_x')
self.calibrate_end_x = config.getfloat('calibrate_end_x')
self.calibrate_y = config.getfloat('calibrate_y')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, they were mandatory when we added the module. I think we should make the x twist variables optional now, to allow users to use y twist compensation without x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I made it optional, and it will check for them when the calibration command is called.
raise self.gcmd.error( | ||
"AXIS_TWIST_COMPENSATION_CALIBRATE: " | ||
"Invalid axis.") | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to return after a raise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
compensation.calibrate_y) | ||
self.y_start_point = (compensation.calibrate_start_y, | ||
compensation.calibrate_x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why swap x and y for the y axis? I find it a bit confusing to have a point(y, x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will swap them
@@ -26,13 +26,24 @@ def __init__(self, config): | |||
self.calibrate_start_x = config.getfloat('calibrate_start_x') | |||
self.calibrate_end_x = config.getfloat('calibrate_end_x') | |||
self.calibrate_y = config.getfloat('calibrate_y') | |||
self.z_compensations = config.getlists('z_compensations', | |||
self.zx_compensations = config.getlists('zx_compensations', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a matter of taste, but I'd factorize these 4 variables in a single type (a named tuple or a dataclass, I'm not sure what's preferred) since they represent the same thing between x and y, maybe AxisCalibration
. Then you can pass it as a single argument to _get_interpolated_z_compensation
instead of three.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is a little bit overkill since I am using it twice; it might result in more lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good to me, just a few minor issues.
I think the auto calibration feature deserves to be better documented. Especially how it works, and what are the downsides. It's still hard for me to understand why this would work, and to what extend the bed should be "completely flat" as the doc says. My bed has irregularities in the range of 0.2mm, the manual X axis twist calibration that I did resulted in values in the range of 0.1mm, how well would the auto calibration behave?
docs/G-Codes.md
Outdated
twist calibration wizard. `SAMPLE_COUNT` specifies the number of points along | ||
the X axis to calibrate at and defaults to 3. | ||
`axis` can either be X or Y | ||
|
||
`AXIS_TWIST_COMPENSATION_AUTOCALIBRATE` performs automatic calibration to calculate the twist of the X and Y axes without manual measurement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it take the same arguments as AXIS_TWIST_COMPENSATION_CALIBRATE? I would put this command in its own section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will add a new section, and make it clear.
) | ||
|
||
# check for valid sample_count | ||
if sample_count is None or sample_count < 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't test for None since it can't be None, it has a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will remove that comparison
max_y = self.y_end_point[0] | ||
|
||
# calculate x positions | ||
spcx = (max_x - min_x) / (sample_count - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to interval_x, to be consistent with the manual implementation? Or maybe rename the variable in the other implementation to spc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
flip = not flip | ||
|
||
# verify no other manual probe is in progress | ||
manual_probe.verify_no_manual_probe(self.printer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this check earlier. More specifically, before the clear_compensations call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will move it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you forgot to move this
|
||
# probe the point | ||
pos = probe.run_single_probe(self.probe, self.gcmd) | ||
#self.current_measured_z = pos[2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
y_coords = [coord[1] for coord in coordinates] | ||
z_coords = [coord[2] for coord in coordinates] | ||
|
||
# Calculate the desired point (average of all corner points in z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering why you take only the corners. My intuition tells me that the average of all points would better cancel out bed irregularities. Is there a particular reason this works better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the average of the corners to establish a reference plane for compensation. However, I calculate the corrections using all points to ensure the adjustments reflect the actual axis conditions. It might need more testing, but it seems to work well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding may be wrong, but what happens if one of the four points is completely off, because there's a hole in the bed just there for example? Wouldn't twist compensation be messed up over the whole bed because of that single corner point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. That's why you shouldn't calibrate the axis twist compensation on a surface that isn't as flat as possible—using a glass bed is a good option. Once it's calibrated, you're free to use any bed you want.
docs/Config_Changes.md
Outdated
@@ -8,6 +8,10 @@ All dates in this document are approximate. | |||
|
|||
## Changes | |||
|
|||
20240709: The `z_compensations` parameter in the `[axis_twist_compensation]` | |||
config section has been renamed to `zx_compensations`. If you don't want | |||
to recalibrate your x_axis_twist_compensation, simply rename the parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would either maintain compatibility and print a warning about the setting being deprecated, or put a fatal error if that setting is present in the config file. At some point, I will upgrade my klipper and I will lose my calibration silently, this is not very user-friendly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to remove this; to make it fully backward compatible, I will keep z_compensations instead of using zx_compensations
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. |
@yochiwarez Hey, I'm interested in this feature. I'm sure others in the Voron community will be too! Keep going Bro! |
6113ea7
to
e93f077
Compare
Awesome!!! Thanks guys! This will be a great feature. |
Guys, is it to late to add the logic for dock-able probes like klicky etc? |
It should work the same way as it does with bed leveling. You would need to add macros to attach and detach the probe within a custom macro. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments, otherwise this looks good to me 👍
if not all([ | ||
self.y_start_point[0], | ||
self.y_end_point[0], | ||
self.y_start_point[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, they were mandatory when we added the module. I think we should make the x twist variables optional now, to allow users to use y twist compensation without x.
self.y_end_point = (compensation.calibrate_end_y, | ||
compensation.calibrate_x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too should be (x, y)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
""" | ||
) | ||
|
||
start_point = (self.y_start_point[1], self.y_start_point[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_point
should be (x, y) too, I find (y, x) very confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have changed that part to make it clear.
xps = [min_x + interval_x * i for i in range(sample_count)] | ||
|
||
# Calculate points array | ||
spcy = (max_y - min_y) / (sample_count - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spcy = (max_y - min_y) / (sample_count - 1) | |
interval_y = (max_y - min_y) / (sample_count - 1) |
for consistency
y_coords = [coord[1] for coord in coordinates] | ||
z_coords = [coord[2] for coord in coordinates] | ||
|
||
# Calculate the desired point (average of all corner points in z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding may be wrong, but what happens if one of the four points is completely off, because there's a hole in the bed just there for example? Wouldn't twist compensation be messed up over the whole bed because of that single corner point?
ea06b2f
to
24c7979
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Could you have a look too @KevinOConnor?
Maybe some of the people interested in this branch could help testing it :)
I think it's really your call on this. I noticed a few minor things:
Thanks, |
f3653e7
to
e55d301
Compare
Hi @KevinOConnor , @blastrock Thanks for your feedback! I've made the changes as you suggested: The command has been updated to AXIS_TWIST_COMPENSATION_CALIBRATE AUTO=1. Let me know if there's anything else you need! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, just tiny doc fixes. I will test this PR myself, but my printer does not exhibit Y axis twist, so it'd be nice if at least someone else could test it. @PhilBaz you seemed interested?
docs/Axis_Twist_Compensation.md
Outdated
[fine-tuning](Axis_Twist_Compensation.md#fine-tuning) as desired | ||
### Basic Usage: X-Axis Calibration | ||
1. After setting up the `[axis_twist_compensation]` module, run: | ||
`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these should be ``` I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
# Defines the minimum Y coordinate of the calibration | ||
# This should be the Y coordinate that positions the nozzle at the starting | ||
# calibration position for the Y axis. This parameter must be provided if | ||
# compensating for Y axis twist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above, you should update the This parameter must be provided.
sentence for the x axis
manual_probe.verify_no_manual_probe(self.printer) | ||
|
||
# clear the current config | ||
self.compensation.clear_compensations() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call clears all compensations, but we should remove only compensations for the axis we are calibrating, otherwise we lose one axis each time we calibrate the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed this.
I did a couple prints with this version and my x twist compensation settings, that part seems to still work at least :) I tried calibrating the y twist compensation, but as expected I got values very close to 0, so I can't really test it. I didn't test the auto calibration as I understood the bed must be super flat, and mine is far from that. |
This commit implements support for the Y-axis in the axis_twist_compensation module. This update enables the module to handle corrections for printers with a twisted Y rail. Signed-off-by: Jorge Apaza Merma <[email protected]>
e55d301
to
1663ee3
Compare
…or autocalibration This commit adds automatic calculation support for compensating X and Y axis twist in the axis_twist_compensation module. Signed-off-by: Jorge Apaza Merma <[email protected]>
1663ee3
to
88c2a27
Compare
Thank you! |
@blastrock Do you still need a tester? Sorry for the delay in response. Ive just moved across contry and s@#t is hectic. |
Yes please. It would be nice to see if this PR improves the prints of at least another person :) |
@blastrock Okay! Im more of a 3d printing guy. No coding or super advanced klipper skills. That being said, Im tech literate. Can you give me a hint of how to proceede? Just need a thread I can pull with googleing etc. Thanks guys! |
I don't know about your specific installation, but I guess you have a clone of the klipper repo (probably in your home on your raspberry pi?). Go inside and checkout this PR
You're ready to go, just restart klipper
Don't forget to put the right config variables in printer.cfg to enable the y twist compensation as written in the doc of this PR. If you want to switch back to the latest version after testing:
Hope this helps, tell us if you need more :) |
Okay, thanks. I'll give another couple of days just to see if there are further comments, but otherwise look to commit. -Kevin |
@blastrock Thanks! Ill try get this done in the next couple of days. Just moved into a new house. Ill try send some others from Voron too test too. |
108eb86
to
88c2a27
Compare
Thanks. -Kevin |
Hey guys....just getting around to testing this. I have a question. I use saved bed meshes. Will the axis twist corection be automaticaly aplied to my bed meshes. Or will I need to rebuild them? I use VGB, so this is cirtical for me... https://github.com/Deutherius/VGB Ps. thanks again for your efforts! |
First of all, I apologize for the misunderstanding regarding this feature. The "Auto" parameter for autocalibration is not applicable in this case, as it is not possible to determine the nozzle height relative to the bed when there is twisting, using just the probe. Therefore, this operation must always be done manually. In the future, I may create a feature called "bend_compensation" (or something similar) that will only visually correct the mesh representation due to bent axes. But for now, the code for this parameter should be removed, and only support for the Y-axis should be kept. I am creating a new pull request to correct my mistake. |
Hi, I think you need to create your mesh again and save it with the correction. Please don't use the "auto" parameter. |
add support for Y-axis in axis_twist_compensation.