Files
RoboMovel/slides/novidades-2026-10-22/diagramas.py
T
mguinhos d17575771b Projeto: app demo, servidor/firmware em software/, simulacao Godot, planta do bloco D, chapas MDF da base, renders e slides
- app/: app demo (Kivy/buildozer) da API do robo
- software/: servidor RoboMovel (SLAM, profundidade, navegacao) e firmware da base movel (movido de firmware/)
- simulacao/: projeto Godot do robo e script de lancamento servidor + simulacao
- modelos/: planta do 5o andar do bloco D, cena Blender do corredor e modelo real do robo
- partes/mdf/: chapas identificadas e nesting da base do robo (DXF/SVG/FCStd)
- projeto/render, relatorio/imagens, slides: renders finais e apresentacoes de progresso
- ferramentas/scripts: encaixe de chapas, planta do bloco D e render do corredor no Blender
- .gitignore: ignora backups do Blender/FreeCAD e .godot/
2026-10-25 23:38:16 -03:00

298 lines
17 KiB
Python

"""Gera os diagramas SVG dos slides 7 (Robô -> Sistema 1 -> Sistema 2) e 8 (clientes e servidor), no estilo
de figura de artigo (caixas pastel de cantos arredondados, grupos tracejados, setas ortogonais, círculos de
operação), e os coloca no index.html entre <!--DIAG7-->...<!--/DIAG7--> e <!--DIAG8-->...<!--/DIAG8-->.
python3 diagramas.py
"""
import pathlib
import re
AQUI = pathlib.Path(__file__).parent
INK = "#111111"
# pares (preenchimento, contorno) no estilo draw.io
VERDE = ("#D5E8D4", "#82B366")
AZUL = ("#DAE8FC", "#6C8EBF")
AMARELO = ("#FFF2CC", "#D6B656")
VERMELHO = ("#F8CECC", "#B85450")
ROXO = ("#E1D5E7", "#9673A6")
BRANCO = ("#FFFFFF", INK)
FONTE = "Verdana, 'DejaVu Sans', sans-serif"
ESTILO = f"""<style>
.dg text {{ font-family: {FONTE}, 'Noto Color Emoji'; fill: {INK}; }}
.dg .b {{ font-weight: 700; }}
.dg .s {{ font-weight: 400; }}
.dg .seta {{ fill: none; stroke: {INK}; stroke-width: 2.6; stroke-linejoin: round; }}
.dg .tr {{ stroke-dasharray: 9 7; }}
</style>"""
DEFS_MODELO = f"""<defs>
<marker id="pt" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M0,0 L10,5 L0,10 Z" fill="{INK}"/>
</marker>
<clipPath id="clip-img"><rect x="0" y="0" width="1" height="1" rx=".06" ry=".1"/></clipPath>
<symbol id="robo" viewBox="-8 0 136 156">
<rect x="14" y="8" width="5" height="116" rx="2.5" fill="#B3B3B3" stroke="{INK}" stroke-width="1.6"/>
<rect x="101" y="8" width="5" height="116" rx="2.5" fill="#B3B3B3" stroke="{INK}" stroke-width="1.6"/>
<rect x="6" y="6" width="108" height="10" rx="4" fill="#F2D3A6" stroke="{INK}" stroke-width="2"/>
<rect x="6" y="50" width="108" height="10" rx="4" fill="#F2D3A6" stroke="{INK}" stroke-width="2"/>
<rect x="6" y="94" width="108" height="10" rx="4" fill="#F2D3A6" stroke="{INK}" stroke-width="2"/>
<rect x="38" y="24" width="44" height="26" rx="4" fill="#E0B47A" stroke="{INK}" stroke-width="2"/>
<rect x="3" y="108" width="114" height="20" rx="7" fill="#F2D3A6" stroke="{INK}" stroke-width="2"/>
<rect x="48" y="111" width="24" height="14" rx="4" fill="{INK}"/>
<circle cx="60" cy="118" r="4.5" fill="#6C8EBF" stroke="#fff" stroke-width="1.4"/>
<use href="#roda" x="-6" y="116" width="40" height="36"/>
<use href="#roda" x="86" y="116" width="40" height="36" transform="translate(212,0) scale(-1,1)"/>
</symbol>
<clipPath id="clip-roda"><rect x="7" y="2" width="20" height="26" rx="5"/></clipPath>
<symbol id="roda" viewBox="0 0 34 30">
<!-- roda mecanum vista de frente: dois cubos (placas) e roletes a 45° entre eles -->
<rect x="7" y="2" width="20" height="26" rx="5" fill="#2E2E2E"/>
<g clip-path="url(#clip-roda)" stroke="{INK}" stroke-width="1.2">
<rect x="-2" y="-1" width="38" height="5.6" rx="2.8" fill="#C9C9C9" transform="rotate(45 17 15) translate(0 0)"/>
<rect x="-2" y="7.2" width="38" height="5.6" rx="2.8" fill="#E2E2E2" transform="rotate(45 17 15)"/>
<rect x="-2" y="15.4" width="38" height="5.6" rx="2.8" fill="#C9C9C9" transform="rotate(45 17 15)"/>
<rect x="-2" y="23.6" width="38" height="5.6" rx="2.8" fill="#E2E2E2" transform="rotate(45 17 15)"/>
</g>
<rect x="7" y="2" width="20" height="26" rx="5" fill="none" stroke="{INK}" stroke-width="2"/>
<rect x="1" y="4" width="7" height="22" rx="3" fill="#F5C518" stroke="{INK}" stroke-width="2"/>
<rect x="26" y="4" width="7" height="22" rx="3" fill="#F5C518" stroke="{INK}" stroke-width="2"/>
<circle cx="4.5" cy="15" r="1.8" fill="{INK}"/><circle cx="29.5" cy="15" r="1.8" fill="{INK}"/>
</symbol>
<linearGradient id="grad-prof" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#3B2A8C"/><stop offset=".45" stop-color="#2FA8E0"/>
<stop offset=".72" stop-color="#7DDB52"/><stop offset=".86" stop-color="#F5C518"/><stop offset="1" stop-color="#D7301F"/>
</linearGradient>
<symbol id="celular" viewBox="0 0 64 120">
<!-- app de teste: abas, imagem de profundidade, dois joysticks e os botões Parar / Manual / Modelo -->
<rect x="2" y="2" width="60" height="116" rx="12" fill="{INK}"/>
<rect x="6" y="9" width="52" height="102" rx="7" fill="#F7F7F7"/>
<rect x="26" y="4.5" width="12" height="2.5" rx="1.2" fill="#666"/>
<rect x="9" y="13" width="46" height="5" rx="2" fill="#DAE8FC"/>
<rect x="9" y="21" width="46" height="31" rx="3" fill="url(#grad-prof)" stroke="{INK}" stroke-width="1"/>
<rect x="9" y="55" width="10" height="5" rx="1.5" fill="#D5E8D4"/><rect x="21" y="55" width="10" height="5" rx="1.5" fill="#E6E6E6"/>
<rect x="33" y="55" width="10" height="5" rx="1.5" fill="#E6E6E6"/><rect x="45" y="55" width="10" height="5" rx="1.5" fill="#E6E6E6"/>
<circle cx="20" cy="80" r="10.5" fill="#E6E6E6" stroke="#8A8A8A" stroke-width="1.4"/>
<circle cx="23" cy="76.5" r="4.6" fill="#F5C518" stroke="{INK}" stroke-width="1.3"/>
<circle cx="44" cy="80" r="10.5" fill="#E6E6E6" stroke="#8A8A8A" stroke-width="1.4"/>
<line x1="35" y1="80" x2="53" y2="80" stroke="#8A8A8A" stroke-width="1.2"/>
<circle cx="44" cy="80" r="4.6" fill="#F5C518" stroke="{INK}" stroke-width="1.3"/>
<rect x="9" y="98" width="14" height="8" rx="2" fill="#F8CECC" stroke="#B85450" stroke-width="1"/>
<rect x="25" y="98" width="14" height="8" rx="2" fill="#D5E8D4" stroke="#82B366" stroke-width="1"/>
<rect x="41" y="98" width="14" height="8" rx="2" fill="#E1D5E7" stroke="#9673A6" stroke-width="1"/>
</symbol>
</defs>"""
def defs(p):
return DEFS_MODELO.replace('id="pt"', f'id="pt{p}"').replace('id="robo"', f'id="robo{p}"').replace(
'id="celular"', f'id="celular{p}"').replace('id="clip-img"', f'id="clip{p}"').replace(
'clip-roda', f'clip-roda{p}').replace('grad-prof', f'grad-prof{p}').replace('id="roda"', f'id="roda{p}"').replace('href="#roda"', f'href="#roda{p}"')
P = "7" # prefixo dos ids do diagrama em construção
def t(x, y, linhas, tam=19, cls="b", ancora="middle", passo=None, cor=None):
passo = passo or tam * 1.22
y0 = y - (len(linhas) - 1) * passo / 2 + tam * 0.36 # centraliza o bloco em y
c = f' style="fill:{cor}"' if cor else ""
ts = "".join(f'<tspan x="{x}" dy="{0 if i == 0 else passo}">{l}</tspan>' for i, l in enumerate(linhas))
return f'<text x="{x}" y="{y0}" class="{cls}" font-size="{tam}" text-anchor="{ancora}"{c}>{ts}</text>'
def caixa(x, y, w, h, linhas, cor=BRANCO, sub=None, tam=19, tracejada=False, rx=11):
d = ' stroke-dasharray="8 6"' if tracejada else ""
o = f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="{rx}" fill="{cor[0]}" stroke="{cor[1]}" stroke-width="2.6"{d}/>'
if sub:
o += t(x + w / 2, y + h / 2 - 11, linhas, tam)
o += t(x + w / 2, y + h / 2 + tam * 0.5 + 6, [sub], 14, "s")
else:
o += t(x + w / 2, y + h / 2, linhas, tam)
return o
def grupo(x, y, w, h, cor, titulo=None, sub=None):
"""Grupo como na figura do Transformer: contorno colorido sólido com um tracejado por dentro; o título
fica acima do grupo."""
o = f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="26" fill="none" stroke="{cor[1]}" stroke-width="3"/>'
o += f'<rect x="{x + 9}" y="{y + 9}" width="{w - 18}" height="{h - 18}" rx="20" fill="#fff" fill-opacity=".55" stroke="{INK}" stroke-width="2" stroke-dasharray="8 6"/>'
if titulo:
o += t(x + 6, y - 22, [titulo], 22, "b", "start")
if sub:
o += t(x + w - 6, y - 21, [sub], 14, "s", "end")
return o
def seta(pts, dupla=False, tracejada=False):
d = "M" + " L".join(f"{a},{b}" for a, b in pts)
ini = f' marker-start="url(#pt{P})"' if dupla else ""
cls = "seta tr" if tracejada else "seta"
return f'<path d="{d}" class="{cls}" marker-end="url(#pt{P})"{ini}/>'
def operador(cx, cy, simbolo="+", r=17):
return (f'<circle cx="{cx}" cy="{cy}" r="{r}" fill="#fff" stroke="{INK}" stroke-width="2.6"/>'
+ t(cx, cy + 1, [simbolo], 22))
def imagem(x, y, w, h, arq, legenda):
return (f'<image href="{arq}" x="{x}" y="{y}" width="{w}" height="{h}" preserveAspectRatio="xMidYMid slice"/>'
f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="6" fill="none" stroke="{INK}" stroke-width="2"/>'
+ t(x + w / 2, y + h + 22, [legenda], 15, "s"))
def painel(W, H):
return f'<rect x="1" y="1" width="{W - 2}" height="{H - 2}" rx="28" fill="#fff" stroke="{INK}" stroke-width="2.5"/>'
def legenda(x, y, itens):
o, cx = "", x
for cor, tracejada, txt in itens:
d = ' stroke-dasharray="6 5"' if tracejada else ""
o += f'<rect x="{cx}" y="{y - 12}" width="34" height="24" rx="6" fill="{cor[0]}" stroke="{cor[1]}" stroke-width="2.4"{d}/>'
o += t(cx + 44, y, [txt], 15, "s", "start")
cx += 44 + len(txt) * 9.4 + 34
return o
# ------------------------------------------------------------------ slide 7
def diag7():
"""Robô em cima; o quadro da câmera vai para o Sistema 1 e o Sistema 2 em paralelo; as saídas dos dois
se juntam em 'reflexos + coordenação', que vira o comando e volta para o robô."""
global P
P = "7"
W, H = 1184, 860
o = [f'<svg class="dg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" xmlns="http://www.w3.org/2000/svg">',
ESTILO, defs(P), painel(W, H)]
cx = W / 2
o.append(legenda(700, 34, [(AZUL, False, "pré-treinado"), (AMARELO, False, "saída"), (BRANCO, True, "próxima etapa")]))
# robô e quadro RGB
o.append(f'<use href="#robo{P}" x="{cx - 64}" y="26" width="128" height="160"/>')
o.append(t(cx, 206, ["Robô"], 22))
o.append(t(cx, 228, ["câmera · mecanum"], 13, "s"))
o.append(seta([(cx, 240), (cx, 256)]))
o.append(imagem(cx - 95, 260, 190, 104, "img/camera.jpg", "Quadro RGB"))
# divisão para os dois sistemas, em paralelo
g1x, g2x, gw, gy, gh = 40, 624, 520, 444, 324
c1, c2 = g1x + gw / 2, g2x + gw / 2
o.append(f'<path d="M{cx},390 L{cx},400 M{c1},400 L{c2},400" class="seta"/>')
o.append(seta([(c1, 400), (c1, gy - 4)]))
o.append(seta([(c2, 400), (c2, gy - 4)]))
o.append(f'<circle cx="{cx}" cy="400" r="5" fill="{INK}"/>')
# ---------- Sistema 1
o.append(grupo(g1x, gy, gw, gh, VERDE, "Sistema 1", "reflexo · rápido"))
o.append(caixa(g1x + 30, gy + 24, gw - 60, 56, ["Depth Anything V2 Small"], AZUL, "pré-treinado · 24,8 M", 18))
o.append(seta([(g1x + 126, gy + 84), (g1x + 126, gy + 106)]))
o.append(imagem(g1x + 36, gy + 112, 180, 100, "img/depth.jpg", "Profundidade monocular"))
o.append(seta([(g1x + 216, gy + 162), (g1x + 266, gy + 162)]))
o.append(caixa(g1x + 270, gy + 134, gw - 300, 56, ["Prevenção de", "colisões"], AMARELO, tam=17))
o.append(t(c1, gy + gh - 26, ["~10 ms por quadro"], 13, "s"))
# S1 -> S2
o.append(seta([(g1x + gw, gy + 150), (g2x, gy + 150)]))
o.append(t((g1x + gw + g2x) / 2, gy + 136, ["profund."], 12, "s"))
# ---------- Sistema 2
o.append(grupo(g2x, gy, gw, gh, ROXO, "Sistema 2", "deliberação · lento"))
xa, xb = g2x + 130, g2x + gw - 130 # centros das colunas V-SLAM e VLAM
o.append(caixa(xa - 100, gy + 16, 200, 38, ["V-SLAM"], VERMELHO, tracejada=True))
o.append(caixa(xb - 100, gy + 16, 200, 38, ["🦜 VLAM"], AZUL, tracejada=True))
o.append(seta([(xa, gy + 54), (xa, gy + 70)]))
o.append(seta([(xb, gy + 54), (xb, gy + 70)]))
# V-SLAM: imagem pixelizada (mapa/pontos); VLAM: imagem RGB com a frase que o modelo "diz"
iw, ih = 116, 64
o.append(f'<image href="img/camera_pixel.png" x="{xa - iw / 2}" y="{gy + 74}" width="{iw}" height="{ih}" preserveAspectRatio="xMidYMid slice" style="image-rendering: pixelated"/>'
f'<rect x="{xa - iw / 2}" y="{gy + 74}" width="{iw}" height="{ih}" rx="5" fill="none" stroke="{INK}" stroke-width="2"/>')
o.append(f'<image href="img/camera.jpg" x="{xb - iw / 2}" y="{gy + 74}" width="{iw}" height="{ih}" preserveAspectRatio="xMidYMid slice"/>'
f'<rect x="{xb - iw / 2}" y="{gy + 74 + ih - 20}" width="{iw}" height="20" fill="#000" fill-opacity=".6"/>'
f'<text x="{xb}" y="{gy + 74 + ih - 6}" font-size="13" text-anchor="middle" font-style="italic" font-weight="700" style="fill:#fff">Veni, vidi, vici</text>'
f'<rect x="{xb - iw / 2}" y="{gy + 74}" width="{iw}" height="{ih}" rx="5" fill="none" stroke="{INK}" stroke-width="2"/>')
o.append(seta([(xa, gy + 140), (xa, gy + 160), (c2 - 21, gy + 160)]))
o.append(seta([(xb, gy + 140), (xb, gy + 160), (c2 + 21, gy + 160)]))
o.append(operador(c2, gy + 160, r=15))
o.append(seta([(c2, gy + 175), (c2, gy + 190)]))
o.append(caixa(g2x + 90, gy + 194, gw - 180, 44, ["S2E + ViNT"], AZUL, "hoje · pré-treinados · Nav. Model Zoo", 17))
o.append(seta([(c2, gy + 242), (c2, gy + 256)]))
o.append(caixa(g2x + 90, gy + 260, gw - 180, 36, ["Planejamento de rota"], AMARELO, tam=16))
# ---------- junção: reflexos + coordenação -> comando
by = 808
o.append(seta([(c1, gy + gh), (c1, by), (cx - 214, by)]))
o.append(seta([(c2, gy + gh), (c2, by), (cx + 214, by)]))
o.append(caixa(cx - 210, by - 28, 420, 56, ["Reflexos + coordenação"], ROXO, "comando · vx · vy · giro", 19))
# volta para o robô
o.append(seta([(cx, by + 28), (cx, 846), (16, 846), (16, 106), (cx - 70, 106)]))
o.append(t(250, 838, ["atuação: rodas mecanum"], 13, "s"))
o.append("</svg>")
return "".join(o)
# ------------------------------------------------------------------ slide 8
def diag8():
"""Servidor no topo, app embaixo à esquerda e robô embaixo à direita, ligados por diagonais."""
global P
P = "8"
W, H = 1728, 680
o = [f'<svg class="dg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" xmlns="http://www.w3.org/2000/svg">',
ESTILO, defs(P), painel(W, H)]
# ---------- servidor (topo, centro)
sx, sw, sy, sh = 604, 520, 60, 352
o.append(grupo(sx, sy, sw, sh, VERDE, "Servidor", "robomovel-server · Flask + Flask-Sock · ONNX + CUDA"))
o.append(caixa(sx + 28, 82, 190, 46, ["REST"], AMARELO, "/api/…", 17))
o.append(caixa(sx + 28, 142, 190, 46, ["WebSocket"], AZUL, "/ws/app", 17))
o.append(caixa(sx + sw - 218, 112, 190, 46, ["WebSocket"], AZUL, "/ws/robo", 17))
o.append(caixa(sx + 28, 236, sw - 56, 48, ["Sistema 1 · Depth Anything V2 Small"], VERDE, "pré-treinado · profundidade", 16))
o.append(caixa(sx + 28, 340, sw - 56, 48, ["Sistema 2 · S2E + ViNT"], VERDE, "pré-treinados · planejamento de rota", 16))
# fluxo interno, com folga de ~8 px entre as setas e as caixas
o.append(seta([(sx + 123, 196), (sx + 123, 228)]))
o.append(t(sx + 106, 214, ["comandos"], 12, "s", "end"))
o.append(seta([(sx + sw - 123, 166), (sx + sw - 123, 228)]))
o.append(t(sx + sw - 138, 200, ["quadros"], 12, "s", "end"))
o.append(seta([(sx + sw / 2, 292), (sx + sw / 2, 332)]))
o.append(seta([(sx + sw - 26, 364), (sx + sw - 17, 364), (sx + sw - 17, 135), (sx + sw - 24, 135)]))
o.append(t(sx + sw + 8, 236, ["controle"], 12, "s", "start"))
# ---------- cliente 1: app (embaixo, esquerda)
ax, aw, ay, ah = 40, 360, 350, 270
o.append(grupo(ax, ay, aw, ah, AMARELO, "Cliente 1 · App", "de teste · Kivy"))
o.append(f'<use href="#celular{P}" x="{ax + 26}" y="{ay + 22}" width="72" height="135"/>')
for i, txt in enumerate(["Joystick", "📍 Coordenadas no espaço", "Profundidade e rota"]):
o.append(caixa(ax + 112, ay + 24 + i * 48, aw - 136, 38, [txt], VERDE, tam=14 if len(txt) > 20 else 15))
o.append(t(ax + aw / 2, ay + 200, ["app temporário para testar a simulação;", "o app final será outro"], 12, "s", passo=16))
# ---------- cliente 2: robô (embaixo, direita)
rx_, rw, ry, rh = 1328, 360, 350, 270
o.append(grupo(rx_, ry, rw, rh, VERMELHO, "Cliente 2 · Robô", "real ou simulação"))
o.append(f'<use href="#robo{P}" x="{rx_ + 24}" y="{ry + 30}" width="96" height="120"/>')
o.append(caixa(rx_ + 136, ry + 30, rw - 160, 56, ["Simulação Godot"], VERDE, "hoje", 15))
o.append(caixa(rx_ + 136, ry + 100, rw - 160, 56, ["Firmware (Arduino)"], BRANCO, "próxima etapa · real", 15, tracejada=True))
o.append(t(rx_ + rw / 2, ry + 200, ["a mesma conexão serve aos dois"], 12, "s"))
# ---------- ligações diagonais (como no rascunho)
o.append(seta([(ax + aw + 4, ay + 50), (sx - 4, 110)], dupla=True, tracejada=True))
o.append(t(372, 226, ["REST · HTTP"], 15))
o.append(t(372, 248, ["POST comandos · GET imagens"], 12, "s"))
o.append(seta([(ax + aw + 4, ay + 110), (sx - 4, 175)], dupla=True))
o.append(t(560, 452, ["WebSocket · /ws/app"], 15))
o.append(t(560, 474, ["joystick · modo · rota ⇄ estado"], 12, "s"))
o.append(seta([(sx + sw + 4, 137), (rx_ - 4, ry + 60)], dupla=True))
o.append(t(1440, 184, ["WebSocket · /ws/robo"], 15))
o.append(t(1440, 232, ["câmera · estado →", "← controle · profundidade", "(o robô não usa REST)"], 12, "s", passo=17))
# legenda
ly = 652
o.append(seta([(40, ly), (110, ly)], dupla=True))
o.append(t(124, ly, ["WebSocket: conexão aberta, mensagens nos dois sentidos"], 15, "s", "start"))
o.append(seta([(700, ly), (770, ly)], dupla=True, tracejada=True))
o.append(t(784, ly, ["REST: pedido e resposta"], 15, "s", "start"))
o.append(legenda(1120, ly, [(AZUL, False, "interface"), (VERDE, False, "modelo pré-treinado")]))
o.append("</svg>")
return "".join(o)
def substituir(html, marca, svg):
return re.sub(rf"<!--{marca}-->.*?<!--/{marca}-->", lambda _m: f"<!--{marca}-->{svg}<!--/{marca}-->", html, flags=re.S)
if __name__ == "__main__":
f = AQUI / "index.html"
h = f.read_text()
h = substituir(h, "DIAG7", diag7())
h = substituir(h, "DIAG8", diag8())
f.write_text(h)
print("diagramas atualizados")