feat: Light panel assembly
This commit is contained in:
parent
3884d75f1c
commit
d1fd830766
|
@ -1,7 +1,9 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import cadquery as Cq
|
import cadquery as Cq
|
||||||
from nhf import Material, Role
|
from nhf import Material, Role
|
||||||
from nhf.build import Model, target, assembly, TargetKind
|
from nhf.build import Model, target, assembly, TargetKind, submodel
|
||||||
|
from nhf.parts.box import MountingBox, Hole
|
||||||
|
from nhf.parts.electronics import ArduinoUnoR3
|
||||||
import nhf.utils
|
import nhf.utils
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -16,12 +18,16 @@ class LightPanel(Model):
|
||||||
# Distance from grid to edge
|
# Distance from grid to edge
|
||||||
grid_margin: float = 20.0
|
grid_margin: float = 20.0
|
||||||
# Number of holes in each row of the grid
|
# Number of holes in each row of the grid
|
||||||
grid_holes: int = 5
|
grid_holes: int = 9
|
||||||
grid_layers: int = 10
|
grid_layers: int = 6
|
||||||
grid_hole_width: float = 10.0
|
grid_hole_width: float = 15.0
|
||||||
|
|
||||||
base_thickness: float = 25.4/16
|
base_thickness: float = 25.4/16
|
||||||
grid_thickness: float = 25.4/8
|
grid_thickness: float = 25.4/8
|
||||||
|
base_material: Material = Material.WOOD_BIRCH
|
||||||
|
grid_material: Material = Material.ACRYLIC_TRANSPARENT
|
||||||
|
|
||||||
|
controller: ArduinoUnoR3 = ArduinoUnoR3()
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
assert self.grid_holes >= 2
|
assert self.grid_holes >= 2
|
||||||
|
@ -38,7 +44,7 @@ class LightPanel(Model):
|
||||||
n = self.grid_holes
|
n = self.grid_holes
|
||||||
w0 = self.grid_hole_width
|
w0 = self.grid_hole_width
|
||||||
t = (w - n * w0) / (n + 1)
|
t = (w - n * w0) / (n + 1)
|
||||||
# The spacing is such that the first and last holes are a distance `t`
|
# The spacing is such that the first and last holes are a distance `margin`
|
||||||
# away from the edges, so it satisfies
|
# away from the edges, so it satisfies
|
||||||
# t + w0/2 + (n-1) * s + w0/2 + t = w
|
# t + w0/2 + (n-1) * s + w0/2 + t = w
|
||||||
step = (w - t*2 - w0) / (n - 1)
|
step = (w - t*2 - w0) / (n - 1)
|
||||||
|
@ -53,6 +59,56 @@ class LightPanel(Model):
|
||||||
.rect(w0, self.grid_height, mode='s')
|
.rect(w0, self.grid_height, mode='s')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def grid(self) -> Cq.Workplane:
|
||||||
|
return (
|
||||||
|
Cq.Workplane('XY')
|
||||||
|
.placeSketch(self.grid_profile())
|
||||||
|
.extrude(self.grid_thickness)
|
||||||
|
)
|
||||||
|
|
||||||
|
@submodel(name="base")
|
||||||
|
def base(self) -> MountingBox:
|
||||||
|
holes = [
|
||||||
|
Hole(
|
||||||
|
x=x, y=y,
|
||||||
|
diam=self.controller.hole_diam,
|
||||||
|
tag=f"controller_conn{i}",
|
||||||
|
)
|
||||||
|
for i, (x, y) in enumerate(self.controller.holes)
|
||||||
|
]
|
||||||
|
return MountingBox(
|
||||||
|
holes=holes,
|
||||||
|
hole_diam=self.controller.hole_diam,
|
||||||
|
length=self.length,
|
||||||
|
width=self.width,
|
||||||
|
centred=(True, False),
|
||||||
|
thickness=self.base_thickness,
|
||||||
|
)
|
||||||
|
|
||||||
|
def assembly(self) -> Cq.Assembly:
|
||||||
|
assembly = (
|
||||||
|
Cq.Assembly()
|
||||||
|
.addS(
|
||||||
|
self.base().generate(),
|
||||||
|
name="base",
|
||||||
|
role=Role.STRUCTURE,
|
||||||
|
material=self.base_material,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# Grid thickness t is fixed, so the spacing of the grid satisfies
|
||||||
|
# margin + t + (n-1) * (t + spacing) + margin = width
|
||||||
|
spacing = (self.width - 2 * self.grid_margin - self.grid_thickness) / (self.grid_layers - 1) - self.grid_thickness
|
||||||
|
shift = self.grid_margin + self.grid_thickness * 2
|
||||||
|
for i in range(self.grid_layers):
|
||||||
|
assembly = assembly.addS(
|
||||||
|
self.grid(),
|
||||||
|
name=f"grid_{i}",
|
||||||
|
role=Role.STRUCTURE,
|
||||||
|
material=self.grid_material,
|
||||||
|
loc=Cq.Location(0, spacing * i + shift, self.base_thickness, 90, 0, 0),
|
||||||
|
)
|
||||||
|
return assembly
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
|
Loading…
Reference in New Issue