Macro to call heaight map based on bed temp
-
Someone asked for this so I thought I'd post it here.
This version uses variables to make it easier to tweak without searching through the code.
It therefore requires RRF3.3b2 or laterThe attached files
LoadMap.g
CreateMultiTempMaps.g; LoadMap.g ; requires RRF 3.3b2 or later! ; called to load height map according to current bed temp ; Bed must be at target temp so use M116 before calling this macro ;height maps must be already created ; adjust file location and file name of height maps to suit your system ; adjust temps to suit your requirements. ; Remember M116 may not wait until bed is fully at temp so set these a few degrees lower than target temp in slicer ;TempTolerance value will be used in M116 to ensure bed is stable to within +/- this amount from target ; ********** Macro assumes bed heater is H0! *************** var HighTemp = 98 var MediumTemp = 68 var LowTemp = 48 var HighTempMap = "0:/sys/heightmapHigh.csv" var MediumTempMap = "0:/sys/heightmapMedium.csv" var LowTempMap = "0:/sys/heightmapLow.csv" var ColdBedMap = "0:/sys/heightmapCold.csv" var ExitIfBedOff = false ; set to true if you don't want to load a height map if the bed is turned off var AbortIfErrorLevel = 1 ; abort process if error level check is equal to or greater than this. 1 = warning, 2 = error var TempTolerance = 1 ; temp must be within this value- will be set in M116 ; Do not adjust under this line unless you know what you're doing if var.AbortIfErrorLevel < 1 || var.AbortIfErrorLevel > 2 echo "AbortIfErrorLevel value must be either 1 or 2" abort echo "Waiting for bed temp to stabilise" M116 H0 S{var.TempTolerance}; wait for any temp changes on bed to be within X degrees of target if move.axes[0].homed !=true || move.axes[1].homed !=true || move.axes[2].homed !=true echo "Machine not homed - height map operation cancelled" abort ; cancel macro & print G29 S2 ; Clear current height map if {var.ExitIfBedOff == true} && {heat.heaters[0].state == "off"} echo "Bed is off. No height map required" M99 ; exiting macro but not cancelling print ;now check temps and load the height map to suit if heat.heaters[0].current >= var.HighTemp G29 S1 P{var.HighTempMap} ; if temp is 100 or greater load this file if result >= var.AbortIfErrorLevel echo "Failed to load height map " ^ {move.compensation.file} abort ; cancel macro and print elif heat.heaters[0].current >= var.MediumTemp ; if temp is less than 100 AND greater then or equal to 70 load this file G29 S1 P{var.MediumTempMap} if result >= var.AbortIfErrorLevel echo "Failed to load height map " ^ {move.compensation.file} abort ; cancel macro and print elif heat.heaters[0].current >= var.LowTemp ; if temp is less than 70 AND greater then or equal to 50 load this file G29 S1 P{var.LowTempMap} if result >= var.AbortIfErrorLevel echo "Failed to load height map " ^ {move.compensation.file} abort ; cancel macro and print ; START COLD BED MAP else ; - temp is under 50 , so we might have a cold bed height map - otherwise delete COLD BED MAP section G29 S1 P{var.ColdBedMap} ; if result >= var.AbortIfErrorLevel echo "Failed to load height map " ^ {move.compensation.file} abort ; cancel macro and print ;END COLD BED MAP ; START FINAL CHECK ;do a final check and report height map loaded ; comment this out if you want no height map when under 50 degrees if move.compensation.file !=null echo "Height map loaded is " ^ {move.compensation.file} else "MACRO ERROR: No heightmap has been loaded" abort ; cancel print ; END FINAL CHECK ; ;if you don't use FINAL CHECK section, uncomment this line ;echo "Height map loaded is " ^ {move.compensation.file}
This macro will create all the height maps in the 0:/sys folder so that they can be viewed in DWC and loaded via the above macro
;CreateMultiTempMaps.g ; used to create multiple height maps based on varying bed temps ; adjust file locations as required. Must be same in LoadMap.g ; M291 P"This process cannot be manually stopped. Do not leave unattended. Ready to begin?" R"Notice" S3 ; var AmbientTemp = 36 ; bed must be below this value to be considered "Cold" var HighTemp = 100 var MediumTemp = 70 var LowTemp = 50 var HighTempMap = "0:/sys/heightmapHigh.csv" var MediumTempMap = "0:/sys/heightmapMedium.csv" var LowTempMap = "0:/sys/heightmapLow.csv" var ColdBedMap = "0:/sys/heightmapCold.csv" var TempTolerance = 1 ; temp must be within this value- will be set in M116 var SoakTime = 180 ; time in seconds to wait for temp to stabilise to allow for over shoot ; if heat.heaters[0].current > var.AmbientTemp M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed M291 P"Waiting for bed to cool to ambient" R"Cold Map" S1 T3 while heat.heaters[0].current > var.AmbientTemp echo "waiting for bed to reach ambient - Current = " ^ heat.heaters[0].current ^ " Ambient = " ^ var.AmbientTemp G4 S10 if move.axes[0].homed !=true || move.axes[1].homed !=true || move.axes[2].homed !=true echo "Homing" M291 P"Homing required. Please wait" R"Homing" S1 T3 G28 ; home all if required ; echo "Creating cold bed map" M291 P"Creating cold bed map" R"Cold Map" S1 T3 G29 S0 ; create bed mesh if result !=0 M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed abort "Failed to create height map" G29 S3 P{var.ColdBedMap} ; save mesh to separate file if result !=0 abort "Failed to create height map" G29 S2 ; clear height map ; echo "Heating for nextmap" M291 P"Heating for next map" R"Heating" S1 T3 M190 R{var.LowTemp} M116 H0 S{var.TempTolerance}; wait for any temp changes on bed to be within X degrees of target echo "waiting for temp to stabilise" G4 S{var.SoakTime} echo "Creating low temp bed map" M291 P"Creating low temp bed map" R"Low Temp Map" S1 T3 G29 S0 ; create bed mesh if result !=0 M140 S-276 ; turn off bed abort "Failed to create height map" G29 S3 P{var.LowTempMap} if result !=0 M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed abort "Failed to create height map" G29 S2 ; clear height map ; echo "Heating for nextmap" M291 P"Heating for next map" R"Heating" S1 T3 M190 R{var.MediumTemp} M116 H0 S{var.TempTolerance}; wait for any temp changes on bed to be within X degrees of target echo "waiting for temp to stabilise" G4 S{var.SoakTime} echo "Creating medium temp bed map" M291 P"Creating medium temp bed map" R"Medium Temp Map" S1 T3 G29 S0 ; create bed mesh if result !=0 M140 S-276 ; turn off bed abort "Failed to create height map" G29 S3 P{var.MediumTempMap} if result !=0 M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed abort "Failed to create height map" G29 S2 ; clear height map ; echo "Heating for nextmap" M291 P"Heating for next map" R"Heating" S1 T3 M190 R{var.HighTemp} M116 H0 S{var.TempTolerance}; wait for any temp changes on bed to be within X degrees of target echo "waiting for temp to stabilise" G4 S{var.SoakTime} echo "Creating high temp bed map" M291 P"Creating high temp bed map" R"High Temp Map" S1 T3 G29 S0 ; create bed mesh if result !=0 M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed abort "Failed to create height map" G29 S3 P{var.HighTempMap} if result !=0 M140 S-273 ; turn off bed abort "Failed to create height map" M140 S0 R0 ; set active and standby temps to zero M140 S-276 ; turn off bed M291 P"Process complete" R"Done!" S1 T3
-
@owend said in Macro to call heaight map based on bed temp:
MediumTempMap
wah...looks great...thx for the sharing.
-
@owend thanks for sharing! Will use it!
Edit: i found that you should check if result is greater than 1 (or equal to 2) for error handling because result=1 is set when a warning is raised. In my case it is raised because i set Z=0 whit a physical endstop triggered by the nozzle and the use a npn probe only for quad gantry leveling and bed mesh. I set it with G92 Zxx.xxx, i don't know if there's another gcode command to make rrd aware that the correct Z0 was set.
-
@mikes
I have revised the code to allow you to set the result level that is allowed before an abort.I have also added a macro to create the height map files files
-
@owend said in Macro to call heaight map based on bed temp:
NOTE: THE FORUM ADDS {1} INTO THE CODE ON SOME LINE BREAKS. DELETE THESE
It's probably a good idea to add the files for download, too? That way we don't have to read every line with 'eagle eyes'
(although this is a great learning exercise)
Thank you
Olaf -
This post is deleted! -
@o_lampe said in Macro to call heaight map based on bed temp:
@owend said in Macro to call heaight map based on bed temp:
NOTE: THE FORUM ADDS {1} INTO THE CODE ON SOME LINE BREAKS. DELETE THESE
It's probably a good idea to add the files for download, too? That way we don't have to read every line with 'eagle eyes'
(although this is a great learning exercise)
Thank you
OlafDone
-
@owend thanks for implementing. I think it would be a good thing to create a repo for these type of macro on github, maybe semi-official from duet? Obviously with all the necessary warning an so on...
-
As an alternative to using M116 to wait for the temperature to settle and then testing heat.heaters[0].current, you could test heat.heaters[0].active which will be the commanded temperature.
-
@dc42 said in Macro to call heaight map based on bed temp:
As an alternative to using M116 to wait for the temperature to settle and then testing heat.heaters[0].current, you could test heat.heaters[0].active which will be the commanded temperature.
That is certainly true in the case of the Macro to load the height naps and it would mean you don't have to worry about whether M116 releases before reaching the target temperature.
ergo. It's a cleaner implementation using .active
I just figured if you get that much bed variation to need this in the first place then you're going to have to wait sometime.