Fix 0 values not being recognized in axis_twist_compensation
When following the Axis Twist Compensation doc, after calling AXIS_TWIST_COMPENSATION_CALIBRATE, I encountered an error that states:
AXIS_TWIST_COMPENSATION for X axis requires calibrate_start_x, calibrate_end_x and calibrate_y to be defined
Following the configuration reference, I set my values like so:
[axis_twist_compensation]
speed: 2000
# X-axis compensation
calibrate_start_x: 0
calibrate_end_x: 230
calibrate_y: 115
# Y-axis compensation
calibrate_start_y: 0
calibrate_end_y: 181
calibrate_x: 115
This works for me, since the 0 X position and the 0 Y position both have my BL Touch sensor hovering over my print bed. However, I still encountered the error back from the AXIS_TWIST_COMPENSATION GCode from above.
This bug is triggered from checks like these, because 0 makes all() return False:
https://github.com/Klipper3d/klipper/blob/fec3e685c92ef263a829a73510c74245d7772c03/klippy/extras/axis_twist_compensation.py?plain=1#L180-L190
For example:
In [1]: all([None, 1])
Out[1]: False
In [2]: all([0, 1])
Out[2]: False
In [3]: all([0.1, 1])
Out[3]: True
In [4]: all([1, 1])
Out[4]: True
This PR replaces the all() calls with explicit is None checks to see if the value really is not present (as opposed to a value that casts to True). I opted to use a few is None checks as opposed to building an array and enumerating with a for loop because the code is smaller and it reads better :+1:
Thankyou for submitting a PR, please be aware you need to sign off, as per point 3 in https://github.com/Klipper3d/klipper/blob/master/docs/CONTRIBUTING.md#what-to-expect-in-a-review
Thanks James
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:
- 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.
- 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.
- 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.