File size: 951 Bytes
cf34346
b8c72c0
 
 
 
 
 
 
 
 
 
 
 
 
 
cf34346
b8c72c0
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const robotIp = "http://127.0.0.1:5001"
window.onload = () => {
    const container = document.getElementById("sliders");
    for (let i = 0; i < 6; i++) {
        const label = document.createElement("label");
        label.innerText = `Motor ${i}`;
        const input = document.createElement("input");
        input.type = "range";
        input.min = 0;
        input.max = 100;
        input.value = 0;
        input.oninput = () => {
            fetch(`${robotIp}/motor_control`, {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ [`motor_${i}`]: parseFloat(input.value) }),
            }).catch(err => console.error("Send error:", err));
        };
        container.appendChild(label);
        container.appendChild(document.createElement("br"));
        container.appendChild(input);
        container.appendChild(document.createElement("br"));
    }
};