Autoleveller is a program used to aid in the process of milling printed circuit boards by probing the surface height of the pcb and using the probe data to create a height map. which is then used to modify gcode to take account of height variations. This allows very fine traces to be milled from the thin copper layer of pcbs.
Autoleveller uses the G31 gcode command to probe the height at several locationa. Unfortunately the G31 command implemented on Chinese MACH3 usb controllers is often found not to be fully functional.
This was the case with the usb controller card supplied with the Sainsmart Genmitsu 3018-MX3 mini cnc.
There are several problems:
- The g31 command will happily run from the command line, but it will fail to complete if it is run from a gcode file containing other commands.
- The g31 command doesn’t update the 2002 variable
- The g31 command should write the triple x,y,z values to a file opened with the M40 macro, unfortunately it doesn’t.
The triple file is used by autoleveller to generate the height map so this is a significant problem.
To try and fix the first problem, I used a macro to insert a delay before and after the g31 gcode command.
1 2 3 4 5 |
Sleep 500 While IsMoving() Sleep 200 Wend |
This introduces a fixed delay followed by a delay until the axis have stopped moving. Unfortunately the g31 command would still not operate reliably. The only reliable solution was to ask the user:
1 2 |
'Ask user when to start g31 StartG31=Question("Start G31 ?") |
1 2 |
'Wait until user indicates g31 has finished FinishG31=Question("Finished G31 ?") |
The second problem was fixed by updating the 2002 variable after the g31 command finished.
1 2 |
'g31 does not update 2002 properly SetVar(2002, GetDro(2)) |
To solve the problem of the triplet file not updating correctly, I opened an alternative file and appended the x,y,z values to it.
1 2 3 4 5 6 7 8 9 |
'Get the x, y and z values x=GetDro(0) y=GetDro(1) z=GetDro(2) ' Open heightmap file and append axis values Open "G:\heightmap.txt" For Append As #1 Write #1,x,y,z Close #1 |
This could then be used by the autoleveller program instead of the file opened by the M40 macro.
The full macros were created with the MACH3 script editor and placed in the Macros directory.
M2001.M1S
1 2 3 4 5 6 7 8 9 10 |
'Time delay Sleep 500 'Wait until axis stop moving. Doesn't always work. While IsMoving() Sleep 200 Wend 'Ask user when to start g31 StartG31=Question("Start G31 ?") |
M2002.M1S
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
'Time delay Sleep 500 'Wait until axis stop moving. Doesn't always work. While IsMoving() Sleep 200 Wend 'Ask user if g31 has finished Fred=Question("Finished G31 ?") 'Get the x, y and z values x=GetDro(0) y=GetDro(1) z=GetDro(2) 'g31 fails to update 2002 SetVar(2002, z) ' Open heightmap file and append axis values Open "G:\heightmap.txt" For Append As #1 Write #1,x,y,z Close #1 |
M2003.M1S
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
'Time delay Sleep 500 'Wait until axis stop moving. Doesn't always work. While IsMoving() Sleep 200 Wend 'Wait until user indicates g31 has finished FinishG31=Question("Finished G31 ?") 'g31 does not update 2002 properly SetVar(2002, GetDro(2)) 'Create a new heightmap file Open "G:\heightmap.txt" For Output As #1 Close #1 |
Autoleveller was set to use a custom controller and the custom controller options configured with the Pre-probe command set to M2001 and the Post probe command set to M2002.
The Z initialisation block was modified to use a custom block and M2002 was replaced with M2003.
Then its simply a case of loading a gcode file and GENERATE PFG
Load the PFG gcode into MACH3 and then you will be asked to manually confirm if the g31 commands should start or if they have finished. It is a bit annoying to do this manually but at least it works!
I left the M40 & M41 macro commands in the script, so it still asks for a file name for the triplet logging, but the resulting file is redundant.
Once the probing process has completed the new file can be selected in Autoleveller.
File – Raw probe File
Select the g:\heightmap.txt file (or whatever you have called it)
Autoleveller should hopefully now work as intended and modify the gcode to take account of the height map.
This was a quick way of getting autoleveller to work with the Sainsmart Genmitsu 3018-MX3 and it may well work for other MACH3 usb controller cards as well.
Where can i get the Z initialisation block code?
Not working it is only x and y, z don’t tuch copper.