Close

STL to kicad to gerber

A project log for EOS RP repair

Lion vs the mighty ERR 01

lion mclionheadlion mclionhead 07/05/2022 at 08:160 Comments

There was a guy who transferred a DXF file from fusion 360 to kicad, 4 years ago.  

It's now the File->import->Graphics dialog.  Helas, these vector graphics formats are limited to sketches while the traces in the camera board are fusions of sweeps & extrusions.

So a C program evolved over several days to convert STLs to kicad polygons.  

https://github.com/heroineworshiper/utils/blob/master/stl_to_pcb.c

https://github.com/heroineworshiper/utils/blob/master/3dstuff.h

Brute force mangling of polygons is brutally slow in python.  The theory was the vertical triangles define the outlines so just sorting the vertical triangles would give the outline of the polygon.  The reality is the freecad sweep tool doesn't generate contiguous outlines of vertical triangles.

It generates many segments of walls with gaps where the segments overlap.  It needs an extra step, searching for horizontal triangles joining the ends of 2 outlines.  There are 4 possible ways 2 outlines can be joined at the ends.  Then it needs to pick the way with the shortest path.

Then there was the problem of defining holes inside polygons.  Kicad doesn't have pen up/pen down, boolean modes.  The only way of doing it is drawing a line from the outer wall to the inner hole, around the inner hole, & back to the outer wall.  Kicad treats the inner contour as an extension of the outer wall with the joining line invisible.

Changing "fill solid" to "fill none" allows the joining lines to be viewed.  There's still the problem of separating polygons which need subtraction from overlapping polygons which don't need subtraction.  For the ribbon cable, these cases can be hard coded.  There were some cases where overlapping polygons ended up subtracting unintentionally.  Those involved fudging the model.

Then there's another step which converts an STL file into vias.  The lion just guessed the via dimensions with calipers.

So the program ended up taking a command file with input STL files, destination layers, subtraction modes, fill modes, via modes.  Then, it outputs a complete kicad_pcb file.  The workflow is to create a kicad project with an empty schematic.  Then create the entire board in freecad & convert it from STL files to a kicad_pcb file.

The result was a complete ribbon cable with more accuracy than what could be done in the kicad bitmap converter, though it still appears to do some quantization.  The mane problem would have been lining up all those bitmaps with different resolutions & offsets.

All kicad does is convert that to gerber files.  There was a shareware program for going directly  from stl to gerber  https://www.artwork.com/gerber/stl2gbr/index.htm but it's a rarely needed, hard enough problem that no-one ever bothered.

Sadly, there's no practical use for this STL to kicad converter besides ribbon cables.  That's the only case which requires large numbers of parameterized curves & doesn't use standard footprints.

The next step was printing a size test on paper.

The model was 1.4mm longer than the original.  The lion kingdom originally wanted it 1mm longer. A bitmap editor would be easier to change length in.  Kicad would have been much harder.  Kicad requires an option to print 1 layer per page & doesn't have persistent settings for gerbers, which makes exporting gerbers hard.  

The last PCB lions ordered was $50 for a 4 layer FR4 from seeeeeeed.  It took 2 weeks to get it.  Only pcbway does flat flex cables.  It's expected to take over 1/2 the price of a new camera to get it right.  

The mane shocker was how they jacked up the quoted price.  The $76.27 had a .06mm track spacing & the .1mm track spacing wasn't an option, so it was probably a catch all for jacking up the price.

Their most expensive option is the e-test.  Disabling that takes $40 off.  They note 7 days to build it & 4 days for $24 snail mail.  There's no way to verify which gerber file is being used for which physical part & that everything imported properly.  It seems to be a manual process of reviewing hundreds of kicad layouts & already knowing what looks like a stiffener.

The total with shipping & credit card fees ended up in the $140's.  It would definitely not be profitable for a business to repair cameras by designing custom ribbon cables.  There's still a good chance the lion kingdom ends up buying a new EOS RP.

Discussions