diff --git a/cad/eagle/SmTIAS_LEDs.brd b/cad/eagle/SmTIAS_LEDs.brd new file mode 100644 index 0000000..75d10cf --- /dev/null +++ b/cad/eagle/SmTIAS_LEDs.brd @@ -0,0 +1,649 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +MountingHole + + +Mounting Hole 3.2mm, no annular, M3, ISO7380 +>NAME +>VALUE +>FOOTPRINT + + +>NAME + + + + + +Connector_Generic + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + +Device + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<b>Fusion Electronics Design Rules</b> +<p> +Die Standard-Design-Rules sind so gewählt, dass sie für +die meisten Anwendungen passen. Sollte ihre Platine +besondere Anforderungen haben, treffen Sie die erforderlichen +Einstellungen hier und speichern die Design Rules unter +einem neuen Namen ab. +<b>Fusion Electronics Design Rules</b> +<p> +The default Design Rules have been set to cover +a wide range of applications. Your particular design +may have different requirements, so please make the +necessary adjustments and save your customized +design rules under a new name. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cad/eagle/SmTIAS_LEDs.sch b/cad/eagle/SmTIAS_LEDs.sch new file mode 100644 index 0000000..53cace9 --- /dev/null +++ b/cad/eagle/SmTIAS_LEDs.sch @@ -0,0 +1,706 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SmTIAS_LEDs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cad/eagle/SmTIASv4_LED_bottom_v2.brd b/cad/eagle/SmTIASv4_LED_bottom_v2.brd new file mode 100644 index 0000000..dd38439 --- /dev/null +++ b/cad/eagle/SmTIASv4_LED_bottom_v2.brd @@ -0,0 +1,517 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +MountingHole + + +Mounting Hole 3.2mm, no annular, M3, ISO7380 +>NAME +>VALUE +>FOOTPRINT + + +>NAME + + + + + +Connector_Generic + + +Wire solder pads for one cable (GND / +12V), 2.0 x 3.0 mm, 1.5 mm gap + + + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + +Device + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<b>Fusion Electronics Design Rules</b> +<p> +Die Standard-Design-Rules sind so gewählt, dass sie für +die meisten Anwendungen passen. Sollte ihre Platine +besondere Anforderungen haben, treffen Sie die erforderlichen +Einstellungen hier und speichern die Design Rules unter +einem neuen Namen ab. +<b>Fusion Electronics Design Rules</b> +<p> +The default Design Rules have been set to cover +a wide range of applications. Your particular design +may have different requirements, so please make the +necessary adjustments and save your customized +design rules under a new name. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cad/eagle/SmTIASv4_LED_bottom_v2.sch b/cad/eagle/SmTIASv4_LED_bottom_v2.sch new file mode 100644 index 0000000..31bc2eb --- /dev/null +++ b/cad/eagle/SmTIASv4_LED_bottom_v2.sch @@ -0,0 +1,490 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Wire solder pads for one cable (GND / +12V), 2.0 x 3.0 mm, 1.5 mm gap + + + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SmTIAS_LEDs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cad/eagle/SmTIASv4_LED_side_v2.brd b/cad/eagle/SmTIASv4_LED_side_v2.brd new file mode 100644 index 0000000..86acfe0 --- /dev/null +++ b/cad/eagle/SmTIASv4_LED_side_v2.brd @@ -0,0 +1,513 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +MountingHole + + +Mounting Hole 3.2mm, no annular, M3, ISO7380 +>NAME +>VALUE +>FOOTPRINT + + +>NAME + + + + + +Connector_Generic + + +Wire solder pads for one cable (GND / +12V), 2.0 x 3.0 mm, 1.5 mm gap + + + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + +Device + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<b>Fusion Electronics Design Rules</b> +<p> +Die Standard-Design-Rules sind so gewählt, dass sie für +die meisten Anwendungen passen. Sollte ihre Platine +besondere Anforderungen haben, treffen Sie die erforderlichen +Einstellungen hier und speichern die Design Rules unter +einem neuen Namen ab. +<b>Fusion Electronics Design Rules</b> +<p> +The default Design Rules have been set to cover +a wide range of applications. Your particular design +may have different requirements, so please make the +necessary adjustments and save your customized +design rules under a new name. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cad/eagle/SmTIASv4_LED_side_v2.sch b/cad/eagle/SmTIASv4_LED_side_v2.sch new file mode 100644 index 0000000..a0947ba --- /dev/null +++ b/cad/eagle/SmTIASv4_LED_side_v2.sch @@ -0,0 +1,466 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Wire solder pads for one cable (GND / +12V), 2.0 x 3.0 mm, 1.5 mm gap + + + + +SMD Solder Jumper, 1x1.5mm Pads, 0.3mm gap, open +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SOD-123 +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION +>SIM.DEVICE +>SIM.PINS + + + + + + + + + + + + + + + + + + +>NAME + + + + +https://www.luckylight.cn/media/component/data-sheet/R2835BC-B2M-M10.pdf +>NAME +>VALUE +>FOOTPRINT +>DESCRIPTION + + + + + + + + + + + + +>NAME + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>NAME +>VALUE + + + + + + + + +>NAME +>VALUE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SmTIAS_LEDs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/fusion/build_smtias_v4_led_modules.py b/scripts/fusion/build_smtias_v4_led_modules.py new file mode 100644 index 0000000..f87eb31 --- /dev/null +++ b/scripts/fusion/build_smtias_v4_led_modules.py @@ -0,0 +1,262 @@ +"""SmTIASv4 の LED モジュール(基板・カバー・台座・ねじ)を Fusion に作り直す. + +Fusion の中で実行するスクリプト(MCP の fusion_mcp_execute で,このファイルを `exec` で読み込んで +`run` を呼ぶ.日本語の名前を化けさせないため中身を貼らずにファイルから読む.TECH_12). + +基板は `scripts/generate_led_module_boards.py`(Fusion Electronics の SmTIASv4_LED_side_v2 / +SmTIASv4_LED_bottom_v2)と同じ外形・部品の位置にする.LED は全部同じ高さ(Z −38.シミュの箱 +では Z −35.TEST_21 結果 12)にそろえる.基板の座標 u(長さ方向)・v(幅方向. +KiCad の Y − 55.+12V の線が v < 0,GND の線が v > 0)を装置の座標へ写す: + +- 左右用(LED 6 個): y = u,右は x = 74 + v,左は x = −74 + v(左は右を平行移動したもの.同じ基板) +- 下用(LED 6 個.1 枚): x = u・y = −84 − v(LED は下の壁から 6 mm.左右用と同じ) + +カバーは SmTIASv3 の「LED 基板カバー」と同じ作り: 基板の部品の面(下)に重ねる厚さ 1 mm の白い板 +(LED・定電流 IC・電源パッドの窓と M3 の穴)と,基板の内側の長い縁を隠す縁.カバーは 3D プリント +なので左右で鏡像にしてよい.ねじ(M3×8)はカバーの下から基板を通し,前側の台座の下穴に締める.台座は基板の上(顔の側)に +あり,横の壁・下の壁から張り出す棚にする. + +実行すると次を作り直す(同じ名前のものは消してから作る): +- コンポーネント「LEDモジュール」(基板・LED・定電流 IC・カバー) +- 筐体の前側の LED 台座(最後の 3 フィーチャ「基準フィーチャ*」「結合*」「結合*」を消してから足す) +- ねじ類の「M3x8 なべ小ねじ」の配置 +""" + +import adsk.core +import adsk.fusion + +# 電源パッドはケーブル 1 本分(+12V と GND を幅の向きに並べた 2.0 × 3.0 mm)が長さの向きに 2 列 +SIDE = { + "u": (-18.3, 44.0), "chamfer": (38.0, 3.5), "holes": (-8.0, 40.0), + "leds": (6.0, 10.0, 14.0, 26.0, 30.0, 34.0), "ccrs": (-2.0, 2.0, 18.0, 22.0), + "pad_u": (-16.1, -12.6), "z_led": -38.0, +} +BOTTOM = { + "u": (-41.3, 41.3), "chamfer": None, "holes": (-31.0, 31.0), + "leds": (-25.0, -21.0, -17.0, 17.0, 21.0, 25.0), "ccrs": (-13.0, -9.0, 9.0, 13.0), + "pad_u": (-39.1, -35.6, 35.6, 39.1), "z_led": -38.0, +} +BOTTOM_LED_Y = -84.0 # 下の LED 列の Y(下の壁の内面 −90 から 6 mm) +HALF_W = 5.0 # 基板の幅の半分(v = −5〜+5) +BOARD_T = 1.6 +LED_H = 0.7 # LED の高さ(発光面 z_led から基板の下面まで) +COVER_T = 1.0 # カバーの板の厚さ(LED の発光面より 0.3 mm 下まで) +LIP_T = 1.0 # カバーの縁の厚さ +HOLE_D = 3.4 # カバー・基板のねじの通し穴 +PILOT_D = 2.6 # 台座の下穴(M3 のタッピング) +PILOT_DEPTH = 6.0 # 下穴の深さ(M3×8 がカバーと基板の 2.6 mm を抜けて 5.4 mm かかる) +BOSS = 7.0 # 台座の一辺 +tbm = adsk.fusion.TemporaryBRepManager.get() + + +def _box(lo, hi): + c = adsk.core.Point3D.create(*((a + b) / 20 for a, b in zip(lo, hi, strict=True))) + ob = adsk.core.OrientedBoundingBox3D.create( + c, adsk.core.Vector3D.create(1, 0, 0), adsk.core.Vector3D.create(0, 1, 0), + *((b - a) / 10 for a, b in zip(lo, hi, strict=True))) + return tbm.createBox(ob) + + +def _cyl(x, y, z0, z1, d): + return tbm.createCylinderOrCone(adsk.core.Point3D.create(x / 10, y / 10, z0 / 10), d / 20, + adsk.core.Point3D.create(x / 10, y / 10, z1 / 10), d / 20) + + +def _sub(body, tool): + tbm.booleanOperation(body, tool, adsk.fusion.BooleanTypes.DifferenceBooleanType) + + +def _union(body, tool): + tbm.booleanOperation(body, tool, adsk.fusion.BooleanTypes.UnionBooleanType) + + +def _layouts(): + """(名前, 基板の定義, (u, v) → (x, y) の写し方, 内側の縁の v の向き) を返す.""" + return [ + ("右", SIDE, lambda u, v: (74.0 + v, u), -1), + ("左", SIDE, lambda u, v: (-74.0 + v, u), +1), + ("下", BOTTOM, lambda u, v: (u, BOTTOM_LED_Y - v), -1), + ] + + +def _rect_uv(f, u0, u1, v0, v1): + xs, ys = zip(*(f(u, v) for u in (u0, u1) for v in (v0, v1)), strict=True) + return (min(xs), min(ys)), (max(xs), max(ys)) + + +def _plate(spec, f, z0, z1): + """基板の外形(左右用は上の端の両角を斜めに落とす)の板を z0〜z1 に作る.""" + u0, u1 = spec["u"] + lo, hi = _rect_uv(f, u0, u1, -HALF_W, HALF_W) + plate = _box((lo[0], lo[1], z0), (hi[0], hi[1], z1)) + if spec["chamfer"] is None: + return plate + uc, vc = spec["chamfer"] + ox, oy = f(0.0, 0.0) + + def vec(du, dv): + x, y = f(du, dv) + return x - ox, y - oy + + for s in (1.0, -1.0): + # 角を落とす線 (uc, s·5) → (u1, s·(5 − vc)) の外側を大きな箱で引く + du, dv = u1 - uc, -s * vc + n = (du * du + dv * dv) ** 0.5 + du, dv = du / n, dv / n + nu, nv = vc / n * 1.0, s * (u1 - uc) / n # 外向きの法線(長さ 1) + mu, mv = (uc + u1) / 2 + nu * 10.0, s * (HALF_W + HALF_W - vc) / 2 + nv * 10.0 + cx, cy = f(mu, mv) + lx, ly = vec(du, dv) + wx, wy = vec(nu, nv) + ob = adsk.core.OrientedBoundingBox3D.create( + adsk.core.Point3D.create(cx / 10, cy / 10, (z0 + z1) / 20), + adsk.core.Vector3D.create(lx, ly, 0), adsk.core.Vector3D.create(wx, wy, 0), + 4.0, 2.0, (z1 - z0 + 2.0) / 10) + _sub(plate, tbm.createBox(ob)) + return plate + + +def _module(comp, base, name, spec, f, inward): + z = spec["z_led"] + zb0, zb1 = z + LED_H, z + LED_H + BOARD_T # 基板の下面・上面 + zc0 = z - (COVER_T - LED_H) # カバーの下面 + board = _plate(spec, f, zb0, zb1) + cover = _plate(spec, f, zc0, zb0) + holes = [] + for hu in spec["holes"]: + x, y = f(hu, 0.0) + _sub(board, _cyl(x, y, zb0 - 1, zb1 + 1, 3.2)) + _sub(cover, _cyl(x, y, zc0 - 1, zb0 + 1, HOLE_D)) + holes.append((x, y)) + parts = [] + for lu in spec["leds"]: + lo, hi = _rect_uv(f, lu - 1.4, lu + 1.4, -1.75, 1.75) + parts.append(("LED", _box((lo[0], lo[1], z), (hi[0], hi[1], zb0)))) + lo, hi = _rect_uv(f, lu - 1.7, lu + 1.7, -2.05, 2.05) + _sub(cover, _box((lo[0], lo[1], zc0 - 1), (hi[0], hi[1], zb0 + 0.1))) + for cu in spec["ccrs"]: + lo, hi = _rect_uv(f, cu - 0.8, cu + 0.8, -1.35, 1.35) + parts.append(("定電流IC", _box((lo[0], lo[1], zb0 - 1.1), (hi[0], hi[1], zb0)))) + lo, hi = _rect_uv(f, cu - 1.1, cu + 1.1, -2.4, 2.4) + _sub(cover, _box((lo[0], lo[1], zc0 - 1), (hi[0], hi[1], zb0 + 0.1))) + for pu in spec["pad_u"]: + lo, hi = _rect_uv(f, pu - 1.3, pu + 1.3, -4.0, 4.0) + _sub(cover, _box((lo[0], lo[1], zc0 - 1), (hi[0], hi[1], zb0 + 0.1))) + # 内側の長い縁を隠す縁(面取りの手前まで) + u0, u1 = spec["u"] + u_end = spec["chamfer"][0] if spec["chamfer"] else u1 + v_edge = inward * HALF_W + lo, hi = _rect_uv(f, u0, u_end, v_edge, v_edge + inward * LIP_T) + _union(cover, _box((lo[0], lo[1], zc0), (hi[0], hi[1], zb1 + 0.4))) + comp.bRepBodies.add(board, base).name = f"基板_{name}" + comp.bRepBodies.add(cover, base).name = f"カバー_{name}" + for k, (kind, body) in enumerate(parts): + comp.bRepBodies.add(body, base).name = f"{kind}_{name}_{k + 1}" + return [(x, y, zc0, zb1) for x, y in holes] + + +def _delete_old_bosses(des, hcomp): + tl = des.timeline + items = [] + for i in range(tl.count): + it = tl.item(i) + try: + pc = it.entity.parentComponent + except Exception: # タイムラインの一部の項目は親を持たない + pc = None + if pc == hcomp: + items.append(it) + last = items[-3:] + names = [it.name for it in last] + if not (names[0].startswith("基準フィーチャ") and all(n.startswith("結合") for n in names[1:])): + raise RuntimeError(f"消そうとした筐体のフィーチャが LED 台座ではない: {names}") + for it in reversed(last): + it.entity.deleteMe() + + +def _bosses(hcomp, front, holes): + hb = hcomp.features.baseFeatures.add() + hb.startEdit() + for i, (x, y, _zc0, zb1, kind) in enumerate(holes): + if kind == "side": + wall = (81.0 if y < 20 else 79.0) * (1 if x > 0 else -1) + x0, x1 = sorted([x - BOSS / 2 * (1 if x > 0 else -1), wall]) + box = _box((x0, y - BOSS / 2, zb1), (x1, y + BOSS / 2, zb1 + 6.0)) + else: # 下の壁(内面 Y −90)から張り出す棚 + box = _box((x - BOSS / 2, -91.0, zb1), (x + BOSS / 2, y + BOSS / 2, zb1 + 6.0)) + hcomp.bRepBodies.add(box, hb).name = f"LED台座_{i}" + pilot = _cyl(x, y, zb1 - 0.1, zb1 + PILOT_DEPTH, PILOT_D) + hcomp.bRepBodies.add(pilot, hb).name = f"LED下穴_{i}" + hb.finishEdit() + join = adsk.core.ObjectCollection.create() + cut = adsk.core.ObjectCollection.create() + for b in hcomp.bRepBodies: + if b.name.startswith("LED台座"): + join.add(b) + if b.name.startswith("LED下穴"): + cut.add(b) + for tools, op in ((join, adsk.fusion.FeatureOperations.JoinFeatureOperation), + (cut, adsk.fusion.FeatureOperations.CutFeatureOperation)): + ci = hcomp.features.combineFeatures.createInput(front, tools) + ci.operation = op + hcomp.features.combineFeatures.add(ci) + + +def _screws(root, holes): + grp = [o.component for o in root.occurrences if o.component.name == "ねじ類"][0] + for o in [o for o in grp.occurrences if o.component.name.startswith("M3x8")]: + o.deleteMe() + + def mat(x, y, z): + m = adsk.core.Matrix3D.create() + m.translation = adsk.core.Vector3D.create(x / 10, y / 10, z / 10) + return m + + x, y, zc0, _zb1, _k = holes[0] + first = grp.occurrences.addNewComponent(mat(x, y, zc0)) + comp = first.component + comp.name = "M3x8 なべ小ねじ" + base = comp.features.baseFeatures.add() + base.startEdit() + head = _cyl(0, 0, -2.0, 0, 5.5) + _union(head, _cyl(0, 0, 0, 8.0, 3.0)) + comp.bRepBodies.add(head, base).name = "M3x8" + base.finishEdit() + for x, y, zc0, _zb1, _k in holes[1:]: + grp.occurrences.addExistingComponent(comp, mat(x, y, zc0)) + + +def run(_context: str): + app = adsk.core.Application.get() + des = adsk.fusion.Design.cast(app.activeProduct) + if app.activeDocument.name != "SmTIASv4": + raise RuntimeError("SmTIASv4 をアクティブにしてから実行する") + root = des.rootComponent + hcomp = [o.component for o in root.occurrences if o.component.name == "筐体"][0] + front = [b for b in hcomp.bRepBodies if b.name == "前側"][0] + for o in list(root.occurrences): + if o.component.name == "LEDモジュール": + o.deleteMe() + _delete_old_bosses(des, hcomp) + occ = root.occurrences.addNewComponent(adsk.core.Matrix3D.create()) + comp = occ.component + comp.name = "LEDモジュール" + base = comp.features.baseFeatures.add() + base.startEdit() + holes = [] + for name, spec, f, inward in _layouts(): + kind = "side" if spec is SIDE else "bottom" + holes += [(*h, kind) for h in _module(comp, base, name, spec, f, inward)] + base.finishEdit() + _bosses(hcomp, front, holes) + _screws(root, holes) + des.computeAll() + bad = [b.name for b in comp.bRepBodies + if any(front.pointContainment(v.geometry) == 0 for v in b.vertices)] + tl = des.timeline + unhealthy = [tl.item(i).name for i in range(tl.count) + if tl.item(i).healthState + != adsk.fusion.FeatureHealthStates.HealthyFeatureHealthState] + print("bodies", comp.bRepBodies.count, "holes", len(holes)) + print("module parts inside front wall:", bad) + print("unhealthy timeline items:", unhealthy) diff --git a/scripts/fusion/build_smtias_v4_wiring.py b/scripts/fusion/build_smtias_v4_wiring.py new file mode 100644 index 0000000..b2206a6 --- /dev/null +++ b/scripts/fusion/build_smtias_v4_wiring.py @@ -0,0 +1,176 @@ +"""SmTIASv4 の LED 基板の配線の通り道(線)とケーブルを通す切れ込みを Fusion に作る. + +Fusion の中で実行するスクリプト(MCP の fusion_mcp_execute で,このファイルを `exec` で読み込んで +`run` を呼ぶ.TECH_12).`build_smtias_v4_led_modules.py` のあとに実行する. + +線の通し方は SmTIASv3 と同じ: スマホホルダの中の電源スイッチから,ホルダの後ろの板の細い穴 +(X ≈ +26.9〜+29.4・Z −170.8〜−166.2.約 2.5 × 4.6 mm)を通って箱の外に出し,後ろの面と下の面の外を +通って,前側と後側のつなぎ目の切れ込みから箱の中に入れる. +箱の後ろの面(評価板の正面)には線を通さない.切れ込みは SPEC_05 の改良点どおり今より右 +(X = +28.2.ホルダの細い穴と同じ X).箱の中も SmTIASv3 と同じく線の途中で分けない: +ケーブルは下の基板の右の端の電源パッドにつなぎ,下の基板の両端の電源パッドから左右の基板へ +1 本ずつ線を出す(数珠つなぎ.分岐は基板の +12V と GND の線がする). + +- 線: +12V と GND の 2 本を 1 本の管(直径 3 mm)で表す.どの線も基板(LED の面 Z −38)より奥の + Z = −42 を通る(下の基板の台座・カバーに当てないため) + - ケーブル: 切れ込み → 下の壁を Z −42 まで手前へ → 下の基板の右の端 + (電源パッドの内側の列 X = +35.6) + - 下の基板 → 左右の基板: 下の基板の端(電源パッドの外側の列 X = ±39.1)→ 下の壁 → 角の丸みの弦 + → 横の壁を上がって左右の基板(電源パッドの外側の列 Y = −16.1) +- 切れ込み: SmTIASv3(前側の端に幅 3.5 mm・深さ約 3.5 mm の切れ込み.後側の端との間に線を挟む)と + 同じ考え方で,どちらの部品も端から切り込むだけにする(穴をあけない).v4 は相欠きなので, + 前側のすそ(外側.Z −80〜−70)の端から 4 mm と,後側のつば(内側)を先の Z −70 から根元の Z −80 + まで,下の面の X = +26.2〜+30.2(幅 4 mm)で切る.組み立てると Z −80〜−76 の 4 × 4 mm の穴になる +- 線を押さえる留め具は付けない(LED の高さがそろって線が壁に沿う短い道だけになったので要らない. + 2026-11-05 ユーザー判断) +- 線は角の丸み(R20・外側 R23)の中を弦で近似している(実物では線が丸みに沿って曲がる) + +実行すると「配線」コンポーネントと,前側・後側の切れ込みを作り直す(前回の分は消す). +""" + +import math + +import adsk.core +import adsk.fusion + +WIRE_D = 3.0 +ENTRY_D = 2.2 # ホルダの細い穴(幅 2.5 mm)を抜ける所の線の太さ(2 芯の細い線) +OFF = 1.6 # 線の中心と壁の距離 +SLOT_X = (26.15, 30.15) # 切れ込みの X.中心 X = 28.15 はホルダの細い穴に合わせる +NOTCH_FRONT_Z = (-80.5, -76.0) # 前側のすその端(Z −80)から 4 mm +NOTCH_BACK_Z = (-80.0, -69.5) # 後側のつばの先(Z −70)から根元(Z −80)まで +Z_WIRE = -42.0 # 箱の中の線の Z(LED の面 Z −38 より奥) +Z_PAD = -39.0 # 電源パッドにつなぐ所(基板のカバーの下 Z −38.3 のすぐ下) +PAD_BOTTOM = (39.1, -84.0) # 下の基板の端の電源パッドの外側の列(左右の基板への線.左は X を反転) +PAD_CABLE = (35.6, -84.0) # 下の基板の右の端の電源パッドの内側の列(ケーブル) +PAD_SIDE = (74.0, -16.1) # 右の基板の電源パッドの外側の列(左は X を反転) +tbm = adsk.fusion.TemporaryBRepManager.get() + + +def _p(x, y, z): + return adsk.core.Point3D.create(x / 10, y / 10, z / 10) + + +def _routes(): + """線の通り道((点の並び.mm, 線の太さ mm) の並び).""" + yb = -90.0 + OFF # 下の壁の内側 + xw = 80.0 - OFF # 横の壁の内側 + out_off = 2.2 # 箱の外の線と面の距離(丸みの弦が面に入らないよう少し離す) + yo = -93.0 - out_off # 下の面の外側 + zo = -163.0 - out_off # 後ろの面の外側 + xs = sum(SLOT_X) / 2 + zs = (NOTCH_FRONT_Z[0] + NOTCH_FRONT_Z[1]) / 2 + 0.25 # 切れ込みの穴(Z −80〜−76)の中 + routes = [] + bx, by = PAD_BOTTOM + sx, sy = PAD_SIDE + for s in (1.0, -1.0): + # 下の基板の端(電源パッド)→ 下の壁 → 角の丸みの弦 → 横の壁を上がって左右の基板へ + routes.append(([(s * bx, by, Z_PAD), (s * bx, yb, Z_WIRE), (s * 60.0, yb, Z_WIRE), + (s * 73.0, -83.0, Z_WIRE), (s * xw, -70.0, Z_WIRE), + (s * xw, sy, Z_WIRE), (s * sx, sy, Z_PAD)], WIRE_D)) + # ケーブル: 下の基板の右の端(電源パッドの内側の列)→ 下の壁 → 切れ込みの前を奥へ + # → 切れ込みを抜けて箱の外 → 下の面の外を奥へ → 後ろの面との丸みの弦 + # → 後ろの面の外を上へ → ホルダの下の枠の切り欠きからホルダの中(電源スイッチ)へ + # 後ろの面と下の面の間の外側の丸み(中心 Y −70・Z −140・半径 23)を 15° ごとの点で回る + r = 23.0 + out_off + arc = [(xs, -70.0 - r * math.cos(math.radians(t)), -140.0 - r * math.sin(math.radians(t))) + for t in range(0, 91, 15)] + # ホルダの後ろの板(Y −9.5〜−8)の細い穴を抜けてホルダの中へ(そこだけ細い線) + cx, cy = PAD_CABLE + routes.append(([(cx, cy, Z_PAD), (cx, yb, Z_WIRE), (xs, yb, Z_WIRE), (xs, yb, zs), + (xs, yo, zs), *arc, (xs, -12.0, zo), + (xs, -12.0, -168.5)], WIRE_D)) + routes.append(([(xs, -12.0, -168.5), (xs, -4.0, -168.5)], ENTRY_D)) + return routes + + +def _tube(points, diameter): + body = None + r = diameter / 20 # mm の直径 → cm の半径 + for a, b in zip(points, points[1:], strict=False): + seg = tbm.createCylinderOrCone(_p(*a), r, _p(*b), r) + joint = tbm.createSphere(_p(*b), r) + for piece in (seg, joint): + if body is None: + body = piece + else: + tbm.booleanOperation(body, piece, adsk.fusion.BooleanTypes.UnionBooleanType) + return body + + +def _remove_previous(des, hcomp): + root = des.rootComponent + for o in list(root.occurrences): + if o.component.name == "配線": + o.deleteMe() + tl = des.timeline + names = [] + for i in range(tl.count): + it = tl.item(i) + try: + ent = it.entity + except Exception: # タイムラインの一部の項目は実体を返さない + continue + if getattr(ent, "parentComponent", None) == hcomp and ent.name.startswith("配線"): + names.append(it) + for it in reversed(names): + it.entity.deleteMe() + + +def run(_context: str): + app = adsk.core.Application.get() + if app.activeDocument.name != "SmTIASv4": + raise RuntimeError("SmTIASv4 をアクティブにしてから実行する") + des = adsk.fusion.Design.cast(app.activeProduct) + root = des.rootComponent + hcomp = [o.component for o in root.occurrences if o.component.name == "筐体"][0] + _remove_previous(des, hcomp) + bodies = {b.name: b for b in hcomp.bRepBodies} + front, back = bodies["前側"], bodies["後側"] + + occ = root.occurrences.addNewComponent(adsk.core.Matrix3D.create()) + comp = occ.component + comp.name = "配線" + base = comp.features.baseFeatures.add() + base.startEdit() + for k, (route, diameter) in enumerate(_routes()): + comp.bRepBodies.add(_tube(route, diameter), base).name = f"線_{k + 1}" + base.finishEdit() + + hb = hcomp.features.baseFeatures.add() + hb.startEdit() + notches = (("配線の切れ込み_前", NOTCH_FRONT_Z), ("配線の切れ込み_後", NOTCH_BACK_Z)) + for name, (z0, z1) in notches: + lo, hi = (SLOT_X[0], -97.0, z0), (SLOT_X[1], -88.0, z1) + center = _p(*((a + b) / 2 for a, b in zip(lo, hi, strict=True))) + ob = adsk.core.OrientedBoundingBox3D.create( + center, adsk.core.Vector3D.create(1, 0, 0), adsk.core.Vector3D.create(0, 1, 0), + *((b - a) / 10 for a, b in zip(lo, hi, strict=True))) + hcomp.bRepBodies.add(tbm.createBox(ob), hb).name = name + hb.finishEdit() + hb.name = "配線の切れ込み" + tools = {b.name[-1]: b for b in hcomp.bRepBodies if b.name.startswith("配線の切れ込み_")} + for target, part in ((front, "前"), (back, "後")): + group = adsk.core.ObjectCollection.create() + group.add(tools[part]) + ci = hcomp.features.combineFeatures.createInput(target, group) + ci.operation = adsk.fusion.FeatureOperations.CutFeatureOperation + hcomp.features.combineFeatures.add(ci).name = f"配線の切れ込み_{part}側" + des.computeAll() + + # 確かめ: 線の軸が壁(通し穴を含む)やスマホホルダに入っていないか + holder = [b for b in root.bRepBodies if b.name == "スマホホルダ"] + clash = [] + for k, (route, _d) in enumerate(_routes()): + for a, b in zip(route, route[1:], strict=False): + for t in (0.1, 0.3, 0.5, 0.7, 0.9): + q = _p(*(a[i] + (b[i] - a[i]) * t for i in range(3))) + if any(body.pointContainment(q) == 0 for body in (front, back, *holder)): + clash.append((k + 1, [round(v, 1) for v in (q.x * 10, q.y * 10, q.z * 10)])) + tl = des.timeline + unhealthy = [tl.item(i).name for i in range(tl.count) + if tl.item(i).healthState + != adsk.fusion.FeatureHealthStates.HealthyFeatureHealthState] + print("wire axis inside walls:", clash) + print("housing bodies:", [(b.name, round(b.volume * 1000)) for b in hcomp.bRepBodies]) + print("unhealthy:", unhealthy) diff --git a/scripts/fusion/import_eagle_boards.py b/scripts/fusion/import_eagle_boards.py new file mode 100644 index 0000000..eb902c8 --- /dev/null +++ b/scripts/fusion/import_eagle_boards.py @@ -0,0 +1,78 @@ +"""EAGLE 形式の基板(cad/eagle/*.sch・*.brd)を Fusion Electronics に取り込み保存する. + +Fusion の中で実行するスクリプト(MCP の fusion_mcp_execute の script にこのファイルの中身を渡す). +`scripts/generate_led_module_boards.py` で作った基板を,人の手を通さずに Fusion の電子デザインに +する. + +- 取り込みはテキストコマンド `Electron.importSchAndBrd `.電子デザイン(EcadDesign)・ + 回路図(Schematic)・基板(Board)の 3 つの無題のドキュメントができる +- 電子デザインのドキュメントを `saveAs` で SmTIAS プロジェクトの一番上に BOARDS の名前で保存する + (回路図と基板もその中に入る).同じ名前のファイルがあるときは保存せず止める(上書きしない) +- 取り込むと基板の検査(DRC)が走るので,`adsk.electron.Board.errors` を表示し,既知の例外(はんだ + パッドの部品の中のパッドの間 0.3 mm.部品の位置に出る銅箔の間隔のエラー)以外のエラーが無いとき + だけ保存する.`Electron.run DRC` は設計ルールの画面を開いたまま止まるので使わない.MCP の + fusion_mcp_electronics_read は開いている基板のどれを読むかが定まらないので,検査結果の確認には + 使わない +- 保存しなかった取り込みのドキュメントは無題のまま残る(保存せずに閉じる操作は自動モードの + 安全確認で止められるので,人が閉じる) + +使い方: BOARDS と SAVE を書き換えて実行する.SAVE = False なら取り込むだけ(確認用). +""" + +import adsk.core +import adsk.electron + +REPO = "C:/Users/rinto/source/SmTIAS-LightSim" +BOARDS = ["SmTIASv4_LED_side_v2", "SmTIASv4_LED_bottom_v2"] +SAVE = True +PROJECT = "SmTIAS" + + +def _j(text: str) -> str: + """MCP 経由で化けて届いた日本語を戻す(正しい文字列はそのまま.TECH_12).""" + try: + return text.encode("latin-1").decode("utf-8") + except (UnicodeEncodeError, UnicodeDecodeError): + return text + + +DESCRIPTION = _j("SmTIASv4 の LED 基板(scripts/generate_led_module_boards.py で作成)") + + +def run(_context: str): + app = adsk.core.Application.get() + keep = app.activeDocument + project = [p for p in app.data.dataProjects if p.name == PROJECT][0] + existing = {f.name for f in project.rootFolder.dataFiles} + for name in BOARDS: + if SAVE and name in existing: + raise RuntimeError(f"{name} はすでに {PROJECT} にある(上書きしない)") + n_before = app.documents.count # 取り込みでできたドキュメントは後ろに足される + sch = f"{REPO}/cad/eagle/{name}.sch" + brd = f"{REPO}/cad/eagle/{name}.brd" + app.executeTextCommand(f"Electron.importSchAndBrd {sch} {brd}") + new = [app.documents.item(i) for i in range(n_before, app.documents.count)] + kinds = {d.products.item(0).objectType.split("::")[-1]: d for d in new} + if set(kinds) != {"EcadDesign", "Schematic", "Board"}: + raise RuntimeError(f"{name}: 取り込みでできたドキュメントが想定と違う: {list(kinds)}") + board = adsk.electron.Board.cast(kinds["Board"].products.item(0)) + # はんだパッドの部品(J*)の 2 つのパッドの間は 0.3 mm で,Fusion の検査が部品の位置に + # 銅箔の間隔のエラーを出す.今の基板と同じ部品の寸法で切削できているので既知の例外にする + jumpers = {(board.elements.item(i).x, board.elements.item(i).y) + for i in range(board.elements.count) + if board.elements.item(i).name.startswith("J")} + errors = [] + mm = 320000.0 # 内部単位 → mm + for i in range(board.errors.count): + e = board.errors.item(i) + known = e.code == 5 and (e.x, e.y) in jumpers + print(f" {name}: {e.description} ({e.x / mm:.2f}, {e.y / mm:.2f}) layer {e.layer}" + + (" [known: solder jumper pad gap 0.3 mm]" if known else "")) + if not known: + errors.append(e) + if SAVE and not errors: + ok = kinds["EcadDesign"].saveAs(name, project.rootFolder, DESCRIPTION, "") + print(name, "saved" if ok else "save failed") + else: + print(name, f"imported (not saved, errors {len(errors)})") + keep.activate() diff --git a/scripts/generate_led_module_boards.py b/scripts/generate_led_module_boards.py new file mode 100644 index 0000000..ef13c9d --- /dev/null +++ b/scripts/generate_led_module_boards.py @@ -0,0 +1,348 @@ +"""SmTIASv4 の LED 基板 2 種類(左右用 6 個・下用 6 個)を EAGLE 形式で作る. + +Fusion Electronics から EAGLE 形式で書き出した今の基板(cad/eagle/SmTIAS_LEDs.{sch,brd}.KiCad の +cad/kicad/SmTIAS_LEDs/ を Fusion に取り込んだもの)を手本にし,部品の形(LED 2835・定電流 IC +SOD-123・M3 の取付穴・はんだパッド)と回路図の記号はそのライブラリを使う.部品の並びと配線は +新しい基板の形に合わせて組み立てる.配線の引き方(+12V と GND の線を基板の縁に沿わせ,部品を +中心線に並べて小さく折れ曲がった線で直列につなぐ)と線の太さ 0.6 mm も今の基板と同じ. + +回路は今と同じ: +12V → 定電流 IC(NSI45030AT1G,30 mA)2 個を並列(60 mA)→ LED 3 個を直列 → GND. +列はどちらも 2 本.電源パッド(+12V / GND)は 2 組ずつ,左右用は片方の端,下用は両方の端に置く. +下用は SmTIASv3 の下の基板と同じく,外から来たケーブルを片方の端で受け,両端から左右の基板へ +1 本ずつ線を出す(線の途中で分けない.基板の +12V と GND の線が分岐の役をする). + +電源パッドはケーブルをはんだごてで付けるので,今の基板のはんだジャンパの部品(1.0 × 1.5 mm・間 +0.3 mm.削る溝の幅 0.3 mm と同じで +12V と GND がつながったまま残るおそれがある)をやめ,専用の +部品 `SMTIAS_WIRE_PAD_2X3`(ケーブル 1 本の +12V と GND を基板の幅の向きに並べた 2.0 × 3.0 mm の +パッド 2 つ・間 1.5 mm.+12V は角の丸い形で GND と見分ける)にする.+12V は基板の +12V の線の側, +GND は GND の線の側に来るので,線を交差させずにつながる.ケーブル 2 本分を長さの向きに 2 列並べる. +定電流 IC の 2 つの間は今の基板の 3 mm から 4 mm に広げる(はんだ付けしやすくする).下用は研究室の +材料 s10(75 × 100.基準ピンの間 90 mm)に縦に収まる長さにする(2026-11-05). + +できた .sch / .brd は scripts/fusion/import_eagle_boards.py(MCP の fusion_mcp_execute で実行)で +Fusion Electronics に取り込み,SmTIAS プロジェクトに保存する.以後は Fusion を正本とする +(基板の検査 DRC・切削のデータは Fusion で扱う).部品の並びは TEST_21 の L5 と SmTIASv4 の LED の +位置に合わせてある(LED は全部 Z −35.TEST_21 結果 12). + +実行方法: + uv run python scripts/generate_led_module_boards.py +""" + +from __future__ import annotations + +import re +from dataclasses import dataclass, field +from pathlib import Path +from xml.sax.saxutils import escape + +ROOT = Path(__file__).resolve().parents[1] +TEMPLATE = ROOT / "cad" / "eagle" / "SmTIAS_LEDs" # .sch / .brd +OUT = ROOT / "cad" / "eagle" +CENTER_Y = 55.0 # 基板の中心線(今の基板の KiCad 座標.Y は下向き) +RAIL_12V_Y = 51.75 +RAIL_GND_Y = 58.25 +TRACK_W = 0.6 +Y_FLIP = 208.28 # EAGLE の Y = Y_FLIP − KiCad の Y(今の基板の書き出しで確かめた値) +# 基板の検査(DRC)の決まり.研究室の MITS 製基板加工機の機種・刃の径は未確認なので,今の基板と同じ +# 線の太さ 0.6 mm・間隔 0.5 mm を暫定で使う(PLAN_03「製造の制約」).Fusion の検査は決まりと同じ +# 間隔も違反にする(電源の線と隣のパッドの間がちょうど 0.5 mm で引っかかった)ので,間隔は 0.49 mm +# にする.はんだパッドの部品は 2 つのパッドの間が 0.3 mm なので SMD どうしだけ 0.25 mm にする. +# 手本のファイルの決まりはほぼ 0 だった +DESIGN_RULES = { + "mdWireWire": "0.49mm", "mdWirePad": "0.49mm", "mdWireVia": "0.49mm", + "mdPadPad": "0.49mm", "mdPadVia": "0.49mm", "mdViaVia": "0.49mm", + "mdSmdPad": "0.49mm", "mdSmdVia": "0.49mm", "mdSmdSmd": "0.25mm", + "mdCopperDimension": "1.0mm", "msWidth": "0.6mm", +} + + +@dataclass +class Part: + """基板の部品 1 つ(回路図の記号と基板の部品の両方を作る).""" + + ref: str + kind: str # "led" / "ccr" / "conn" / "hole" + u: float # 基板の長さ方向の位置 [mm](X = x0 + u) + y: float = CENTER_Y + nets: dict[str, str] = field(default_factory=dict) # パッド番号 → ネット名 + + +@dataclass +class Board: + """基板 1 種類.""" + + name: str + title: str + x0: float # u = 0 の X + outline: list[tuple[float, float]] # (u, Y.下向き) の多角形 + parts: list[Part] + segments: list[tuple[tuple[float, float], tuple[float, float], str]] # (u, y) と ネット名 + + +# --------------------------------------------------------------------------- +# 部品の並びと配線(今の基板と同じ引き方) +# --------------------------------------------------------------------------- + +def _string(parts: list[Part], segs: list, c1: float, c2: float, leds: list[float], + refs: list[str], net_prefix: str) -> None: + """定電流 IC 2 個(c1 が LED 側)と LED 3 個の列を足す.leds は c1 から遠ざかる順.""" + sign = 1.0 if leds[0] > c1 else -1.0 # LED が c1 より大きい側なら +1 + n_ccr = f"{net_prefix}_CCR" + parts.append(Part(refs[0], "ccr", c1, nets={"2": "+12V", "1": n_ccr})) + parts.append(Part(refs[1], "ccr", c2, nets={"2": "+12V", "1": n_ccr})) + for c in (c1, c2): + segs.append(((c, 53.35), (c, RAIL_12V_Y), "+12V")) + # 定電流 IC の陰極どうし → 1 個目の LED の陽極 + pts = [(c2, 56.65), (c1, 56.65), (c1 + sign * 1.05, 56.65), (c1 + sign * 1.8, 55.9), + (c1 + sign * 1.8, 54.3), (c1 + sign * 2.625, 53.475), (leds[0], 53.475)] + segs.extend((a, b, n_ccr) for a, b in zip(pts, pts[1:], strict=False)) + for k, x in enumerate(leds): + ref = refs[2 + k] + anode = n_ccr if k == 0 else f"{net_prefix}_L{k}" + cathode = "GND" if k == len(leds) - 1 else f"{net_prefix}_L{k + 1}" + parts.append(Part(ref, "led", x, nets={"2": anode, "1": cathode})) + if k < len(leds) - 1: + pts = [(x, 56.05), (x + sign * 1.25, 56.05), (x + sign * 1.9, 55.4), + (x + sign * 1.9, 53.9), (x + sign * 2.325, 53.475), (leds[k + 1], 53.475)] + segs.extend((a, b, cathode) for a, b in zip(pts, pts[1:], strict=False)) + else: + segs.append(((x, 56.05), (x, RAIL_GND_Y), "GND")) + + +# 電源パッドの列の中心の,基板の端からの距離(パッドの幅 2.0 mm・外形まで 1.2 mm・列の間 1.5 mm) +PAD_COLUMNS = (2.2, 5.7) +# 取付穴の中心から電源パッドの端までの距離.カバーのパッドの窓(パッド + 0.3 mm)が M3 のねじの頭 +# (半径 2.75 mm)にかからないようにする +HOLE_TO_PADS = 3.6 + + +def _power_pads(parts: list[Part], u_edge: float, refs: tuple[str, str], + side: float = 1.0) -> float: + """基板の端(u_edge)に電源パッド 2 列(ケーブル 2 本分)を置き,外側の列の u を返す. + + side は基板が u_edge から見てどちらにあるか(+1: u が増える側,−1: 減る側). + パッドは +12V が +12V の線(RAIL_12V_Y),GND が GND の線(RAIL_GND_Y)に重なるので, + 線をパッドの列まで延ばせばつながる. + """ + cols = [u_edge + side * c for c in PAD_COLUMNS] + for ref, u in zip(refs, cols, strict=True): + parts.append(Part(ref, "conn", u, nets={"1": "GND", "2": "+12V"})) + return cols[0] + + +def side_board() -> Board: + """左右用(6 個.装置の Y = u): パッド −16.1・−12.6・穴 −8・+40・IC ±2 / 18・22・LED 6〜34.""" + parts: list[Part] = [] + segs: list = [] + u_edge = -8.0 - HOLE_TO_PADS - PAD_COLUMNS[1] - 1.0 + uj = _power_pads(parts, u_edge, ("J1", "J2")) + _string(parts, segs, 2.0, -2.0, [6.0, 10.0, 14.0], ["D7", "D8", "D1", "D2", "D3"], "S1") + _string(parts, segs, 22.0, 18.0, [26.0, 30.0, 34.0], ["D9", "D10", "D4", "D5", "D6"], "S2") + segs.append(((uj, RAIL_12V_Y), (22.0, RAIL_12V_Y), "+12V")) + segs.append(((uj, RAIL_GND_Y), (34.0, RAIL_GND_Y), "GND")) + parts += [Part("H1", "hole", -8.0), Part("H2", "hole", 40.0)] + # 上の端の両角を落とす(箱の角の丸みに当てないため) + outline = [(u_edge, 50.0), (38.0, 50.0), (44.0, 53.5), (44.0, 56.5), (38.0, 60.0), + (u_edge, 60.0)] + return Board("SmTIASv4_LED_side_v2", "SmTIASv4 LED 基板(左右用・6 個)", 120.0, outline, + parts, segs) + + +BOTTOM_LEDS = (17.0, 21.0, 25.0) # 下用の LED の |X|(s10 の基準ピンの間 90 mm に収める長さ) + + +def bottom_board() -> Board: + """下用(6 個.装置の X = u): パッド ±35.6・±39.1・穴 ±31・LED ±17〜±25・IC ±9,±13. + + 左右用の部品の間隔をそのまま左右対称に並べたもの.真ん中(−8〜+8)は部品が無い. + """ + parts: list[Part] = [] + segs: list = [] + led_in, _, led_out = BOTTOM_LEDS + hole = led_out + 6.0 + u_edge = hole + HOLE_TO_PADS + PAD_COLUMNS[1] + 1.0 + uj_l = _power_pads(parts, -u_edge, ("J1", "J2"), side=1.0) + uj_r = _power_pads(parts, u_edge, ("J3", "J4"), side=-1.0) + c1, c2 = led_in - 4.0, led_in - 8.0 + _string(parts, segs, -c1, -c2, [-v for v in BOTTOM_LEDS], ["D7", "D8", "D1", "D2", "D3"], + "S1") + _string(parts, segs, c1, c2, list(BOTTOM_LEDS), ["D9", "D10", "D4", "D5", "D6"], "S2") + segs.append(((uj_l, RAIL_12V_Y), (uj_r, RAIL_12V_Y), "+12V")) + segs.append(((uj_l, RAIL_GND_Y), (uj_r, RAIL_GND_Y), "GND")) + parts += [Part("H1", "hole", -hole), Part("H2", "hole", hole)] + outline = [(-u_edge, 50.0), (u_edge, 50.0), (u_edge, 60.0), (-u_edge, 60.0)] + return Board("SmTIASv4_LED_bottom_v2", "SmTIASv4 LED 基板(下用・6 個)", 100.0, outline, + parts, segs) + + +# --------------------------------------------------------------------------- +# EAGLE 形式の書き出し +# --------------------------------------------------------------------------- + +LIBRARY = {"led": "Device", "ccr": "Device", "conn": "Connector_Generic", "hole": "MountingHole"} +PACKAGE = { + "led": "LED_SMD_LED_PLCC_2835_HANDSOLDERING", + "ccr": "DIODE_SMD_D_SOD-123", + "conn": "SMTIAS_WIRE_PAD_2X3", + "hole": "MOUNTINGHOLE_3.2MM_M3_ISO7380", +} +DEVICESET = {"led": "LED", "ccr": "D", "conn": "CONN_01X02"} +VALUE = {"led": "LP-2835D90VW", "ccr": "NSI45030AT1G", "conn": "Conn_01x02", + "hole": "MountingHole_3.2mm_M3_ISO7380"} +# パッド番号 → 記号のピン名と,記号の座標でのピンの位置(Y は上向き) +PINS = { + "led": {"1": ("K", (-3.81, 0.0)), "2": ("A", (3.81, 0.0))}, + "ccr": {"1": ("K", (-3.81, 0.0)), "2": ("A", (3.81, 0.0))}, + "conn": {"1": ("Pin_1", (-5.08, 0.0)), "2": ("Pin_2", (-5.08, -2.54))}, +} + + +def _replace_section(text: str, tag: str, body: str) -> str: + """`...`(最初の 1 つ)を body に置き換える.""" + start = text.index(f"<{tag}>") + end = text.index(f"", start) + len(f"") + return text[:start] + body + text[end:] + + +def _f(v: float) -> str: + return f"{round(v, 4):g}" + + +# ケーブルをはんだ付けする電源パッドの部品(1 本分).R90 で置くと pad 1 = GND が GND の線の側, +# pad 2 = +12V が +12V の線の側に来る.間 1.5 mm.+12V は角の丸い形にして見分ける +WIRE_PAD_PACKAGE = """ +Wire solder pads for one cable (GND / +12V), 2.0 x 3.0 mm, 1.5 mm gap + + + +""" +WIRE_PAD_DEVICE = """ + + + + + + + + +""" + + +def add_wire_pad_part(text: str, schematic: bool) -> str: + """手本のライブラリ Connector_Generic に電源パッドの部品(回路図では device も)を足す.""" + start = text.index('') + pos = text.index("", start) + len("") + text = text[:pos] + "\n" + WIRE_PAD_PACKAGE.rstrip("\n") + text[pos:] + if schematic: + ds = text.index('", ds) + len("") + text = text[:pos] + "\n" + WIRE_PAD_DEVICE.rstrip("\n") + text[pos:] + return text + + +def write_brd(board: Board, template: str, dest: Path) -> None: + """基板(.brd): 外形(層 20)・部品の配置・配線(層 1).""" + def xy(u: float, y: float) -> tuple[str, str]: + return _f(board.x0 + u), _f(Y_FLIP - y) + + plain = [""] + pts = board.outline + board.outline[:1] + for (u0, y0), (u1, y1) in zip(pts, pts[1:], strict=False): + (x1, ya), (x2, yb) = xy(u0, y0), xy(u1, y1) + plain.append(f'') + plain.append("") + + elements = [""] + for part in board.parts: + x, y = xy(part.u, part.y) + rot = "" if part.kind == "hole" else ' rot="R90"' + elements.append(f'') + elements.append("") + + signals = [""] + for net in sorted({n for p in board.parts for n in p.nets.values()}): + signals.append(f'') + for part in board.parts: + for pad, n in sorted(part.nets.items()): + if n == net: + signals.append(f'') + for (u0, y0), (u1, y1), n in board.segments: + if n == net and (u0, y0) != (u1, y1): + (x1, ya), (x2, yb) = xy(u0, y0), xy(u1, y1) + signals.append(f'') + signals.append("") + signals.append("") + + text = _replace_section(template, "plain", "\n".join(plain)) + text = _replace_section(text, "elements", "\n".join(elements)) + text = _replace_section(text, "signals", "\n".join(signals)) + for name, value in DESIGN_RULES.items(): + text, n = re.subn(rf'', + f'', text) + if n != 1: + raise RuntimeError(f"手本の .brd に設計の決まり {name} が見つからない") + text = re.sub(r' None: + """回路図(.sch): 部品の配置と,ピンごとの短い線とネット名のラベル(同じ名前でつながる).""" + parts = [""] + instances = [""] + segments: dict[str, list[str]] = {} + col = {"conn": 0, "ccr": 0, "led": 0} + row_y = {"conn": 160.02, "ccr": 134.62, "led": 109.22} + for part in board.parts: + if part.kind == "hole": + continue + parts.append(f'') + x = 50.8 + 25.4 * col[part.kind] + y = row_y[part.kind] + col[part.kind] += 1 + instances.append(f'') + for pad, (pin, (px, py)) in PINS[part.kind].items(): + net = part.nets[pad] + x0, y0 = x + px, y + py + x1 = x0 + (-2.54 if px < 0 else 2.54) + rot = ' rot="MR0"' if px < 0 else "" + segments.setdefault(net, []).append( + f'\n\n' + f'') + parts.append("") + instances.append("") + nets = [""] + for name, segs in segments.items(): + nets.append(f'') + nets.extend(segs) + nets.append("") + nets.append("") + text = _replace_section(template, "parts", "\n".join(parts)) + text = _replace_section(text, "instances", "\n".join(instances)) + text = _replace_section(text, "nets", "\n".join(nets)) + text = re.sub(r".*?", "\n", text, count=1, flags=re.S) + dest.write_text(text, encoding="utf-8", newline="\n") + + +def main() -> int: + sch = add_wire_pad_part(TEMPLATE.with_suffix(".sch").read_text(encoding="utf-8"), True) + brd = add_wire_pad_part(TEMPLATE.with_suffix(".brd").read_text(encoding="utf-8"), False) + for board in (side_board(), bottom_board()): + write_sch(board, sch, OUT / f"{board.name}.sch") + write_brd(board, brd, OUT / f"{board.name}.brd") + n_led = sum(p.kind == "led" for p in board.parts) + n_ccr = sum(p.kind == "ccr" for p in board.parts) + print(f"[saved] {OUT / board.name}.sch / .brd(LED {n_led}・定電流 IC {n_ccr}・" + f"配線 {len(board.segments)} 本)") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())