INTI-CMNB / KiBot

KiCad automation utility
GNU Affero General Public License v3.0
573 stars 68 forks source link

[HOW] Generate complex panel preview (with pcbdraw raise Huge input lookup error) #369

Closed palandri closed 1 year ago

palandri commented 1 year ago

What do you want to achieve? I was trying to render with pcbdraw a panel generated by panelize, and depending on the size/complexity of the panel, raised the following error: ERROR:PcbDraw error: internal error: Huge input lookup, line 397862, column 23 (<string>, line 397862) (kibot - out_pcbdraw.py:498)

I don't know if this is just my inability, or is a bug. I can generate the preview of the panel with a grid of 6x6, but not more than that. Also, even with a 6x6 grid, pcbdraw takes a lot of time (around 10 minutes).

Do you have some PCB/Schematic to use as example? In here there is the single pcb file, and panel generated.

Do you have some configuration file (.kibot.yaml) that you are using? Relevant yaml section

  - name: panel
    comment: Generate panel for fabrication
    dir: JLCPCB-Panel
    type: panelize
    options:
      # create_preview: true # disabled so I could generate the panel
      configs:
        - cuts:
            # type: vcuts
            type: mousebites
            drill: 0.5mm
            spacing: 1mm
            offset: 0.2mm
            prolong: 0.5mm
        - layout:
            rows: 10
            cols: 9
            space: 2mm
            vbackbone: 4mm
            vbonecut: true
            vboneskip: 1
            hboneskip: 1
        - tabs:
            type: fixed
            width: 3mm
            vcount: 0
            hcount: 2
        - post:
            millradius: 1mm
        - framing:
            type: frame
            width: 5mm
            space: 3mm
            cuts: both
            fillet: 1mm
            mintotalheight: 300mm
            mintotalwidth: 200mm
        - copperfill:
            type: hatched
            clearance: 2mm
            spacing: 0.5mm
            width: 0.5mm
        - tooling:
            type: 4hole
            hoffset: 2.5mm
            voffset: 2.5mm
            size: 1.5mm
        - fiducials:
            type: 4fid
            hoffset: 2.5mm
            voffset: 2.5mm
            coppersize: 2mm
            opening: 1mm
        - text:
            type: simple
            text: '{boardTitle}({boardRevision}), {date}'
            anchor: mt
            voffset: 2.5mm
            hjustify: center
            vjustify: center

Environment (please complete the following information): Where are you running KiBot:

Additional context Add any other context about your setup/project.

set-soft commented 1 year ago

Hi @palandri !

I'm not the pcbdraw author, but contributed various patches. When looking at the code you see it wasn't optimized for speed, but for maintainability. It does the same heavy tasks over and over, discarding what was generated in the previous passes.

For small PCBs is fast, but it becomes really slow when the complexity grows. I recommend you using the render_3d output. I tried the following config:

kibot:
  version: 1

outputs:
  - name: "base"
    type: render_3d
    run_by_default: false
    options:
      width: 1000
      height: 1500
      transparent_background: true
      auto_crop: true
      zoom: 4
      # The following needs the schematic
      # show_components: none

  - name: "top"
    type: render_3d
    extends: "base"

  - name: "bottom"
    type: render_3d
    extends: "top"
    options:
      view: "bottom"

In around 6 minutes I got:

sd_stick-panel-3D_top

And

sd_stick-panel-3D_bottom

BTW: On my system PcbDraw failed after 40 minutes. The error seems to be from Python itself.

palandri commented 1 year ago

Thank you for your reply, @set-soft!

I'll integrate your suggestion in our CI, thanks for your support and amazing software!

set-soft commented 6 months ago

Hi @palandri !

I revisited this issue, I was able to plot your 10x9 panel using KiBot 1.6.5. It was sloooowwww (14 minutes), but it worked.

I then optimized some stuff on PcbDraw and reduced the time to 2.5 minutes (only 1m 48" for the plot), here is a PNG generated from the SVG (the SVG is a 25 MB file):

pp

So now PcbDraw output is much faster and reliable. Note that the problem here is triggered by the panelization. The slow process in PcbDraw is extracting the PCB contour, much more complex in a panel than in any kind of PCB.

palandri commented 6 months ago

Hey @set-soft.

Wow, amazing work! Plot being slow is not a problem, at least for us, because it is only generated as part of the documentation process, which is triggered only in major releases.

I was not able to test it already, but looking at the image you posted, looks like there is some tabs which is incorrect, highlighted below.

image

I don't know if it is a configuration problem, or something changed in software, but it does not matter. I'm just pointing it because I noticed it.

Again, amazing work.

set-soft commented 6 months ago

Hi @palandri !

This might be related to some of the parameters. The difference is in KiKit, PcbDraw won't "move" the contour, which looks valid. Here is the same artifact in a 2x2 panel:

image

Here is the same reducing the millradius to 0.9 mm:

image

palandri commented 6 months ago

Yeah, I agree with you. No problems, just wanted to point it to you.