Skip to content

add TOOLSHIFT=0 support while printing #74

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

Ibot-11
Copy link

@Ibot-11 Ibot-11 commented Mar 6, 2025

While troubleshooting a problem, I noticed that _SELECT_TOOL TOOLSHIFT=0 does not work when printing.
With this small fix it now works while printing.
Toolshift can now be disabled during printing with another T0/T1 override.
[gcode_macro T0] gcode:
{% set x = params.X|default(-1.0)|float %}
{% set y = params.Y|default(-1.0)|float %}
{% set z = params.Z|default(0.0)|float %}
{% set s = params.S|default(1)|int %}
{% if printer["gcode_macro _SELECT_TOOL"] is defined %}
_SELECT_TOOL T=0 X={x} Y={y} Z={z} TOOLSHIFT=0
{% endif %}

Removing XYZ to force it to disable toolshift messes up the z-hop

Summary by CodeRabbit

  • Refactor
    • Enhanced the toolhead management during dual carriage operations to optimize performance when tool shifting is enabled.

Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

The changes update the toolhead movement logic in the G-code macro configuration for dual carriage operations. The revised code introduces a nested conditional structure that checks the toolshift flag. When toolshift is enabled, the macro compares the distances of toolheads T0 and T1 to determine which move command to execute first and adds a parking command for T1 after the copy move. If toolshift is disabled, the existing logic for T1 parking and moving T0 remains unchanged.

Changes

File Change Summary
configuration/macros/.../toolheads.cfg Modified tool shifting logic: added nested conditionals based on toolshift enabling; compares T0 vs T1 distances to determine copy/move commands; adds parking commands for T1 when toolshift is true.

Sequence Diagram(s)

sequenceDiagram
    participant Macro
    participant T0
    participant T1

    Macro->>Macro: Check toolshift flag
    alt toolshift true
        Macro->>Macro: Compare distances (T0 vs T1)
        alt T0 distance ≥ T1 distance
            Macro->>T1: Execute Copy Command (mode A)
            Macro->>T0: Execute Move Command for T0
            Macro->>T1: Execute Parking Command
        else T0 distance < T1 distance
            Macro->>T1: Execute Copy Command (mode B)
            Macro->>T0: Execute Move Command for T0
            Macro->>T1: Execute Parking Command
        end
    else toolshift false
        Macro->>T1: Execute Parking Command
        Macro->>T0: Execute Move Command for T0
    end
Loading

Poem

I hopped through lines with nimble grace,
Adjusting toolheads in our coding space.
A nimble switch—command so bright,
Parking T1 with purely rabbit delight.
Carrots and code, in harmony bound,
This update makes our macros renowned!


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

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/macros/idex/toolheads.cfg (3)

464-488: Consider DRY-ing the conditional logic and improving readability.
The nested conditions for toolshift and comparing t0_distance vs. t1_distance largely duplicate lines of code in both branches. Extracting common operations (like parking T1 or moving T0) into separate helper macros would make this logic more concise and easier to maintain down the line.


542-565: Unify the approach for T0 and T1 to reduce duplicate patterns.
This block mirrors the previous approach for T0 but includes very similar commands for T1. Merging these into a single function or macro call with parameters for tool indices and distances can simplify maintenance and reduce potential inconsistencies between T0 and T1 logic.


542-565: Check if the “copy move” and “park” operations should handle Z safely.
Similar to the T0 block above, there is no explicit Z-hop or additional clearance step before the “copy move” or “park T0/T1” lines. In certain printers, moving on the X-axis alone without a Z-lift may risk collision when the tools are close. Consider an optional Z-hop or collision check if your hardware tolerances are tight.

📜 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 2822695.

📒 Files selected for processing (1)
  • configuration/macros/idex/toolheads.cfg (2 hunks)
🔇 Additional comments (1)
configuration/macros/idex/toolheads.cfg (1)

464-488: Verify collision-safety when performing copy moves.
When using these copy moves (lines 469, 478), ensure that there is enough clearance on the Y-axis, especially if new_y + yoffset might exceed the physical limits or get too close to the parked toolhead’s location. If there's a risk of collision or out-of-bounds movement, consider adding boundary checks or explicitly homing the axes to ensure safe movements.

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.

1 participant