import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { Slider } from "@/components/ui/slider"; type Joint = { name: string; label: string; min: number; max: number; step: number; default: number; }; const JOINTS: Joint[] = [ { name: "shoulder_pan.pos", label: "Shoulder Pan", min: -180, max: 180, step: 1, default: 0 }, { name: "shoulder_lift.pos", label: "Shoulder Lift", min: -180, max: 180, step: 1, default: 0 }, { name: "elbow_flex.pos", label: "Elbow Flex", min: -180, max: 180, step: 1, default: 0 }, { name: "wrist_flex.pos", label: "Wrist Flex", min: -180, max: 180, step: 1, default: 0 }, { name: "wrist_roll.pos", label: "Wrist Roll", min: -180, max: 180, step: 1, default: 0 }, { name: "gripper.pos", label: "Gripper", min: 0, max: 100, step: 1, default: 0 }, ]; type Props = { onSendAction?: (values: Record) => void; className?: string; }; const initialJointState = () => { const state: Record = {}; JOINTS.forEach(j => (state[j.name] = j.default)); return state; }; const DirectFollowerControlPanel: React.FC = ({ onSendAction, className }) => { const [jointValues, setJointValues] = useState>(initialJointState); // Handler for slider changes const handleSliderChange = (joint: Joint, value: number[]) => { setJointValues(v => ({ ...v, [joint.name]: value[0] })); }; // Quick action examples const handleHome = () => { const home: Record = {}; JOINTS.forEach(j => (home[j.name] = 0)); setJointValues(home); }; const handleSend = () => { // You'd call the backend API here. For now, just call prop if present. if (onSendAction) onSendAction(jointValues); // TODO: Real API integration fetch("http://localhost:8000/send-follower-command", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(jointValues), }).then(res => { // Optionally handle response // Could use a toast here }); }; return (

Direct Follower Control

{JOINTS.map(joint => (
handleSliderChange(joint, value)} className="my-1" />
{joint.min} {joint.max}
))}
); }; export default DirectFollowerControlPanel;