14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

KiCADの製造データをGitHub Actionsに生成させてみた

Posted at

やりたかったこと

  • KiCAD(電子回路設計ソフト)のデータをGitHubでいい感じに管理したい。
  • 設計データをpushしたらガーバーデータ(基板製造業者に発注するデータ)を自動で生成してほしい。
  • 回路図とかのドキュメントのpdfも生成してほしい。
  • 生成したデータはでWebからzipでダウンロードできるようにしたい。

つくったもの

試しにpublicなリポジトリにつくってみた。

こんなことができます。

tagをつけてpushすると自動でリリースしてくれる。リリースには生成データが添付される。
image.png

リリースしなくてもpushするたびに Artifacts にデータが生成される。
image.png

プルリクで回路のエラーチェックが走る。
image.png

やりかた

GitHub Actions の kicad-exportsを使うと簡単にできてしまいました。
https://github.com/marketplace/actions/kicad-exports

やることはリポジトリ内にyamlファイルを数個配置するだけです。

手順

以下の手順でつくった完成品がこちらです。
https://github.com/YamadaKyohei/kicad-actions-sample

1. KiCADのデータ(.shc, .kicad_pcb)が配置されたGitHubリポジトリをつくる。

2. GitHub Actions 設定用のyamlファイルを配置する。

.github/workflowsの中にActionsの挙動を定義します。
pushしたとき用の動作を .github/workflows/main.ymlに以下のように記述しました。

name: KiCad-exports

on:
  push:
    paths:
    - '**.sch'
    - '**.kicad_pcb'
  pull_request:
    paths:
      - '**.sch'
      - '**.kicad_pcb'

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: nerdyscout/kicad-exports@v2.1
      with:
      # Required - kibot config file
        config: ./config/docs.kibot.yaml
      # optional - prefix to output defined in config
        dir: docs
      # optional - schematic file
        schema: '*.sch'
      # optional - PCB design file
        board: '*.kicad_pcb'
    - uses: nerdyscout/kicad-exports@v2.1
      with:
      # Required - kibot config file
        config: ./config/fabrications.kibot.yaml
      # optional - prefix to output defined in config
        dir: gerber
      # optional - schematic file
        schema: '*.sch'
      # optional - PCB design file
        board: '*.kicad_pcb'
    - name: upload results
      uses: actions/upload-artifact@v2
      with:
        name: docs
        path: |
          docs/docs
          !docs/docs/*.ogv
    - name: upload results
      uses: actions/upload-artifact@v2
      with:
        name: gerber
        path: gerber/gerber

また、tagをつけてpushされたとき自動でリリースする動作は .github/workflows/release.ymlに以下のように記述しました。スクリーンキャプチャの.ogvファイルなども一緒に生成されてしまうので、zip化の際に除外しています。

name: KiCad-exports-release

on:
  push:
    tags:
      - 'v*'

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: nerdyscout/kicad-exports@v2.1
      with:
      # Required - kibot config file
        config: ./config/docs.kibot.yaml
      # optional - prefix to output defined in config
        dir: docs
      # optional - schematic file
        schema: '*.sch'
      # optional - PCB design file
        board: '*.kicad_pcb'
    - uses: nerdyscout/kicad-exports@v2.1
      with:
      # Required - kibot config file
        config: ./config/fabrications.kibot.yaml
      # optional - prefix to output defined in config
        dir: gerber
      # optional - schematic file
        schema: '*.sch'
      # optional - PCB design file
        board: '*.kicad_pcb'
       
    - name: Create release
      id: create_release
      uses: actions/create-release@v1.0.0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: Release ${{ github.ref }}
        draft: false
        prerelease: false
    - name: docs zip output
      run: |
        cd ./docs/docs
        zip ../../docs * -x *.ogv
    - name: Upload Release Docs
      id: upload-release-docs
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: docs.zip
        asset_name: docs.zip
        asset_content_type: application/zip
    - name: docs zip output
      run: |
        cd ./gerber/gerber
        zip ../../gerber *.*
    - name: Upload Release Gerbers
      id: upload-release-gerber
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: gerber.zip
        asset_name: gerber.zip
        asset_content_type: application/zip

3. kicad-exports 設定用のyamlファイルを配置する。

回路図と配線図のpdfはconfig/docs.kibot.yamlに生成に関する設定を記述しました。

kibot:
  version: 1

preflight:
  run_erc: true
  run_drc: true
  check_zone_fills: true
  ignore_unconnected: false

outputs:
  - name: 'print schema'
    comment: "Print schematic (PDF)"
    type: pdf_sch_print
    dir: docs
    options:
      output: '%p-Schematic_%r.%x'

  - name: 'print board'
    comment: "Print board (PDF)"
    type: pdf_pcb_print
    dir: docs
    options:
      output: '%p-Board_%r.%x'
    layers:
      - 'all'

ガーバーデータの生成は、config/fabrications.kibot.yamlに次のように設定しました。もうちょっと設定を詰めれば、Fusion PCBとかにそのままアップロードできるzipが作れると思います。

kibot:
  version: 1

preflight:
  run_erc: true
  update_xml: true
  run_drc: true
  check_zone_fills: true
  ignore_unconnected: false

outputs:
  - name: 'interactive_bom'
    comment: "Interactive Bill of Materials (HTML)"
    type: ibom
    dir: BoM
    options:
      blacklist: 'DNF*'
      name_format: '%f_%r_iBoM'

  - name: 'bom_csv'
    comment: "Bill of Materials in CSV format"
    type: kibom
    dir: BoM
    options:
      format: CSV  # HTML or CSV

  - name: 'gerbers'
    comment: "Gerbers for the board house"
    type: gerber
    dir: gerber
    options:
      # generic layer options
      exclude_edge_layer: true
      exclude_pads_from_silkscreen: true
      use_aux_axis_as_origin: false
      plot_sheet_reference: false
      plot_footprint_refs: true
      plot_footprint_values: true
      force_plot_invisible_refs_vals: false
      tent_vias: false

      # gerber options
      line_width: 0.1
      subtract_mask_from_silk: false
      use_protel_extensions: true
      gerber_precision: 4.6
      create_gerber_job_file: false
      use_gerber_x2_attributes: false
      use_gerber_net_attributes: false

    # for 2-layer pcb
    layers:
      - layer: F.Cu
        suffix: F_Cu
      - layer: B.Cu
        suffix: B_Cu
      - layer: F.Paste
        suffix: F_Paste
      - layer: B.Paste
        suffix: B_Paste
      - layer: F.SilkS
        suffix: F_SilkS
      - layer: B.SilkS
        suffix: B_SilkS
      - layer: F.Mask
        suffix: F_Mask
      - layer: B.Mask
        suffix: B_Mask
      - layer: Edge.Cuts
        suffix: Edge_Cuts

  - name: "Excellon drills"
    comment: "Excellon drill files"
    type: "excellon"
    dir: "gerber"
    options:
      use_aux_axis_as_origin: true
      metric_units: true
      pth_and_npth_single_file: false
      minimal_header: true
      mirror_y_axis: false

以上4つのyamlファイルを設置すると、以後GitHub Actionsが欲しいデータをつくってくれます。

感想

  • GitHub Actionsが無料枠でけっこう遊べてしまってびっくり。
  • ハードウェアを自動デプロイしてるような感じがして楽しい。
  • 「回路図ください」「ガーバーください」とSlackで催促しあう文化から、これで卒業したい。
  • ReleaseからドキュメントがダウンロードできるっていうUIは、回路設計者以外のプロジェクトメンバーにも使いやすそう。
  • stepデータ(3Dの機械図面)も生成できるらしいので試したい。
14
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?