diff --git a/app/page.tsx b/app/page.tsx index bb2839a..fac6573 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -67,16 +67,21 @@ export default function RobotDashboard() { if (activeGp) { const rawX = activeGp.axes[0]; - const maju = activeGp.buttons[6].value; // RT untuk maju - const mundur = activeGp.buttons[7].value; // LT untuk mundur + // SESUAI PERMINTAAN: RT(7) Maju, LT(6) Mundur + const maju = activeGp.buttons[7].value; + const mundur = activeGp.buttons[6].value; + + // PERBAIKAN 1: Karena Pi minta nilai minus untuk maju, pengurangannya dibalik (mundur - maju) const throttle = mundur - maju; + currentX = Math.abs(rawX) > 0.15 ? Number(rawX.toFixed(2)) : 0; currentY = Number(throttle.toFixed(2)); } } } else if (controlMode === 'keyboard') { - currentY = (keysRef.current.up ? 1 : 0) - (keysRef.current.down ? 1 : 0); + // PERBAIKAN 2: Keyboard disamakan. W/Up (maju) menghasilkan minus (-1), S/Down menghasilkan plus (+1) + currentY = (keysRef.current.down ? 1 : 0) - (keysRef.current.up ? 1 : 0); currentX = (keysRef.current.right ? 1 : 0) - (keysRef.current.left ? 1 : 0); } @@ -95,13 +100,13 @@ export default function RobotDashboard() { }; }, [controlMode, PI_IP]); - // --- PERBAIKAN VISUALIZER --- - // Membatasi titik hijau agar tidak menembus batas lingkaran (radius 48px - setengah ukuran dot 12px) + // --- PERBAIKAN 3: VISUALIZER --- const maxRadius = 36; - // Nilai input stik (-1 sampai 1) dikali dengan radius maksimal const dotX = steering.x * maxRadius; - // Sumbu Y dibalik (* -1) karena di CSS titik Y=0 ada di atas, sedangkan maju (positif) inginnya ke atas - const dotY = steering.y * -1 * maxRadius; + + // Karena 'maju' nilainya sudah minus (-), dan di CSS nilai minus (-) membuat titik NAIK KE ATAS, + // maka kita HAPUS perkalian (* -1) yang sebelumnya. Sekarang titiknya akan maju sempurna! + const dotY = steering.y * maxRadius; return (
@@ -132,7 +137,6 @@ export default function RobotDashboard() { Live Feed
- {/* PERBAIKAN KAMERA HP: Menggunakan img standar dengan error fallback */} {/* eslint-disable-next-line @next/next/no-img-element */}
Visualizer (X / Y)
- - {/* PERBAIKAN VISUALIZER CSS */}
- {/* Grid Crosshair Tengah */}
- - {/* Titik Hijau */}
-
X: {steering.x} Y: {steering.y}