Skip to content
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

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

yochiwarez
Copy link
Contributor

@yochiwarez yochiwarez commented Jun 21, 2024

add support for Y-axis in axis_twist_compensation.

@yochiwarez yochiwarez changed the title add_y_axis_support add_y_axis_support to axis_twist_compensation Jun 21, 2024
@yochiwarez yochiwarez force-pushed the y-axis-twist-support branch 3 times, most recently from 2c39e55 to 29fc0ac Compare June 21, 2024 03:09
@JamesH1978
Copy link
Collaborator

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
James

@yochiwarez yochiwarez marked this pull request as draft June 23, 2024 15:20
@yochiwarez yochiwarez force-pushed the y-axis-twist-support branch 2 times, most recently from 29fc0ac to bdf6ea1 Compare June 23, 2024 15:23
@yochiwarez yochiwarez marked this pull request as ready for review June 23, 2024 15:30
@yochiwarez yochiwarez changed the title add_y_axis_support to axis_twist_compensation add_y_axis_support and automatica compensation to axis_twist_compensation Jun 29, 2024
@yochiwarez yochiwarez changed the title add_y_axis_support and automatica compensation to axis_twist_compensation add_y_axis_support and automatic_compensation to axis_twist_compensation Jun 29, 2024
@yochiwarez
Copy link
Contributor Author

yochiwarez commented Jun 29, 2024

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!

@KevinOConnor
Copy link
Collaborator

Thanks. @koonweee, @blastrock - do you have any comments?

On a quick glance through this PR, it seems some of the config options change (z_compensations to zx_compensations). At a minimum that would need to be documented in docs/Config_Changes.md .

-Kevin

@yochiwarez
Copy link
Contributor Author

Hi Kevin,

Thanks for the feedback. I've updated docs/Config_Changes.md to document the change from z_compensations to zx_compensations.

Copy link
Contributor

@blastrock blastrock left a 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',
Copy link
Contributor

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]
Copy link
Contributor

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?

Copy link
Contributor Author

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')

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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)

Copy link
Contributor Author

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',
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@blastrock blastrock left a 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will move it.

Copy link
Contributor

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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.
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link

github-actions bot commented Aug 1, 2024

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:

  1. Perform a self-review of your Pull Request by following the steps at: https://www.klipper3d.org/CONTRIBUTING.html#what-to-expect-in-a-review
    If you have completed a self-review, be sure to state the results of that self-review explicitly in the Pull Request comments. A reviewer is more likely to participate if the bulk of a review has already been completed.
  2. Consider opening a topic on the Klipper Discourse server to discuss this work. The Discourse server is a good place to discuss development ideas and to engage users interested in testing. Reviewers are more likely to prioritize Pull Requests with an active community of users.
  3. Consider helping out reviewers by reviewing other Klipper Pull Requests. Taking the time to perform a careful and detailed review of others work is appreciated. Regular contributors are more likely to prioritize the contributions of other regular contributors.

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,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@PhilBaz
Copy link

PhilBaz commented Oct 16, 2024

@yochiwarez Hey, I'm interested in this feature. I'm sure others in the Voron community will be too! Keep going Bro!

@PhilBaz
Copy link

PhilBaz commented Oct 17, 2024

Awesome!!! Thanks guys! This will be a great feature.

@PhilBaz
Copy link

PhilBaz commented Oct 17, 2024

Guys, is it to late to add the logic for dock-able probes like klicky etc?

@yochiwarez
Copy link
Contributor Author

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.

Copy link
Contributor

@blastrock blastrock left a 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]
Copy link
Contributor

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.

Comment on lines 116 to 117
self.y_end_point = (compensation.calibrate_end_y,
compensation.calibrate_x)
Copy link
Contributor

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)

Copy link
Contributor Author

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])
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

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?

Copy link
Contributor

@blastrock blastrock left a 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 :)

@KevinOConnor
Copy link
Collaborator

Could you have a look too @KevinOConnor?

I think it's really your call on this.

I noticed a few minor things:

  • We should get a bunch of people to test this before making the change, as it would be preferable to avoid follow up fixes as much as we can.
  • In general, I'd prefer to avoid adding new commands - so if we can do something like AXIS_TWIST_COMPENSATION_CALIBRATE AUTO=1 that might be nicer than adding a new command.
  • If an existing user is going to observe some change to continue with existing functionality (eg, the need to recalibrate, the need to change some config, the need to change some scripts) then lets make sure Config_Changes.md is updated to alert them to this. (I don't know if it is there are any changes like this.)
  • If the "autocalibrate" is separate functionality from y-axis support it would be nice to have that in a separate commit. (And to squash and merge the commits with appropriate commit message wording so that I can commit them with a commit-and-rebase action.) https://www.klipper3d.org/CONTRIBUTING.html#format-of-commit-messages
  • The additions to the docs should ideally be wrapped to 80 columns.

Thanks,
-Kevin

@yochiwarez yochiwarez force-pushed the y-axis-twist-support branch 3 times, most recently from f3653e7 to e55d301 Compare October 23, 2024 01:38
@yochiwarez
Copy link
Contributor Author

yochiwarez commented Oct 23, 2024

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.
I’ve ensured that no changes are needed to the configuration file, so it is now fully backward compatible.
I've clearly separated the two commits as requested.
I made sure that the documentation files are wrapped to 80 columns.

Let me know if there's anything else you need!

Copy link
Contributor

@blastrock blastrock left a 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?

[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:
``
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed this.

@blastrock
Copy link
Contributor

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]>
…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]>
@blastrock
Copy link
Contributor

Thank you!

@PhilBaz
Copy link

PhilBaz commented Nov 4, 2024

@blastrock Do you still need a tester? Sorry for the delay in response. Ive just moved across contry and s@#t is hectic.

@blastrock
Copy link
Contributor

Yes please. It would be nice to see if this PR improves the prints of at least another person :)

@PhilBaz
Copy link

PhilBaz commented Nov 4, 2024

@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!

@blastrock
Copy link
Contributor

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

cd klipper
git fetch origin pull/6624/head:ytwist
git checkout ytwist

You're ready to go, just restart klipper

sudo systemctl 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:

git checkout v0.12.0

Hope this helps, tell us if you need more :)

@yochiwarez
Copy link
Contributor Author

yochiwarez commented Nov 4, 2024

This is my test for the auto calibration
before:
Screenshot 2024-11-04 182950

After auto calibration:
Screenshot 2024-11-04 183425

@KevinOConnor
Copy link
Collaborator

Okay, thanks. I'll give another couple of days just to see if there are further comments, but otherwise look to commit.

-Kevin

@PhilBaz
Copy link

PhilBaz commented Nov 7, 2024

@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.

@KevinOConnor KevinOConnor merged commit 38bf6f2 into Klipper3d:master Nov 13, 2024
2 checks passed
@KevinOConnor
Copy link
Collaborator

Thanks.

-Kevin

@PhilBaz
Copy link

PhilBaz commented Nov 14, 2024

@yochiwarez @blastrock

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!

@yochiwarez
Copy link
Contributor Author

yochiwarez commented Nov 14, 2024

Hi @KevinOConnor, @blastrock

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.

@yochiwarez
Copy link
Contributor Author

@yochiwarez @blastrock

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!

Hi, I think you need to create your mesh again and save it with the correction. Please don't use the "auto" parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants