-
-
Notifications
You must be signed in to change notification settings - Fork 53
Macros/Beacon: replace beacon expansion multiplier adjustment with a straight forward runtime offset. #75
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
base: development
Are you sure you want to change the base?
Conversation
…c-reference-position
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes update the BeaconMesh module and associated configuration files. In Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant BM as BeaconMesh
participant BMgr as BedMesh Manager
U->>BM: cmd_CREATE_BEACON_COMPENSATION_MESH(probe_count)
BM->>BM: Validate probe_count and config
BM->>BM: load_extra_mesh_params()
BM->>BMgr: create_compensation_mesh(profile, probe_count)
BMgr-->>BM: Compensation mesh created (or error)
BM-->>U: Return confirmation/error
sequenceDiagram
participant U as User
participant BM as BeaconMesh
participant BMgr as BedMesh Manager
U->>BM: cmd_BEACON_APPLY_SCAN_COMPENSATION(profile)
BM->>BM: Verify beacon presence and mesh parameters
BM->>BMgr: Retrieve profile from bed_mesh.pmgr
BM->>BM: apply_scan_compensation(profile)
BM-->>U: Return applied compensation/error message
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
configuration/klippy/beacon_mesh.py (3)
56-61: Use of internal_check_incompatible_profiles()API.
Callingself.bed_mesh.pmgr._check_incompatible_profiles()directly may rely on an internal method that could change in future versions. Consider a stable interface or guard usage with try-except to handle potential naming changes.
78-98: Improve exception chaining for clarity.
When re-raising the caughtBedMesh.BedMeshError(line 93), consider usingraise self.gcode.error(str(e)) from efor better traceability in logs.🧰 Tools
🪛 Ruff (0.8.2)
93-93: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
279-326: Iterate over dictionary directly.
Transition fromfor profile_name in profiles.keys():tofor profile_name in profiles:to improve readability and adhere to best practices:-for profile_name in profiles.keys(): +for profile_name in profiles:🧰 Tools
🪛 Ruff (0.8.2)
283-283: Use
key in dictinstead ofkey in dict.keys()Remove
.keys()(SIM118)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
configuration/klippy/beacon_mesh.py(3 hunks)configuration/macros/overrides.cfg(0 hunks)configuration/macros/util.cfg(0 hunks)configuration/z-probe/beacon.cfg(3 hunks)
💤 Files with no reviewable changes (2)
- configuration/macros/util.cfg
- configuration/macros/overrides.cfg
🧰 Additional context used
🪛 Ruff (0.8.2)
configuration/klippy/beacon_mesh.py
93-93: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
283-283: Use key in dict instead of key in dict.keys()
Remove .keys()
(SIM118)
🔇 Additional comments (11)
configuration/z-probe/beacon.cfg (4)
44-45: Confirm overhead of per-print calibration.
Enablingvariable_beacon_contact_calibrate_model_on_printis useful when frequently swapping build plates. However, consider verifying the added print start overhead, especially for large or frequent prints.
905-905: Check backward compatibility for required PROBE_COUNT.
IntroducingPROBE_COUNT={probe_count_x},{probe_count_y}ensures finer mesh control. If existing macros or scripts still invokeCREATE_BEACON_COMPENSATION_MESHwithout specifyingPROBE_COUNT, they will break. Confirm all call sites are updated.
1010-1023: Verify offset logic correctness.
The macro_BEACON_SET_RUNTIME_OFFSETsubtractsapplied_expansion_offsetfrom the current homing origin and saves the result. Double-check that subtracting the offset (rather than adding) is indeed the intended direction of adjustment.
1024-1031: Ensure restore sequence aligns with previous offset.
_BEACON_RESTORE_RUNTIME_OFFSEToverwrites the Z offset to the storedbeacon_saved_runtime_offset. Confirm it does not need to add or account for an already-applied offset from preceding macros.configuration/klippy/beacon_mesh.py (7)
4-16: Good introduction of mesh constants.
Defining constants for temporary and default mesh naming fosters clarity. The typed dictionaryRATOS_MESH_PROFILE_OPTIONSis also a useful pattern for structured mesh parameters.
33-37: Initialize references safely.
Settingself.beacon,self.ratos, andself.bed_meshtoNoneclarifies that they are conditionally loaded. This is good practice to avoidAttributeError.
67-76: Conditional command registration looks solid.
Registering beacon-specific commands only if the[beacon]section exists prevents runtime errors when Beacon is not used.
100-109: Clean parameter validation flow.
The updatedCREATE_BEACON_COMPENSATION_MESHcommand ensuresPROFILEandPROBE_COUNTare set. This explicit check helps avoid ambiguous G-code errors.
110-135: Zero reference position approach is sensible.
The macro for setting zero reference updates the active mesh and optionally saves it. This is a straightforward method to re-baseline the bed mesh without re-running a full calibration.
139-214: Reasonable approach to apply compensation.
apply_scan_compensationmerges an offset mesh with the current scan mesh. Confirm that users can revert if needed since the profile update is destructive. Otherwise, no critical issues found.
217-278: Valid logic for generating compensation mesh.
This method properly generates two temporary meshes—contact and scan—and subtracts them to build the compensation mesh. Verify the final calibration results remain consistent under different tool or bed temperatures.
44912d2 to
28acb48
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
configuration/klippy/beacon_mesh.py (2)
79-98: Enhanced error handling in scan compensationThe improved error handling provides clearer feedback when something goes wrong. This will make debugging easier for users.
One minor improvement for future updates would be to use
raise ... from errin line 93 for better exception chaining:- except BedMesh.BedMeshError as e: - raise self.gcode.error(str(e)) + except BedMesh.BedMeshError as e: + raise self.gcode.error(str(e)) from e🧰 Tools
🪛 Ruff (0.8.2)
93-93: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
279-326: Well-structured profile parameter handlingThe new load_extra_mesh_params method provides a clean way to handle additional profile options and version compatibility. This will make future extensions easier.
A minor optimization for line 283 would be to use
key in dictdirectly instead ofkey in dict.keys():- for profile_name in profiles.keys(): + for profile_name in profiles:🧰 Tools
🪛 Ruff (0.8.2)
283-283: Use
key in dictinstead ofkey in dict.keys()Remove
.keys()(SIM118)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
configuration/klippy/beacon_mesh.py(3 hunks)configuration/macros/mesh.cfg(5 hunks)configuration/macros/overrides.cfg(0 hunks)configuration/macros/util.cfg(0 hunks)configuration/z-probe/beacon.cfg(4 hunks)
💤 Files with no reviewable changes (2)
- configuration/macros/overrides.cfg
- configuration/macros/util.cfg
🧰 Additional context used
🪛 Ruff (0.8.2)
configuration/klippy/beacon_mesh.py
93-93: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
283-283: Use key in dict instead of key in dict.keys()
Remove .keys()
(SIM118)
🔇 Additional comments (16)
configuration/macros/mesh.cfg (4)
50-59: Well-structured Y-axis parameter handling addedThese changes nicely complement the existing X-axis parameter handling by adding equivalent Y-axis parameters, making the coordinate system handling more symmetrical and complete.
61-64: Good addition of zero reference position logicThis adds support for the dynamic zero reference position, with a sensible fallback to the safe home coordinates if not defined in the configuration.
101-101: Improved conditional scan compensation applicationRenaming to _BEACON_APPLY_SCAN_COMPENSATION_IF_ENABLED makes the function more explicit about its conditional behavior and aligns with the implementation in beacon.cfg.
Also applies to: 158-158, 191-191
108-109: Essential zero reference position setting after mesh operationsSetting the zero reference position after mesh calibration or loading ensures proper coordinate system alignment throughout the printing process.
Also applies to: 114-114
configuration/z-probe/beacon.cfg (5)
44-45: Improved default for build plate swapping scenariosChanging the default to calibrate a new beacon model on every print is a good choice, especially for users who swap build plates frequently. This ensures more accurate first layers across different build surfaces.
906-906: Added necessary PROBE_COUNT parameterAdding the PROBE_COUNT parameter to CREATE_BEACON_COMPENSATION_MESH matches the updated Python implementation which now requires this parameter. This ensures proper mesh resolution.
941-952: More explicit conditional scan compensation applicationRenaming to _BEACON_APPLY_SCAN_COMPENSATION_IF_ENABLED makes the function's behavior clearer. The implementation properly checks if compensation is enabled before applying it, which prevents unnecessary operations.
1010-1023: Simplified runtime offset calculation replaces multiplier approachThis is the core of the PR change - replacing the beacon expansion multiplier with a straightforward runtime offset. The new approach:
- Gets the current Z offset
- Subtracts any applied expansion compensation
- Saves the result as a direct offset value
This is more intuitive and easier to understand than the previous multiplier approach.
1024-1031: Clean restoration of runtime offsetThe restoration logic is straightforward - simply apply the previously saved runtime offset. This direct approach reduces complexity and potential for calculation errors compared to the previous multiplier-based method.
configuration/klippy/beacon_mesh.py (7)
4-15: Good addition of mesh constants and configuration optionsAdding named constants and configuration options improves code maintainability and makes it easier to manage different mesh profiles. The version tracking will be helpful for future compatibility checks.
35-37: Improved initialization and parameter validationProperly initializing attributes to None and adding parameter validation ensures the code behaves predictably even in edge cases. The additional mesh parameter loading and compatibility checks help prevent runtime errors.
Also applies to: 56-61
67-76: Better conditional command registrationOnly registering commands when the beacon section exists prevents errors when the beacon is not configured, making the code more robust.
101-108: Added required probe_count parameterNow requiring the probe_count parameter ensures that compensation meshes are created with the correct resolution, avoiding potential issues with default or incorrect values.
110-134: Well-implemented zero reference position functionalityThis new method enables setting a zero reference position for the current bed mesh, which is critical for the runtime offset approach. The error handling and user feedback are thorough.
139-216: Significantly improved scan compensation with better error checkingThe renamed and enhanced apply_scan_compensation method has much more robust error checking, including:
- Verification of loaded meshes
- Version compatibility checks
- Beacon model and temperature compatibility warnings
This will help users diagnose and fix issues more easily.
217-278: Enhanced compensation mesh creation with temporary meshesThe updated create_compensation_mesh method properly creates temporary meshes, calculates offsets, and cleans up afterward. This is good practice and prevents profile pollution.
…ints, not the interpolated points.
…E_BEACON_COMPENSATION_MESH
…can compensation mesh issues rather than failing late eg after heat soaking.
…reasonably close to the current beacon coil temp. Currently allowing up to 20C difference as the acceptable range.
…ault name for the beacon scan compensation mesh
…n model according to beacon_contact_calibrate_model_on_print
…ION, now always saves. From discussion with MS there was no known use case for *not* saving, and not saving creates a profile in a confusing ephemeral state which is lost when the profile is reloaded.
- Implement _RAISE_ERROR in python instead of jinja for cleaner error messages - Implement _TRY, the try/except/finally pattern for macros
…tatus instead of raising an error.
…ated functionality
- Change and enhance the set of metadata stored:
- Remove beacon_model_temp as this is not relevant.
- Add bed temperature, mesh kind and probe method.
- Add warnings in create_compensation_mesh() for unapplied z-tilt or QGL
- Add various new gcode commands
- Defer profile deserialization using delayed gcode to ensure that warnings are seen in the console
- Replace/improve checks and warnings/errors
- Enhance preflight checks called from START_PRINT
- Apply extended metadata to all profiles/meshes created via BED_MESH_CALIBRATE
1ebe329 to
47c7115
Compare
- Support saving via the standard Z_OFFSET_APPLY_PROBE macro - Exclude active IDEX toolhead offset from the saved value
This branch depends on
feature/dynamic-reference-position.Summary by CodeRabbit
New Features
Chores