@deckingman said in Conditional Code Based on temperature:
Not specifically. I was looking for something that would return true if M116 P0 was satisified that I could then check with a minimum setpoint for extrusion.
I have what I want working now, although having to proceed all defined variables with "var." was interesting. I saw that in the documentation, but it didn't click till I tried to run my gcode files.
In the end, this is what I came up with if anyone else needs something like this in the future and it works for my intended purposes without interfering with manual tool changes.
tretract.g
; tretract.g ; This will retract filament from the heatzone on tool change if printing and at temperature ; ; Variable details ;------------------------------------------------------------------------------------ ; state.currentTool - Number of the currently selected tool or -1 if none is selected ; tools[].heaters[] - List of associated heaters (indices) ; heat.heaters[].state == "active" ; heat.heaters[].active - Active temperature of the heater (in C) ; heat.heaters[].current - Current temperature of the heater (in C) ; heat.coldExtrudeTemperature - Minimum required temperature for extrusion moves (in C) ; heat.coldRetractTemperature - Minimum required temperature for retraction moves (in C) M116 P0 ; Wait for set temperatures to be reached M302 P0 ; Prevent Cold Extrudes, just in case temp setpoints are at 0 var tool = state.currentTool; var heater = tools[var.tool].heaters[0]; var minPrintTemp = max(heat.coldExtrudeTemperature, heat.coldRetractTemperature); var curPrintTempTol = 5; var curTemp = heat.heaters[var.heater].current; var minActiveTemp = heat.heaters[var.heater].active - var.curPrintTempTol; var isActive = heat.heaters[var.heater].state == "active"; if state.status == "processing" if var.curTemp > var.minActiveTemp && var.curTemp > var.minPrintTemp && var.isActive M83 ; Relative extrusion mode G1 E-18 F800 ; retract 18mm filamenttprime.g
; tprime.g ; This will prime the heatzone on tool change if printing and at temperature ; ; Variable details ;------------------------------------------------------------------------------------ ; state.currentTool - Number of the currently selected tool or -1 if none is selected ; tools[].heaters[] - List of associated heaters (indices) ; heat.heaters[].state == "active" ; heat.heaters[].active - Active temperature of the heater (in C) ; heat.heaters[].current - Current temperature of the heater (in C) ; heat.coldExtrudeTemperature - Minimum required temperature for extrusion moves (in C) ; heat.coldRetractTemperature - Minimum required temperature for retraction moves (in C) M116 P0 ; Wait for set temperatures to be reached M302 P0 ; Prevent Cold Extrudes, just in case temp setpoints are at 0 var tool = state.currentTool; var heater = tools[var.tool].heaters[0]; var minPrintTemp = max(heat.coldExtrudeTemperature, heat.coldRetractTemperature); var curPrintTempTol = 5; var curTemp = heat.heaters[var.heater].current; var minActiveTemp = heat.heaters[var.heater].active - var.curPrintTempTol; var isActive = heat.heaters[var.heater].state == "active"; if state.status == "processing" if var.curTemp > var.minActiveTemp && var.curTemp > var.minPrintTemp && var.isActive M83 ; Relative extrusion mode G1 E20 F800 ; prime 20mm filamentAnd I just use this in my postX.g files
; tpost0.g ; called after firmware thinks Tool0 is selected ; Note: tool offsets are applied at this point! ; Note that commands preempted with G53 will NOT apply the tool offset. M116 P0 ; Wait for set temperatures to be reached M302 P0 ; Prevent Cold Extrudes, just in case temp setpoints are at 0 G90 ; Ensure the machine is in absolute mode before issuing movements. G53 G1 Y-40 F6000 ; Move to the pickup position with tool-0. M98 P"/macros/tool_lock.g" ; Lock the tool M98 P"/sys/tprime.g" ; prime filament into the heatzone G53 G1 Y-5 F6000 ; Move off the parking posts M591 D0 S1 ; Enable filament sensor G1 R2 Z0 ; Restore prior Z position before tool change was initiated. ; Note: tool tip position is automatically saved to slot 2 upon the start of a tool change. ; Restore Z first so we don't crash the tool on retraction. G1 R0 Y0 ; Retract tool by restoring Y position next now accounting for new tool offset. ; Restoring Y next ensures the tool is fully removed from parking post. G1 R0 X0 ; Restore X position now accounting for new tool offset. M106 R2 ; restore print cooling fan speedAnd this in my tfreeX.g files
; tfree0.g ; Runs at the start of a toolchange if the current tool is tool-0. ; Note: tool offsets are applied at this point unless we preempt commands with G53! G91 ; Relative Mode. G1 Z2 ; Pop Z up slightly so we don't crash while traveling over the usable bed region. G90 ; Absolute Mode. G53 G0 X11 Y5 F12000 ; Rapid to the back of the post. Stay away from the tool rack so we don't collide with tools. ; ; This position must be chosen such that the most protruding y face of the current tool ; ; (while on the carriage) does not collide with the most protruding y face of any parked tool. M98 P"/sys/tretract.g" ; retract filament out of heatzone M591 D0 S0 ; Disable filament sensor G53 G1 Y-40 F6000 ; Controlled move to the park position with tool-1. (park_x, park_y) M98 P"/macros/tool_unlock.g" ; Unlock the tool G53 G1 Y-5 F6000 ; Retract the pin.