Skip to content

Conversation

@miklschmidt
Copy link
Member

@miklschmidt miklschmidt commented Mar 14, 2025

This branch depends on feature/dynamic-reference-position.

Summary by CodeRabbit

  • New Features

    • Added a command to set the bed mesh zero reference position.
    • Updated compensation mesh creation to require a probe count for improved calibration accuracy.
    • Introduced new configuration variables for enhanced flexibility in bed mesh calibration.
  • Chores

    • Streamlined beacon calibration routines with clearer error feedback and more direct runtime offset adjustments.
    • Removed legacy macros for applying and saving offsets.
    • Enabled automatic beacon model calibration on every print for consistent performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes update the BeaconMesh module and associated configuration files. In beacon_mesh.py, new constants have been introduced, and command methods have been updated with additional parameters and error handling. A new method for setting the zero reference has been added, and method names and signatures have been revised for clarity. Additionally, obsolete macros in the overrides and utility configuration files have been removed. The beacon configuration has been streamlined by updating calibration settings, removing redundant G-code commands, and renaming macros for runtime offset handling.

Changes

File(s) Change Summary
configuration/klippy/beacon_mesh.py • Added new constants for mesh names, options, and version.
• Extended the constructor to initialize beacon, ratos, and bed_mesh.
• Updated command methods (cmd_BEACON_APPLY_SCAN_COMPENSATIONapply_scan_compensation, cmd_CREATE_BEACON_COMPENSATION_MESH with probe_count parameter) with improved error handling.
• Added new methods: cmd_SET_ZERO_REFERENCE_POSITION and load_extra_mesh_params.
configuration/macros/overrides.cfg
configuration/macros/util.cfg
• Removed obsolete macros: [gcode_macro SET_GCODE_OFFSET] from overrides.cfg and [gcode_macro SAVE_Z_OFFSET] from util.cfg.
configuration/z-probe/beacon.cfg • Changed variable_beacon_contact_calibrate_model_on_print from False to True.
• Removed redundant G-code commands for contact/temporary scan mesh creation in favor of a unified compensation command with PROBE_COUNT.
• Renamed macros: _BEACON_SAVE_MULTIPLIER_BEACON_SET_RUNTIME_OFFSET and _BEACON_APPLY_RUNTIME_MULTIPLIER_BEACON_RESTORE_RUNTIME_OFFSET, with updated logic and debug messages.
configuration/macros/mesh.cfg • Added new variables: printable_y_max, safe_home_y, and zero_ref_pos.
• Updated logic for safe_home_x and safe_home_y to include checks and defaults.
• Replaced _BEACON_APPLY_SCAN_COMPENSATION with _BEACON_APPLY_SCAN_COMPENSATION_IF_ENABLED.

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
Loading
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
Loading

Poem

I hop through code with a bounce so light,
New constants and methods shining bright.
Meshes are calibrated on every print,
Obsolete macros vanish in a squinty glint.
A happy hare cheers—coding delights! 🐇


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@miklschmidt
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.
Calling self.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 caught BedMesh.BedMeshError (line 93), consider using raise self.gcode.error(str(e)) from e for better traceability in logs.

🧰 Tools
🪛 Ruff (0.8.2)

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)


279-326: Iterate over dictionary directly.
Transition from for profile_name in profiles.keys(): to for 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 dict instead of key in dict.keys()

Remove .keys()

(SIM118)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1322e24 and 44912d2.

📒 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.
Enabling variable_beacon_contact_calibrate_model_on_print is 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.
Introducing PROBE_COUNT={probe_count_x},{probe_count_y} ensures finer mesh control. If existing macros or scripts still invoke CREATE_BEACON_COMPENSATION_MESH without specifying PROBE_COUNT, they will break. Confirm all call sites are updated.


1010-1023: Verify offset logic correctness.
The macro _BEACON_SET_RUNTIME_OFFSET subtracts applied_expansion_offset from 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_OFFSET overwrites the Z offset to the stored beacon_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 dictionary RATOS_MESH_PROFILE_OPTIONS is also a useful pattern for structured mesh parameters.


33-37: Initialize references safely.
Setting self.beacon, self.ratos, and self.bed_mesh to None clarifies that they are conditionally loaded. This is good practice to avoid AttributeError.


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 updated CREATE_BEACON_COMPENSATION_MESH command ensures PROFILE and PROBE_COUNT are 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_compensation merges 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.

@miklschmidt miklschmidt force-pushed the feature/beacon-runtime-offset branch from 44912d2 to 28acb48 Compare March 14, 2025 15:04
@miklschmidt
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 compensation

The 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 err in 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 except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


279-326: Well-structured profile parameter handling

The 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 dict directly instead of key in dict.keys():

-		for profile_name in profiles.keys():
+		for profile_name in profiles:
🧰 Tools
🪛 Ruff (0.8.2)

283-283: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44912d2 and 28acb48.

📒 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 added

These 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 logic

This 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 application

Renaming 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 operations

Setting 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 scenarios

Changing 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 parameter

Adding 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 application

Renaming 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 approach

This is the core of the PR change - replacing the beacon expansion multiplier with a straightforward runtime offset. The new approach:

  1. Gets the current Z offset
  2. Subtracts any applied expansion compensation
  3. 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 offset

The 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 options

Adding 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 validation

Properly 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 registration

Only 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 parameter

Now 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 functionality

This 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 checking

The 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 meshes

The updated create_compensation_mesh method properly creates temporary meshes, calculates offsets, and cleans up afterward. This is good practice and prevents profile pollution.

tg73 added 13 commits April 7, 2025 21:24
…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
tg73 and others added 4 commits April 22, 2025 15:33
…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
@tg73 tg73 force-pushed the feature/beacon-runtime-offset branch from 1ebe329 to 47c7115 Compare April 22, 2025 17:22
- Support saving via the standard Z_OFFSET_APPLY_PROBE macro
- Exclude active IDEX toolhead offset from the saved value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants