tambahkan 3D object menggunakan Three.js. di bagian HUD Section di halaman web berdasarkan metode yang digunakan pada example di bawah ini
Browse filesGunakan metode yang sama seperti implementasi di bawah ini namun untuk scala menyesuaikan ukuran object gambar dengan canvas. nama Model Flying drone_.glb. tujuan menambahkan 3d ini agar sebagai monitor realtime dengan kondisi yaw pitch roll dan lainnya pada drone
<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8" />
<title>Drone Tuner — Full (Flying drone_.glb)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
:root{
--bg:#071021; --panel:#071625; --accent:#00b4d8; --muted:#94a3b8;
}
html,body{height:100%;margin:0;font-family:Inter,system-ui,Segoe UI,Arial;background:linear-gradient(180deg,var(--bg),#04121a);color:#e6eef6}
#app{display:flex;height:100vh;gap:12px;padding:12px;box-sizing:border-box}
#canvas-wrap{flex:1;border-radius:8px;overflow:hidden;background:#051225;display:flex;flex-direction:column;min-width:0}
#scene-container{flex:1;position:relative}
#controls{width:420px;min-width:320px;background:linear-gradient(180deg,var(--panel),#052033);border-radius:8px;padding:14px;overflow:auto}
h2{margin:4px 0 12px 0;font-size:18px}
.group{margin-bottom:12px;background:rgba(255,255,255,0.02);padding:10px;border-radius:8px}
label{display:block;font-size:13px;color:var(--muted);margin-bottom:6px}
input[type="range"]{width:100%}
.value{min-width:54px;text-align:right;font-variant-numeric:tabular-nums}
button{background:var(--accent);color:#021019;border:none;padding:8px 10px;border-radius:6px;cursor:pointer;font-weight:600}
button.secondary{background:transparent;border:1px solid rgba(255,255,255,0.06);color:var(--muted)}
.small{font-size:12px;color:var(--muted)}
.status{padding:8px 10px;border-radius:6px;background:rgba(255,255,255,0.02);font-size:13px;margin-top:8px}
#dropZone{border:2px dashed rgba(255,255,255,0.03);padding:10px;border-radius:6px;text-align:center;color:var(--muted);cursor:pointer}
pre.small{white-space:pre-wrap;font-size:12px;color:var(--muted);background:rgba(255,255,255,0.01);padding:8px;border-radius:6px}
footer.small{margin-top:10px;color:var(--muted)}
#loadingOverlay{position:absolute;left:8px;top:8px;padding:8px 10px;border-radius:6px;background:rgba(0,0,0,0.4);font-size:13px}
</style>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.158.0/build/three.module.js",
"OrbitControls": "https://unpkg.com/three@0.158.0/examples/jsm/controls/OrbitControls.js",
"GLTFLoader": "https://unpkg.com/three@0.158.0/examples/jsm/loaders/GLTFLoader.js",
"OBJLoader": "https://unpkg.com/three@0.158.0/examples/jsm/loaders/OBJLoader.js"
}
}
</script>
</head>
<body>
<div id="app">
<div id="canvas-wrap">
<div style="padding:10px;display:flex;justify-content:space-between;align-items:center">
<div style="font-weight:700">Drone Tuner — Realtime 3D</div>
<div class="small">Orbit/zoom: mouse • CTRL+drag to pan</div>
</div>
<div id="scene-container">
<div id="loadingOverlay" style="display:none">Memuat model...</div>
</div>
</div>
<div id="controls">
<h2>Kontrol & Model</h2>
<div class="group">
<strong>Model</strong>
<div id="dropZone">Klik / drag & drop file model (.glb .gltf .obj) atau biarkan default (Flying drone_.glb)</div>
<input id="fileInput" type="file" accept=".glb,.gltf,.obj" style="display:none" />
<div style="display:flex;gap:8px;margin-top:8px">
<button id="chooseBtn">Pilih Model</button>
<button id="resetModel" class="secondary">Reset ke default</button>
</div>
<div id="modelInfo" class="small" style="margin-top:8px">Model default: <strong>Flying drone_.glb</strong> (harus ditempatkan di folder yang sama dengan file ini)</div>
</div>
<div class="group">
<strong>Transform Model</strong>
<div style="margin-top:6px">
<label>Scale <span id="scaleVal" class="value">1.00</span></label>
<input id="scale" type="range" min="0.01" max="5" step="0.01" value="1" />
</div>
<div style="margin-top:6px">
<label>Rotate X <span id="rxVal" class="value">0°</span></label>
<input id="rx" type="range" min="-180" max="180" step="1" value="0" />
</div>
<div style="margin-top:6px">
<label>Rotate Y <span id="ryVal" class="value">0°</span></label>
<input id="ry" type="range" min="-180" max="180" step="1" value="0" />
</div>
<div style="margin-top:6px">
<label>Rotate Z <span id="rzVal" class="value">0°</span></label>
<input id="rz" type="range" min="-180" max="180" step="1" value="0" />
</div>
<div style="display:flex;gap:8px;margin-top:8px">
<button id="applyTransform" class="secondary">Apply Transform</button>
</div>
</div>
<div class="group">
<strong>Attitude (yaw / pitch / roll)</strong>
<div style="margin-top:6px">
<label>Yaw <span id="yawVal" class="value">0°</span></label>
<input id="yaw" type="range" min="-180" max="180" step="0.1" value="0" />
</div>
<div style="margin-top:6px">
<label>Pitch <span id="pitchVal" class="value">0°</span></label>
<input id="pitch" type="range" min="-90" max="90" step="0.1" value="0" />
</div>
<div style="margin:6px 0 0 0">
<label>Roll <span id="rollVal" class="value">0°</span></label>
<input id="roll" type="range" min="-180" max="180" step="0.1" value="0" />
</div>
<div style="display:flex;gap:8px;margin-top:8px">
<button id="applyManualBtn">Apply Manual</button>
<button id="resetAttBtn" class="secondary">Reset Attitude</button>
</div>
<div style="margin-top:8px">
<label><input type="checkbox" id="smoothChk" checked /> Smoothing gerakan (visual)</label>
</div>
</div>
<div class="group">
<strong>PID Tuning</strong>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:6px">
<div>
<label>P <span id="pVal" class="value">1.00</span></label>
<input id="p" type="range" min="0" max="20" step="0.01" value="1.0" />
</div>
<div>
<label>I <span id="iVal" class="value">0.00</span></label>
<input id="i" type="range" min="0" max="10" step="0.001" value="0.0" />
</div>
<div>
<label>D <span id="dVal" class="value">0.05</span></label>
<input id="d" type="range" min="0" max="5" step="0.001" value="0.05" />
</div>
<div>
<label>Trim <span id="trimVal" class="value">0</span></label>
<input id="trim" type="range" min="-100" max="100" step="1" value="0" />
</div>
</div>
<div style="display:flex;gap:8px;margin-top:8px">
<button id="sendPidBtn">Send PID</button>
<button id="savePidBtn" class="secondary">Save</button>
<button id="loadPidBtn" class="secondary">Load</button>
</div>
<div style="margin-top:8px">
<label><input type="checkbox" id="autoSendPid" /> Auto-send saat slider berubah</label>
</div>
</div>
<div class="group">
<strong>Serial / Telemetry</strong>
<div style="display:flex;gap:8px;align-items:center;justify-content:space-between">
<div>
<div class="small">Baud</div>
<select id="baud"><option>115200</option><option>57600</option><option>38400</option><option>9600</option></select>
</div>
<div style="display:flex;gap:8px">
<button id="connectBtn">Connect</button>
<button id="disconnectBtn" class="secondary">Disconnect</button>
</div>
</div>
<div style="margin-top:8px" class="flex-between">
<div class="small">Status</div>
<div id="portStatus" class="status">Not connected</div>
</div>
<div style="margin-top:8px">
<label><input type="checkbox" id="simulate" /> Simulate telemetry (tanpa hardware)</label>
</div>
<div style="margin-top:8px">
<div class="small">Last received:</div>
<div id="lastReceived" class="status">—</div>
</div>
<div style="margin-top:8px">
<label>Raw send</label>
<div style="display:flex;gap:8px">
<input id="rawText" placeholder='Contoh: PID 1.0 0.0 0.05' style="flex:1" />
<button id="sendRawBtn">Send</button>
</div>
</div>
</div>
<pre class="small">
Format telemetry yang didukung (contoh):
Y:10.2,P:-3.4,R:1.5
{"yaw":10,"pitch":-3.4,"roll":1.5}
10.2,-3.4,1.5
</pre>
<footer class="small">Jalankan halaman ini via HTTPS atau <code>http://localhost</code>. Web Serial hanya bekerja di Chrome/Edge (Chromium)</footer>
</div>
</div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'OrbitControls';
import { GLTFLoader } from 'GLTFLoader';
import { OBJLoader } from 'OBJLoader';
// ---------- Scene ----------
const container = document.getElementById('scene-container');
const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(container.clientWidth || window.innerWidth, container.clientHeight || window.innerHeight);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x051225);
const camera = new THREE.PerspectiveCamera(50, (container.clientWidth || window.innerWidth) / (container.clientHeight || window.innerHeight), 0.1, 1000);
camera.position.set(0, 3, 6);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
window.addEventListener('resize', onWindowRe
- README.md +9 -5
- index.html +1175 -19
|
@@ -1,10 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: undefined
|
| 3 |
+
colorFrom: gray
|
| 4 |
+
colorTo: gray
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
| 14 |
+
|
|
@@ -1,19 +1,1175 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="id">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Drone Control Center - Real Hardware</title>
|
| 7 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
--bg-dark: #0f1720;
|
| 11 |
+
--panel-dark: #1f2937;
|
| 12 |
+
--accent: #f59e0b;
|
| 13 |
+
--accent-light: #ffb020;
|
| 14 |
+
--text-light: #f8fafc;
|
| 15 |
+
--text-gray: #94a3b8;
|
| 16 |
+
--danger: #ef4444;
|
| 17 |
+
--success: #10b981;
|
| 18 |
+
--warning: #f59e0b;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
* {
|
| 22 |
+
margin: 0;
|
| 23 |
+
padding: 0;
|
| 24 |
+
box-sizing: border-box;
|
| 25 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
body {
|
| 29 |
+
background-color: var(--bg-dark);
|
| 30 |
+
color: var(--text-light);
|
| 31 |
+
overflow: hidden;
|
| 32 |
+
height: 100vh;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.container {
|
| 36 |
+
display: grid;
|
| 37 |
+
grid-template-rows: auto 1fr;
|
| 38 |
+
height: 100vh;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Header Styles */
|
| 42 |
+
.header {
|
| 43 |
+
background-color: var(--panel-dark);
|
| 44 |
+
padding: 12px 24px;
|
| 45 |
+
display: flex;
|
| 46 |
+
justify-content: space-between;
|
| 47 |
+
align-items: center;
|
| 48 |
+
border-bottom: 1px solid #334155;
|
| 49 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 50 |
+
flex-shrink: 0;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.app-title {
|
| 54 |
+
font-size: 1.5rem;
|
| 55 |
+
font-weight: 600;
|
| 56 |
+
color: var(--accent);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.connection-status {
|
| 60 |
+
display: flex;
|
| 61 |
+
align-items: center;
|
| 62 |
+
gap: 12px;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.serial-indicator {
|
| 66 |
+
display: flex;
|
| 67 |
+
align-items: center;
|
| 68 |
+
gap: 8px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.led {
|
| 72 |
+
width: 12px;
|
| 73 |
+
height: 12px;
|
| 74 |
+
border-radius: 50%;
|
| 75 |
+
background-color: var(--danger);
|
| 76 |
+
box-shadow: 0 0 4px rgba(239, 68, 68, 0.5);
|
| 77 |
+
transition: all 0.3s ease;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.led.connected {
|
| 81 |
+
background-color: var(--success);
|
| 82 |
+
box-shadow: 0 0 6px rgba(16, 185, 129, 0.7);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.led.connecting {
|
| 86 |
+
background-color: var(--warning);
|
| 87 |
+
box-shadow: 0 0 6px rgba(245, 158, 11, 0.7);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/* Main Content Layout */
|
| 91 |
+
.main-content {
|
| 92 |
+
display: grid;
|
| 93 |
+
grid-template-columns: 1fr 380px;
|
| 94 |
+
height: 100%;
|
| 95 |
+
overflow: hidden;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* Map Section */
|
| 99 |
+
.map-section {
|
| 100 |
+
position: relative;
|
| 101 |
+
overflow: hidden;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
#map {
|
| 105 |
+
height: 100%;
|
| 106 |
+
width: 100%;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.map-controls {
|
| 110 |
+
position: absolute;
|
| 111 |
+
top: 16px;
|
| 112 |
+
right: 16px;
|
| 113 |
+
z-index: 1000;
|
| 114 |
+
display: flex;
|
| 115 |
+
flex-direction: column;
|
| 116 |
+
gap: 8px;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.map-btn {
|
| 120 |
+
background-color: var(--panel-dark);
|
| 121 |
+
color: var(--text-light);
|
| 122 |
+
border: 1px solid #334155;
|
| 123 |
+
border-radius: 4px;
|
| 124 |
+
padding: 8px 16px;
|
| 125 |
+
cursor: pointer;
|
| 126 |
+
transition: all 0.2s ease;
|
| 127 |
+
font-size: 0.9rem;
|
| 128 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.map-btn:hover {
|
| 132 |
+
background-color: #374151;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.map-btn.active {
|
| 136 |
+
background-color: var(--accent);
|
| 137 |
+
color: var(--bg-dark);
|
| 138 |
+
font-weight: 600;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.map-btn:disabled {
|
| 142 |
+
opacity: 0.5;
|
| 143 |
+
cursor: not-allowed;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* Sidebar Styles - PERBAIKAN UTAMA DI SINI */
|
| 147 |
+
.sidebar {
|
| 148 |
+
background-color: var(--panel-dark);
|
| 149 |
+
border-left: 1px solid #334155;
|
| 150 |
+
display: flex;
|
| 151 |
+
flex-direction: column;
|
| 152 |
+
overflow: hidden;
|
| 153 |
+
height: 100%;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.sidebar-content {
|
| 157 |
+
display: flex;
|
| 158 |
+
flex-direction: column;
|
| 159 |
+
height: 100%;
|
| 160 |
+
overflow-y: auto; /* Scroll untuk seluruh konten sidebar */
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.sidebar-section {
|
| 164 |
+
padding: 16px;
|
| 165 |
+
border-bottom: 1px solid #334155;
|
| 166 |
+
flex-shrink: 0; /* Mencegah section menyusut */
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.sidebar-section-title {
|
| 170 |
+
font-size: 1rem;
|
| 171 |
+
font-weight: 600;
|
| 172 |
+
margin-bottom: 12px;
|
| 173 |
+
color: var(--accent);
|
| 174 |
+
display: flex;
|
| 175 |
+
justify-content: space-between;
|
| 176 |
+
align-items: center;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* Connection Controls */
|
| 180 |
+
.connection-controls {
|
| 181 |
+
display: flex;
|
| 182 |
+
flex-direction: column;
|
| 183 |
+
gap: 12px;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.connection-row {
|
| 187 |
+
display: flex;
|
| 188 |
+
gap: 8px;
|
| 189 |
+
align-items: center;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.connection-select {
|
| 193 |
+
flex: 1;
|
| 194 |
+
background-color: #0f1720;
|
| 195 |
+
border: 1px solid #334155;
|
| 196 |
+
border-radius: 4px;
|
| 197 |
+
color: var(--text-light);
|
| 198 |
+
padding: 6px 8px;
|
| 199 |
+
font-family: monospace;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.btn {
|
| 203 |
+
background-color: var(--accent);
|
| 204 |
+
color: var(--bg-dark);
|
| 205 |
+
border: none;
|
| 206 |
+
border-radius: 4px;
|
| 207 |
+
padding: 8px 16px;
|
| 208 |
+
cursor: pointer;
|
| 209 |
+
transition: all 0.2s ease;
|
| 210 |
+
font-weight: 600;
|
| 211 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.btn:hover {
|
| 215 |
+
background-color: var(--accent-light);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.btn:disabled {
|
| 219 |
+
opacity: 0.5;
|
| 220 |
+
cursor: not-allowed;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.btn.secondary {
|
| 224 |
+
background-color: #374151;
|
| 225 |
+
color: var(--text-light);
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.btn.secondary:hover {
|
| 229 |
+
background-color: #475569;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.btn.danger {
|
| 233 |
+
background-color: var(--danger);
|
| 234 |
+
color: white;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/* HUD Display */
|
| 238 |
+
.hud-display {
|
| 239 |
+
display: grid;
|
| 240 |
+
grid-template-columns: 1fr 1fr;
|
| 241 |
+
gap: 12px;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
.hud-item {
|
| 245 |
+
background-color: #0f1720;
|
| 246 |
+
border-radius: 4px;
|
| 247 |
+
padding: 12px;
|
| 248 |
+
text-align: center;
|
| 249 |
+
border: 1px solid #334155;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
.hud-value {
|
| 253 |
+
font-size: 1.2rem;
|
| 254 |
+
font-weight: 600;
|
| 255 |
+
font-family: monospace;
|
| 256 |
+
margin-top: 4px;
|
| 257 |
+
color: var(--accent);
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.hud-label {
|
| 261 |
+
font-size: 0.8rem;
|
| 262 |
+
color: var(--text-gray);
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/* Target Bar */
|
| 266 |
+
.target-bar {
|
| 267 |
+
display: flex;
|
| 268 |
+
flex-direction: column;
|
| 269 |
+
gap: 8px;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
.target-coords {
|
| 273 |
+
display: flex;
|
| 274 |
+
flex-direction: column;
|
| 275 |
+
gap: 4px;
|
| 276 |
+
margin-bottom: 8px;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
.coord-row {
|
| 280 |
+
display: flex;
|
| 281 |
+
justify-content: space-between;
|
| 282 |
+
font-family: monospace;
|
| 283 |
+
font-size: 0.9rem;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
.coord-label {
|
| 287 |
+
color: var(--text-gray);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
.distance-info {
|
| 291 |
+
background-color: #0f1720;
|
| 292 |
+
border-radius: 4px;
|
| 293 |
+
padding: 8px;
|
| 294 |
+
text-align: center;
|
| 295 |
+
border: 1px solid #334155;
|
| 296 |
+
margin-bottom: 8px;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
.distance-value {
|
| 300 |
+
font-size: 1.1rem;
|
| 301 |
+
font-weight: 600;
|
| 302 |
+
color: var(--accent);
|
| 303 |
+
font-family: monospace;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/* Tuning Controls */
|
| 307 |
+
.tuning-controls {
|
| 308 |
+
display: flex;
|
| 309 |
+
flex-direction: column;
|
| 310 |
+
gap: 16px;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
.slider-container {
|
| 314 |
+
display: flex;
|
| 315 |
+
flex-direction: column;
|
| 316 |
+
gap: 8px;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.slider-label {
|
| 320 |
+
display: flex;
|
| 321 |
+
justify-content: space-between;
|
| 322 |
+
font-size: 0.9rem;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
.slider-value {
|
| 326 |
+
font-family: monospace;
|
| 327 |
+
color: var(--accent);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
.slider {
|
| 331 |
+
-webkit-appearance: none;
|
| 332 |
+
width: 100%;
|
| 333 |
+
height: 6px;
|
| 334 |
+
background: #0f1720;
|
| 335 |
+
border-radius: 3px;
|
| 336 |
+
outline: none;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
.slider::-webkit-slider-thumb {
|
| 340 |
+
-webkit-appearance: none;
|
| 341 |
+
width: 16px;
|
| 342 |
+
height: 16px;
|
| 343 |
+
border-radius: 50%;
|
| 344 |
+
background: var(--accent);
|
| 345 |
+
cursor: pointer;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
.slider::-moz-range-thumb {
|
| 349 |
+
width: 16px;
|
| 350 |
+
height: 16px;
|
| 351 |
+
border-radius: 50%;
|
| 352 |
+
background: var(--accent);
|
| 353 |
+
cursor: pointer;
|
| 354 |
+
border: none;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
/* Log Display - PERBAIKAN SCROLL LOG */
|
| 358 |
+
.log-section {
|
| 359 |
+
flex: 1;
|
| 360 |
+
display: flex;
|
| 361 |
+
flex-direction: column;
|
| 362 |
+
min-height: 200px; /* Minimum height untuk log */
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
.log-container {
|
| 366 |
+
background-color: #0f1720;
|
| 367 |
+
border-radius: 4px;
|
| 368 |
+
padding: 12px;
|
| 369 |
+
flex: 1;
|
| 370 |
+
overflow-y: auto;
|
| 371 |
+
border: 1px solid #334155;
|
| 372 |
+
font-family: monospace;
|
| 373 |
+
font-size: 0.8rem;
|
| 374 |
+
min-height: 150px;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
.log-entry {
|
| 378 |
+
margin-bottom: 4px;
|
| 379 |
+
padding: 4px;
|
| 380 |
+
border-radius: 2px;
|
| 381 |
+
word-break: break-word;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
.log-entry.telemetry {
|
| 385 |
+
color: var(--success);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
.log-entry.command {
|
| 389 |
+
color: var(--accent);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
.log-entry.ack {
|
| 393 |
+
color: #60a5fa;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
.log-entry.error {
|
| 397 |
+
color: var(--danger);
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
.log-entry.info {
|
| 401 |
+
color: var(--text-gray);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.log-timestamp {
|
| 405 |
+
color: #6b7280;
|
| 406 |
+
margin-right: 8px;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
/* Responsive Design */
|
| 410 |
+
@media (max-width: 1024px) {
|
| 411 |
+
.main-content {
|
| 412 |
+
grid-template-columns: 1fr 320px;
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
@media (max-width: 768px) {
|
| 417 |
+
.main-content {
|
| 418 |
+
grid-template-columns: 1fr;
|
| 419 |
+
grid-template-rows: 1fr auto;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
.sidebar {
|
| 423 |
+
max-height: 50vh; /* Tinggi lebih besar di mobile */
|
| 424 |
+
border-left: none;
|
| 425 |
+
border-top: 1px solid #334155;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
.sidebar-content {
|
| 429 |
+
max-height: 100%;
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
/* Custom markers */
|
| 434 |
+
.drone-marker {
|
| 435 |
+
background: transparent !important;
|
| 436 |
+
border: none !important;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
.target-marker {
|
| 440 |
+
background: transparent !important;
|
| 441 |
+
border: none !important;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
/* Scrollbar styling */
|
| 445 |
+
.sidebar-content::-webkit-scrollbar {
|
| 446 |
+
width: 8px;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
.sidebar-content::-webkit-scrollbar-track {
|
| 450 |
+
background: #1f2937;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
.sidebar-content::-webkit-scrollbar-thumb {
|
| 454 |
+
background: #4b5563;
|
| 455 |
+
border-radius: 4px;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
.sidebar-content::-webkit-scrollbar-thumb:hover {
|
| 459 |
+
background: #6b7280;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
.log-container::-webkit-scrollbar {
|
| 463 |
+
width: 6px;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
.log-container::-webkit-scrollbar-track {
|
| 467 |
+
background: #0f1720;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
.log-container::-webkit-scrollbar-thumb {
|
| 471 |
+
background: #374151;
|
| 472 |
+
border-radius: 3px;
|
| 473 |
+
}
|
| 474 |
+
</style>
|
| 475 |
+
</head>
|
| 476 |
+
<body>
|
| 477 |
+
<div class="container">
|
| 478 |
+
<header class="header">
|
| 479 |
+
<div class="app-title">DRONE CONTROL CENTER - REAL HARDWARE</div>
|
| 480 |
+
<div class="connection-status">
|
| 481 |
+
<div class="serial-indicator">
|
| 482 |
+
<div class="led" id="connection-led"></div>
|
| 483 |
+
<span id="connection-status">Disconnected</span>
|
| 484 |
+
</div>
|
| 485 |
+
</div>
|
| 486 |
+
</header>
|
| 487 |
+
|
| 488 |
+
<main class="main-content">
|
| 489 |
+
<section class="map-section">
|
| 490 |
+
<div id="map"></div>
|
| 491 |
+
<div class="map-controls">
|
| 492 |
+
<button id="follow-drone-btn" class="map-btn">Follow Drone</button>
|
| 493 |
+
<button id="select-target-btn" class="map-btn">Pilih Target</button>
|
| 494 |
+
<button id="clear-path-btn" class="map-btn">Clear Path</button>
|
| 495 |
+
</div>
|
| 496 |
+
</section>
|
| 497 |
+
|
| 498 |
+
<aside class="sidebar">
|
| 499 |
+
<div class="sidebar-content">
|
| 500 |
+
<div class="sidebar-section">
|
| 501 |
+
<div class="sidebar-section-title">
|
| 502 |
+
<span>KONEKSI SERIAL</span>
|
| 503 |
+
</div>
|
| 504 |
+
<div class="connection-controls">
|
| 505 |
+
<div class="connection-row">
|
| 506 |
+
<select id="port-select" class="connection-select">
|
| 507 |
+
<option value="">Pilih Port Serial</option>
|
| 508 |
+
</select>
|
| 509 |
+
<button id="refresh-ports-btn" class="btn secondary">⟳</button>
|
| 510 |
+
</div>
|
| 511 |
+
<div class="connection-row">
|
| 512 |
+
<select id="baud-select" class="connection-select">
|
| 513 |
+
<option value="9600">9600</option>
|
| 514 |
+
<option value="19200">19200</option>
|
| 515 |
+
<option value="38400">38400</option>
|
| 516 |
+
<option value="57600">57600</option>
|
| 517 |
+
<option value="115200" selected>115200</option>
|
| 518 |
+
</select>
|
| 519 |
+
<button id="connect-btn" class="btn">Connect</button>
|
| 520 |
+
<button id="disconnect-btn" class="btn danger" disabled>Disconnect</button>
|
| 521 |
+
</div>
|
| 522 |
+
</div>
|
| 523 |
+
</div>
|
| 524 |
+
|
| 525 |
+
<div class="sidebar-section">
|
| 526 |
+
<div class="sidebar-section-title">
|
| 527 |
+
<span>HUD DRONE</span>
|
| 528 |
+
</div>
|
| 529 |
+
<div class="hud-display">
|
| 530 |
+
<div class="hud-item">
|
| 531 |
+
<div class="hud-label">POSISI</div>
|
| 532 |
+
<div class="hud-value" id="position-value">-,-</div>
|
| 533 |
+
</div>
|
| 534 |
+
<div class="hud-item">
|
| 535 |
+
<div class="hud-label">ALTITUDE</div>
|
| 536 |
+
<div class="hud-value" id="altitude-value">- m</div>
|
| 537 |
+
</div>
|
| 538 |
+
<div class="hud-item">
|
| 539 |
+
<div class="hud-label">YAW</div>
|
| 540 |
+
<div class="hud-value" id="yaw-value">-°</div>
|
| 541 |
+
</div>
|
| 542 |
+
<div class="hud-item">
|
| 543 |
+
<div class="hud-label">PITCH</div>
|
| 544 |
+
<div class="hud-value" id="pitch-value">-°</div>
|
| 545 |
+
</div>
|
| 546 |
+
</div>
|
| 547 |
+
</div>
|
| 548 |
+
|
| 549 |
+
<div class="sidebar-section">
|
| 550 |
+
<div class="sidebar-section-title">
|
| 551 |
+
<span>TARGET</span>
|
| 552 |
+
</div>
|
| 553 |
+
<div class="target-bar">
|
| 554 |
+
<div class="target-coords">
|
| 555 |
+
<div class="coord-row">
|
| 556 |
+
<span class="coord-label">Latitude:</span>
|
| 557 |
+
<span id="target-lat">-</span>
|
| 558 |
+
</div>
|
| 559 |
+
<div class="coord-row">
|
| 560 |
+
<span class="coord-label">Longitude:</span>
|
| 561 |
+
<span id="target-lon">-</span>
|
| 562 |
+
</div>
|
| 563 |
+
<div class="coord-row">
|
| 564 |
+
<span class="coord-label">Altitude:</span>
|
| 565 |
+
<span id="target-alt">-</span>
|
| 566 |
+
</div>
|
| 567 |
+
</div>
|
| 568 |
+
<div class="distance-info">
|
| 569 |
+
<div class="hud-label">JARAK KE TARGET</div>
|
| 570 |
+
<div class="distance-value" id="distance-value">-</div>
|
| 571 |
+
</div>
|
| 572 |
+
<button id="send-target-btn" class="btn" disabled>Kirim Target ke Drone</button>
|
| 573 |
+
</div>
|
| 574 |
+
</div>
|
| 575 |
+
|
| 576 |
+
<div class="sidebar-section">
|
| 577 |
+
<div class="sidebar-section-title">
|
| 578 |
+
<span>TUNING PID</span>
|
| 579 |
+
</div>
|
| 580 |
+
<div class="tuning-controls">
|
| 581 |
+
<div class="slider-container">
|
| 582 |
+
<div class="slider-label">
|
| 583 |
+
<span>Kp (Proporsional)</span>
|
| 584 |
+
<span class="slider-value" id="kp-value">1.0</span>
|
| 585 |
+
</div>
|
| 586 |
+
<input type="range" min="0" max="5" step="0.1" value="1.0" class="slider" id="kp-slider">
|
| 587 |
+
</div>
|
| 588 |
+
<div class="slider-container">
|
| 589 |
+
<div class="slider-label">
|
| 590 |
+
<span>Ki (Integral)</span>
|
| 591 |
+
<span class="slider-value" id="ki-value">0.1</span>
|
| 592 |
+
</div>
|
| 593 |
+
<input type="range" min="0" max="2" step="0.01" value="0.1" class="slider" id="ki-slider">
|
| 594 |
+
</div>
|
| 595 |
+
<div class="slider-container">
|
| 596 |
+
<div class="slider-label">
|
| 597 |
+
<span>Kd (Derivative)</span>
|
| 598 |
+
<span class="slider-value" id="kd-value">0.5</span>
|
| 599 |
+
</div>
|
| 600 |
+
<input type="range" min="0" max="5" step="0.1" value="0.5" class="slider" id="kd-slider">
|
| 601 |
+
</div>
|
| 602 |
+
<button id="send-tuning-btn" class="btn" disabled>Kirim Tuning</button>
|
| 603 |
+
</div>
|
| 604 |
+
</div>
|
| 605 |
+
|
| 606 |
+
<div class="sidebar-section log-section">
|
| 607 |
+
<div class="sidebar-section-title">
|
| 608 |
+
<span>LOG</span>
|
| 609 |
+
<button id="clear-log-btn" class="btn secondary" style="padding: 4px 8px; font-size: 0.8rem;">Clear</button>
|
| 610 |
+
</div>
|
| 611 |
+
<div class="log-container" id="log-container">
|
| 612 |
+
<!-- Log entries will be added here -->
|
| 613 |
+
</div>
|
| 614 |
+
</div>
|
| 615 |
+
</div>
|
| 616 |
+
</aside>
|
| 617 |
+
</main>
|
| 618 |
+
</div>
|
| 619 |
+
|
| 620 |
+
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
| 621 |
+
<script>
|
| 622 |
+
// Inisialisasi variabel global
|
| 623 |
+
let map;
|
| 624 |
+
let droneMarker;
|
| 625 |
+
let targetMarker;
|
| 626 |
+
let pathPolyline;
|
| 627 |
+
let pathCoordinates = [];
|
| 628 |
+
let isSelectingTarget = false;
|
| 629 |
+
let isFollowingDrone = false;
|
| 630 |
+
let currentPosition = null;
|
| 631 |
+
let targetPosition = null;
|
| 632 |
+
let serialPort = null;
|
| 633 |
+
let reader = null;
|
| 634 |
+
let writer = null;
|
| 635 |
+
let isConnected = false;
|
| 636 |
+
let logEntries = [];
|
| 637 |
+
let readBuffer = '';
|
| 638 |
+
|
| 639 |
+
// Inisialisasi peta
|
| 640 |
+
function initMap() {
|
| 641 |
+
// Default position (Bandung, Indonesia)
|
| 642 |
+
const defaultPosition = [-6.914744, 107.609810];
|
| 643 |
+
|
| 644 |
+
map = L.map('map').setView(defaultPosition, 15);
|
| 645 |
+
|
| 646 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
| 647 |
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
| 648 |
+
}).addTo(map);
|
| 649 |
+
|
| 650 |
+
// Buat ikon kustom untuk drone
|
| 651 |
+
const droneIcon = L.divIcon({
|
| 652 |
+
className: 'drone-marker',
|
| 653 |
+
html: `
|
| 654 |
+
<div style="
|
| 655 |
+
position: relative;
|
| 656 |
+
width: 30px;
|
| 657 |
+
height: 30px;
|
| 658 |
+
">
|
| 659 |
+
<div style="
|
| 660 |
+
position: absolute;
|
| 661 |
+
top: 50%;
|
| 662 |
+
left: 50%;
|
| 663 |
+
transform: translate(-50%, -50%);
|
| 664 |
+
width: 24px;
|
| 665 |
+
height: 24px;
|
| 666 |
+
background: #f59e0b;
|
| 667 |
+
border-radius: 50%;
|
| 668 |
+
border: 3px solid white;
|
| 669 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.5);
|
| 670 |
+
"></div>
|
| 671 |
+
<div style="
|
| 672 |
+
position: absolute;
|
| 673 |
+
top: 50%;
|
| 674 |
+
left: 50%;
|
| 675 |
+
transform: translate(-50%, -50%) rotate(45deg);
|
| 676 |
+
width: 0;
|
| 677 |
+
height: 0;
|
| 678 |
+
border-left: 8px solid transparent;
|
| 679 |
+
border-right: 8px solid transparent;
|
| 680 |
+
border-bottom: 12px solid #f59e0b;
|
| 681 |
+
"></div>
|
| 682 |
+
</div>
|
| 683 |
+
`,
|
| 684 |
+
iconSize: [30, 30],
|
| 685 |
+
iconAnchor: [15, 15]
|
| 686 |
+
});
|
| 687 |
+
|
| 688 |
+
// Tambahkan marker drone awal
|
| 689 |
+
droneMarker = L.marker(defaultPosition, {
|
| 690 |
+
icon: droneIcon,
|
| 691 |
+
zIndexOffset: 1000
|
| 692 |
+
}).addTo(map);
|
| 693 |
+
|
| 694 |
+
// Inisialisasi polyline untuk jejak lintasan
|
| 695 |
+
pathPolyline = L.polyline([], {
|
| 696 |
+
color: '#f59e0b',
|
| 697 |
+
weight: 3,
|
| 698 |
+
opacity: 0.7
|
| 699 |
+
}).addTo(map);
|
| 700 |
+
|
| 701 |
+
// Event listener untuk kontrol peta
|
| 702 |
+
document.getElementById('follow-drone-btn').addEventListener('click', toggleFollowDrone);
|
| 703 |
+
document.getElementById('select-target-btn').addEventListener('click', toggleSelectTarget);
|
| 704 |
+
document.getElementById('clear-path-btn').addEventListener('click', clearPath);
|
| 705 |
+
|
| 706 |
+
// Event listener untuk klik peta saat mode pemilihan target aktif
|
| 707 |
+
map.on('click', function(e) {
|
| 708 |
+
if (isSelectingTarget) {
|
| 709 |
+
setTarget(e.latlng.lat, e.latlng.lng);
|
| 710 |
+
}
|
| 711 |
+
});
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
// Toggle mode mengikuti drone
|
| 715 |
+
function toggleFollowDrone() {
|
| 716 |
+
const btn = document.getElementById('follow-drone-btn');
|
| 717 |
+
isFollowingDrone = !isFollowingDrone;
|
| 718 |
+
|
| 719 |
+
if (isFollowingDrone && currentPosition) {
|
| 720 |
+
btn.classList.add('active');
|
| 721 |
+
map.setView([currentPosition.lat, currentPosition.lng], map.getZoom());
|
| 722 |
+
addLogEntry('info', 'Map following drone');
|
| 723 |
+
} else {
|
| 724 |
+
btn.classList.remove('active');
|
| 725 |
+
addLogEntry('info', 'Map following disabled');
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
// Toggle mode pemilihan target
|
| 730 |
+
function toggleSelectTarget() {
|
| 731 |
+
const btn = document.getElementById('select-target-btn');
|
| 732 |
+
isSelectingTarget = !isSelectingTarget;
|
| 733 |
+
|
| 734 |
+
if (isSelectingTarget) {
|
| 735 |
+
btn.classList.add('active');
|
| 736 |
+
btn.textContent = 'Klik pada peta untuk set target';
|
| 737 |
+
addLogEntry('info', 'Target selection mode active');
|
| 738 |
+
} else {
|
| 739 |
+
btn.classList.remove('active');
|
| 740 |
+
btn.textContent = 'Pilih Target';
|
| 741 |
+
addLogEntry('info', 'Target selection cancelled');
|
| 742 |
+
}
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
// Set target pada peta
|
| 746 |
+
function setTarget(lat, lng, alt = 25) {
|
| 747 |
+
targetPosition = { lat, lng, alt };
|
| 748 |
+
|
| 749 |
+
// Hapus marker target lama jika ada
|
| 750 |
+
if (targetMarker) {
|
| 751 |
+
map.removeLayer(targetMarker);
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
// Buat ikon kustom untuk target
|
| 755 |
+
const targetIcon = L.divIcon({
|
| 756 |
+
className: 'target-marker',
|
| 757 |
+
html: `
|
| 758 |
+
<div style="
|
| 759 |
+
position: relative;
|
| 760 |
+
width: 24px;
|
| 761 |
+
height: 24px;
|
| 762 |
+
">
|
| 763 |
+
<div style="
|
| 764 |
+
position: absolute;
|
| 765 |
+
top: 50%;
|
| 766 |
+
left: 50%;
|
| 767 |
+
transform: translate(-50%, -50%);
|
| 768 |
+
width: 20px;
|
| 769 |
+
height: 20px;
|
| 770 |
+
background: #ef4444;
|
| 771 |
+
border-radius: 50%;
|
| 772 |
+
border: 3px solid white;
|
| 773 |
+
box-shadow: 0 0 10px rgba(239,68,68,0.7);
|
| 774 |
+
"></div>
|
| 775 |
+
<div style="
|
| 776 |
+
position: absolute;
|
| 777 |
+
top: 50%;
|
| 778 |
+
left: 50%;
|
| 779 |
+
transform: translate(-50%, -50%);
|
| 780 |
+
width: 30px;
|
| 781 |
+
height: 30px;
|
| 782 |
+
border: 2px solid #ef4444;
|
| 783 |
+
border-radius: 50%;
|
| 784 |
+
animation: pulse 1.5s infinite;
|
| 785 |
+
"></div>
|
| 786 |
+
</div>
|
| 787 |
+
<style>
|
| 788 |
+
@keyframes pulse {
|
| 789 |
+
0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
|
| 790 |
+
100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
|
| 791 |
+
}
|
| 792 |
+
</style>
|
| 793 |
+
`,
|
| 794 |
+
iconSize: [30, 30],
|
| 795 |
+
iconAnchor: [15, 15]
|
| 796 |
+
});
|
| 797 |
+
|
| 798 |
+
// Tambahkan marker target baru
|
| 799 |
+
targetMarker = L.marker([lat, lng], {
|
| 800 |
+
icon: targetIcon,
|
| 801 |
+
zIndexOffset: 900
|
| 802 |
+
}).addTo(map);
|
| 803 |
+
|
| 804 |
+
// Update UI dengan koordinat target
|
| 805 |
+
document.getElementById('target-lat').textContent = lat.toFixed(6);
|
| 806 |
+
document.getElementById('target-lon').textContent = lng.toFixed(6);
|
| 807 |
+
document.getElementById('target-alt').textContent = alt.toFixed(1) + ' m';
|
| 808 |
+
|
| 809 |
+
// Aktifkan tombol kirim target
|
| 810 |
+
document.getElementById('send-target-btn').disabled = false;
|
| 811 |
+
|
| 812 |
+
// Hitung dan tampilkan jarak jika ada posisi drone
|
| 813 |
+
if (currentPosition) {
|
| 814 |
+
updateDistance();
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
// Keluar dari mode pemilihan target
|
| 818 |
+
isSelectingTarget = false;
|
| 819 |
+
document.getElementById('select-target-btn').classList.remove('active');
|
| 820 |
+
document.getElementById('select-target-btn').textContent = 'Pilih Target';
|
| 821 |
+
|
| 822 |
+
addLogEntry('info', `Target set to: ${lat.toFixed(6)}, ${lng.toFixed(6)}, ${alt.toFixed(1)}m`);
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
// Kirim target ke drone
|
| 826 |
+
async function sendTargetToDrone() {
|
| 827 |
+
if (!targetPosition || !isConnected) return;
|
| 828 |
+
|
| 829 |
+
const targetData = {
|
| 830 |
+
cmd: "set_target",
|
| 831 |
+
lat: targetPosition.lat,
|
| 832 |
+
lon: targetPosition.lng,
|
| 833 |
+
alt: targetPosition.alt
|
| 834 |
+
};
|
| 835 |
+
|
| 836 |
+
const jsonString = JSON.stringify(targetData) + '\n';
|
| 837 |
+
|
| 838 |
+
try {
|
| 839 |
+
await writeToSerial(jsonString);
|
| 840 |
+
addLogEntry('command', `Sent target: ${jsonString.trim()}`);
|
| 841 |
+
} catch (error) {
|
| 842 |
+
addLogEntry('error', `Failed to send target: ${error.message}`);
|
| 843 |
+
}
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
// Update posisi drone
|
| 847 |
+
function updateDronePosition(lat, lng, alt, yaw, pitch, roll) {
|
| 848 |
+
currentPosition = { lat, lng, alt };
|
| 849 |
+
|
| 850 |
+
// Update marker drone
|
| 851 |
+
droneMarker.setLatLng([lat, lng]);
|
| 852 |
+
|
| 853 |
+
// Update path
|
| 854 |
+
pathCoordinates.push([lat, lng]);
|
| 855 |
+
pathPolyline.setLatLngs(pathCoordinates);
|
| 856 |
+
|
| 857 |
+
// Update HUD
|
| 858 |
+
document.getElementById('position-value').textContent = `${lat.toFixed(4)}, ${lng.toFixed(4)}`;
|
| 859 |
+
document.getElementById('altitude-value').textContent = `${alt.toFixed(1)} m`;
|
| 860 |
+
document.getElementById('yaw-value').textContent = `${yaw.toFixed(1)}°`;
|
| 861 |
+
document.getElementById('pitch-value').textContent = `${pitch.toFixed(1)}°`;
|
| 862 |
+
|
| 863 |
+
// Update jarak jika ada target
|
| 864 |
+
if (targetPosition) {
|
| 865 |
+
updateDistance();
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
// Ikuti drone jika mode aktif
|
| 869 |
+
if (isFollowingDrone) {
|
| 870 |
+
map.setView([lat, lng], map.getZoom());
|
| 871 |
+
}
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
// Hitung jarak menggunakan rumus Haversine
|
| 875 |
+
function calculateDistance(lat1, lon1, lat2, lon2) {
|
| 876 |
+
const R = 6371000; // Radius bumi dalam meter
|
| 877 |
+
const dLat = (lat2 - lat1) * Math.PI / 180;
|
| 878 |
+
const dLon = (lon2 - lon1) * Math.PI / 180;
|
| 879 |
+
const a =
|
| 880 |
+
Math.sin(dLat/2) * Math.sin(dLat/2) +
|
| 881 |
+
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
|
| 882 |
+
Math.sin(dLon/2) * Math.sin(dLon/2);
|
| 883 |
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
| 884 |
+
return R * c;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
// Update tampilan jarak
|
| 888 |
+
function updateDistance() {
|
| 889 |
+
if (!targetPosition || !currentPosition) return;
|
| 890 |
+
|
| 891 |
+
const distance = calculateDistance(
|
| 892 |
+
currentPosition.lat, currentPosition.lng,
|
| 893 |
+
targetPosition.lat, targetPosition.lng
|
| 894 |
+
);
|
| 895 |
+
|
| 896 |
+
document.getElementById('distance-value').textContent =
|
| 897 |
+
distance < 1000 ? `${distance.toFixed(1)} m` : `${(distance/1000).toFixed(2)} km`;
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
// Hapus jejak lintasan
|
| 901 |
+
function clearPath() {
|
| 902 |
+
pathCoordinates = [];
|
| 903 |
+
pathPolyline.setLatLngs([]);
|
| 904 |
+
addLogEntry('info', 'Flight path cleared');
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
// ==================== SERIAL COMMUNICATION ====================
|
| 908 |
+
|
| 909 |
+
// Cek dukungan Web Serial API
|
| 910 |
+
function checkSerialSupport() {
|
| 911 |
+
if (!navigator.serial) {
|
| 912 |
+
addLogEntry('error', 'Web Serial API tidak didukung di browser ini. Gunakan Chrome/Edge versi terbaru.');
|
| 913 |
+
document.getElementById('connect-btn').disabled = true;
|
| 914 |
+
return false;
|
| 915 |
+
}
|
| 916 |
+
return true;
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
// Koneksi ke port serial
|
| 920 |
+
async function connectSerial() {
|
| 921 |
+
if (!checkSerialSupport()) return;
|
| 922 |
+
|
| 923 |
+
try {
|
| 924 |
+
addLogEntry('info', 'Meminta akses port serial...');
|
| 925 |
+
|
| 926 |
+
// Minta izin pengguna untuk mengakses port serial
|
| 927 |
+
serialPort = await navigator.serial.requestPort();
|
| 928 |
+
|
| 929 |
+
const baudRate = parseInt(document.getElementById('baud-select').value);
|
| 930 |
+
addLogEntry('info', `Membuka port dengan baud rate ${baudRate}...`);
|
| 931 |
+
|
| 932 |
+
await serialPort.open({
|
| 933 |
+
baudRate: baudRate,
|
| 934 |
+
dataBits: 8,
|
| 935 |
+
stopBits: 1,
|
| 936 |
+
parity: 'none'
|
| 937 |
+
});
|
| 938 |
+
|
| 939 |
+
// Setup writer dan reader
|
| 940 |
+
writer = serialPort.writable.getWriter();
|
| 941 |
+
reader = serialPort.readable.getReader();
|
| 942 |
+
|
| 943 |
+
// Update status koneksi
|
| 944 |
+
isConnected = true;
|
| 945 |
+
updateConnectionStatus();
|
| 946 |
+
|
| 947 |
+
// Kirim handshake
|
| 948 |
+
await writeToSerial("BEGIN\n");
|
| 949 |
+
addLogEntry('info', 'Handshake sent: BEGIN');
|
| 950 |
+
|
| 951 |
+
// Mulai membaca data dari serial
|
| 952 |
+
readSerialData();
|
| 953 |
+
|
| 954 |
+
} catch (error) {
|
| 955 |
+
addLogEntry('error', `Koneksi gagal: ${error.message}`);
|
| 956 |
+
}
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
// Membaca data dari serial
|
| 960 |
+
async function readSerialData() {
|
| 961 |
+
try {
|
| 962 |
+
while (isConnected && reader) {
|
| 963 |
+
const { value, done } = await reader.read();
|
| 964 |
+
|
| 965 |
+
if (done) {
|
| 966 |
+
reader.releaseLock();
|
| 967 |
+
break;
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
// Decode data yang diterima
|
| 971 |
+
const text = new TextDecoder().decode(value);
|
| 972 |
+
readBuffer += text;
|
| 973 |
+
|
| 974 |
+
// Process complete lines
|
| 975 |
+
const lines = readBuffer.split('\n');
|
| 976 |
+
readBuffer = lines.pop() || ''; // Keep incomplete line in buffer
|
| 977 |
+
|
| 978 |
+
for (const line of lines) {
|
| 979 |
+
if (line.trim()) {
|
| 980 |
+
processIncomingData(line.trim());
|
| 981 |
+
}
|
| 982 |
+
}
|
| 983 |
+
}
|
| 984 |
+
} catch (error) {
|
| 985 |
+
if (isConnected) {
|
| 986 |
+
addLogEntry('error', `Error membaca data serial: ${error.message}`);
|
| 987 |
+
}
|
| 988 |
+
}
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
// Memproses data yang masuk dari Arduino
|
| 992 |
+
function processIncomingData(data) {
|
| 993 |
+
try {
|
| 994 |
+
const jsonData = JSON.parse(data);
|
| 995 |
+
|
| 996 |
+
if (jsonData.type === "telemetry") {
|
| 997 |
+
// Update posisi drone dengan data real dari Arduino
|
| 998 |
+
updateDronePosition(
|
| 999 |
+
jsonData.lat,
|
| 1000 |
+
jsonData.lon,
|
| 1001 |
+
jsonData.alt || 0,
|
| 1002 |
+
jsonData.yaw || 0,
|
| 1003 |
+
jsonData.pitch || 0,
|
| 1004 |
+
jsonData.roll || 0
|
| 1005 |
+
);
|
| 1006 |
+
addLogEntry('telemetry', `Position: ${jsonData.lat.toFixed(6)}, ${jsonData.lon.toFixed(6)}, Alt: ${jsonData.alt?.toFixed(1) || 0}m`);
|
| 1007 |
+
|
| 1008 |
+
} else if (jsonData.type === "ack") {
|
| 1009 |
+
addLogEntry('ack', `ACK received: ${jsonData.cmd} - ${jsonData.status}`);
|
| 1010 |
+
|
| 1011 |
+
} else if (jsonData.type === "error") {
|
| 1012 |
+
addLogEntry('error', `Drone error: ${jsonData.message}`);
|
| 1013 |
+
|
| 1014 |
+
} else if (jsonData.type === "status") {
|
| 1015 |
+
addLogEntry('info', `Drone status: ${jsonData.message}`);
|
| 1016 |
+
|
| 1017 |
+
} else {
|
| 1018 |
+
addLogEntry('info', `Unknown data: ${data}`);
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
} catch (e) {
|
| 1022 |
+
// Jika bukan JSON, tampilkan sebagai raw data
|
| 1023 |
+
if (data.length > 0) {
|
| 1024 |
+
addLogEntry('info', `Raw: ${data}`);
|
| 1025 |
+
}
|
| 1026 |
+
}
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
// Menulis data ke serial
|
| 1030 |
+
async function writeToSerial(data) {
|
| 1031 |
+
if (!writer) {
|
| 1032 |
+
throw new Error('Serial writer tidak tersedia');
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
const encoder = new TextEncoder();
|
| 1036 |
+
await writer.write(encoder.encode(data));
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
// Putuskan koneksi serial
|
| 1040 |
+
async function disconnectSerial() {
|
| 1041 |
+
try {
|
| 1042 |
+
if (reader) {
|
| 1043 |
+
await reader.cancel();
|
| 1044 |
+
reader = null;
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
if (writer) {
|
| 1048 |
+
writer.releaseLock();
|
| 1049 |
+
writer = null;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
if (serialPort) {
|
| 1053 |
+
await serialPort.close();
|
| 1054 |
+
serialPort = null;
|
| 1055 |
+
}
|
| 1056 |
+
|
| 1057 |
+
isConnected = false;
|
| 1058 |
+
updateConnectionStatus();
|
| 1059 |
+
addLogEntry('info', 'Serial disconnected');
|
| 1060 |
+
|
| 1061 |
+
} catch (error) {
|
| 1062 |
+
addLogEntry('error', `Error saat disconnect: ${error.message}`);
|
| 1063 |
+
}
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
// Update status koneksi di UI
|
| 1067 |
+
function updateConnectionStatus() {
|
| 1068 |
+
const led = document.getElementById('connection-led');
|
| 1069 |
+
const status = document.getElementById('connection-status');
|
| 1070 |
+
const connectBtn = document.getElementById('connect-btn');
|
| 1071 |
+
const disconnectBtn = document.getElementById('disconnect-btn');
|
| 1072 |
+
const sendTuningBtn = document.getElementById('send-tuning-btn');
|
| 1073 |
+
|
| 1074 |
+
if (isConnected) {
|
| 1075 |
+
led.className = 'led connected';
|
| 1076 |
+
status.textContent = 'Connected';
|
| 1077 |
+
connectBtn.disabled = true;
|
| 1078 |
+
disconnectBtn.disabled = false;
|
| 1079 |
+
sendTuningBtn.disabled = false;
|
| 1080 |
+
} else {
|
| 1081 |
+
led.className = 'led';
|
| 1082 |
+
status.textContent = 'Disconnected';
|
| 1083 |
+
connectBtn.disabled = false;
|
| 1084 |
+
disconnectBtn.disabled = true;
|
| 1085 |
+
sendTuningBtn.disabled = true;
|
| 1086 |
+
}
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
// Kirim parameter tuning PID ke Arduino
|
| 1090 |
+
async function sendTuningParameters() {
|
| 1091 |
+
if (!isConnected) return;
|
| 1092 |
+
|
| 1093 |
+
const kp = parseFloat(document.getElementById('kp-value').textContent);
|
| 1094 |
+
const ki = parseFloat(document.getElementById('ki-value').textContent);
|
| 1095 |
+
const kd = parseFloat(document.getElementById('kd-value').textContent);
|
| 1096 |
+
|
| 1097 |
+
const tuningData = {
|
| 1098 |
+
cmd: "set_pid",
|
| 1099 |
+
kp: kp,
|
| 1100 |
+
ki: ki,
|
| 1101 |
+
kd: kd
|
| 1102 |
+
};
|
| 1103 |
+
|
| 1104 |
+
const jsonString = JSON.stringify(tuningData) + '\n';
|
| 1105 |
+
|
| 1106 |
+
try {
|
| 1107 |
+
await writeToSerial(jsonString);
|
| 1108 |
+
addLogEntry('command', `Sent PID tuning: Kp=${kp}, Ki=${ki}, Kd=${kd}`);
|
| 1109 |
+
} catch (error) {
|
| 1110 |
+
addLogEntry('error', `Failed to send tuning: ${error.message}`);
|
| 1111 |
+
}
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
// Tambah entri log
|
| 1115 |
+
function addLogEntry(type, message) {
|
| 1116 |
+
const timestamp = new Date().toLocaleTimeString();
|
| 1117 |
+
const logEntry = document.createElement('div');
|
| 1118 |
+
logEntry.className = `log-entry ${type}`;
|
| 1119 |
+
logEntry.innerHTML = `<span class="log-timestamp">[${timestamp}]</span> ${message}`;
|
| 1120 |
+
|
| 1121 |
+
const logContainer = document.getElementById('log-container');
|
| 1122 |
+
logContainer.appendChild(logEntry);
|
| 1123 |
+
logContainer.scrollTop = logContainer.scrollHeight;
|
| 1124 |
+
|
| 1125 |
+
// Simpan entri log (maks 200 entri)
|
| 1126 |
+
logEntries.push({ type, message, timestamp });
|
| 1127 |
+
if (logEntries.length > 200) {
|
| 1128 |
+
logEntries.shift();
|
| 1129 |
+
}
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
// Hapus log
|
| 1133 |
+
function clearLog() {
|
| 1134 |
+
document.getElementById('log-container').innerHTML = '';
|
| 1135 |
+
logEntries = [];
|
| 1136 |
+
addLogEntry('info', 'Log cleared');
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
// ==================== INITIALIZATION ====================
|
| 1140 |
+
|
| 1141 |
+
// Inisialisasi saat halaman dimuat
|
| 1142 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 1143 |
+
initMap();
|
| 1144 |
+
|
| 1145 |
+
// Event listeners untuk kontrol serial
|
| 1146 |
+
document.getElementById('connect-btn').addEventListener('click', connectSerial);
|
| 1147 |
+
document.getElementById('disconnect-btn').addEventListener('click', disconnectSerial);
|
| 1148 |
+
document.getElementById('send-target-btn').addEventListener('click', sendTargetToDrone);
|
| 1149 |
+
document.getElementById('send-tuning-btn').addEventListener('click', sendTuningParameters);
|
| 1150 |
+
document.getElementById('clear-log-btn').addEventListener('click', clearLog);
|
| 1151 |
+
|
| 1152 |
+
// Event listeners untuk slider PID
|
| 1153 |
+
document.getElementById('kp-slider').addEventListener('input', function() {
|
| 1154 |
+
document.getElementById('kp-value').textContent = this.value;
|
| 1155 |
+
});
|
| 1156 |
+
|
| 1157 |
+
document.getElementById('ki-slider').addEventListener('input', function() {
|
| 1158 |
+
document.getElementById('ki-value').textContent = this.value;
|
| 1159 |
+
});
|
| 1160 |
+
|
| 1161 |
+
document.getElementById('kd-slider').addEventListener('input', function() {
|
| 1162 |
+
document.getElementById('kd-value').textContent = this.value;
|
| 1163 |
+
});
|
| 1164 |
+
|
| 1165 |
+
// Cek dukungan Web Serial
|
| 1166 |
+
checkSerialSupport();
|
| 1167 |
+
|
| 1168 |
+
// Tambah beberapa log awal
|
| 1169 |
+
addLogEntry('info', 'Drone Control Center initialized - REAL HARDWARE MODE');
|
| 1170 |
+
addLogEntry('info', 'Ready to connect to Arduino via Web Serial API');
|
| 1171 |
+
addLogEntry('info', 'Ensure Arduino is connected and running compatible firmware');
|
| 1172 |
+
});
|
| 1173 |
+
</script>
|
| 1174 |
+
</body>
|
| 1175 |
+
</html>
|