Skip to content

Conversation

@dbstf
Copy link

@dbstf dbstf commented May 7, 2025

Update to make compatible with Klipper refactoring (Klipper3d/klipper#6815), in particular

  • idex_modes: Internal refactoring of handling dual carriages

Summary by CodeRabbit

  • New Features

    • Added the ability to clear homing state for specific axes, enabling targeted re-homing without affecting others.
  • Improvements

    • Improved dual-carriage handling and homing coordination for more consistent multi-carriage movement.
    • Refined homing logic and parameter handling to reduce unexpected behavior during homing and position setting.

Update to make compatible with Klipper refactoring (Klipper3d/klipper#6815), in particular
* idex_modes: Internal refactoring of handling dual carriages
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

Refactors dual-carriage initialization and selection, standardizes homing calls to pass axis, adds clear_homing_state(clear_axes) to reset homing limits for axes, removes a step-generator registration, and fixes comment capitalization and attribution year.

Changes

Cohort / File(s) Change Summary
Kinematics — single file
configuration/klippy/kinematics/ratos_hybrid_corexy.py
Refactored dual-carriage construction to pass primary/secondary rail lists and axes; simplified primary-rail selection (checks axis == 0); changed dc_module.home call to accept axis; removed toolhead.register_step_generator(s.generate_steps) registration; added clear_homing_state(self, clear_axes) to reset homing limits; updated comment capitalization and added 2025 attribution.

Sequence Diagram(s)

sequenceDiagram
    participant Printer
    participant RatOSHybridCoreXYKinematics as Kinematics
    participant DualCarriages as DC

    Printer->>Kinematics: initialize(printer, config)
    Kinematics->>DC: new DualCarriages(primary_rails=[rails[0]], secondary_rails=[rails[3]], axes=[0], safe_dist)
    Note right of DC #DFF2E1: Dual-carriage object created with explicit axes

    loop Homing flow
        Printer->>Kinematics: home(homing_state)
        alt axis == 0
            Kinematics->>DC: home(homing_state, axis)
        else other axis
            Kinematics->>Kinematics: home_axis(homing_state, axis)
        end
    end

    Printer->>Kinematics: clear_homing_state(clear_axes)
    Kinematics->>Kinematics: set limits for each axis in clear_axes to (1.0, -1.0)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (1 passed, 1 warning, 1 inconclusive)

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The current title "Update ratos_hybrid_corexy.py" correctly names the modified file but is overly generic and does not communicate the primary purpose of the change (adapting the kinematics for Klipper's dual‑carriage/idex refactor, adding clear_homing_state, and related homing/axis adjustments), so it does not give reviewers enough context at a glance. Please replace the generic title with a short, specific one that states the intent; for example: "Adapt ratos_hybrid_corexy.py for Klipper idex/dual‑carriage refactor (PR 6815 compatibility)" or "ratos_hybrid_corexy: handle dual‑carriage/idex_modes and add clear_homing_state." Update the PR title to one of these or a similar concise summary so reviewers can immediately see the change's purpose.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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 (1)
configuration/klippy/kinematics/ratos_hybrid_corexy.py (1)

6-6: Attribution line added.

Good practice adding an attribution line for the changes. However, note that the year 2025 is in the future.

Consider updating to the current year:

-# Modified 2025 by Github user 'dbstf'
+# Modified 2024 by Github user 'dbstf'
📜 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 d5f5cf3.

📒 Files selected for processing (1)
  • configuration/klippy/kinematics/ratos_hybrid_corexy.py (5 hunks)
🔇 Additional comments (5)
configuration/klippy/kinematics/ratos_hybrid_corexy.py (5)

46-46: Fixed capitalization of "Cartesian".

Proper capitalization of "Cartesian" is correct as it's derived from René Descartes' name.


64-67: Refactored dual carriage initialization for compatibility with Klipper PR #6815.

The dual carriage initialization has been updated to match Klipper's refactored IDEX modes handling. This change properly initializes the DualCarriages object with the printer, rail lists, axes specification, and safe distance parameter.


105-106: Simplified primary rail selection logic.

The condition to determine when to use the dual carriage module has been simplified, and the axis parameter is now explicitly passed to get_primary_rail(), which aligns with the updated Klipper IDEX API.


110-113: Added method to clear homing state for specified axes.

Good addition. This new method provides a way to selectively invalidate the homing state for specific axes, which complements the existing note_z_not_homed method and enhances the kinematics module's functionality.


132-132: Updated dual carriage homing to include axis parameter.

The home method call has been updated to pass the axis parameter to the dual carriage module's home method, which is required for compatibility with the refactored Klipper IDEX implementation.

@tg73
Copy link
Collaborator

tg73 commented May 10, 2025

Hi Stefan @dbstf - can I ask how much practical testing this change has received and on what machines?

@dbstf
Copy link
Author

dbstf commented May 10, 2025

Hi Tom, unfortunately, the code is not tested in production at all, yet. I should have mentioned this in the original commit. I'm currently in the process of piecing all parts together for a V-Core 4. For testing, I flashed the latest release of RatOS and updated Klipper to the recent version on Github. The most recent updates broke the ratos_kinematic (lots of warning on the Mainsail status screen), hence I updated the script to the best of my knowledge till all errors in Mainsail were gone. I committed my modified script to provide a starting point for all the other people developing, updating and testing RatOS.

@tg73
Copy link
Collaborator

tg73 commented May 10, 2025

If you're going to be commissioning a new machine, I'd recommend that you stick with the pinned commit of klipper that's defined in the RatOS/moonraker.conf file rather than manually pulling the latest version via git (which I assume is what you did). We have the pinned commit because we have to be rather careful when moving to a new klipper version as things often break. Moving beyond the pinned commit is only for the brave (and ideally experienced), and generally only worth considering if there's some specific klipper fix or feature that you need that comes after the pinned commit. If you do decide to move beyond the pinned commit, be sure to mention that if you run into any kind of problem and need to ask for help on discord or facebook etc.

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/kinematics/ratos_hybrid_corexy.py (3)

46-47: No-op getchoice: confirm intent and config UX.

Calling getchoice('axis', {'x': 'x'}, default='x') purely for validation is fine, but it silently ignores non-x values. If users set axis: x only to satisfy config parsing, consider adding a brief comment in docs or log a debug explaining it’s ignored.


110-114: New helper looks good; add a short docstring for maintainers.

Tiny docs help future readers understand accepted values for clear_axes.

Apply:

-    def clear_homing_state(self, clear_axes):
+    def clear_homing_state(self, clear_axes):
+        """Reset homing limits for the given axes.
+        clear_axes: iterable of axis names, e.g. {'x','y'} or 'xz'."""
         for axis, axis_name in enumerate("xyz"):
             if axis_name in clear_axes:
                 self.limits[axis] = (1.0, -1.0)

65-67: Consider a backward/forward-compat shim with pinned Klipper.

Given RatOS pins Klipper to a specific commit, guard new-API usage to avoid breaking stable installs. Detect the available signature at runtime and route accordingly (constructor with axes=[...] vs. legacy, get_primary_rail(axis) vs. get_primary_rail().get_rail(), and home(homing_state, axis) vs. home(homing_state)).

If you want, I can draft a minimal shim using inspect.signature to branch on parameter names and method arity.

Also applies to: 102-109, 132-132

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5f5cf3 and 0dadb89.

📒 Files selected for processing (1)
  • configuration/klippy/kinematics/ratos_hybrid_corexy.py (5 hunks)
🔇 Additional comments (5)
configuration/klippy/kinematics/ratos_hybrid_corexy.py (5)

6-6: Attribution update acknowledged.

No functional impact; OK to merge.


70-70: No functional change.

Blank line from surrounding edits. Nothing to do.


65-67: DualCarriages init: align with new API and make default explicit.

idex_modes.py not found in repo — cannot verify DualCarriages constructor or status keys. Extract safe_dist for readability and pass it explicitly; then confirm the DualCarriages signature and that get_status exposes 'carriage_1'.

File: configuration/klippy/kinematics/ratos_hybrid_corexy.py (around lines 65-67)

-            self.dc_module = idex_modes.DualCarriages(
-                    self.printer, [self.rails[0]], [self.rails[3]], axes=[0],
-                    safe_dist=dc_config.getfloat(
-                        'safe_distance', None, minval=0.))
+            safe_dist = dc_config.getfloat('safe_distance', default=None, minval=0.)
+            self.dc_module = idex_modes.DualCarriages(
+                self.printer,
+                [self.rails[0]],
+                [self.rails[3]],
+                axes=[0],
+                safe_dist=safe_dist
+            )

Verify by locating idex_modes.py and checking DualCarriages.init and get_status (ensure 'carriage_1' key).


102-109: Shadowed variable in set_position; small clarity refactor.

File: configuration/klippy/kinematics/ratos_hybrid_corexy.py (set_position, ~lines 102–109)

-        for i, rail in enumerate(self.rails):
-            rail.set_position(newpos)
+        for i, r in enumerate(self.rails):
+            r.set_position(newpos)
             for axis in homing_axes:
-                if self.dc_module and axis == 0:
-                    rail = self.dc_module.get_primary_rail(axis)
-                else:
-                    rail = self.rails[axis]
-                self.limits[axis] = rail.get_range()
+                if self.dc_module and axis == 0:
+                    selected_rail = self.dc_module.get_primary_rail(axis)
+                else:
+                    selected_rail = self.rails[axis]
+                self.limits[axis] = selected_rail.get_range()

Confirm get_primary_rail(axis) returns an object exposing get_range() (repo search did not locate its definition; ensure it isn’t the older wrapper requiring .get_rail()).


132-132: Confirm DualCarriages.home accepts (homing_state, axis).

DualCarriages is instantiated at configuration/klippy/kinematics/ratos_hybrid_corexy.py:64 and called at configuration/klippy/kinematics/ratos_hybrid_corexy.py:131–132; the class definition wasn't found in the repo — verify idex_modes.DualCarriages.home signature matches this call.

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.

2 participants