LeRobot-Arena / src /lib /components /3d /robot /URDF /createRobot.svelte.ts
blanchon's picture
Mostly UI Update
18b0fa5
raw
history blame contribute delete
844 Bytes
import type { RobotState } from "$lib/types/robot";
import type { RobotUrdfConfig } from "$lib/types/urdf";
import { UrdfParser } from "./utils/UrdfParser";
export async function createRobot(urdfConfig: RobotUrdfConfig): Promise<RobotState> {
const customParser = new UrdfParser(urdfConfig.urdfUrl, "/robots/so-100/");
const urdfData = await customParser.load();
const robot = customParser.fromString(urdfData);
// Make the robot data reactive so mutations to joint.rotation trigger reactivity
const reactiveRobot = $state(robot);
// Make the selection state reactive as well
const reactiveSelection = $state({
isSelected: false,
selectedLink: undefined,
selectedJoint: undefined
});
const robotState: RobotState = {
robot: reactiveRobot,
urdfConfig: urdfConfig,
selection: reactiveSelection
};
return robotState;
}