; Conditional auto trigger height calculation ; Reprap firmware version 3.3b2 or later required! ; define some variables to store readings var NumTests=10 ; modify this value to define number of tests ; Do not change below this line var RunningTotal=0 var Average=0 var Lowest=0 var Highest=0 M291 P"Grid bed compensation map and Z Probe trigger height will be cleared. Ok or Cancel?" R"WARNING" S3 M98 P"0:/macros/extra/Set LED Red" M561 ; Disable any current bed compensation M290 R0 S0 ; clear baby stepping G29 S2 ; Clear mesh bed compensation parameters G31 Z0 ; Reset Z probe trigger height M291 P"Preheating bed to 60 and nozzle to 195 for accurate probing" if heat.heaters[0].current <=60 && heat.heaters[1].current <=195 if heat.heaters[0].current <55 M140 S55 ; Set bed temperature to 55 M116 ; waiting for bed to reach temperature M140 S60 if heat.heaters[1].current <195 M104 S195 ; Set current tool temperature to 195C M116 S3 ; waiting for heaters to reach temperature M584 X0:3 Y1:4 Z7:8:9 E2:5:6 P3 ; If the printer hasn't been homed, home it if !move.axes[0].homed || !move.axes[1].homed G28 ; Set lower speeds for Z homing and lower Z motor current M566 Z10 ; Set maximum instantaneous speed changes (mm/min) (Jerk) M203 Z100 ; Set maximum speeds (mm/min) M201 Z30 ; Set maximum accelerations (mm/s^2) M400 ;wait for all movement to complete M913 Z70 ; Set 70% motor current to prevent damage in case of head crash ; Move nozzle to centre of bed at z5 M291 P"Nozzle will now move to centre of bed to reset Z0 and calibrate probe" G91 ; relative mode G1 Z5 F2000 ; move bed down 5mm G90 ; absolute mode G1 X150 Y100 F4000 ; Move to bed centre ; Reset z to 5 to allow jogging up to touch bed to nozzle G92 Z5 ; Dialogue to allow user to jog z to touch nozzle to bed gently and then move Z down 10 M564 S0 ; allow Z below 0 M291 P"Jog the Z Axis until the bed and nozzle are touching and click OK" R"Setting Z=0.1" Z1 S3 ;G92 Z0.1 ; Set z = 0.1 G92 Z0 ; Set z = 0 ; Probe trigger heights M291 P"Probe will now measure the trigger heights" R"ZProbe Trigger Height Calibration" while iterations < var.NumTests G1 Z10 G30 S-1 M291 P{"Test " ^ iterations+1 ^ ", Height = " ^ move.axes[2].machinePosition} if iterations == 0 set var.Lowest={move.axes[2].machinePosition} ; set the new lowest reading to first probe height set var.Highest={move.axes[2].machinePosition} ; set the new highest reading to first probe height if move.axes[2].machinePosition < var.Lowest set var.Lowest={move.axes[2].machinePosition} ; set the new lowest reading if move.axes[2].machinePosition > var.Highest set var.Highest={move.axes[2].machinePosition} ; set the new highest reading set var.RunningTotal={var.RunningTotal + move.axes[2].machinePosition} ; set new running total M291 P{"Test " ^ iterations+1 ^ ", Height = " ^ move.axes[2].userPosition} set var.Average = {(var.RunningTotal - var.Highest - var.Lowest) / (var.NumTests - 2)} ; calculate the average after discarding th ehigh & low reading M118 P3 S{"running total = " ^ var.RunningTotal} ; send running total to DWC console M118 P3 S{"low reading = " ^ var.Lowest} ; send low reading to DWC console M118 P3 S{"high reading = " ^ var.Highest} ; send high reading to DWC console M118 P3 S{"Average excluding high and low reading = " ^ var.Average} ; send average to DWC console G31 P500 Z{var.Average} ; set Z probe offset to the average reading G91 ; relative mode G1 Z5 F2000 ; move bed down 5mm G90 ; absolute mode M291 P{"Trigger height set to : " ^ sensors.probes[0].triggerHeight ^ " OK to save to config-overide.g, cancel to use until next restart"} R"Finished" S3 M500 P31 ; optionally save result to config-overide.g ; Turn off heaters M140 S0 ; Set bed to 0C M104 S0 ; Set nozzle to 0 and release ; return motor settings M566 Z60 ; Set maximum instantaneous speed changes (mm/min) (Jerk) M203 Z100 ; Set maximum speeds (mm/min) M201 Z30 ; Set maximum accelerations (mm/s^2) M913 Z100 ; Return Z motor current % to normal M400 ; Pause M98 P"0:/macros/extra/Set LED Green" G1 Y228 X118 F3000 ; Park position M291 P"Probing complete. Check console for auto set trigger height, results" S2