import React, { useState } from "react"; import { Button } from "./ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import { Badge } from "./ui/badge"; import { Alert, AlertDescription } from "./ui/alert"; import { Progress } from "./ui/progress"; import { useTeleoperation } from "../hooks/useTeleoperation"; import type { ConnectedRobot } from "../types"; import { KEYBOARD_CONTROLS } from "../../lerobot/web/teleoperate"; interface TeleoperationPanelProps { robot: ConnectedRobot; onClose: () => void; } export function TeleoperationPanel({ robot, onClose, }: TeleoperationPanelProps) { const [enabled, setEnabled] = useState(false); const { isConnected, isActive, motorConfigs, keyStates, error, start, stop, goToHome, simulateKeyPress, simulateKeyRelease, } = useTeleoperation({ robot, enabled, onError: (err: string) => console.error("Teleoperation error:", err), }); const handleStart = async () => { setEnabled(true); await start(); }; const handleStop = () => { stop(); setEnabled(false); }; const handleClose = () => { stop(); setEnabled(false); onClose(); }; // Virtual keyboard component const VirtualKeyboard = () => { const isKeyPressed = (key: string) => { return keyStates[key]?.pressed || false; }; const KeyButton = ({ keyCode, children, className = "", size = "default" as "default" | "sm" | "lg" | "icon", }: { keyCode: string; children: React.ReactNode; className?: string; size?: "default" | "sm" | "lg" | "icon"; }) => { const control = KEYBOARD_CONTROLS[keyCode as keyof typeof KEYBOARD_CONTROLS]; const pressed = isKeyPressed(keyCode); return ( ); }; return (
{robot.robotId || robot.name} - {robot.serialNumber}
💡 Pro tip: Use your physical keyboard for faster control, or click the virtual keys below. Hold keys down for continuous movement.