CoolFace
Apppublic

lerobot/glove_visualizer

sourceHugging Faceapache-2.0updated 8d agoView on Hugging Face
5likes
handedness.js21 linesDownload Raw Back to src
1import { vector, quaternion, serializePose } from "./kinematics.js";2 3// Mirror the source assembly across its YZ plane. Conjugating rotations by4// S = diag(-1,1,1) keeps every exported orientation a proper right-handed frame:5// p_right = S p_source, R_right = S R_source S. Joint readings stay unchanged.6export function mirrorPosesX(value) {7  if (value === null || typeof value !== "object") return value;8  if (Array.isArray(value)) return value.map(mirrorPosesX);9  if (Array.isArray(value.position_m) && Array.isArray(value.quaternion_xyzw)) {10    const [px, py, pz] = value.position_m, [x, y, z, w] = value.quaternion_xyzw;11    return { ...value, ...serializePose(vector([-px, py, pz]), quaternion([x, -y, -z, w])) };12  }13  return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, mirrorPosesX(item)]));14}15 16export function rightHandFrame(sourceFrame) {17  return { frame_id: `${sourceFrame}_right`, source_frame_id: sourceFrame, model_handedness: "right",18    convention: "right-handed coordinates; Z up; X mirrored from source URDF",19    source_to_model_matrix_row_major: [[-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] };20}21