Z calibration - Need programming advice
-
Hello,
I am building a custom multi-tool tool changer system and now working on the Z calibration process. I am using a precision tool setter-type switch where each tool will come down touch the tool setter and register the machine Z coordinate. I am thinking of the following sequence of actions:
- Create a macro/job file called calibrateZ.g
- Select Tool, heat to 215C
- Move tool to XY position above the tool setter sensor. Note: I have already done XY calibration of each tool and have stored XY offsets for all tools in tpre#.g using G10 P# Xnn Ynn Z0.0
- Using G30 S-1 come down in Z and touch off the sensor to determine machine Z position at which sensor was triggered
- Do #4 for five times and store values in an array and compute the average and standard deviation
- Update Z offset for the tool using G10 P# Z{average_value}
- Turn of heater for tool
- Select next tool and repeat 2 to 6
rough attempt at trying to code this
; calibrateZ.g T1; Select and load tool 1 M109 P1 S215; Set temp (can also use M568??) M116 P1; Wait to reach temp G1 X0.0 Y0.0 F1000; move to HRP set to above Z tool setter sensor. X and Y offsets for tool stored in tpre#.g using G10 P1 Xnnn Ynnn Z0.0 var zPos = {}; 5 element array - not sure how to define this for(i=1;i<=5;i++) { G30 S-1; zPos(i) = move.axes[2].machinePosition; G1 Zxx F100; relative move up } ; compute the average of zPos array ; compute std dev of zPos array if (stddev(zPos) > threshold) alert user stop else ;set Z offset G10 P1 Z{avg(zPos)} - need to check sign M109 P1 S0; Set temp (can also use M568??) T-1 P1; unload tool 1 ; repeat for remaining tools
Questions:
- Are there readily available G/M codes that can do this automatically? Don't want to re-invent the wheel. M585 seems to do this but although only once
- What is the right syntax to define the array, store value within the for loop and compute avg and std dev?
- Where would be the best place to store and use the calibrated Z position - tpre#.g or tpost#.g?
- Any other considerations I need to be aware of?
-
@RockB If the tool setter is defined as a probe with M558 (rather than an endstop), you can use the M558 A and S parameters to control multiple probing:
Annn Maximum number of times to probe each point, default 1. Maximum, as of 2.03, is 31. Setting M558 A parameter to anything >31 set it to 0 instead of to 31
Snnn Tolerance when probing multiple times, default 0.03mmThe A and S parameters control multiple probing. Probing is repeated until two consecutive probe attempts produce results that differ by no more than the S parameter; then the average of those two results is used. For example, S-1 would force averaging. However, if the number of attempts specified by the A parameter is reached without getting two consecutive results within tolerance of each other, no further probe attempts are made and the average result of all the attempts is used.
So setting M558 S-1 A5 would force it to average 5 contacts with the probe.
With that set, you can use M585 to probe the tool (with the M558 settings it should do it multiple times) and calculate the offset.
Ian
-
@droftarts Thanks for pointing me to M558 A and S parameters
in my config.g, I have defined a Z probe as follows:
; Z Probe M558 K0 P5 C"!io3.in" A5 S-1 F130:100 T100 ; Z-probe tool setter connected to io3.in pin, Type 5 (switch- NC), Probe 5 times and average the results
I move the nozzle about 5 mm above the tool setter and issue the following command in DWC
M585 Z5 P0 S1 F100
The probing just happens once and stops. I see the Z offset value automatically updated (Current Z position under axis name in DWC changes), However, probing is not happening 5 times as defined in M558. Any suggestions as to why this may be happening?
-
-
@droftarts Thank you. Also, When I try to save the machine Z position at which the Z probe was triggered as the Z offset using G10, nothing happens
G10 P1 X{-move.axes[2].machinePosition}
What is the correct way to update the Z offset after M585? I have noticed the Z offset is not retained after the tool change.
-
@RockB @droftarts @dc42 any suggestions?
-