Massive refactor that changes nothing in the shape of the case :-)

This commit is contained in:
Roberto Alsina 2023-03-01 15:47:06 -03:00
parent 120638f50f
commit 576edc839b
12 changed files with 234 additions and 104 deletions

View File

@ -0,0 +1,16 @@
# Hole to expose a USB audio card (YMMV)
# The hole is for a USB-A plug, y is measured in the hub
# (from the bottom face to middle of the hole)
# Consumers should set proper offsets for the hole
holes = [
# 2-jack plug
{
"x": 0,
"y": 4,
"height": 6,
"width": 17,
"fillet": 2,
},
]

View File

@ -6,14 +6,6 @@ stands = (
)
pillar_height = 7
# Holes for the battery power cable and button
power_in = cq.Sketch().trapezoid(12, 6.5, 90, mode="a").vertices().fillet(1)
power_in_offset_x = 15
power_in_offset_y = -1
button_offset_x = 67
button_offset_y = 5.5
power_button_cut = cq.Sketch().trapezoid(7, 7, 90, mode="a").vertices().fillet(1)
# This is a holder for DuPont cables so they connect to this
# things' pogo pins which are used to power the CPU
@ -38,3 +30,44 @@ pin_holder = (
mode="s",
)
)
elements = [
# Battery holder stands
{
"x": 0,
"y": 0,
"shape": stands,
"height": pillar_height,
},
# Pogo pin connector channels
{
"x": 0,
"y": 40,
"shape": pin_holder,
"height": 3,
},
]
# Hole distances are relative to the rightmost pillar
# seen from the back of the case, that's why they are negative
# Heights are relative to base of pillars
# All distances are measured to the CENTER of the hole
holes = [
# Power inlet
{
"x": -15,
"y": -1 + pillar_height,
"height": 6.5,
"width": 12,
"fillet": 1,
},
# Power button
{
"x": -67,
"y": 5.5 + pillar_height,
"height": 7,
"width": 7,
"fillet": 1,
},
]

View File

@ -1,8 +0,0 @@
import cadquery as cq
cpu_stand_positions = [(0, 0), (0, 23), (58, 23), (58, 0)]
stands = (
cq.Sketch().push(cpu_stand_positions).circle(3, mode="a").circle(2.65 / 2, mode="s")
)
pillar_height = 7

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,8 +1,11 @@
import cadquery as cq
from cadquery import exporters
import audio_plug
import battery_holder
import cpu_holder
import usb_hub
import zero_holder as cpu_holder
from utils import extrude_shape, punch_hole
# Base for the notebook. Basically a kbd base that extends back
# as much as possible
@ -76,30 +79,29 @@ mounting_pillars = (
screw_holes = cq.Sketch().push(mounting_pillar_positions).circle(3, mode="a")
# Hole for the USB hub's exposed port
usb_in = cq.Sketch().trapezoid(13, 5.5, 90, mode="a").vertices().fillet(2)
# Thing to "grab" the hub so it stays in place
usb_holder = (
cq.Sketch().trapezoid(22, 10, 90, mode="a").trapezoid(17, 10, 90, mode="s").clean()
)
# Distance from edge to center of USB plug
usb_offset = 48
# Hole for the USB hub's exposed port
audio_in = cq.Sketch().trapezoid(17, 6, 90, mode="a").vertices().fillet(1)
# CPU holder position from back-left corner of the case
cpu_offset_x = 160
cpu_offset_y = 25
# CPU holder position from back-right corner of the case
cpu_offset_x = 150
cpu_offset_y = 55
# Battery holder position from back-left corner of the case
battery_offset_x = 22
battery_offset_y = 8
# Battery holder position from front-left corner of the case
battery_offset_x = 21
battery_offset_y = 56
# Offset for the USB port from back-right corner of the case
usb_offset = 48
def model():
return (
# Create the basic shape of the case bottom.
# Currently also adds keyboard stuff, but that should be refactored
# out (FIXME)
model = (
cq.Workplane("XY")
.workplane(offset=thickness / 2)
.tag("mid_height")
@ -109,52 +111,6 @@ def model():
.fillet(2)
.faces(">Z")
.shell(-shell_t)
# Power inlet
# The position is arbitrary, based on the components available
.faces(">Y")
.workplane(centerOption="CenterOfBoundBox")
# The 15 is distance from stand hole center to center of USB plug
# The -1 is distance from top of the pillar to center of USB plug
.center(
width / 2 - battery_offset_x - battery_holder.power_in_offset_x,
-thickness / 2
+ battery_holder.pillar_height
+ shell_t
+ battery_holder.power_in_offset_y,
)
.placeSketch(battery_holder.power_in)
.cutBlind(-shell_t)
# Power button
# The position is arbitrary, based on the components available,
.faces(">Y")
.workplane(centerOption="CenterOfBoundBox")
# The 67 is distance from stand hole center to center of power button
# The 5 is distance from top of the pillar to center of power button
.center(
width / 2 - battery_offset_x - battery_holder.button_offset_x,
-thickness / 2
+ battery_holder.pillar_height
+ shell_t
+ battery_holder.button_offset_y,
)
.placeSketch(battery_holder.power_button_cut)
.cutBlind(-shell_t)
# USB inlet
# The position is arbitrary, based on the components
# available, keyboard height, cable length, etc.
.faces(">Y")
.workplane(centerOption="CenterOfBoundBox")
.center(-width / 2 + shell_t + usb_offset + 13 / 2, -8)
.placeSketch(usb_in)
.cutBlind(-shell_t)
# Audio plugs
# The position is arbitrary, based on the components
# available, keyboard height, cable length, etc.
.faces(">X")
.workplane(centerOption="CenterOfBoundBox")
.center(height / 2 - shell_t - 34.5 - 17 / 2, -8)
.placeSketch(audio_in)
.cutBlind(-shell_t)
# Slanted mounting pillars on the kbd top
.faces(">Z")
.workplane(centerOption="CenterOfBoundBox")
@ -191,35 +147,91 @@ def model():
.placeSketch(screw_holes)
# 13 is 20-7 (screw thread length - threaded insert depth)
.cutBlind(thickness - 13)
# CPU Stands
.workplaneFromTagged("mid_height")
.workplane(offset=-thickness / 2, centerOption="CenterOfBoundBox")
.center(width / 2 - cpu_offset_x, height / 2 - cpu_offset_y)
.placeSketch(cpu_holder.stands)
.extrude(cpu_holder.pillar_height)
# Battery Stands
.workplaneFromTagged("mid_height")
.workplane(offset=-thickness / 2, centerOption="CenterOfBoundBox")
.center(-width / 2 + battery_offset_x, height / 2 - battery_offset_y)
.placeSketch(battery_holder.stands)
.extrude(shell_t + battery_holder.pillar_height)
# Pogo pin connector holders
.workplaneFromTagged("mid_height")
.workplane(offset=-thickness / 2, centerOption="CenterOfBoundBox")
.center(
-width / 2 + battery_offset_x,
height / 2 - battery_offset_y - battery_holder.pin_holder_height / 2,
)
.placeSketch(battery_holder.pin_holder)
.extrude(shell_t + 3)
# Channel for the usb hub
.faces(">Y")
.workplane(centerOption="CenterOfBoundBox")
.center(-width / 2 + shell_t + usb_offset + 13 / 2, -8)
.placeSketch(usb_holder)
.extrude(-shell_t - 8)
)
# Now the basic box shape is in place, start adding things
# and cutting holes.
# Holes in the back of the case for battery holder
for hole in battery_holder.holes:
model = punch_hole(
model=model,
face=">Y",
w=width,
h=thickness,
x_offset=width - battery_offset_x,
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
# Hole for USB hub in the back
for hole in usb_hub.holes:
model = punch_hole(
model=model,
face=">Y",
w=width,
h=thickness,
x_offset=usb_offset + shell_t + usb_hub.holes[0]["width"] / 2,
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
# USB hub holder
for element in usb_hub.elements:
model = extrude_shape(
model=model,
face="<Z",
w=width,
h=height,
x_offset=width - usb_offset - shell_t - +usb_hub.holes[0]["width"] / 2,
y_offset=shell_t + element["y"],
shape=element["shape"],
height=-(element["height"] + shell_t),
)
# Hole for audio in right side
for hole in audio_plug.holes:
model = punch_hole(
model=model,
face=">X",
w=height,
h=thickness,
x_offset=height - shell_t - 34.5 - audio_plug.holes[0]["width"] / 2,
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
# Battery holder stands and pogo pin holder
for element in battery_holder.elements:
model = extrude_shape(
model=model,
face="<Z",
w=width,
h=height,
x_offset=battery_offset_x + element["x"],
y_offset=shell_t + battery_offset_y + element["y"],
shape=element["shape"],
height=-(element["height"] + shell_t),
)
# CPU holder stands
for element in cpu_holder.elements:
model = extrude_shape(
model=model,
face="<Z",
w=width,
h=height,
x_offset=cpu_offset_x + element["x"],
y_offset=shell_t + cpu_offset_y + element["y"],
shape=element["shape"],
height=-(element["height"] + shell_t),
)
return model
if __name__ == "__main__":

Binary file not shown.

Binary file not shown.

33
notebook_nueva/usb_hub.py Normal file
View File

@ -0,0 +1,33 @@
import cadquery as cq
# Measurements for my USB hub, YMMV
# The hole is for a USB-A plug, y is measured in the hub
# (from the bottom face to middle of the hole)
# Consumers should set proper offsets for the hole
holes = [
# USB-A port
{
"x": 0,
"y": 4,
"height": 5.5,
"width": 13,
"fillet": 2,
},
]
elements = [
# Thing to grab the hub
{
"x": 0,
"y": 5,
"shape": (
cq.Sketch()
.trapezoid(22, 10, 90, mode="a")
.trapezoid(17, 10, 90, mode="s")
.clean()
),
"height": 8,
}
]

26
notebook_nueva/utils.py Normal file
View File

@ -0,0 +1,26 @@
import cadquery as cq
# TODO make API of extrude_shape and punch_hole more consistent
def extrude_shape(*, model, face, w, h, x_offset, y_offset, shape, height):
return (
model.faces(face)
.workplane(centerOption="CenterOfBoundBox")
.center(-w / 2 + x_offset, -h / 2 + y_offset)
.placeSketch(shape)
.extrude(height)
)
def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth):
return (
model.faces(face)
.workplane(centerOption="CenterOfBoundBox")
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
.placeSketch(
cq.Sketch()
.trapezoid(hole["width"], hole["height"], 90, mode="a")
.vertices()
.fillet(hole["fillet"])
)
.cutBlind(-depth)
)

View File

@ -0,0 +1,18 @@
import cadquery as cq
positions = [(0, 0), (0, 23), (58, 23), (58, 0)]
stands = (
cq.Sketch().push(positions).circle(3, mode="a").circle(2.65 / 2, mode="s")
)
pillar_height = 7
elements = [
# CPU holder stands
{
"x": 0,
"y": 0,
"shape": stands,
"height": pillar_height,
}
]