> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wuji.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# IMU

手背模组内搭载 1 个 6 轴 IMU（3 轴陀螺仪 + 3 轴加速度计，不含磁力计），提供两组订阅接口：

| API | 数据 | `orientation` |
| - | - | - |
| `glove.imu_palm()` | 原始数据：角速度 + 线加速度 | 不可用（`orientation_covariance[0]` = -1，见 REP-145） |
| `glove.imu_data_palm()` | 融合数据：原始数据 + 互补滤波解算的朝向 | 可用 |

```python theme={null}
# 融合数据：带朝向
sub = glove.imu_data_palm().subscribe()
imu = await sub.recv_async()
print(f"朝向: {imu.orientation}")            # 四元数 (x, y, z, w)
print(f"角速度: {imu.angular_velocity}")      # rad/s
print(f"线加速度: {imu.linear_acceleration}") # m/s²

# 原始数据：仅角速度与线加速度
sub = glove.imu_palm().subscribe()
raw = await sub.recv_async()
print(f"角速度: {raw.angular_velocity}, 线加速度: {raw.linear_acceleration}")
```

<Info>
  融合朝向由 SDK 互补滤波给出，滤波在**首个订阅者**建立数据流时启动。roll / pitch 由首帧加速度按重力初始化并长期稳定，yaw 缺少绝对参考，以数据流启动时刻为零点，长期会缓慢漂移。所有订阅者（含 `tf` 这类间接依赖）都取消订阅后重新订阅，yaw 零点才会重置。
</Info>

<Info>
  IMU 数据格式与 ROS `sensor_msgs/Imu` 兼容，可直接用于 ROS 生态系统集成。两组数据流均可用 TopicRecorder 录制为 MCAP 文件导出，见 SDK [数据录制](/docs/wuji-sdk/data-recording)。
</Info>

## ImuData

IMU 传感器数据，兼容 ROS `sensor_msgs/Imu`。

| 字段 | 类型 | 说明 |
| - | - | - |
| `header` | [FrameHeader](/docs/wuji-sdk/data-reference#frameheader) | 帧头 |
| `orientation` | [Quaternion](/docs/wuji-sdk/data-reference#quaternion) | 朝向四元数。仅 `imu_data_palm()` 提供融合值（`orientation_covariance[0]` = 0），`imu_palm()` 上为单位四元数且 `orientation_covariance[0]` = -1 表示不可用（REP-145） |
| `orientation_covariance` | `List[float]` | 朝向协方差矩阵（3×3，行优先） |
| `angular_velocity` | [Vector3F64](/docs/wuji-sdk/data-reference/#vector3-/-vector3f64) | 角速度（rad/s） |
| `angular_velocity_covariance` | `List[float]` | 角速度协方差矩阵 |
| `linear_acceleration` | [Vector3F64](/docs/wuji-sdk/data-reference/#vector3-/-vector3f64) | 线加速度（m/s²） |
| `linear_acceleration_covariance` | `List[float]` | 线加速度协方差矩阵 |

`imu_palm()` 原始数据帧示例：

```json theme={null}
{
  "header": {
    "seq": 500,
    "timestamp_us": 1709876543210,
    "frame_id": ""
  },
  "orientation": {
    "x": 0.0,
    "y": 0.0,
    "z": 0.0,
    "w": 1.0
  },
  "orientation_covariance": [-1, 0, 0, 0, 0, 0, 0, 0, 0],
  "angular_velocity": {
    "x": 0.01,
    "y": -0.02,
    "z": 0.005
  },
  "angular_velocity_covariance": [0, 0, 0, 0, 0, 0, 0, 0, 0],
  "linear_acceleration": {
    "x": 0.1,
    "y": -0.05,
    "z": 9.8
  },
  "linear_acceleration_covariance": [0, 0, 0, 0, 0, 0, 0, 0, 0]
}
```

<Tabs>
  <Tab title="Python">
    Python：本页前文已展示 Python 接口。
  </Tab>

  <Tab title="C">
    C SDK 为手背 IMU 和融合 IMU 提供强类型订阅接口。

    ```c theme={null}
    wuji_glove_subscribe_imu_palm(dev, on_imu, user_data, &imu_sub);
    wuji_glove_subscribe_imu_data_palm(dev, on_imu_data, user_data, &imu_data_sub);
    ```

    回调帧指针仅在回调期间有效。使用完毕后调用 `wuji_sub_close`。
  </Tab>
</Tabs>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.