"""Batch 2565 -- printed ball check valve (ours): an 8 mm steel ball held on a 6 mm sharp-edged seat by a light spring; flow lifts
the ball, back-flow presses it on the seat. Two PETG halves sealed by an O-ring (16 x 2 mm) and held by 3 x M3; barbs for 6 mm ID hose.
Run: OUT=<dir> freecadcmd build_valve.py (mm, flow along +z, seat face at z = 0)."""
import os, math
import FreeCAD as App, Part, MeshPart
V = App.Vector
OUT = os.environ.get("OUT", ".")
R_FL, BORE, SEAT_R, BALL_R = 14.0, 4.0, 3.0, 4.0
CH_R, CH_TOP = 5.0, 14.0 # chamber radius, chamber top (z) where the spring rests
GROOVE_R0, GROOVE_R1, GROOVE_D = 8.0, 10.2, 1.5
SCREW_AT = 11.8
def cyl(r, z0, z1, x=0, y=0): return Part.makeCylinder(r, z1 - z0, V(x, y, z0))
def barb(z0, direction): # 3 barbs for 6 mm ID hose, 18 mm long, pointing away from the body
s = cyl(3.6, min(z0, z0 + 18 * direction), max(z0, z0 + 18 * direction))
for k in range(3):
zb = z0 + direction * (6 + 4 * k)
s = s.fuse(Part.makeCone(3.6, 4.4, 3.0, V(0, 0, zb + (0 if direction > 0 else -3.0)), V(0, 0, 1) if direction > 0 else V(0, 0, 1)) if direction < 0
else Part.makeCone(4.4, 3.6, 3.0, V(0, 0, zb), V(0, 0, 1)))
return s
def save(sh, name):
sh = sh.removeSplitter(); bb = sh.BoundBox
print(name, "valid", sh.isValid(), "solids", len(sh.Solids), "bbox", [round(v, 1) for v in (bb.XLength, bb.YLength, bb.ZLength)], "volume_cm3", round(sh.Volume / 1000, 2))
if not os.environ.get("NOSAVE"):
MeshPart.meshFromShape(Shape=sh, LinearDeflection=0.02, AngularDeflection=0.1).write(os.path.join(OUT, name + ".stl"))
return sh
screws = [(SCREW_AT * math.cos(math.radians(90 + 120 * k)), SCREW_AT * math.sin(math.radians(90 + 120 * k))) for k in range(3)]
# inlet half: flange z -6..0 with the seat at its top face, barb below
inlet = cyl(R_FL, -6, 0).fuse(barb(-6, -1)).cut(cyl(BORE / 2, -30, 1))
inlet = inlet.cut(cyl(SEAT_R, -1.0, 0.1)) # 6 mm hole, 1 mm deep: its top edge is the seat
inlet = inlet.cut(cyl(GROOVE_R1, -GROOVE_D, 0.1).cut(cyl(GROOVE_R0, -GROOVE_D - 1, 1))) # O-ring groove
for x, y in screws: inlet = inlet.cut(cyl(1.25, -7, 1, x, y)) # M3 pilot 2.5 mm
inlet = save(inlet, "cv-inlet")
# outlet half: body z 0..16 with the chamber, barb above
outlet = cyl(R_FL, 0, 16).fuse(barb(16, 1)).cut(cyl(CH_R, -0.1, CH_TOP)).cut(cyl(BORE / 2, CH_TOP - 1, 40))
for x, y in screws: outlet = outlet.cut(cyl(1.7, -1, 17, x, y)).cut(cyl(3.0, 12.5, 17, x, y)) # M3 clearance + counterbore
outlet = save(outlet, "cv-outlet")
# clash check: ball on the seat, O-ring in the groove
zc = math.sqrt(BALL_R ** 2 - SEAT_R ** 2) # ball (r 4) rests on the 6 mm seat edge at z = 0
ball = Part.makeSphere(BALL_R, V(0, 0, zc))
oring = Part.makeTorus(9.1, 1.0, V(0, 0, -0.9))
print("ball centre z", round(zc, 2), "ball top z", round(zc + BALL_R, 2), "spring space to chamber top", round(CH_TOP - zc - BALL_R, 2))
for n, s in (("ball-inlet", ball.common(inlet).Volume), ("ball-outlet", ball.common(outlet).Volume), ("oring-outlet (squeeze, meant)", oring.common(outlet).Volume),
("inlet-outlet", inlet.common(outlet).Volume)):
print("clash", n, round(s, 3))