
Aircraft gyroscopic instruments modeled from M series MacBook IMU
Turns your MacBook into half of a six-pack.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Turns your MacBook into half of a six-pack.
An attitude indicator, directional gyro, turn-and-slip indicator and per-axis G meters, all driven by the MacBook's inertial measurement unit (IMU).
Apple Silicon MacBooks have a Bosch BMI282 IMU (gyro and accelerometer) on the always-on sensor hub, and macOS exposes it as vendor HID devices. It's silent until its AppleSPUHIDDriver gets SensorPropertyReportingState, SensorPropertyPowerState and a ReportInterval. Setting the interval back to 0 stops it. No root is needed.
imu.c does that and queues every report, and sensors.py drains the queue through ctypes. Each sample gives:
Details of the hardware probing are in sensors.md.
$\Delta t$ is the time between samples, $s = \pm1$ is the axis sign, and $\text{lag}_\tau(x)$ smooths toward $x$ with $y \leftarrow y + \frac{\Delta t}{\tau + \Delta t}(x - y)$.
Rates. $b$ is the gyro bias, measured over 3 s at startup.
$$ \dot\psi = s_\psi(\omega_z - b_z), \qquad \dot\theta = s_\theta(\omega_x - b_x), \qquad \dot\phi = s_\phi(\omega_y - b_y) $$
$$ r = \text{lag}_{\text{0.3 s}}(\dot\psi) $$
$$ \psi \leftarrow (\psi + \dot\psi \Delta t) \bmod 360° $$
Pitch and roll. Integrate the gyro, then pull toward gravity (only while $\lVert a\rVert \approx 1$ g).
$$ \theta^g = s_\theta\mathrm{atan2}(-a_y, -a_z), \qquad \phi^g = s_\phi\mathrm{atan2}(a_x, -a_z) $$
$$ \theta \leftarrow \theta + \dot\theta \Delta t, \qquad \theta \leftarrow \theta + \frac{\Delta t}{\text{2 s} + \Delta t}\left(\theta^g - \theta\right) \qquad \text{(same for } \phi\text{)} $$
Ball. Apparent gravity in the X–Z plane, with the lag standing in for fluid damping.
$$ \beta = \text{lag}{\text{0.15 s}}\left(s\phi\mathrm{atan2}(a_x, -a_z)\right) $$
$$ n_i = \text{lag}_{\text{0.1 s}}(-a_i), \qquad i \in \lbrace x, y, z \rbrace $$
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。