# WARNING: DO NOT EDIT THIS FILE # To override settings from this file, you can copy and paste the relevant # sections into your printer.cfg and change it there. ##### # CONFIGURATION VARIABLES ##### [gcode_macro ECHO_RATOS_VARS] description: Echo RatOS variables to the console. gcode: {% for var, value in printer["gcode_macro RatOS"].items() %} {action_respond_info(var ~ ": " ~ value)} {% endfor %} [gcode_macro RatOS] description: RatOS variable storage macro, will echo variables to the console when run. # Configuration Defaults # This is only here to make the config backwards compatible. # Configuration should exclusively happen in printer.cfg. variable_preheat_extruder: True variable_nozzle_priming: "primeblob" variable_start_print_park_in: "back" variable_start_print_park_z_height: 50 variable_end_print_park_in: "back" variable_pause_print_park_in: "back" variable_macro_travel_speed: 150 gcode: ECHO_RATOS_VARS ##### # GENERAL MACROS ##### [gcode_macro MAYBE_HOME] description: Only home unhomed axis gcode: {% 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 %} [gcode_macro PAUSE] description: Pauses the printer rename_existing: PAUSE_BASE variable_extrude: 1.5 gcode: SAVE_GCODE_STATE NAME=PAUSE_state # Define park positions {% set E = printer["gcode_macro PAUSE"].extrude|float %} {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} # Calculate safe Z position {% set max_z = printer.toolhead.axis_maximum.z|float %} {% set act_z = printer.toolhead.position.z|float %} {% if act_z < (max_z - 2.0) %} {% set z_safe = 2.0 %} {% else %} {% set z_safe = max_z - act_z %} {% endif %} PAUSE_BASE G91 # Retract {% if printer.extruder.can_extrude|lower == 'true' %} G1 E-{E} F2100 {% else %} {action_respond_info("Extruder not hot enough")} {% endif %} # Move to park position {% if "xyz" in printer.toolhead.homed_axes %} G1 Z{z_safe} F900 _PARK LOCATION={printer["gcode_macro RatOS"].pause_print_park_in} X={printer["gcode_macro RatOS"].pause_print_park_x} {% else %} {action_respond_info("Printer not homed")} {% endif %} [gcode_macro RESUME] description: Resumes the print if the printer is paused. rename_existing: RESUME_BASE gcode: {% set E = printer["gcode_macro PAUSE"].extrude|float %} # Prime {% if printer.extruder.can_extrude|lower == 'true' %} G91 G1 E{E} F2100 G90 {% else %} {action_respond_info("Extruder not hot enough")} {% endif %} RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 RESUME_BASE [gcode_macro CANCEL_PRINT] description: Cancels the printer rename_existing: CANCEL_PRINT_BASE gcode: END_PRINT TURN_OFF_HEATERS CLEAR_PAUSE #SDCARD_RESET_FILE CANCEL_PRINT_BASE [gcode_macro PRIME_LINE] description: Prints a primeline, used internally, if configured, as part of the START_PRINT macro. gcode: SAVE_GCODE_STATE NAME=prime_line_state {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} # Absolute positioning G90 # Absolute extrusion M82 M117 Priming nozzle with prime line.. RESPOND MSG="Priming nozzle with prime line.." # Lift 5 mm G1 Z5 F3000 # Move to prime area G1 X{printer.toolhead.axis_minimum.x + 5} Y{printer.toolhead.axis_minimum.y + 10} F{speed} # Get ready to prime G1 Z0.3 F3000 # Reset extrusion distance G92 E0 # Prime nozzle G1 Y{printer.toolhead.axis_minimum.y + 80} E16 F1200 # Wipe G1 Y{printer.toolhead.axis_minimum.y + 100} F{speed} RESTORE_GCODE_STATE NAME=prime_line_state [gcode_macro PRIME_BLOB] description: Prints a primeblob, used internally, if configured, as part of the START_PRINT macro. Slower than PRIME_LINE but much more effective. gcode: SAVE_GCODE_STATE NAME=prime_blob_state M117 Priming nozzle with prime blob.. RESPOND MSG="Priming nozzle with prime blob.." {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} # Absolute positioning G90 # Relative extrusion M83 # Lift 5 mm G1 Z5 F3000 # move to blob position G1 X{printer.toolhead.axis_minimum.x + 5} Y{printer.toolhead.axis_minimum.y + 10} Z0.5 F{speed} # Extrude a blob G1 F60 E20 # 40% fan M106 S102 # Move the extruder up by 5mm while extruding, breaks away from blob G1 Z5 F100 E5 # Move to wipe position, but keep extruding so the wipe is attached to blob G1 F200 Y{printer.toolhead.axis_minimum.y + 25} E1 # Go down diagonally while extruding # Broken down in z moves under 2mm as a workaround for a tuning tower test. # The tuning tower command thinks a new print has been started when z moves over 2mm and aborts. G1 F200 Y{printer.toolhead.axis_minimum.y + 30} Z3.8 E0.5 G1 F200 Y{printer.toolhead.axis_minimum.y + 35} Z2.6 E0.5 G1 F200 Y{printer.toolhead.axis_minimum.y + 40} Z1.4 E0.5 G1 F200 Y{printer.toolhead.axis_minimum.y + 45} Z0.2 E0.5 # 0% fan M106 S0 # small wipe line G1 F200 Y{printer.toolhead.axis_minimum.y +50} Z0.2 E0.6 # Break away wipe G1 F{speed} Y{printer.toolhead.axis_minimum.y + 100} RESTORE_GCODE_STATE NAME=prime_blob_state [gcode_macro _PARK] gcode: {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} # Get X position {% if params.X != '' %} {% if params.X|float >= printer.toolhead.axis_minimum.x + 5 and params.X|float <= printer.toolhead.axis_maximum.x - 5 %} {% set safe_x = params.X|float %} {% else %} {action_respond_info('The requested X co-ordinate is outside the defined axis bounds - using defaults')} {% set safe_x = printer.toolhead.axis_maximum.x / 2 %} {% endif %} {% else %} {% set safe_x = printer.toolhead.axis_maximum.x / 2 %} {% endif %} # Get Y position {% if params.LOCATION|default('back')|lower == 'back' %} {% set y = printer.toolhead.axis_maximum.y - 5 %} {% elif params.LOCATION|lower == 'front' %} {% set y = printer.toolhead.axis_minimum.y + 5 %} {% elif params.LOCATION|lower == 'center' %} {% set y = printer.toolhead.axis_maximum.y / 2 %} {% endif %} # Absolute positioning G90 # Park G0 X{safe_x} Y{y} F{speed} ##### # COLOR CHANGE ##### [gcode_macro M600] description: Executes a color change by pausing the printer an unloading the filament. gcode: PAUSE UNLOAD_FILAMENT M117 Please load new filament and resume RESPOND MSG="Please load new filament and resume" ##### # FILAMENT MANAGEMENT ##### [gcode_macro UNLOAD_FILAMENT] description: Unloads the filament. Note: be careful with PETG, make sure you inspect the tip of your filament before reloading to avoid jams. gcode: SAVE_GCODE_STATE NAME=unload_state G91 {% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %} M117 Heating... # Heat up hotend to provided temp or 220 as default as that should work OK with most filaments. M104 S{params.TEMP|default(220, true)} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)} {% endif %} M117 Unloading filament... # Extract filament to cold end area G0 E-5 F3600 # Wait for three seconds G4 P3000 # Push back the filament to smash any stringing G0 E5 F3600 # Extract back fast in to the cold zone G0 E-15 F3600 # Continue extraction slowly, allow the filament time to cool solid before it reaches the gears G0 E-130 F300 M117 Filament unloaded! RESPOND MSG="Filament unloaded! Please inspect the tip of the filament before reloading." RESTORE_GCODE_STATE NAME=unload_state [gcode_macro LOAD_FILAMENT] description: Loads new filament. Note: be careful with PETG, make sure you inspect the tip of your filament before loading to avoid jams. gcode: SAVE_GCODE_STATE NAME=load_state G91 # Heat up hotend to provided temp or 220 as default as that should work OK with most filaments. {% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %} M117 Heating... M104 S{params.TEMP|default(220, true)} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)} {% endif %} M117 Loading filament... # Load the filament into the hotend area. G0 E100 F600 # Wait a secod G4 P1000 # Purge G0 E40 F100 # Wait for purge to complete M400e M117 Filament loaded! RESPOND MSG="Filament loaded!" RESTORE_GCODE_STATE NAME=load_state [gcode_macro SET_CENTER_KINEMATIC_POSITION] description: FOR DEBUGGING PURPOSES ONLY. Sets the internal printer kinematic state to the center of all axes regardless of actual physical position. gcode: SET_KINEMATIC_POSITION X={printer.toolhead.axis_maximum.x / 2} Y={printer.toolhead.axis_maximum.y / 2} Z={printer.toolhead.axis_maximum.z / 2} ##### # START PRINT MACROS # Call this from your slicer (custom g-code). # Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers ##### [gcode_macro START_PRINT] description: Start print procedure, use this in your Slicer. gcode: CLEAR_PAUSE SAVE_GCODE_STATE NAME=start_print_state # Metric values G21 # Absolute positioning G90 # Set extruder to absolute mode M82 # Home if needed MAYBE_HOME M117 Heating bed... RESPOND MSG="Heating bed..." # Wait for bed to heat up M190 S{params.BED_TEMP|default(printer.heater_bed.target, true) } # Run the customizable "AFTER_HEATING_BED" macro. _START_PRINT_AFTER_HEATING_BED # Start heating extruder M104 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) } # Run the customizable "PARK" macro _START_PRINT_PARK # Wait for extruder to heat up M109 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) } # Run the customizable "AFTER_HEATING_EXTRUDER" macro. _START_PRINT_AFTER_HEATING_EXTRUDER M117 Printing... RESPOND MSG="Printing..." RESTORE_GCODE_STATE NAME=start_print_state # Set extrusion mode based on user configuration M82 G92 E0 ##### # START PRINT MACRO HOOKS # You can copy these to printer.cfg and modify them to your liking, or just use them as is. #### [gcode_macro _START_PRINT_AFTER_HEATING_BED] gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} M117 Pre-heating extruder... RESPOND MSG="Pre-heating extruder..." # Wait for extruder to reach 150 so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S150 TEMPERATURE_WAIT SENSOR=extruder MINIMUM=150 {% endif %} [gcode_macro _START_PRINT_BED_MESH] gcode: BED_MESH_PROFILE LOAD=default [gcode_macro _START_PRINT_PARK] gcode: {% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %} _PARK LOCATION={printer["gcode_macro RatOS"].start_print_park_in} X={printer["gcode_macro RatOS"].start_print_park_x} G0 Z{z} F6000 [gcode_macro _START_PRINT_AFTER_HEATING_EXTRUDER] gcode: {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeline' %} PRIME_LINE {% endif %} {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeblob' %} PRIME_BLOB {% endif %} {% if printer["gcode_macro RatOS"].skew_profile is defined %} SKEW_PROFILE LOAD={printer["gcode_macro RatOS"].skew_profile} {% endif %} ##### # END PRINT MACROS # Call this from your slicer (custom g-code). # Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers ##### # The end_print macro is also called from CANCEL_PRINT. [gcode_macro END_PRINT] description: End print procedure, use this in your Slicer. gcode: SAVE_GCODE_STATE NAME=end_print_state _END_PRINT_BEFORE_HEATERS_OFF TURN_OFF_HEATERS _END_PRINT_AFTER_HEATERS_OFF _END_PRINT_PARK # Clear skew profile if any was loaded. {% if printer["gcode_macro RatOS"].skew_profile is defined %} SET_SKEW CLEAR=1 {% endif %} # Steppers off M84 # Part cooling fan off M107 M117 Done :) RESPOND MSG="Done :)" RESTORE_GCODE_STATE NAME=end_print_state ##### # END PRINT MACRO HOOKS # You can copy these to printer.cfg and modify them to your liking, or just use them as is. #### [gcode_macro _END_PRINT_BEFORE_HEATERS_OFF] gcode: RESPOND MSG="Cleaning up..." [gcode_macro _END_PRINT_AFTER_HEATERS_OFF] gcode: # Calculate safe Z position {% set max_z = printer.toolhead.axis_maximum.z|float %} {% set act_z = printer.toolhead.position.z|float %} {% if act_z < (max_z - 2.0) %} {% set z_safe = 2.0 %} {% else %} {% set z_safe = max_z - act_z %} {% endif %} # Relative positioning G91 # Retract the filament a bit before lifting the nozzle. G1 E-2 F3600 # Move to safe Z position G0 Z{z_safe} F3600 # Retract filament even more G1 E-2 F3600 [gcode_macro _END_PRINT_PARK] gcode: _PARK LOCATION={printer["gcode_macro RatOS"].end_print_park_in} X={printer["gcode_macro RatOS"].end_print_park_x}