Spaces:
Running
Running
File size: 10,910 Bytes
deaf936 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reachy Mini - Basic Example</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
padding: 40px 20px;
max-width: 600px;
margin: 0 auto;
background: #f5f5f5;
}
h1 {
font-size: 24px;
margin-bottom: 8px;
color: #333;
}
.subtitle {
color: #666;
margin-bottom: 32px;
font-size: 14px;
}
.card {
background: white;
border-radius: 12px;
padding: 24px;
margin-bottom: 16px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card h2 {
font-size: 16px;
margin-bottom: 16px;
color: #333;
}
button {
width: 100%;
padding: 12px 20px;
font-size: 14px;
font-weight: 500;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
margin-bottom: 8px;
font-family: inherit;
}
.btn-primary {
background: #2563eb;
color: white;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-success {
background: #16a34a;
color: white;
}
.btn-success:hover { background: #15803d; }
.btn-success:disabled { background: #86efac; cursor: not-allowed; }
.btn-danger {
background: #dc2626;
color: white;
}
.btn-danger:hover { background: #b91c1c; }
.btn-secondary {
background: #f3f4f6;
color: #374151;
border: 1px solid #e5e7eb;
}
.btn-secondary:hover { background: #e5e7eb; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.status {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
margin-bottom: 16px;
}
.status-disconnected {
background: #fee2e2;
color: #dc2626;
}
.status-connected {
background: #dcfce7;
color: #16a34a;
}
#output {
background: #f9fafb;
padding: 16px;
border-radius: 8px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 12px;
line-height: 1.6;
color: #374151;
max-height: 300px;
overflow-y: auto;
margin-top: 16px;
}
.output-line {
margin-bottom: 4px;
}
.note {
background: #fef3c7;
border: 1px solid #fde047;
padding: 12px;
border-radius: 8px;
font-size: 13px;
color: #854d0e;
margin-bottom: 16px;
}
</style>
</head>
<body>
<h1>π€ Reachy Mini Control</h1>
<p class="subtitle">Basic control example</p>
<div class="note">
<strong>Note:</strong> Use Chrome or Edge browser. Make sure your Reachy Mini is connected via USB or the WebSocket server is running on localhost:8000.
</div>
<div class="card">
<h2>Connection</h2>
<div id="status-indicator" class="status status-disconnected">Disconnected</div>
<button id="btn-connect" class="btn-primary">Connect to Robot</button>
</div>
<div class="card">
<h2>Motor Control</h2>
<button id="btn-torque-on" class="btn-success" disabled>Enable Torque</button>
<button id="btn-torque-off" class="btn-secondary" disabled>Disable Torque</button>
</div>
<div class="card">
<h2>Kinematics Test</h2>
<button id="btn-fk" class="btn-secondary" disabled>Test Forward Kinematics</button>
<button id="btn-ik" class="btn-secondary" disabled>Test Inverse Kinematics</button>
</div>
<div class="card">
<h2>Recording</h2>
<button id="btn-record" class="btn-secondary" disabled>Record (10s)</button>
<button id="btn-replay" class="btn-secondary" disabled>Replay</button>
<button id="btn-stop" class="btn-danger" disabled>Stop</button>
</div>
<div class="card">
<h2>Console Output</h2>
<div id="output"></div>
</div>
<script type="module">
// Import WASM module and functions from unpkg (published version)
import init, {
connect,
torque_on,
torque_off,
forward_kinematics,
inverse_kinematics,
record,
replay,
stop
} from 'https://unpkg.com/reachy-mini@0.2.1/index.js';
// Elements
const btnConnect = document.getElementById('btn-connect');
const btnTorqueOn = document.getElementById('btn-torque-on');
const btnTorqueOff = document.getElementById('btn-torque-off');
const btnFK = document.getElementById('btn-fk');
const btnIK = document.getElementById('btn-ik');
const btnRecord = document.getElementById('btn-record');
const btnReplay = document.getElementById('btn-replay');
const btnStop = document.getElementById('btn-stop');
const statusIndicator = document.getElementById('status-indicator');
const output = document.getElementById('output');
let isConnected = false;
// Logging
function log(message, type = 'info') {
const line = document.createElement('div');
line.className = 'output-line';
const timestamp = new Date().toLocaleTimeString();
const icon = type === 'success' ? 'β' : type === 'error' ? 'β' : 'βΉ';
line.textContent = `[${timestamp}] ${icon} ${message}`;
output.appendChild(line);
output.scrollTop = output.scrollHeight;
}
// Initialize WASM (serial helpers auto-exposed to window!)
try {
await init();
log('WASM module loaded successfully', 'success');
} catch (err) {
log(`Failed to load WASM module: ${err.message}`, 'error');
log('Please make sure you are running this from a local server (not file://)', 'error');
}
// Connection
btnConnect.addEventListener('click', async () => {
try {
btnConnect.disabled = true;
btnConnect.textContent = 'Connecting...';
log('Attempting to connect to Reachy Mini...');
await connect();
isConnected = true;
statusIndicator.textContent = 'Connected';
statusIndicator.className = 'status status-connected';
btnConnect.textContent = 'Connected';
// Enable other buttons
[btnTorqueOn, btnTorqueOff, btnFK, btnIK, btnRecord, btnReplay, btnStop].forEach(btn => {
btn.disabled = false;
});
log('Successfully connected to Reachy Mini!', 'success');
} catch (err) {
btnConnect.disabled = false;
btnConnect.textContent = 'Connect to Robot';
log(`Connection failed: ${err.message}`, 'error');
}
});
// Torque Control
btnTorqueOn.addEventListener('click', async () => {
try {
log('Enabling torque...');
await torque_on();
log('Torque enabled', 'success');
} catch (err) {
log(`Error: ${err.message}`, 'error');
}
});
btnTorqueOff.addEventListener('click', async () => {
try {
log('Disabling torque...');
await torque_off();
log('Torque disabled', 'success');
} catch (err) {
log(`Error: ${err.message}`, 'error');
}
});
// Forward Kinematics
btnFK.addEventListener('click', () => {
try {
log('Testing forward kinematics...');
const angles = [0, 0, 0, 0, 0, 0, 0, 0]; // All motors at 0 degrees
const pose = forward_kinematics(angles);
log(`Input angles: [${angles.join(', ')}]`);
log(`Output pose [x, y, z, roll, pitch, yaw]: [${pose.map(v => v.toFixed(2)).join(', ')}]`, 'success');
} catch (err) {
log(`Error: ${err.message}`, 'error');
}
});
// Inverse Kinematics
btnIK.addEventListener('click', () => {
try {
log('Testing inverse kinematics...');
const pose = [0, 0, 0, 0, 0, 0]; // x, y, z, roll, pitch, yaw
const joints = inverse_kinematics(pose);
log(`Input pose [x, y, z, roll, pitch, yaw]: [${pose.join(', ')}]`);
log(`Output joints (degrees): [${joints.map(v => v.toFixed(2)).join(', ')}]`, 'success');
} catch (err) {
log(`Error: ${err.message}`, 'error');
}
});
// Recording
btnRecord.addEventListener('click', async () => {
try {
log('Recording movement for 10 seconds...');
btnRecord.disabled = true;
await record();
btnRecord.disabled = false;
log('Recording complete', 'success');
} catch (err) {
btnRecord.disabled = false;
log(`Error: ${err.message}`, 'error');
}
});
btnReplay.addEventListener('click', async () => {
try {
log('Replaying recorded movement...');
btnReplay.disabled = true;
await replay();
btnReplay.disabled = false;
log('Replay complete', 'success');
} catch (err) {
btnReplay.disabled = false;
log(`Error: ${err.message}`, 'error');
}
});
btnStop.addEventListener('click', async () => {
try {
log('Stopping current operation...');
await stop();
log('Stopped', 'success');
} catch (err) {
log(`Error: ${err.message}`, 'error');
}
});
log('Ready to connect. Click "Connect to Robot" to begin.');
</script>
</body>
</html>
|