Files
faceclaw/app/native/imu-types.ts
T
James Babcock e09f8eae96 Simplify glanceboard-trigger angle setting; fix incorrectly-rotated accelerometer readings on G1
The glanceboard head-tilt option was more complicated than necessary,
because it wanted the user to take two angle measurements, a baseline
angle and a tilt angle. That was a workaround to not knowing the
accelerometer's orientation/calibration, but actually, we do know those.

(Except, as it turns out, on the G1, the accelerometer orientation is
different than it is on the G2, and there was a bug where EvenHub apps
got their accelerometer readings in the wrong orientation. So for
example the EvenHub Level app didn't work correctly.)
2026-11-15 23:29:02 -08:00

34 lines
1.1 KiB
TypeScript

/** Platform-neutral IMU types, shared by imu.ts and imu.ios.ts. */
/**
* An accelerometer sample in g, in Faceclaw's frame for every glasses model
* (the G2's own; the session rotates other models' samples into it, see
* ImuOrientation.kt): +x forward, +y to the wearer's left, +z up through the
* top of the head. At rest it is the "up" direction: head level reads
* (0, 0, 1), looking 45° up (0.71, 0, 0.71), the head tilted 45° to the right
* (0, 0.71, 0.71).
*/
export type ImuReading = { x: number; y: number; z: number; source: number };
/**
* How far the head is tilted up from level, in degrees (negative: down), from
* a reading taken at rest. Rolling the head to the side does not change it.
*/
export function imuPitchDegrees(reading: { x: number; y: number; z: number }): number {
return (Math.atan2(reading.x, Math.hypot(reading.y, reading.z)) * 180) / Math.PI;
}
/** Map an IMU sample's EventSource to a short label. */
export function imuSourceLabel(source: number): string {
switch (source) {
case 1:
return "R arm";
case 2:
return "ring";
case 3:
return "L arm";
default:
return "device";
}
}