Skip to content

Commit

Permalink
Macros: implement IDEX support (#162)
Browse files Browse the repository at this point in the history
Adds support for IDEX along with a couple of new features such as homing Y before X, `RATOS_ECHO`, `DEBUG_ENABLE/DISABLE/ECHO` and priming along X instead of Y.

---------

Co-authored-by: HelgeKeck <[email protected]>
  • Loading branch information
miklschmidt and HelgeKeck authored Jan 25, 2024
1 parent 236650e commit 8ffee45
Show file tree
Hide file tree
Showing 27 changed files with 3,467 additions and 826 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ConfiguratorTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
path: "ratos-configurator"
repository: Rat-OS/RatOS-configurator
ref: ${{ github.base_ref || github.ref_name }}
ref: "development"

- name: Setup Node.js environment
uses: actions/[email protected]
Expand Down
246 changes: 161 additions & 85 deletions homing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,111 @@ axes: xyz
z_hop: 15
z_hop_speed: 15
gcode:
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %}
{% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %}

{% if printer["dual_carriage"] is defined %}
# reset IDEX mode
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set target_idex_mode = printer["dual_carriage"].carriage_1|lower %}
_IDEX_SINGLE
_SELECT_TOOL T={default_toolhead} TOOLSHIFT=false
{% endif %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %}

# Make stowable probe assertion failures cause an emergency stop
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True

# Wait for moves to finish
M400
# Absolute positioning
G90

# home printer
{% set X = true if params.X is defined else false %}
{% set Y = true if params.Y is defined else false %}
{% set Z = true if params.Z is defined else false %}
{% if printer["gcode_macro RatOS"].home_y_first|default(false)|lower == 'true' %}
HOME_Y X={X} Y={Y} Z={Z}
HOME_X X={X} Y={Y} Z={Z}
{% else %}
HOME_X X={X} Y={Y} Z={Z}
HOME_Y X={X} Y={Y} Z={Z}
{% endif %}
{% set z_probe = printer["gcode_macro RatOS"].z_probe|lower %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %}
{% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %}
HOME_Z X={X} Y={Y} Z={Z}

# Reset stowable probe stop on error state
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error}

{% if printer["dual_carriage"] is defined %}
# restore IDEX mode
{% if target_idex_mode == "copy" %}
_IDEX_COPY
{% elif target_idex_mode == "mirror" %}
_IDEX_MIRROR
{% endif %}
{% endif %}

[gcode_macro HOME_X]
gcode:
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set homing = printer["gcode_macro RatOS"].homing|lower %}
{% set homing_x = printer["gcode_macro RatOS"].homing_x|lower %}
{% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %}
{% set homing_x = homing_x if homing_x else homing %}
{% set homing_y = homing_y if homing_y else homing %}
{% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %}

# Make stowable probe assertion failures cause an emergency stop
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %}
{% endif %}

M400 # Wait for moves to finish
G90 # Absolute positioning
{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}

{% if params.X is defined or params.Y is not defined and params.Z is not defined %}
{% if X or not Y and not Z %}
{% if homing_x == 'endstop' %}
G28 X
{% elif homing_x == 'sensorless' %}
{% if printer["dual_carriage"] is defined %}
{ action_emergency_stop("sensorless homing not supported on IDEX!") }
{% endif %}
HOME_X_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_x to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_x, homing)) }
{% endif %}
{% if printer["dual_carriage"] is defined %}
# park secondary toolhead in its parking position instead of the endstop position
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
{% set parking_position = printer["gcode_macro RatOS"].parking_position %}
SET_DUAL_CARRIAGE CARRIAGE={0 if default_toolhead==1 else 1} MODE=PRIMARY
G1 X{parking_position[0 if default_toolhead==1 else 1]} F{speed}
SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} MODE=PRIMARY
{% endif %}
{% set x_homed = True %}
G0 X{safe_home_x} F{speed}
{% endif %}

{% if params.Y is defined or params.X is not defined and params.Z is not defined %}
[gcode_macro HOME_Y]
gcode:
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set homing = printer["gcode_macro RatOS"].homing|lower %}
{% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %}
{% set homing_y = homing_y if homing_y else homing %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %}
{% endif %}

{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}

{% if Y or not X and not Z %}
{% if homing_y == 'endstop' %}
G28 Y
{% elif homing_y == 'sensorless' %}
{% if printer["dual_carriage"] is defined %}
{ action_emergency_stop("sensorless homing not supported on IDEX!") }
{% endif %}
HOME_Y_SENSORLESS
{% else %}
{ action_emergency_stop("expected RatOS variable_homing_y to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_y, homing)) }
Expand All @@ -59,10 +120,29 @@ gcode:
G0 Y{safe_home_y} F{speed}
{% endif %}

{% if params.Z is defined or params.Y is not defined and params.X is not defined %}
RESPOND MSG="Homing Z"
[gcode_macro HOME_Z]
gcode:
{% set x_homed = 'x' in printer.toolhead.homed_axes %}
{% set y_homed = 'y' in printer.toolhead.homed_axes %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}
{% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %}
{% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %}
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %}
{% endif %}
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %}
{% endif %}

{% set X = true if params.X|lower == 'true' else false %}
{% set Y = true if params.Y|lower == 'true' else false %}
{% set Z = true if params.Z|lower == 'true' else false %}

{% if Z or not Y and not X %}
RATOS_ECHO MSG="Homing Z"
{% if x_homed == False or y_homed == False %}
M118 X and Y must be homed before homing Z
{ action_emergency_stop("X and Y must be homed before homing Z") }
{% else %}
{% if z_probe == "stowable" %}
Expand All @@ -78,12 +158,10 @@ gcode:
{% endif %}
{% endif %}
{% endif %}

# Reset stowable probe stop on error state
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error}

[gcode_macro HOME_X_SENSORLESS]
gcode:
CACHE_TOOLHEAD_SETTINGS
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
{% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %}
Expand Down Expand Up @@ -137,11 +215,11 @@ gcode:
{% endif %}
# Wait for currents to settle
G4 P300
# Restore acceleration
M204 S{printer.configfile.config.printer.max_accel}
RESTORE_TOOLHEAD_SETTINGS

[gcode_macro HOME_Y_SENSORLESS]
gcode:
CACHE_TOOLHEAD_SETTINGS
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
{% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %}
Expand Down Expand Up @@ -195,62 +273,60 @@ gcode:
{% endif %}
# Wait for currents to settle
G4 P300
# Restore acceleration
M204 S{printer.configfile.config.printer.max_accel}
RESTORE_TOOLHEAD_SETTINGS

[gcode_macro MAYBE_HOME]
description: Only home unhomed axis
variable_is_kinematic_position_overriden: False
gcode:
{% if printer["gcode_macro MAYBE_HOME"].is_kinematic_position_overriden|lower == 'true' %}
RESPOND MSG="SET_CENTER_KINEMATIC_POSITION has been abused. Homing all axes. Please refrain from using SET_CENTER_KINEMATIC_POSITION outside of debugging purposes."
G28
SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=False
{% else %}
{% set axes = '' %}
{% set isHomed = true %}
{% set axesToHome = '' %}
{% if params.X is defined %}
{% set axes = axes ~ 'X ' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% endif %}
{% if params.Y is defined %}
{% set axes = axes ~ 'Y ' %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% endif %}
{% if params.Z is defined %}
{% set axes = axes ~ 'Z ' %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if params.X is not defined and params.Y is not defined and params.Z is not defined %}
{% set axes = '' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if isHomed is false %}
M117 Homing {axesToHome}
RESPOND MSG="Homing {axesToHome}"
G28 {axesToHome}
{% else %}
RESPOND MSG="All requested axes already homed, skipping.."
{% endif %}
{% endif %}
{% if printer["gcode_macro MAYBE_HOME"].is_kinematic_position_overriden|lower == 'true' %}
RATOS_ECHO MSG="SET_CENTER_KINEMATIC_POSITION has been abused. Homing all axes. Please refrain from using SET_CENTER_KINEMATIC_POSITION outside of debugging purposes."
G28
SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=False
{% else %}
{% set axes = '' %}
{% set isHomed = true %}
{% set axesToHome = '' %}
{% if params.X is defined %}
{% set axes = axes ~ 'X ' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% endif %}
{% if params.Y is defined %}
{% set axes = axes ~ 'Y ' %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% endif %}
{% if params.Z is defined %}
{% set axes = axes ~ 'Z ' %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if params.X is not defined and params.Y is not defined and params.Z is not defined %}
{% set axes = '' %}
{% if 'x' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'X ' %}
{% endif %}
{% if 'y' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Y ' %}
{% endif %}
{% if 'z' not in printer.toolhead.homed_axes %}
{% set isHomed = false %}
{% set axesToHome = axesToHome ~ 'Z ' %}
{% endif %}
{% endif %}
{% if isHomed is false %}
RATOS_ECHO MSG="Homing {axesToHome}"
G28 {axesToHome}
{% else %}
RATOS_ECHO MSG="All requested axes already homed, skipping.."
{% endif %}
{% endif %}
Loading

0 comments on commit 8ffee45

Please sign in to comment.