Next-Servo / index.html
Lamapi's picture
Publish tested Next AI Lab release
dd50617 verified
Raw History Blame Contribute Delete
4.6 kB
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Next Servo</title>
<style>
*{box-sizing:border-box}body{margin:0;background:#f3f6f1;color:#142c27;font:16px system-ui}
main{max-width:960px;margin:auto;padding:36px 20px}h1{font-size:clamp(42px,8vw,78px);letter-spacing:-.06em;margin:0}
p{line-height:1.55;color:#415a52}canvas,video{width:100%;display:block;border-radius:16px;background:#e4eee5}
button,select,input,textarea{font:inherit}button,select,input,textarea{padding:9px;border:1px solid #aabdaf;border-radius:8px;background:white}
button{background:#08775e;color:white;cursor:pointer;margin:8px 0}button:disabled{opacity:.5}
textarea{width:100%;font:16px monospace}a{color:#08644f}label{display:inline-block;margin:6px}
</style>
<main><h1>Next Servo</h1><p>Plan a collision-aware transfer and inspect each joint movement.</p>
<canvas id="map" width="720" height="480" aria-label="Arm and payload"></canvas>
<form id="form"><div id="fields"></div><button id="run" disabled>Plan transfer</button></form>
<label>Motion <input id="motion" type="range" value="0" min="0" max="1000"></label>
<p id="status" role="status">Loading planner...</p>
<video controls playsinline poster="preview.png" src="replay.mp4"></video>
<script type="module">
const el=id=>document.getElementById(id), pen=el("map").getContext("2d");
const inputs=["Pickup X","Pickup Y","Goal X","Goal Y","Obstacle X","Obstacle Y","Radius"].map(name=>{
const label=document.createElement("label"), input=document.createElement("input");
input.type="number";input.step="any";input.required=true;input.style.width="85px";
label.append(name+" ",input);el("fields").append(label);return input;
});
let py, route=[], scene, anim;
function xy([x,y]){return [360+105*x,240-105*y]}
function dot(p,r,color){pen.beginPath();pen.arc(...xy(p),r,0,Math.PI*2);pen.fillStyle=color;pen.fill()}
function line(points,color,width){pen.beginPath();points.forEach((p,i)=>i?pen.lineTo(...xy(p)):pen.moveTo(...xy(p)));pen.strokeStyle=color;pen.lineWidth=width;pen.lineCap="round";pen.stroke()}
function forward([a,b]){const e=[Math.cos(a),Math.sin(a)];return [e,[e[0]+Math.cos(a+b),e[1]+Math.sin(a+b)]]}
function draw(){
pen.fillStyle="#e4eee5";pen.fillRect(0,0,720,480);
for(let n=-2;n<=2;n+=.5){line([[n,-2],[n,2]],"#cadbcc",1);line([[-2,n],[2,n]],"#cadbcc",1)}
if(!scene)return;
const [start,target,[x,y,r]]=scene;
dot(start,6,"#647c74");dot(target,10,"#3376b5");dot([x,y],r*105,"#db9682");
if(!route.length)return;
const t=el("motion").value/1000*(route.length-1), i=Math.floor(t);
const q=route[i].map((a,j)=>a+(route[Math.min(i+1,route.length-1)][j]-a)*(t-i));
const [e,tip]=forward(q);
line([...route.slice(0,i+1).map(q=>forward(q)[1]),tip],"#359b83",3);
line([[0,0],e,tip],"#142c27",7);dot([0,0],8,"#142c27");dot(e,8,"#142c27");dot(tip,6.8,"#08775e");
}
function solve(){
cancelAnimationFrame(anim);
const [a,b,c,d,x,y,r]=inputs.map(input=>input.valueAsNumber);
if(Math.hypot(a,b)>=2||Math.hypot(c,d)>=2||r<=0||r>1){
el("status").textContent="Choose reachable endpoints and a radius between 0 and 1.";return;
}
scene=[[a,b],[c,d],[x,y,r]]; route=[];
try{
py.globals.set("request_text",JSON.stringify(scene));
route=JSON.parse(py.runPython("json.dumps(plan(*json.loads(request_text)))"));
el("status").textContent=route.length ? "Transfer planned · "+(route.length-1)+" edges" : "No route certified.";
el("motion").value=0;draw();
if(route.length){const start=performance.now();function play(t){el("motion").value=Math.min(1000,(t-start)/2.4);draw();if(el("motion").value<1000)anim=requestAnimationFrame(play)}anim=requestAnimationFrame(play)}
}catch(error){el("status").textContent=error.message;draw()}
}
el("form").onsubmit=e=>{e.preventDefault();solve()};
el("motion").oninput=()=>{cancelAnimationFrame(anim);draw()};
draw();
try{
const indexURL="https://cdn.jsdelivr.net/pyodide/v0.27.7/full/";
py=await (await import(indexURL+"pyodide.mjs")).loadPyodide({indexURL});
const res=await fetch("servo.py");if(!res.ok)throw Error("Planner source unavailable");
py.runPython((await res.text()).replace(/^\uFEFF/,"")+"\nimport json");
JSON.parse(py.runPython("json.dumps(DEMOS[0])")).flat().forEach((n,i)=>inputs[i].value=n);
el("run").disabled=false;solve();
}catch(error){el("status").textContent="Could not load planner. "+error.message}
</script>
<p><a href="https://huggingface.co/thelamapi/Next-Servo">Model card and source</a></p>
</main></html>