API

Everything you need is in metaquest_teleop. Start with QuestHands; each frame it gives you is a Frame, which holds up to two Hands, whose joints are Poses.

Below, method is something you call with (), like quest.wait(); property and attribute are values you read, like hand.pinch.

QuestHands: the stream

class QuestHands(port: int = 8012, adb: bool = True, udp: tuple[str, int] | None = None, host: str = '127.0.0.1', hands: str = 'right')

Hand tracking from a Meta Quest, received in background threads.

with QuestHands() as quest:      # then press Start in the headset
    frame = quest.wait()         # the next frame from the headset
    frame.right.wrist.position   # metres
    frame.right.angles           # (5, 4) radians

Only this computer can connect (the headset comes in through the USB cable), so nothing else on the network can send it frames.

Parameters:
port: int = 8012

The port: the headset opens http://localhost:<port>.

adb: bool = True

Set up the USB link to the headset automatically, with adb.

udp: tuple[str, int] | None = None

(host, port): also send every frame there as JSON, over UDP. None for no UDP.

host: str = '127.0.0.1'

Who can connect: "127.0.0.1" is only this computer, "0.0.0.0" the network.

hands: str = 'right'

The hands to keep: "right" (the default), "left" or "both". The others are reported as not tracked.

frames

Frames received since the start.

Type:

int

headset

What the connected page reported: agent, mode, fps, space, session and stats; empty while no page is connected.

Type:

dict

usb_ok

Whether the last USB check succeeded.

Type:

bool

usb

The USB link’s status, as the dashboard shows it.

Type:

str

events

The last six (time.time(), text) status events.

Type:

collections.deque

calibration

The file the 3D view saves the ADAPT calibration you make in it to, all of it at every point (metaquest-teleop --calibration sets it); None, the default: the 3D view does not calibrate.

Type:

pathlib.Path or None

start() → QuestHands

Serve the page and the stream in background threads; returns self.

Raises OSError if the port is taken, for example by another running copy.

stop() → None

Stop serving and watching USB; a pending wait() returns None.

property url : str

The address to open in the Quest browser.

property view_url : str

The address of the 3D view of the hands, to open in a browser on this computer.

property connected : bool

Whether a headset page is connected.

latest() → Frame | None

The most recent frame, or None before the first one.

wait(timeout: float | None = None) → Frame | None

Block until a new frame arrives and return it; None on timeout or stop.

on_frame(callback: Callable[[Frame], None], raw: bool = False) → None

Call callback(frame) for every frame.

It runs in the background thread that receives the frames, so keep it fast. raw gives it every frame with both hands, whichever hands keeps (for gestures).

rates() → dict

Statistics of the stream, as a dict.

hz: frames in the last second. changed_hz: how many of them carried new hand data. interval_p95_ms: time between frames, in ms, that 95% of frames beat. age_ms: age of the newest frame, in ms.

Teleop: one hand drives, the other pauses

class Teleop(quest: QuestHands, pinch_on: float = 0.02, pinch_off: float = 0.04, stale: float = 0.1, adapt: bool = True)

Drive a robot with one hand and pause it with the other (see the module’s documentation).

The driving hand is the hand quest keeps (the right one by default, also with hands="both"); the other one gives the gestures. pinch_on and pinch_off [m] are when its pinch closes and opens again; stale [s] how long without a frame before holding. adapt=False drives any robot: your joint angles and your wrist’s axes, no motors.

update(frame: Frame) → Command

Take a new frame, with both hands; quest calls this for every frame.

command(now: float | None = None) → Command

The latest command; holding with "no frames" once frames stop for stale s.

class Command(hold: bool, reason: str, wrist: Pose | None, joints: ndarray | None, motors: ndarray | None, received: float)

What the robot should do now.

hold : bool

keep the robot where it is.

Type:

True

reason : str

Why it holds, such as "left hand pinching"; empty while it moves.

wrist : Pose | None

room coordinates, with the ADAPT hand’s axes (with adapt=False, your wrist’s). It starts at your wrist and then moves as your hand moves, except while holding. None before the first move.

Type:

Where the robot’s wrist goes

joints : ndarray | None

(20,) the ADAPT hand’s joint angles, within limits (with adapt=False, yours, in ANGLE_NAMES order); unchanged while holding.

motors : ndarray | None

(13,) the ADAPT hand’s motor angles; unchanged while holding. None with adapt=False.

received : float

time.time() when the frame it comes from arrived.

Frame: one moment

class Frame(seq: int, time: float, received: float, head: Pose | None, left: Hand | None, right: Hand | None)

Everything the headset reported for one rendered frame.

seq : int

Frame counter from the headset; it restarts when the page reloads.

time : float

The headset’s clock when it rendered the frame, seconds.

received : float

time.time() on this computer when the frame arrived.

head : Pose | None

The headset’s pose, or None if it was not tracked.

left : Hand | None

The left hand, or None while it is not tracked.

right : Hand | None

The right hand, or None while it is not tracked.

hand(side: str) → Hand | None

The "left" or "right" hand, or None while it is not tracked.

to_dict() → dict

The frame as plain lists and dicts, ready for json.dumps; the UDP format.

Hand: one hand

class Hand(side: str, positions: ndarray, quaternions: ndarray)

One tracked hand: the pose of each of its 25 joints, and what follows from them.

side : str

"left" or "right".

positions : ndarray

(25, 3) joint positions, metres, in JOINTS order.

quaternions : ndarray

(25, 4) joint orientations, unit quaternions (x, y, z, w), in the same order.

property wrist : Pose

the hand’s position and orientation.

Type:

The wrist’s pose

joint(name: str) → Pose

The pose of one joint by its WebXR name, for example "index-finger-tip".

property rotations : ndarray

(25, 3, 3) joint rotation matrices.

property angles : ndarray

one row per finger, thumb to pinky.

Columns: bend at the base of the finger, sideways spread at the base, bend at the middle joint, bend at the joint nearest the tip. Bending towards the palm and spreading towards the thumb are positive, on both hands. A straight finger reads 0; the thumb’s base does not, since it is measured against the wrist.

The medical names, used in ANGLE_NAMES: thumb CMC flexion, CMC abduction, MCP flexion, IP flexion; fingers MCP flexion, MCP abduction, PIP flexion, DIP flexion.

Type:

(5, 4) joint angles in radians

property angle_dict : dict[str, float]

The 20 joint angles by name (ANGLE_NAMES), radians.

property local_quaternions : ndarray

(25, 4) each joint’s rotation relative to the joint before it, towards the wrist.

The wrist’s is its rotation in the room.

property pinch : float

Thumb tip to index tip, metres.

to_dict() → dict

Wrist pose, angles by name, pinch and the 25 joints as (x, y, z, qx, qy, qz, qw) rows.

Pose: a position and an orientation

class Pose(position: ndarray, quaternion: ndarray)

A position and an orientation, in the room’s coordinates (x right, y up, -z forward).

position : ndarray

(3,) position, metres.

quaternion : ndarray

(4,) orientation, a unit quaternion (x, y, z, w).

property rotation : ndarray

(3, 3) rotation matrix.

property matrix : ndarray

(4, 4) homogeneous transform.

ADAPT Hand: metaquest_teleop.adapt

joint_angles(hand: Hand, clip: bool = True, coupled: bool = True, fit: bool | None = None) → ndarray

(20,) the ADAPT joint angles for your hand, radians, in JOINTS order: a pose it can take.

The thumb follows the calibration (CALIBRATION): each of its joints the angles of yours it follows (FOLLOWS), through its points.

The fit (fit=True, the default: FIT): the fingers’ pose that puts them closest to yours, through the hand’s forward kinematics, around that thumb. Your knuckles on its knuckles (a scale and a shift), its fingers’ PIP, DIP and tips on yours, and a fingertip as near the thumb tip as yours is, when you pinch. Only poses the hand can take: its motors (COUPLING), within JOINT_LIMITS (clip=False: without them).

Joint for joint (fit=False): the fingers follow the calibration too: a finger’s spread, MCP, PIP and DIP follow your spread, base, middle and tip. Then the pose the hand can take, as in virtualmodelcontrol: a finger’s DIP mimics its PIP (both the mean of the two), and one motor spreads the fingers (the best fit of the three). The fit starts from this pose.

coupled=False gives the joint-for-joint angles before the motors, joint by joint (with or without fit). clip keeps every joint within JOINT_LIMITS.

motor_angles(source, clip: bool = True, fit: bool | None = None) → ndarray

(13,) the ADAPT motor angles, radians, in MOTORS order: targets for a motor PID.

source is a Hand (the motors of joint_angles(), with the same fit) or 20 joint angles. 13 motors cannot set any 20 joints, so for joint angles this is the least-squares fit through COUPLING: a finger’s PIP motor takes the mean of its PIP and DIP, and the spread motor the best fit of the index, ring and pinky spreads. For joint_angles(), a pose the hand can take, it is exact. clip keeps each motor where every joint it turns stays within JOINT_LIMITS.

wrist_pose(hand: Hand) → Pose

Your wrist, in the room, with the axes of the ADAPT base frame: +z towards the fingers, +y on the palm side, the thumb towards -x. Put the ADAPT hand’s base there (through your arm’s calibration) and it faces as your hand does.

positions(joints) → dict[str, ndarray]

The ADAPT hand’s shape for 20 joint angles: for each digit, (6, 3) points in its base frame [m]: the digit’s base, its four joints and its tip.

JOINTS

The ADAPT hand’s 20 joints, in the order of joint_angles().

MOTORS

The ADAPT hand’s 13 motors, in the order of motor_angles(). The two wrist motors are not among them: they hold the wrist still.

JOINT_LIMITS

The range of each joint, (low, high) in radians, as in virtualmodelcontrol.

COUPLING

joint angles = COUPLING @ motor angles. Each finger’s PIP motor turns its PIP and DIP joints together, and one motor spreads the index, ring and pinky (the middle finger stays).

Type:

(20, 13)

FIT = True

Fit the ADAPT fingers to yours, around the thumb (True, the default of joint_angles() and motor_angles()), or have them follow the calibration too, joint for joint (False). Change it at any time: metaquest-teleop --no-adapt-fit sets it to False.

CALIBRATION

for each ADAPT joint, points of yours and the angle it takes there, in degrees: {your angle: its angle}; for the thumb’s CMC2, {(your base, your spread): its angle} (FOLLOWS). Each joint follows the line closest to its points (for two angles of yours, the plane), by least squares: through them with two points (three for a plane), their best fit with more. Then within its limits (JOINT_LIMITS). At least two points, at different angles of yours (for two angles, three not on one line).

These are the library’s points. Change them at any time, in Python or in the 3D view (metaquest-teleop --calibration, which saves each calibration to a file in CALIBRATIONS); a calibration becomes the library’s with scripts/set_calibration.py in the repository.

Type:

The calibration

FOLLOWS

the thumb’s CMC2 two, its base and its spread; the middle finger’s spread none (it stays at 0); the others one.

Type:

The angles of yours (YOUR_ANGLES) that each ADAPT joint follows

YOUR_ANGLES

each finger’s base, spread, middle and tip (the thumb’s too: Hand.angles), and the thumb’s turn: how far its first bone has turned about the hand’s long axis, from sideways towards the palm’s front, as the ADAPT’s CMC1 turns its own. your_angles() reads them, in degrees.

Type:

Your angles that the ADAPT joints follow, as the dashboard and the 3D view show them

CALIBRATIONS

Where metaquest-teleop --calibration saves each calibration, a new file each time, named by when it started: ~/.config/metaquest-teleop/calibrations ($XDG_CONFIG_HOME instead of ~/.config when set).

load_calibration(path: str | PathLike) → None

Load a calibration saved by save_calibration() (or metaquest-teleop --calibration): its joints take its points, the others the library’s. OSError if there is no such file, ValueError if it is not a calibration; nothing changes then.

save_calibration(path: str | PathLike) → Path

Save the calibration as it is now, every joint’s points, for load_calibration() and scripts/set_calibration.py. As JSON: {"thumb_IP": [[0, 0], [45, 90]], ...}, each point your angle(s) then its angle, in degrees. Returns where it saved.

reset_calibration(joint: str | None = None) → None

Back to the library’s calibration: of every joint, or of joint.

your_angles(hand: Hand) → dict[str, float]

Your angles that the ADAPT joints follow (YOUR_ANGLES), in degrees, by name.

calibrated(joint: str, *yours: float) → float

The angle of the ADAPT joint, in degrees, for these angles of yours, in degrees (its FOLLOWS, in that order): the line closest to its CALIBRATION points (the plane, for two angles of yours); before its limits. calibrated("thumb_CMC2", 20, 35) is the CMC2 for your thumb’s base at 20° and spread at 35°.

Names

JOINTS

The 25 joints of each hand, as WebXR names them, in the order of the rows of Hand.positions and Hand.quaternions.

ANGLE_NAMES

The names of the 20 joint angles, in the order of hand.angles.ravel().

FINGERS

The five fingers, in the order of the rows of Hand.angles.

DEFAULT_PORT = 8012

The port of the page and the stream unless you choose another.