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) radiansOnly 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.
- port: int =
- frames¶
Frames received since the start.
- Type:
int
- headset¶
What the connected page reported:
agent,mode,fps,space,sessionandstats; 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 --calibrationsets 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.
- 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.
-
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.
rawgives it every frame with both hands, whicheverhandskeeps (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
questkeeps (the right one by default, also withhands="both"); the other one gives the gestures.pinch_onandpinch_off[m] are when its pinch closes and opens again;stale[s] how long without a frame before holding.adapt=Falsedrives any robot: your joint angles and your wrist’s axes, no motors.
- 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, inANGLE_NAMESorder); 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.
- 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".
- quaternions : ndarray¶
(25, 4) joint orientations, unit quaternions (x, y, z, w), in the same order.
- 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
JOINTSorder: 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), withinJOINT_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 invirtualmodelcontrol: 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=Falsegives the joint-for-joint angles before the motors, joint by joint (with or withoutfit).clipkeeps every joint withinJOINT_LIMITS.
-
motor_angles(source, clip: bool =
True, fit: bool | None =None) ndarray¶ (13,) the ADAPT motor angles, radians, in
MOTORSorder: targets for a motor PID.sourceis aHand(the motors ofjoint_angles(), with the samefit) or 20 joint angles. 13 motors cannot set any 20 joints, so for joint angles this is the least-squares fit throughCOUPLING: 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. Forjoint_angles(), a pose the hand can take, it is exact.clipkeeps each motor where every joint it turns stays withinJOINT_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()andmotor_angles()), or have them follow the calibration too, joint for joint (False). Change it at any time:metaquest-teleop --no-adapt-fitsets 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 inCALIBRATIONS); a calibration becomes the library’s withscripts/set_calibration.pyin 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,middleandtip(the thumb’s too:Hand.angles), and the thumb’sturn: 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 --calibrationsaves each calibration, a new file each time, named by when it started:~/.config/metaquest-teleop/calibrations($XDG_CONFIG_HOMEinstead of~/.configwhen set).
- load_calibration(path: str | PathLike) None¶
Load a calibration saved by
save_calibration()(ormetaquest-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()andscripts/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 itsCALIBRATIONpoints (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.positionsandHand.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.