dualsense-ts
Version:
The natural interface for your DualSense and DualSense Access controllers, with Typescript
62 lines • 2.48 kB
TypeScript
/**
* High-level orientation tracker for the DualSense controller.
*
* Wraps the Madgwick AHRS filter and provides:
* - Fused orientation as Euler angles and quaternion
* - Accelerometer-only tilt (no drift, no yaw — useful for
* gravity-reference applications like steering)
* - Automatic unit conversion from the library's [-1, 1] calibrated
* values to the rad/s and g units the filter expects
*
* DualSense IMU hardware constants:
* Gyroscope: ±2000 deg/s full scale → 1.0 = 2000 deg/s
* Accelerometer: ±4 g full scale → 0.25 ≈ 1 g
*/
import { type Quaternion } from "./quaternion";
export interface OrientationParams {
/**
* Madgwick filter gain. Higher = more accelerometer trust (less drift,
* more noise). Lower = smoother but driftier.
*
* - 0.01–0.04: very smooth, noticeable drift over minutes
* - 0.05–0.15: general purpose (default 0.1)
* - 0.2–0.5: aggressive correction, jittery under vibration
*/
beta?: number;
}
export declare class Orientation {
/** Fused orientation as Euler angles (radians, updated each sample). */
pitch: number;
yaw: number;
roll: number;
/** Fused orientation as a unit quaternion [w, x, y, z]. */
quaternion: Quaternion;
/**
* Tilt derived from the accelerometer gravity vector alone.
* No drift, but also no yaw — only pitch and roll.
* Noisy during motion; best used when the controller is relatively still.
*/
tiltPitch: number;
tiltRoll: number;
/** Madgwick filter gain. Can be adjusted at runtime. */
get beta(): number;
set beta(v: number);
private readonly filter;
constructor(params?: OrientationParams);
/** Reset to identity orientation (call when zeroing the view). */
reset(): void;
/**
* Incorporate one IMU sample. Called automatically by the Dualsense
* class on each HID report — you don't normally call this yourself.
*
* @param gx Calibrated gyro X (pitch), [-1, 1]
* @param gy Calibrated gyro Y (yaw), [-1, 1]
* @param gz Calibrated gyro Z (roll), [-1, 1]
* @param ax Calibrated accel X, [-1, 1]
* @param ay Calibrated accel Y, [-1, 1]
* @param az Calibrated accel Z, [-1, 1]
* @param dt Time delta in seconds
*/
update(gx: number, gy: number, gz: number, ax: number, ay: number, az: number, dt: number): void;
}
//# sourceMappingURL=orientation.d.ts.map