Tudo: Primeiro commit
This commit is contained in:
commit
06a90928dc
4633 files changed
+6327263
No files matched your search
@@ -0,0 +1,140 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Cabos: fita de 4 vias do NEMA17 (PH2.0 6P -> DuPont 4P 2,54) e fios
|
||||
genéricos. O traçado é uma B-spline pelos pontos dados; os fios da fita
|
||||
seguem um referencial de transporte paralelo (sem torção)."""
|
||||
import math
|
||||
import FreeCAD as App
|
||||
import Part
|
||||
from FreeCAD import Vector as V, Placement, Rotation
|
||||
from lib_rm import cyl, cbox, box, fuse, placed
|
||||
|
||||
WIRE_D = 1.3 # 26 AWG com isolação
|
||||
PITCH = 1.35 # passo da fita
|
||||
CORES_NEMA = ["vermelho", "azul", "verde", "preto"] # ordem do cabo Twotrees
|
||||
|
||||
|
||||
def _frames(pts, n0, samples=120):
|
||||
spl = Part.BSplineCurve()
|
||||
spl.interpolate(pts)
|
||||
a, b = spl.FirstParameter, spl.LastParameter
|
||||
P, T = [], []
|
||||
for k in range(samples + 1):
|
||||
u = a + (b - a) * k / samples
|
||||
P.append(spl.value(u))
|
||||
t = spl.tangent(u)[0]
|
||||
t.normalize()
|
||||
T.append(t)
|
||||
N = []
|
||||
n = n0 - T[0] * n0.dot(T[0])
|
||||
n.normalize()
|
||||
N.append(n)
|
||||
for k in range(1, len(T)):
|
||||
r = Rotation(T[k - 1], T[k])
|
||||
n = r.multVec(N[-1])
|
||||
n = n - T[k] * n.dot(T[k])
|
||||
n.normalize()
|
||||
N.append(n)
|
||||
return P, T, N, spl
|
||||
|
||||
|
||||
def _tube(pts, r):
|
||||
spl = Part.BSplineCurve()
|
||||
spl.interpolate(pts)
|
||||
e = spl.toShape()
|
||||
t0 = spl.tangent(spl.FirstParameter)[0]
|
||||
c = Part.Wire(Part.makeCircle(r, pts[0], t0))
|
||||
return Part.Wire(e).makePipeShell([c], True, True)
|
||||
|
||||
|
||||
def ribbon(pts, n0, n_wires=4, pitch=PITCH, d=WIRE_D, samples=120):
|
||||
"""Devolve (lista de sólidos dos fios, frame inicial, frame final).
|
||||
n0 = normal do plano da fita no início."""
|
||||
P, T, N, spl = _frames([V(*p) for p in pts], n0, samples)
|
||||
wires = []
|
||||
for j in range(n_wires):
|
||||
off = (j - (n_wires - 1) / 2) * pitch
|
||||
wp = [P[k] + T[k].cross(N[k]) * off for k in range(len(P))]
|
||||
sub = wp[::3]
|
||||
if sub[-1] is not wp[-1]:
|
||||
sub.append(wp[-1])
|
||||
wires.append(_tube(sub, d / 2))
|
||||
return wires, (P[0], T[0], N[0]), (P[-1], T[-1], N[-1]), spl.length()
|
||||
|
||||
|
||||
def frame_rot(t, n):
|
||||
"""Rotation com X=b (largura da fita), Y=n, Z=t (direção do cabo)."""
|
||||
b = t.cross(n)
|
||||
m = App.Matrix(b.x, n.x, t.x, 0, b.y, n.y, t.y, 0, b.z, n.z, t.z, 0, 0, 0, 0, 1)
|
||||
return Rotation(m)
|
||||
|
||||
|
||||
def ph20_plug(n=6):
|
||||
"""Plugue JST PH 2,0 mm fêmea (housing) — cabo sai em +Z, encaixe em -Z.
|
||||
Largura = 2*n + 1,95 ; espessura 4,5 ; comprimento 6,0."""
|
||||
w = 2.0 * n + 1.95
|
||||
h = cbox(w, 4.5, 6.0, 0, 0, -6.0)
|
||||
h = h.cut(cbox(w - 1.2, 1.0, 1.2, 0, 2.25, -6.1)) # rasgo da trava
|
||||
for i in range(n):
|
||||
x = (i - (n - 1) / 2) * 2.0
|
||||
h = h.cut(cbox(1.0, 1.0, 2.0, x, -0.3, -6.2))
|
||||
return h
|
||||
|
||||
|
||||
def dupont_housing(n=4):
|
||||
"""Housing DuPont fêmea 2,54 mm (preto), cabo em +Z, encaixe em -Z."""
|
||||
w = 2.54 * n
|
||||
h = cbox(w, 2.54, 14.0, 0, 0, -14.0)
|
||||
for i in range(n):
|
||||
x = (i - (n - 1) / 2) * 2.54
|
||||
h = h.cut(cbox(1.0, 1.0, 3.0, x, 0, -14.2))
|
||||
h = h.cut(cbox(1.6, 0.9, 2.0, x, 1.2, -9.0)) # janelas das travas
|
||||
return h
|
||||
|
||||
|
||||
def stepper_cable(pts, n0, n_end=None):
|
||||
"""Cabo completo: plugue PH2.0 6P no primeiro ponto (encaixando para trás
|
||||
do sentido do cabo), fita de 4 fios e DuPont 4P no último ponto.
|
||||
n0 = normal da fita no início (largura do plugue = t0 x n0); n_end
|
||||
idem para o DuPont. Retorna (dict nome->(shape, cor), comprimento)."""
|
||||
wires, f0, f1, length = ribbon(pts, n0)
|
||||
out = {}
|
||||
for j, w in enumerate(wires):
|
||||
out["fio_%d_%s" % (j + 1, CORES_NEMA[j])] = (w, CORES_NEMA[j])
|
||||
p0, t0, nn0 = f0
|
||||
plug = ph20_plug(6)
|
||||
plug = placed(plug, p0, frame_rot(t0, nn0))
|
||||
out["plug_PH2.0_6P"] = (plug, "branco")
|
||||
p1, t1, nn1 = f1
|
||||
if n_end is not None: # orienta a largura do DuPont ao longo da barra de pinos
|
||||
nn1 = n_end - t1 * n_end.dot(t1)
|
||||
nn1.normalize()
|
||||
dup = dupont_housing(4)
|
||||
dup = placed(dup, p1, frame_rot(-t1, nn1))
|
||||
out["dupont_4P"] = (dup, "preto")
|
||||
return out, length
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- fios avulsos
|
||||
def wire(pts, d):
|
||||
"""Fio (tubo) pela B-spline dos pontos."""
|
||||
return _tube([V(*p) for p in pts], d / 2)
|
||||
|
||||
|
||||
def male_pin_end(p, direction):
|
||||
"""Ponta macho DuPont: housing 2,54 x 2,54 x 14 com pino de 6 mm saindo
|
||||
em 'direction' (p = ponto onde o fio entra no housing)."""
|
||||
d = V(direction)
|
||||
d.normalize()
|
||||
rot = Rotation(V(0, 0, 1), d)
|
||||
h = placed(cbox(2.54, 2.54, 14.0, 0, 0, 0), p, rot)
|
||||
pin = placed(cbox(0.64, 0.64, 6.0, 0, 0, 14.0), p, rot)
|
||||
return h, pin
|
||||
|
||||
|
||||
def female_end(p, direction):
|
||||
"""Ponta fêmea DuPont: housing 2,54 x 2,54 x 14; 'direction' aponta do fio
|
||||
para o pino (p = ponto de entrada do fio)."""
|
||||
d = V(direction)
|
||||
d.normalize()
|
||||
rot = Rotation(V(0, 0, 1), d)
|
||||
return placed(cbox(2.54, 2.54, 14.0, 0, 0, 0), p, rot)
|
||||
Reference in new issue
Block a user