/pglt

Leveling tool for PCB milling.

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

pglt

PCB GCode Leveling Tool.

Leveling tool for PCB milling.

Probes a PCB surface, and uses bicubic spline interpolation to fit a GCode to the surface's irregularites.

Concept

Millig a PCB with fine traces can be challenging, because small variations in cut depth - caused by an irregular PCB surface relative to the mill's path - can lead to unusable traces. Compensating such irregularites generaly involves probing the PCB's surface at multiple points, and fitting the mill's trajectory to it. Very few CNC firwares properly implement this feature. The goal with pglt is to move this fitting functionality to a host computer - generating a 'fitted' GCode from the original PCB toolpath.

Requirements

  • A CNC mill (or 3D printer) with a serial interface
  • A PBC milling setup that enables probing the PCB surface (endstop), like this
  • PCB's GCode for the toolpaths.
  • [Optional] PCB's Excellon drill file.
  • Python's Matplotlib >= 1.4.3 (Scipy is also required, but will be installed along)

This was only tested under Mac and Linux, with the Marlin firmware and GCodes generated by Flatcam. Test boards were designed under KiCad. YMMV.

Usage

Suppose the workflow for a dual-sided board:

  1. Drill the holes
  2. Mill the top copper
  3. Flip board around (using e.g. alignment holes)
  4. Mill the bottom copper
  5. Cut the outline

Surface probings and GCode fitting should be done between steps 1 and 2, and 3 and 4. Let's setup pglt for that, by editing the supplied pglt.conf:

# Comments start with a hashtag
# conf for pglt
comm_baud = 115200
comm_port = /dev/ttyACM1

# io files
hmap_path  = path/to/my_heightmap_file.csv
gcode_path = path/to/my_gcode_file.g
gcode_out  = path/to/my_fitted_gcode.g
excellon_path = path/to/my_excellon_drill_file.drl

# probing 
probe_xmin = -5.0
probe_ymin = -5.0
probe_xmax = 25.0
probe_ymax = 20.0
probe_xpts = 4
probe_ypts = 5

The comm_* fields specify the parameters of the mill's serial connection. The # io files section presents the files used during GCode fitting and surface probing. The probe_* fields define the start and end of the probing job, as well as how many points will be read in the X and Y directions.

After setting up the file, use you mill's host to move it to the desired X/Y position. pglt considers that the mill begins at (probe_xmin, probe_ymin). Z axis will be homed, so the height is irrelevant. If desired, use your host to drill the board. Disconnect your host from the mill and execute:

$ pglt -c pglt.cont -p

The -p flag runs pglt in probe mode (run pglt -h to see all options). It will generate surface probing points along a grid, avoiding the drills in the excellon file (this behavior can be supressed with -id). Enabling --plot displays the generated probing points and the avoided drills, like shown below:

The xs stand for the probe points, and the o represent the drills on the board. The red outline dispays the desired clearance from the holes (in this case, 1mm).

After executing the probing, a CSV heightmap will be saved to path/to/my_heightmap_file.csv. The GCode can now be fitted to this heightmap. Execute just:

$ pglt -c pglt.conf

The GCode in path/to/my_gcode_file.g will be fitted and saved to path/to/my_fitted_gcode_file.g. Running this command with --plot enabled displays the 3D probed heightmap, for example:

After flipping the board, it must be probed again. Suppose the board was flipped along an axis parallel to X, at Y=15. In order to compensate for the mirroring of the drills, the probing should be executed as:

$ pglt -c pglt.conf -p --mirrorx 15

Note that the probe_* values are not changed by mirroring.