Spaces:
Running
Running
File size: 46,631 Bytes
a1cdf4d a8d792f a1cdf4d 946780b a1cdf4d 946780b a1cdf4d a8d792f 946780b a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f a1cdf4d a8d792f f680c3f a1cdf4d f680c3f a1cdf4d a8d792f a1cdf4d a8d792f f680c3f a8d792f a1cdf4d 946780b a1cdf4d a8d792f 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b f680c3f 946780b f680c3f 946780b f680c3f 946780b a1cdf4d f680c3f a8d792f f680c3f 946780b a8d792f 946780b a1cdf4d a8d792f a1cdf4d f680c3f 946780b a8d792f 946780b a1cdf4d a8d792f a1cdf4d f680c3f 946780b a8d792f 946780b a1cdf4d a8d792f a1cdf4d f680c3f 946780b e2c12d2 946780b e2c12d2 946780b e2c12d2 946780b b7ce6b9 e2c12d2 946780b f680c3f a8d792f a1cdf4d 946780b a1cdf4d 946780b a1cdf4d 946780b a1cdf4d 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 01b5ace 946780b 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 |
"use client";
import type React from "react";
import {
Book,
Code2,
Terminal,
Copy,
Check,
Server,
Package,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useState, createContext, useContext } from "react";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
type CLIMode = "npm" | "npx";
const CLIModeContext = createContext<{
mode: CLIMode;
setMode: (mode: CLIMode) => void;
}>({
mode: "npx",
setMode: () => {},
});
const CLIModeProvider = ({ children }: { children: React.ReactNode }) => {
const [mode, setMode] = useState<CLIMode>("npx");
return (
<CLIModeContext.Provider value={{ mode, setMode }}>
{children}
</CLIModeContext.Provider>
);
};
const CLIModeSwitch = ({ className = "" }: { className?: string }) => {
const { mode, setMode } = useContext(CLIModeContext);
return (
<div className={`flex gap-1 w-fit ${className}`}>
<Button
variant="ghost"
size="sm"
onClick={() => setMode("npx")}
className={`font-mono text-xs px-3 min-w-[60px] h-8 border transition-colors ${
mode === "npx"
? "bg-foreground text-background border-foreground"
: "bg-transparent border-input hover:bg-accent hover:text-accent-foreground"
}`}
>
npx
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setMode("npm")}
className={`font-mono text-xs px-3 min-w-[60px] h-8 border transition-colors ${
mode === "npm"
? "bg-foreground text-background border-foreground"
: "bg-transparent border-input hover:bg-accent hover:text-accent-foreground"
}`}
>
npm
</Button>
</div>
);
};
const CLICodeBlock = ({
children,
language = "bash",
}: {
children: React.ReactNode;
language?: string;
}) => {
const { mode } = useContext(CLIModeContext);
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);
}
};
// Convert commands based on mode
const convertCommands = (text: string) => {
if (mode === "npx") {
return text
.replace(/^lerobot /gm, "npx lerobot@latest ")
.replace(/# lerobot /gm, "# npx lerobot@latest ");
}
return text;
};
const codeText =
typeof children === "string" ? children : children?.toString() || "";
const convertedCode = convertCommands(codeText);
return (
<div className="my-4">
<div className="flex items-center justify-between mb-2">
<CLIModeSwitch />
</div>
<div className="bg-slate-800 dark:bg-black/40 border border-border dark:border-white/10 rounded-md overflow-hidden 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",
},
}}
>
{convertedCode}
</SyntaxHighlighter>
<Button
variant="outline"
size="sm"
onClick={() => copyToClipboard(convertedCode)}
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>
</div>
);
};
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 all lerobot.js packages
</p>
</div>
<div className="bg-muted/40 dark:bg-black/30 border border-border dark:border-white/10 p-4 md:p-6 lg:p-8 rounded-lg">
<Tabs defaultValue="web" className="w-full">
<TabsList className="grid w-full grid-cols-3 mb-8 h-auto p-2">
<TabsTrigger
value="web"
className="flex flex-col sm:flex-row items-center gap-2 sm:gap-3 h-20 sm:h-16 px-2 sm:px-4 data-[state=active]:bg-background"
>
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-primary/20 rounded-lg flex items-center justify-center">
<Package className="w-4 h-4 sm:w-5 sm:h-5 text-primary" />
</div>
<div className="text-center sm:text-left">
<div className="font-bold text-xs sm:text-sm uppercase tracking-wider">
WEB
</div>
<div className="text-xs text-muted-foreground hidden sm:block">
@lerobot/web
</div>
</div>
</TabsTrigger>
<TabsTrigger
value="node"
className="flex flex-col sm:flex-row items-center gap-2 sm:gap-3 h-20 sm:h-16 px-2 sm:px-4 data-[state=active]:bg-background"
>
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-primary/20 rounded-lg flex items-center justify-center">
<Server className="w-4 h-4 sm:w-5 sm:h-5 text-primary" />
</div>
<div className="text-center sm:text-left">
<div className="font-bold text-xs sm:text-sm uppercase tracking-wider">
NODE
</div>
<div className="text-xs text-muted-foreground hidden sm:block">
@lerobot/node
</div>
</div>
</TabsTrigger>
<TabsTrigger
value="cli"
className="flex flex-col sm:flex-row items-center gap-2 sm:gap-3 h-20 sm:h-16 px-2 sm:px-4 data-[state=active]:bg-background"
>
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-primary/20 rounded-lg flex items-center justify-center">
<Terminal className="w-4 h-4 sm:w-5 sm:h-5 text-primary" />
</div>
<div className="text-center sm:text-left">
<div className="font-bold text-xs sm:text-sm uppercase tracking-wider">
CLI
</div>
<div className="text-xs text-muted-foreground hidden sm:block">
lerobot
</div>
</div>
</TabsTrigger>
</TabsList>
<TabsContent value="web" className="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>
{/* Quick Start */}
<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" />
Quick Start
</h3>
<p className="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-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 tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<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 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">
<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-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 tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<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 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">
<li>
• <code>result: Promise<CalibrationResults></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-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 tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<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 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">
<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-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 tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<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>
{/* record */}
<div>
<h4 className="font-bold text-primary">record(config)</h4>
<p className="text-sm mt-1">
Records robot teleoperator data and camera streams in the LeRobot dataset format.
</p>
<CodeBlock>
{`import { teleoperate, record } from "@lerobot/web";
// Start teleoperation first
const teleoperationProcess = await teleoperate({
robot: connectedRobot,
teleop: { type: "keyboard" },
calibrationData: calibrationData,
});
// Create recording with teleoperator
const recordProcess = await record({
teleoperator: teleoperationProcess.teleoperator,
videoStreams: {
main: mainCameraStream,
wrist: wristCameraStream,
},
robotType: "so100",
options: {
fps: 30,
taskDescription: "Pick and place task",
onStateUpdate: (state) => {
console.log(\`Recording: \${state.frameCount} frames\`);
},
},
});
// Start both recording and teleoperation
teleoperationProcess.start();
recordProcess.start();
// Manage recording during operation
recordProcess.nextEpisode(); // Start new episode if needed
// Stop recording when finished
const robotData = await recordProcess.stop();
await recordProcess.exportForLeRobot("zip-download");`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>teleoperator: WebTeleoperator</code> - The teleoperator to record from
</li>
<li>
• <code>videoStreams?: {`{ [name: string]: MediaStream }`}</code> - Optional camera streams
</li>
<li>
• <code>robotType?: string</code> - Robot metadata (e.g., "so100")
</li>
<li>
• <code>options?: RecordOptions</code> - Optional configuration:
<ul className="mt-1 ml-4 space-y-1">
<li>
• <code>fps?: number</code> - Target frames per second (default: 30)
</li>
<li>
• <code>taskDescription?: string</code> - Task description
</li>
<li>
• <code>onStateUpdate?: (state: RecordingState) => void</code> - State changes
</li>
</ul>
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Returns: RecordProcess
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>start(): void</code> - Start recording
</li>
<li>
• <code>stop(): Promise<RobotRecordingData></code> - Stop recording
</li>
<li>
• <code>getState(): RecordingState</code> - Current recording state
</li>
<li>
• <code>getEpisodeCount(): number</code> - Get number of episodes
</li>
<li>
• <code>nextEpisode(): Promise<number></code> - Start new episode
</li>
<li>
• <code>clearEpisodes(): void</code> - Delete all episodes
</li>
<li>
• <code>addCamera(name: string, stream: MediaStream): void</code> - Add camera dynamically
</li>
<li>
• <code>exportForLeRobot(format?: "blobs" | "zip" | "zip-download"): Promise<any></code> - Export dataset
</li>
</ul>
</div>
</div>
</div>
</div>
</TabsContent>
<TabsContent value="node" className="space-y-14">
{/* Node.js Requirements */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase">
Node.js Requirements
</h3>
<div className="mt-4 space-y-2 text-sm">
<div>
• <strong>Node.js 18+</strong> (Windows, macOS, Linux)
</div>
<div>
• <strong>Serial port access</strong> (may require
permissions)
</div>
<div>
• <strong>SO-100 robot hardware</strong> with USB connection
</div>
</div>
</div>
{/* Quick Start */}
<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" />
Quick Start
</h3>
<p className="text-sm mt-2 mb-4">
Complete workflow from discovery to teleoperation in Node.js.
</p>
<CodeBlock>
{`import { findPort, connectPort, releaseMotors, calibrate, teleoperate } from "@lerobot/node";
// 1. find available robot ports
console.log("🔍 finding available robot ports...");
const findProcess = await findPort();
const robots = await findProcess.result;
if (robots.length === 0) {
console.log("❌ no robots found. check connections.");
process.exit(1);
}
// 2. connect to the first robot found
console.log(\`✅ found \${robots.length} robot(s). connecting to first one...\`);
const robot = await connectPort(robots[0].path, robots[0].robotType);
// 3. release motors for manual positioning
console.log("🔓 releasing motors for manual positioning...");
await releaseMotors(robot);
// 4. calibrate motors by moving through full range
console.log("⚙️ starting calibration...");
const calibrationProcess = await calibrate({
robot,
onProgress: (message) => console.log(message),
onLiveUpdate: (data) => console.log("live positions:", data),
});
// move robot through its range, then stop calibration
console.log("👋 move robot through full range, press enter when done...");
process.stdin.once("data", () => {
calibrationProcess.stop();
});
const calibrationData = await calibrationProcess.result;
console.log("✅ calibration complete!");
// 5. control robot with keyboard
console.log("🎮 starting keyboard control...");
const teleop = await teleoperate({
robot,
calibrationData,
teleop: { type: "keyboard" },
});
teleop.start();`}
</CodeBlock>
</div>
{/* How It Works */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase">
How It Works
</h3>
<div className="mt-4 space-y-6">
<div>
<h4 className="font-bold text-primary">
Beginner Flow: findPort() → connectPort() → Use Robot
</h4>
<p className="text-sm mt-1 mb-3">
Most users should start with findPort() for discovery, then
connectPort() for connection:
</p>
<CodeBlock>
{`// ✅ recommended: discover then connect
const findProcess = await findPort();
const robots = await findProcess.result;
const robot = await connectPort(robots[0].path, robots[0].robotType);`}
</CodeBlock>
</div>
<div>
<h4 className="font-bold text-primary">
Advanced: Direct Connection with connectPort()
</h4>
<p className="text-sm mt-1 mb-3">
Only use connectPort() when you already know the exact port:
</p>
<CodeBlock>
{`// ⚡ advanced: direct connection to known port
const robot = await connectPort("/dev/ttyUSB0", "so100_follower");`}
</CodeBlock>
</div>
</div>
</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-sm mt-1">
Discovers available robotics hardware on serial ports.
Unlike the web version, this only discovers ports -
connection happens separately with connectPort().
</p>
<CodeBlock>
{`// Discover all available robots
const findProcess = await findPort();
const robots = await findProcess.result;
console.log(\`Found \${robots.length} robot(s):\`);
robots.forEach((robot) => {
console.log(\`- \${robot.robotType} on \${robot.path}\`);
});
// Connect to specific robot
const robot = await connectPort(robots[0].path, robots[0].robotType);`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Returns: FindPortProcess
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>result: Promise<DiscoveredRobot[]></code>{" "}
- Array of discovered robots with path, robotType, and
other metadata
</li>
<li>
• <code>stop(): void</code> - Cancel discovery process
</li>
</ul>
</div>
</div>
{/* connectPort */}
<div>
<h4 className="font-bold text-primary">
connectPort(port, robotType, robotId?)
</h4>
<p className="text-sm mt-1">
Creates a connection to a robot on the specified serial
port.
</p>
<CodeBlock>
{`// Connect to SO-100 follower arm
const robot = await connectPort(
"/dev/ttyUSB0", // Serial port path
"so100_follower", // Robot type
"my_robot_arm" // Custom robot ID
);
// Windows
const robot = await connectPort("COM4", "so100_follower", "my_robot");
// Connection is ready to use
console.log(\`Connected to \${robot.robotType} on \${robot.port.path}\`);`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Parameters
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>port: string</code> - Serial port path (e.g.,
/dev/ttyUSB0, COM4)
</li>
<li>
•{" "}
<code>
robotType: "so100_follower" | "so100_leader"
</code>{" "}
- Type of robot
</li>
<li>
• <code>robotId?: string</code> - Custom identifier for
your robot
</li>
</ul>
</div>
</div>
{/* calibrate */}
<div>
<h4 className="font-bold text-primary">calibrate(config)</h4>
<p className="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...
// When finished, stop calibration
calibrationProcess.stop();
const calibrationData = await calibrationProcess.result;
// Save to file (Python-compatible format)
import { writeFileSync } from "fs";
writeFileSync(
"./my_robot_calibration.json",
JSON.stringify(calibrationData, null, 2)
);`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Returns: CalibrationProcess
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>result: Promise<CalibrationResults></code>{" "}
- <strong>Python-compatible</strong> calibration data
</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-sm mt-1">
Real-time robot control with keyboard input.{" "}
<strong>Smooth, responsive movement</strong> optimized for
Node.js.
</p>
<CodeBlock>
{`const teleop = await teleoperate({
robot,
teleop: { type: "keyboard" },
onStateUpdate: (state) => {
console.log(\`Active: \${state.isActive}\`);
state.motorConfigs.forEach((motor) => {
console.log(\`\${motor.name}: \${motor.currentPosition}\`);
});
},
});
// Start keyboard control
teleop.start();
// Control will be active until stopped
setTimeout(() => teleop.stop(), 60000);`}
</CodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Keyboard Controls (SO-100)
</h5>
<div className="mt-1 ml-4 text-sm font-mono">
<div>Arrow Keys: Shoulder pan/lift</div>
<div>WASD: Elbow flex, wrist flex</div>
<div>Q/E: Wrist roll</div>
<div>O/C: Gripper open/close</div>
<div>ESC: Emergency stop</div>
<div>Ctrl+C: Exit</div>
</div>
</div>
</div>
{/* releaseMotors */}
<div>
<h4 className="font-bold text-primary">
releaseMotors(robot)
</h4>
<p className="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);
console.log("Motors released - you can now move the robot freely");`}
</CodeBlock>
</div>
</div>
</div>
{/* Serial Port Permissions */}
<div>
<h3 className="text-xl font-bold text-cyan-600 dark:text-accent-cyan tracking-wider uppercase">
Serial Port Permissions
</h3>
<div className="mt-4 space-y-4">
<div>
<h4 className="font-bold text-primary">Linux/macOS</h4>
<CodeBlock language="bash">
{`# Add user to dialout group (Linux)
sudo usermod -a -G dialout $USER
# Set permissions (macOS)
sudo chmod 666 /dev/tty.usbserial-*`}
</CodeBlock>
</div>
<div>
<h4 className="font-bold text-primary">Windows</h4>
<p className="text-sm">No additional setup required.</p>
</div>
</div>
</div>
</TabsContent>
<TabsContent value="cli" className="space-y-14">
<CLIModeProvider>
{/* Commands */}
<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" />
Available Commands
</h3>
<div className="space-y-8 mt-4">
{/* find-port */}
<div>
<h4 className="font-bold text-primary">find-port</h4>
<p className="text-sm mt-1">
Interactive port discovery using cable detection.
</p>
<CLICodeBlock language="bash">
{`lerobot find-port`}
</CLICodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Interactive Process
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>• Lists current ports</li>
<li>• Prompts to unplug USB cable</li>
<li>• Detects which port disappeared</li>
<li>• Prompts to reconnect cable</li>
</ul>
</div>
</div>
{/* calibrate */}
<div>
<h4 className="font-bold text-primary">calibrate</h4>
<p className="text-sm mt-1">
Calibrate robot motors and save calibration data.
</p>
<CLICodeBlock language="bash">
{`lerobot calibrate --robot.type=so100_follower --robot.port=/dev/ttyUSB0 --robot.id=my_arm`}
</CLICodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>--robot.type</code> - Robot type
(so100_follower, so100_leader)
</li>
<li>
• <code>--robot.port</code> - Serial port
(/dev/ttyUSB0, COM4)
</li>
<li>
• <code>--robot.id</code> - Robot identifier (default:
"default")
</li>
<li>
• <code>--output</code> - Custom output path for
calibration file
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Storage Location
</h5>
<div className="mt-1 ml-4 text-sm font-mono">
~/.cache/huggingface/lerobot/calibration/robots/{robot_type}/{robot_id}.json
</div>
</div>
</div>
{/* teleoperate */}
<div>
<h4 className="font-bold text-primary">teleoperate</h4>
<p className="text-sm mt-1">
Control robot through keyboard input.
</p>
<CLICodeBlock language="bash">
{`lerobot teleoperate --robot.type=so100_follower --robot.port=/dev/ttyUSB0 --robot.id=my_arm`}
</CLICodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>--robot.type</code> - Robot type (e.g.,
so100_follower)
</li>
<li>
• <code>--robot.port</code> - Serial port (e.g.,
/dev/ttyUSB0, COM4)
</li>
<li>
• <code>--robot.id</code> - Robot identifier (default:
"default")
</li>
<li>
• <code>--teleop.type</code> - Teleoperator type
(default: "keyboard")
</li>
<li>
• <code>--duration</code> - Duration in seconds, 0 =
unlimited (default: "0")
</li>
</ul>
</div>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Keyboard Controls
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>w/s</code> - Elbow flex/extend
</li>
<li>
• <code>a/d</code> - Wrist down/up
</li>
<li>
• <code>q/e</code> - Wrist roll left/right
</li>
<li>
• <code>o/c</code> - Gripper open/close
</li>
<li>
• <code>Arrow keys</code> - Shoulder lift/pan
</li>
<li>
• <code>Ctrl+C</code> - Stop and exit
</li>
</ul>
</div>
</div>
{/* release-motors */}
<div>
<h4 className="font-bold text-primary">release-motors</h4>
<p className="text-sm mt-1">
Release robot motors for manual positioning.
</p>
<CLICodeBlock language="bash">
{`lerobot release-motors --robot.type=so100_follower --robot.port=/dev/ttyUSB0 --robot.id=my_arm`}
</CLICodeBlock>
<div className="mt-3">
<h5 className="font-bold text-sm tracking-wider">
Options
</h5>
<ul className="mt-1 ml-4 space-y-1 text-sm">
<li>
• <code>--robot.type</code> - Robot type (e.g.,
so100_follower)
</li>
<li>
• <code>--robot.port</code> - Serial port (e.g.,
/dev/ttyUSB0, COM4)
</li>
<li>
• <code>--robot.id</code> - Robot identifier (default:
"default")
</li>
<li>
• <code>--motors</code> - Specific motor IDs to
release (comma-separated)
</li>
</ul>
</div>
</div>
</div>
</div>
</CLIModeProvider>
</TabsContent>
</Tabs>
</div>
</div>
);
}
|