Spaces:
Running
Running
File size: 14,479 Bytes
a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f f680c3f a1cdf4d f680c3f a1cdf4d a8d792f a1cdf4d a8d792f f680c3f a8d792f a1cdf4d f680c3f a1cdf4d a8d792f f680c3f a8d792f a1cdf4d a8d792f a1cdf4d f680c3f a8d792f f680c3f a1cdf4d a8d792f f680c3f a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d f680c3f a8d792f f680c3f a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d f680c3f a8d792f e2c12d2 f680c3f a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d f680c3f a8d792f e2c12d2 f680c3f a8d792f a1cdf4d f680c3f a1cdf4d f680c3f e2c12d2 f680c3f a1cdf4d a8d792f a1cdf4d a8d792f |
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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
"use client";
import type React from "react";
import { Book, Code2, Terminal, Copy, Check } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useState } from "react";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
const CodeBlock = ({
children,
language = "typescript",
}: {
children: React.ReactNode;
language?: string;
}) => {
const [copied, setCopied] = useState(false);
const copyToClipboard = async (text: string) => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy:", err);
}
};
const codeText =
typeof children === "string" ? children : children?.toString() || "";
return (
<div className="bg-slate-800 dark:bg-black/40 border border-border dark:border-white/10 rounded-md overflow-hidden my-4 relative">
<SyntaxHighlighter
language={language}
style={oneDark}
customStyle={{
margin: 0,
padding: "1rem",
fontSize: "0.875rem",
background: "transparent",
backgroundColor: "transparent",
fontFamily:
"Geist Mono, ui-monospace, SFMono-Regular, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace",
}}
wrapLines={true}
wrapLongLines={true}
codeTagProps={{
style: {
background: "transparent",
backgroundColor: "transparent",
},
}}
>
{codeText}
</SyntaxHighlighter>
<Button
variant="outline"
size="sm"
onClick={() => copyToClipboard(codeText)}
className="absolute top-2 right-2 h-7 w-7 p-0 transition-all"
>
{copied ? <Check className="w-3 h-3" /> : <Copy className="w-3 h-3" />}
</Button>
</div>
);
};
export function DocsSection() {
return (
<div className="font-mono">
<div className="mb-6">
<h2 className="text-3xl font-bold tracking-wider mb-2 uppercase flex items-center gap-3">
<Book className="w-6 h-6" />
Docs
</h2>
<p className="text-sm text-muted-foreground">
Complete API reference for @lerobot/web
</p>
</div>
<div className="bg-muted/40 dark:bg-black/30 border border-border dark:border-white/10 p-6 md:p-8 rounded-lg space-y-14">
{/* Browser Requirements */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase">
Browser Requirements
</h3>
<div className="mt-4 space-y-2 text-sm">
<div>
• <strong>Chromium 89+</strong> with WebSerial and WebUSB API
support
</div>
<div>
• <strong>HTTPS or localhost</strong>
</div>
<div>
• <strong>User gesture</strong> required for initial port
selection
</div>
</div>
</div>
{/* Getting Started */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase flex items-center gap-2">
<Terminal className="w-5 h-5" />
Getting Started
</h3>
<p className="text-muted-foreground text-sm mt-2 mb-4">
Complete workflow from discovery to teleoperation.
</p>
<CodeBlock>
{`import { findPort, releaseMotors, calibrate, teleoperate } from "@lerobot/web";
// 1. find and connect to hardware like a robot arm
const findProcess = await findPort();
const robots = await findProcess.result;
const robot = robots[0];
// 2. release the motors and put them into the homing position
await releaseMotors(robot);
// 3. calibrate the motors by moving each motor through its full range of motion
const calibrationProcess = await calibrate({
robot,
onProgress: (message) => console.log(message),
onLiveUpdate: (data) => console.log("Live positions:", data),
});
// when done, stop calibration and get the min/max ranges for each motor
calibrationProcess.stop();
const calibrationData = await calibrationProcess.result;
// 4. start controlling the robot arm with your keyboard
const teleop = await teleoperate({
robot,
calibrationData,
teleop: { type: "keyboard" },
});
teleop.start();
// 5. stop control (run this when you're done)
teleop.stop();`}
</CodeBlock>
</div>
{/* API Reference */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase flex items-center gap-2">
<Code2 className="w-5 h-5" />
API Reference
</h3>
<div className="space-y-12 mt-4">
{/* findPort */}
<div>
<h4 className="font-bold text-primary">findPort(config?)</h4>
<p className="text-muted-foreground text-sm mt-1">
Discovers and connects to robotics hardware using WebSerial API.
</p>
<CodeBlock>
{`// Interactive Mode (Default) - Shows port dialog
const findProcess = await findPort();
const robots = await findProcess.result; // RobotConnection[]
// Auto-Connect Mode - Reconnects to known robots
const findProcess = await findPort({
robotConfigs: [
{ robotType: "so100_follower", robotId: "left_arm", serialNumber: "USB123" }
],
onMessage: (msg) => console.log(msg),
});`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>robotConfigs?: RobotConfig[]</code> - Auto-connect
to these known robots
</li>
<li>
• <code>onMessage?: (message: string) => void</code> -
Progress messages callback
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Returns:{" "}
<code className="bg-muted/50 px-1 rounded">
FindPortProcess
</code>
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>result: Promise<RobotConnection[]></code> -
Array of robot connections
</li>
<li>
• <code>stop(): void</code> - Cancel discovery process
</li>
</ul>
</div>
</div>
{/* calibrate */}
<div>
<h4 className="font-bold text-primary">calibrate(config)</h4>
<p className="text-muted-foreground text-sm mt-1">
Calibrates motor homing offsets and records range of motion.
</p>
<CodeBlock>
{`const calibrationProcess = await calibrate({
robot,
onProgress: (message) => {
console.log(message); // "⚙️ Setting motor homing offsets"
},
onLiveUpdate: (data) => {
// Real-time motor positions during range recording
Object.entries(data).forEach(([motor, info]) => {
console.log(\`\${motor}: \${info.current} (range: \${info.range})\`);
});
},
});
// Move robot through full range of motion...
calibrationProcess.stop(); // Stop range recording
const calibrationData = await calibrationProcess.result;`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>robot: RobotConnection</code> - Connected robot from
findPort()
</li>
<li>
• <code>onProgress?: (message: string) => void</code> -
Progress messages callback
</li>
<li>
•{" "}
<code>
onLiveUpdate?: (data: LiveCalibrationData) => void
</code>{" "}
- Real-time position updates
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Returns:{" "}
<code className="bg-muted/50 px-1 rounded">
CalibrationProcess
</code>
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>result: Promise<WebCalibrationResults></code>{" "}
- Python-compatible format
</li>
<li>
• <code>stop(): void</code> - Stop calibration process
</li>
</ul>
</div>
</div>
{/* teleoperate */}
<div>
<h4 className="font-bold text-primary">teleoperate(config)</h4>
<p className="text-muted-foreground text-sm mt-1">
Enables real-time robot control with extensible input devices.
</p>
<CodeBlock>
{`// Keyboard Teleoperation
const keyboardTeleop = await teleoperate({
robot,
calibrationData: savedCalibrationData,
teleop: { type: "keyboard" },
onStateUpdate: (state) => {
console.log(\`Active: \${state.isActive}\`);
console.log(\`Motors:\`, state.motorConfigs);
},
});
// Direct Teleoperation
const directTeleop = await teleoperate({
robot,
calibrationData: savedCalibrationData,
teleop: { type: "direct" },
});`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>robot: RobotConnection</code> - Connected robot from
findPort()
</li>
<li>
• <code>teleop: TeleoperatorConfig</code> - Teleoperator
configuration:
<ul className="mt-1 ml-4 space-y-1">
<li>
• <code>{`{ type: "keyboard" }`}</code> - Keyboard
control
</li>
<li>
• <code>{`{ type: "direct" }`}</code> - Direct
programmatic control
</li>
</ul>
</li>
<li>
•{" "}
<code>
calibrationData?: {`{ [motorName: string]: any }`}
</code>{" "}
- Calibration data from calibrate()
</li>
<li>
•{" "}
<code>
onStateUpdate?: (state: TeleoperationState) => void
</code>{" "}
- State change callback
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Returns:{" "}
<code className="bg-muted/50 px-1 rounded">
TeleoperationProcess
</code>
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>start(): void</code> - Begin teleoperation
</li>
<li>
• <code>stop(): void</code> - Stop teleoperation and clear
states
</li>
<li>
• <code>getState(): TeleoperationState</code> - Current
state and motor positions
</li>
<li>
• <code>teleoperator: BaseWebTeleoperator</code> - Access
teleoperator-specific methods
</li>
<li>
• <code>disconnect(): Promise<void></code> - Stop and
disconnect
</li>
</ul>
</div>
</div>
{/* releaseMotors */}
<div>
<h4 className="font-bold text-primary">
releaseMotors(robot, motorIds?)
</h4>
<p className="text-muted-foreground text-sm mt-1">
Releases motor torque so robot can be moved freely by hand.
</p>
<CodeBlock>
{`// Release all motors for calibration
await releaseMotors(robot);
// Release specific motors only
await releaseMotors(robot, [1, 2, 3]);`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm text-muted-foreground tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm text-muted-foreground">
<li>
• <code>robot: RobotConnection</code> - Connected robot
</li>
<li>
• <code>motorIds?: number[]</code> - Specific motor IDs
(default: all motors for robot type)
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
|