跳转至

GOAP 实施计划:ESP32-S3 + Pi Zero 2 W WiFi 姿态估计

日期: 2026-04-02 版本: 1.0 状态: 提议 依赖: ADR-029、ADR-068、SOTA 调研(sota-wifi-sensing-2025.md)


1. 目标状态定义

1.1 最终目标

一个可投入生产的基于 WiFi 的人体姿态估计系统,其中: - ESP32-S3 节点以 100 Hz 采集 WiFi CSI,执行时间特征提取,并通过 UDP 传输压缩特征 - Raspberry Pi Zero 2 W 接收来自 1-4 个 ESP32 节点的特征,运行神经推理,并以 >= 10 Hz 的速度输出 17 关键点的 COCO 姿态 - 单人体 MPJPE 在已训练环境中 < 100mm - 端到端延迟 < 150ms(从 CSI 采集到姿态输出) - 总 BOM 成本 < $30/感知区域(1 个 Pi Zero + 2 个 ESP32)

1.2 世界状态变量

current_state:
  esp32_csi_capture:           true    # Already implemented
  multi_node_aggregation:      true    # ADR-018 UDP aggregator
  phase_alignment:             true    # ruvsense/phase_align.rs
  coherence_gating:            true    # ruvsense/coherence_gate.rs
  multistatic_fusion:          true    # ruvsense/multistatic.rs
  kalman_pose_tracking:        true    # ruvsense/pose_tracker.rs
  onnx_inference_engine:       true    # wifi-densepose-nn
  modality_translator:         true    # wifi-densepose-nn/translator.rs
  training_pipeline:           true    # wifi-densepose-train
  pi_zero_deployment:          false   # No Pi Zero target
  lightweight_model:           false   # No edge-optimized model
  temporal_conv_module:        false   # No TCN in inference path
  csi_compression:             false   # No ESP32-side compression
  int8_quantization:           false   # No quantization pipeline
  bone_constraint_loss:        false   # No skeleton physics in loss
  esp32_pi_protocol:           false   # No lightweight protocol
  edge_inference_engine:       false   # No ARM-optimized inference
  cross_env_adaptation:        false   # No domain adaptation
  multi_person_paf:            false   # No PAF-based multi-person
  3d_pose_lifting:             false   # No Z-axis estimation

goal_state:
  esp32_csi_capture:           true
  multi_node_aggregation:      true
  phase_alignment:             true
  coherence_gating:            true
  multistatic_fusion:          true
  kalman_pose_tracking:        true
  onnx_inference_engine:       true
  modality_translator:         true
  training_pipeline:           true
  pi_zero_deployment:          true    # TARGET
  lightweight_model:           true    # TARGET
  temporal_conv_module:        true    # TARGET
  csi_compression:             true    # TARGET
  int8_quantization:           true    # TARGET
  bone_constraint_loss:        true    # TARGET
  esp32_pi_protocol:           true    # TARGET
  edge_inference_engine:       true    # TARGET
  cross_env_adaptation:        true    # TARGET (Phase 2)
  multi_person_paf:            true    # TARGET (Phase 2)
  3d_pose_lifting:             true    # TARGET (Phase 3)

2. 动作定义

每个动作都有前置条件、效果、预估成本(开发者天数)和优先级。

动作 1:定义 ESP32-Pi 通信协议(ADR-069){#action-1-define-esp32-pi-communication-protocol-adr-069}

name:           define_esp32_pi_protocol
cost:           3 days
priority:       CRITICAL (blocks all Pi Zero work)
preconditions:  [esp32_csi_capture]
effects:        [esp32_pi_protocol := true]

描述: 设计一种轻量级二进制协议,用于 ESP32 -> Pi Zero 通过 UDP(WiFi)或 UART(有线备用)进行通信。

协议规范:

Frame Header (8 bytes):
  [0:1]   magic:         0xCF01 (CSI Frame v1)
  [2]     node_id:       u8 (0-255, identifies ESP32 node)
  [3]     frame_type:    u8 (0=raw_csi, 1=compressed_features, 2=heartbeat)
  [4:5]   sequence:      u16 (monotonic frame counter, wraps at 65535)
  [6:7]   payload_len:   u16 (bytes following header)

Raw CSI Payload (frame_type=0):
  [0:3]   timestamp_us:  u32 (microseconds since boot, wraps at ~71 minutes)
  [4]     channel:       u8 (WiFi channel 1-13)
  [5]     bandwidth:     u8 (0=20MHz, 1=40MHz)
  [6]     rssi:          i8 (dBm)
  [7]     noise_floor:   i8 (dBm)
  [8:9]   num_sc:        u16 (number of subcarriers, typically 52 or 114)
  [10..]  csi_data:      [i16; num_sc * 2] (interleaved I/Q, little-endian)

Compressed Feature Payload (frame_type=1):
  [0:3]   timestamp_us:  u32
  [4]     compression:   u8 (0=none, 1=pca_16, 2=pca_32, 3=autoencoder)
  [5]     num_features:  u8 (number of feature dimensions)
  [6..]   features:      [f16; num_features] (half-precision floats)

Heartbeat Payload (frame_type=2):
  [0:3]   uptime_s:      u32
  [4:7]   frames_sent:   u32
  [8:9]   free_heap:     u16 (KB)
  [10]    wifi_rssi:     i8 (connection to AP)
  [11]    battery_pct:   u8 (0-100, 0xFF if wired)

实现位置: - ESP32 固件:firmware/esp32-csi-node/main/protocol_v2.h - Rust 解析器:wifi-densepose-hardware/src/protocol_v2.rs

设计原理: - 固定 8 字节头部配合魔数实现帧同步 - 压缩特征使用半精度(f16)相比 f32 可节省 50% 带宽 - 心跳机制使 Pi Zero 能够检测节点故障并重新平衡 - 原始 CSI 模式用于调试;压缩模式用于生产

动作 2:实现轻量级模型架构

name:           implement_lightweight_model
cost:           10 days
priority:       CRITICAL (core inference capability)
preconditions:  [training_pipeline, onnx_inference_engine]
effects:        [lightweight_model := true, temporal_conv_module := true]

架构:WiFlowPose(混合 WiFlow + MultiFormer)

基于 SOTA 分析,我们定义了一个结合最佳要素的自定义架构:

Input: CSI amplitude tensor [B, T, S]
  B = batch size
  T = temporal window (20 frames at 20 Hz = 1 second context)
  S = subcarriers (52 for ESP32-S3 20MHz, 114 for 40MHz)

Stage 1: Temporal Encoder (runs on ESP32 optionally, or Pi Zero)
  TCN with 4 layers, dilation [1, 2, 4, 8]
  Input:  [B, T, S] = [B, 20, 52]
  Output: [B, T', C_t] = [B, 20, 64] (temporal features)

Stage 2: Spatial Encoder (runs on Pi Zero)
  Asymmetric convolution blocks (1xk kernels on subcarrier dimension)
  4 residual blocks: 64 -> 128 -> 128 -> 64 channels
  Subcarrier compression: 52 -> 26 -> 13 -> 7
  Output: [B, 64, 7]

Stage 3: Keypoint Decoder (runs on Pi Zero)
  Axial self-attention (2-stage, 4 heads)
  Reshape to [B, 17, 64] (17 keypoints x 64 features)
  Linear projection: 64 -> 2 (x, y coordinates)
  Output: [B, 17, 2] (17 COCO keypoints, normalized 0-1)

Optional Stage 4: Multi-person (Phase 2)
  PAF branch: predict 19 limb affinity fields
  Hungarian assignment for person grouping

预估模型大小: - 时间编码器:约 0.5M 参数 - 空间编码器:约 1.2M 参数 - 关键点解码器:约 0.8M 参数 - 总计:约 2.5M 参数 - INT8 大小:约 2.5 MB - FP16 大小:约 5 MB - 预估 Pi Zero 2 W 推理:每帧 30-60ms

Rust 实现位置: 新模块位于 wifi-densepose-nn/src/wiflow_pose.rs

/// WiFlowPose: Lightweight WiFi CSI to pose estimation model
///
/// Hybrid architecture combining WiFlow's TCN temporal encoder
/// with MultiFormer's dual-token spatial processing and
/// axial self-attention for keypoint decoding.
pub struct WiFlowPoseConfig {
    /// Number of input subcarriers (52 for ESP32 20MHz, 114 for 40MHz)
    pub num_subcarriers: usize,
    /// Temporal window size in frames (default: 20)
    pub temporal_window: usize,
    /// TCN dilation factors (default: [1, 2, 4, 8])
    pub tcn_dilations: Vec<usize>,
    /// Number of output keypoints (default: 17, COCO format)
    pub num_keypoints: usize,
    /// Hidden dimension for spatial encoder (default: 64)
    pub hidden_dim: usize,
    /// Number of attention heads in axial attention (default: 4)
    pub num_attention_heads: usize,
    /// Enable multi-person PAF branch (default: false)
    pub multi_person: bool,
}

impl Default for WiFlowPoseConfig {
    fn default() -> Self {
        Self {
            num_subcarriers: 52,
            temporal_window: 20,
            tcn_dilations: vec![1, 2, 4, 8],
            num_keypoints: 17,
            hidden_dim: 64,
            num_attention_heads: 4,
            multi_person: false,
        }
    }
}

操作 3:实现骨骼约束损失

name:           implement_bone_constraint_loss
cost:           2 days
priority:       HIGH
preconditions:  [training_pipeline, lightweight_model]
effects:        [bone_constraint_loss := true]

遵循 WiFlow 的损失函数:

L_total = L_keypoint + lambda_bone * L_bone + lambda_physics * L_physics

L_keypoint = SmoothL1(pred, gt, beta=0.1)

L_bone = (1/|B|) * sum_{(i,j) in bones} | ||pred_i - pred_j|| - bone_length_{ij} |

L_physics = (1/N) * sum_t max(0, ||pred_t - pred_{t-1}|| - v_max * dt)

其中: - bones = 14 个 COCO 骨骼连接(例如 left_shoulder-left_elbow) - bone_length_{ij} = 平均人体骨骼长度比例(归一化到躯干长度) - v_max = 最大生理上合理的关键点速度(行走为 2 m/s,快速手势为 10 m/s) - lambda_bone = 0.2, lambda_physics = 0.1

骨骼长度比例(归一化到躯干 = shoulder_center 到 hip_center = 1.0):

骨骼 比例
肩-肘 0.55
肘-腕 0.50
髋-膝 0.85
膝-踝 0.80
肩-髋 1.00
颈-鼻 0.30
鼻-眼 0.08
眼-耳 0.12

实现位置: wifi-densepose-train/src/losses.rs(添加 BoneConstraintLoss)

操作 4:实现 INT8 量化流水线

name:           implement_int8_quantization
cost:           5 days
priority:       HIGH
preconditions:  [lightweight_model, training_pipeline]
effects:        [int8_quantization := true]

方法:带校准的训练后量化(PTQ)

  1. 使用标准流水线以 FP32 训练模型
  2. 导出为 ONNX 格式
  3. 使用校准数据集运行 ONNX Runtime 量化工具:
  4. 在多个环境中收集 1000 个具有代表性的 CSI 帧
  5. 运行校准以确定逐层量化范围
  6. 对权重应用对称 INT8 量化,对激活应用非对称量化
  7. 验证量化模型精度(目标:PCK@20 下降 <2%)

量化感知注意事项: - TCN 层:按通道量化(空洞卷积对量化敏感) - 注意力层:将注意力 logits 保持为 FP16(softmax 对数值敏感) - 输出层:保持为 FP32(最终坐标回归需要精度)

Rust 实现:

// In wifi-densepose-nn/src/quantize.rs
pub struct QuantizationConfig {
    /// Quantization method
    pub method: QuantMethod, // PTQ, QAT, Dynamic
    /// Per-layer precision overrides
    pub layer_overrides: HashMap<String, Precision>,
    /// Calibration dataset path
    pub calibration_data: PathBuf,
    /// Number of calibration samples
    pub num_calibration_samples: usize,
    /// Target accuracy degradation threshold
    pub max_accuracy_loss: f32,
}

pub enum Precision {
    INT8,
    FP16,
    FP32,
}

ONNX 量化命令(用于构建流水线):

python -m onnxruntime.quantization.quantize \
  --input model_fp32.onnx \
  --output model_int8.onnx \
  --calibrate \
  --calibration_data_reader CsiCalibrationReader \
  --quant_format QDQ \
  --activation_type QUInt8 \
  --weight_type QInt8

操作 5:为 Pi Zero 构建边缘推理引擎

name:           build_edge_inference_engine
cost:           8 days
priority:       CRITICAL
preconditions:  [lightweight_model, int8_quantization, esp32_pi_protocol]
effects:        [edge_inference_engine := true, pi_zero_deployment := true]

架构:带环形缓冲区的流式推理

                    UDP/UART
ESP32-S3 ---------> Pi Zero 2 W
                    |
                    v
            +-- RingBuffer<CsiFrame> --+
            |  (capacity: 64 frames)   |
            +------ |  | -------------+
                    v  v
            +-- TemporalWindow --------+
            |  (20 frames, sliding)    |
            +------ | ----------------+
                    v
            +-- WiFlowPose ONNX ------+
            |  (INT8, XNNPACK accel)  |
            +------ | ----------------+
                    v
            +-- PoseTracker -----------+
            |  (Kalman + skeleton)    |
            +------ | ----------------+
                    v
              PoseEstimate output
              (17 keypoints + confidence)

新的 Rust 二进制文件: wifi-densepose-cli/src/bin/edge_infer.rs

/// Edge inference daemon for Raspberry Pi Zero 2 W
///
/// Receives CSI frames from ESP32 nodes via UDP, maintains a temporal
/// sliding window, runs INT8 ONNX inference, and outputs pose estimates.
///
/// Usage:
///   wifi-densepose edge-infer \
///     --model model_int8.onnx \
///     --listen 0.0.0.0:5555 \
///     --output-port 5556 \
///     --window-size 20 \
///     --max-nodes 4

struct EdgeInferConfig {
    /// Path to INT8 ONNX model
    model_path: PathBuf,
    /// UDP listen address for CSI frames
    listen_addr: SocketAddr,
    /// UDP output address for pose results
    output_addr: Option<SocketAddr>,
    /// Temporal window size
    window_size: usize,
    /// Maximum ESP32 nodes to accept
    max_nodes: usize,
    /// Inference thread count (1-4 on Pi Zero 2 W)
    num_threads: usize,
    /// Enable XNNPACK acceleration
    use_xnnpack: bool,
}

针对 Pi Zero 2 W 的交叉编译:

# Install cross-compilation toolchain
rustup target add aarch64-unknown-linux-gnu
sudo apt install gcc-aarch64-linux-gnu

# Build for Pi Zero 2 W (64-bit Raspberry Pi OS)
cross build --target aarch64-unknown-linux-gnu \
  --release \
  -p wifi-densepose-cli \
  --features edge-inference \
  --no-default-features

# Or for 32-bit Raspberry Pi OS:
# rustup target add armv7-unknown-linux-gnueabihf
# cross build --target armv7-unknown-linux-gnueabihf ...

ARM 的 ONNX Runtime 链接: - 使用带有 download-binaries 功能的 ort crate,以自动下载 aarch64 二进制文件 - 替代方案:从源码构建 OnnxStream,以获得最小的二进制体积(约 2 MB,而完整 ONNX Runtime 约为 30 MB)

操作 6:在 ESP32 上实现 CSI 压缩

name:           implement_csi_compression
cost:           5 days
priority:       MEDIUM
preconditions:  [esp32_csi_capture, esp32_pi_protocol]
effects:        [csi_compression := true]

三个压缩层级:

层级 0:无压缩(原始 CSI) - 载荷:52 个子载波 x 2(I/Q)x 2 字节 = 每帧 208 字节 - 用例:调试、最高保真度

层级 1:PCA-16(在 ESP32 上运行) - 预计算的 PCA 投影矩阵(52 -> 16 维) - 在配置期间存储到 NVS 闪存中 - 载荷:16 个特征 x 2 字节(f16)= 每帧 32 字节 - 压缩率:6.5 倍 - 计算:在 ESP32-S3 上约 0.1ms(矩阵-向量乘法,SIMD)

层级 2:PCA-32(更高保真度) - 52 -> 32 维 - 载荷:32 x 2 = 64 字节 - 压缩率:3.25 倍

层级 3:学习式自编码器(未来) - ESP32-S3 具有足够的算力来运行小型编码器(约 10K 参数) - 需要在闪存中存储量化后的编码器权重 - 带宽效率最高,但需要训练

PCA 计算(离线,在配置期间):

// wifi-densepose-train/src/compression.rs

/// Compute PCA projection matrix from calibration CSI data
pub fn compute_pca_projection(
    calibration_data: &[CsiFrame],
    target_dims: usize,
) -> PcaProjection {
    // 1. Stack all CSI amplitude vectors into matrix [N, S]
    // 2. Center (subtract mean)
    // 3. Compute covariance matrix [S, S]
    // 4. Eigendecomposition, take top `target_dims` eigenvectors
    // 5. Return projection matrix [S, target_dims] and mean vector [S]
    // ...
}

pub struct PcaProjection {
    /// Projection matrix [num_subcarriers, target_dims]
    pub matrix: Vec<f32>,
    /// Mean vector for centering [num_subcarriers]
    pub mean: Vec<f32>,
    /// Number of input subcarriers
    pub input_dims: usize,
    /// Number of output features
    pub output_dims: usize,
}

ESP32 固件集成: - 将 PCA 矩阵存储在 NVS 分区中(PCA-32 为 32x52x4 = 6.5 KB) - 在 UDP 传输前,在 CSI 回调中应用投影 - 可通过配置命令选择

操作 7:实现跨环境自适应

name:           implement_cross_env_adaptation
cost:           8 days
priority:       MEDIUM (Phase 2)
preconditions:  [lightweight_model, training_pipeline, pi_zero_deployment]
effects:        [cross_env_adaptation := true]

方法:基于少样本自适应的快速环境校准

受 Arena Physica 的基于模板的设计空间和 MERIDIAN(ADR-027)启发:

  1. 环境指纹识别(在 Pi Zero 上,部署时):
  2. 采集 60 秒“空房间” CSI
  3. 计算房间签名:平均幅度剖面、延迟扩展、K 因子
  4. 匹配到最近的房间模板(走廊、办公室、卧室等)
  5. 加载模板特定的模型权重

  6. 少样本微调(可选,在工作站上):

  7. 采集 5 分钟具有已知姿态的校准数据
  8. 微调模型的最后 2 层(约 50K 参数)
  9. 将更新后的模型传回 Pi Zero

  10. 在线自适应(持续,在 Pi Zero 上):

  11. 随时间跟踪 CSI 统计量(滑动窗口均值/方差)
  12. 检测分布偏移(KL 散度超过阈值)
  13. 应用批归一化统计量更新(无需梯度计算)

实现位置: wifi-densepose-train/src/rapid_adapt.rs(扩展现有模块)

操作 8:实现多人 PAF 解码

name:           implement_multi_person_paf
cost:           6 days
priority:       LOW (Phase 2)
preconditions:  [lightweight_model, bone_constraint_loss]
effects:        [multi_person_paf := true]

架构(遵循 MultiFormer):

为 WiFlowPose 模型添加一个 PAF 分支:

Stage 3 features [B, 64, 7]
  |
  +--> Keypoint head: [B, 17, 2] (single-person keypoints)
  |
  +--> PAF head: [B, 38, H, W] (19 limb affinity fields)
  |
  +--> Confidence head: [B, 19, H, W] (part confidence maps)

Pi Zero 上的多人分配: 1. 通过 NMS 从置信度图中提取候选关键点 2. 计算候选对之间的 PAF 积分分数 3. 使用匈牙利算法求解二分图匹配 4. 将关键点分组为人员实例

预计额外成本: 约 1M 参数,约 10ms 额外推理时间

操作 9:实现 3D 姿态提升

name:           implement_3d_pose_lifting
cost:           5 days
priority:       LOW (Phase 3)
preconditions:  [lightweight_model, multi_person_paf, multistatic_fusion]
effects:        [3d_pose_lifting := true]

方法:多视角三角测量 + 学习式深度先验

在已知位置部署 2 个或更多 ESP32 节点时,通过以下方式计算 3D 姿态:

  1. 每个节点对提供 WiFi 场的不同视角
  2. 独立估计每个视角的 2D 姿态
  3. 对极几何从 2D 观测中约束 3D 位置
  4. 学习式深度先验解决歧义(前后混淆)

这利用了 wifi-densepose-ruvector 中现有的 viewpoint/geometry.rs 模块,该模块已经为多节点配置计算 GeometricDiversityIndex 和费雪信息。

3. 硬件架构

3.1 系统拓扑

                    WiFi AP (existing home router)
                    /         |          \
                   /          |           \
            ESP32-S3 #1   ESP32-S3 #2   ESP32-S3 #3
            (CSI node)    (CSI node)    (CSI node, optional)
                |             |              |
                +------+------+------+-------+
                       | UDP (WiFi)  |
                       v             v
                  Raspberry Pi Zero 2 W
                  (edge inference node)
                       |
                       v
                  Pose output (UDP/MQTT/WebSocket)
                  to display / home automation / API

3.2 数据流时序

T=0ms     ESP32 #1 captures CSI frame (channel 1)
T=2ms     ESP32 #1 applies PCA compression (0.1ms compute)
T=3ms     ESP32 #1 sends UDP packet to Pi Zero (64 bytes)
T=5ms     ESP32 #2 captures CSI frame (channel 6, TDM slot)
T=7ms     ESP32 #2 sends UDP packet to Pi Zero
T=10ms    Pi Zero receives both frames, adds to ring buffer
T=10ms    Pi Zero checks temporal window (20 frames accumulated?)
          If yes: run inference
T=15ms    Temporal encoder processes 20-frame window (5ms)
T=35ms    Spatial encoder + attention (20ms)
T=45ms    Keypoint decoder (10ms)
T=48ms    Kalman filter update + skeleton constraints (3ms)
T=50ms    Pose estimate emitted (17 keypoints + confidence)

总延迟:约 50ms(远低于 150ms 目标) 吞吐量:20 Hz(与 TDMA 周期匹配)

3.3 硬件物料清单

组件 单价 数量 总计
ESP32-S3 DevKit (8MB) $9 2 $18
Raspberry Pi Zero 2 W $15 1 $15
MicroSD 卡(16GB) $5 1 $5
USB-C 电源适配器 $5 1 $5
总计 $43

若使用 ESP32-S3 SuperMini(每个 $6),总成本降至 $37。

最低可行配置(1 个 ESP32 + 1 个 Pi Zero):$24。

3.4 Pi Zero 2 W 规格

参数 值
SoC BCM2710A1(四核 Cortex-A53 @ 1 GHz)
RAM 512 MB LPDDR2
WiFi 802.11b/g/n(仅 2.4 GHz)
蓝牙 BLE 4.2
GPIO 40 针脚排针(UART、SPI、I2C)
电源 5V/2A USB micro-B
操作系统 Raspberry Pi OS Lite(64 位,无头模式)

推理内存预算:

组件 内存
操作系统 + 服务 ~100 MB
WiFlowPose INT8 模型 ~3 MB
ONNX Runtime / OnnxStream ~10-30 MB
环形缓冲区(64 帧 x 4 节点) ~1 MB
推理工作区 ~20 MB
总计 ~134-164 MB
可用 ~348-378 MB headroom

可轻松容纳在 512 MB RAM 内。

4. Rust Crate 修改

4.1 修改的 Crate

wifi-densepose-hardware

新增文件: - src/protocol_v2.rs -- 轻量级 ESP32-Pi 二进制协议解析器/序列化器 - src/pi_zero.rs -- Pi Zero UDP 接收器,带环形缓冲区管理

修改文件: - src/lib.rs -- 添加 pub mod protocol_v2; pub mod pi_zero; - src/aggregator/mod.rs -- 添加对 protocol_v2 帧格式的支持

wifi-densepose-nn

新增文件: - src/wiflow_pose.rs -- WiFlowPose 模型定义(TCN + 非对称卷积 + 轴向注意力) - src/edge_engine.rs -- 边缘优化推理引擎(流式、ARM NEON) - src/quantize.rs -- INT8 量化配置与验证

修改文件: - src/lib.rs -- 添加新模块导出 - src/onnx.rs -- 添加 XNNPACK 执行提供程序选项、INT8 模型加载 - src/translator.rs -- 添加兼容 WiFlowPose 的输入格式

wifi-densepose-train

新增文件: - src/wiflow_pose_trainer.rs -- WiFlowPose 架构的训练循环 - src/compression.rs -- 用于 ESP32 CSI 压缩的 PCA 计算 - src/bone_loss.rs -- 骨骼约束与物理一致性损失

修改文件: - src/losses.rs -- 添加 BoneConstraintLoss、PhysicsConsistencyLoss - src/config.rs -- 添加 WiFlowPose 训练配置选项 - src/dataset.rs -- 添加 ESP32-S3 CSI 格式支持(52/114 子载波) - src/rapid_adapt.rs -- 添加少样本环境校准

wifi-densepose-signal

新增文件: - src/ruvsense/temporal_encoder.rs -- TCN 时序特征提取(ESP32 和 Pi 共享代码)

修改文件: - src/ruvsense/mod.rs -- 添加 pub mod temporal_encoder;

wifi-densepose-cli

新增文件: - src/bin/edge_infer.rs -- Pi Zero 边缘推理守护进程 - src/bin/calibrate.rs -- 环境校准工具(PCA 计算、房间指纹)

wifi-densepose-core

修改文件: - src/types.rs -- 添加 CompressedCsiFrame、EdgePoseEstimate 类型

4.2 新特性标志

# wifi-densepose-nn/Cargo.toml
[features]
default = ["onnx"]
onnx = ["ort"]
edge-inference = ["onnx", "xnnpack"]  # NEW: ARM NEON + XNNPACK
candle = ["candle-core", "candle-nn"]
tch-backend = ["tch"]

# wifi-densepose-cli/Cargo.toml
[features]
default = ["full"]
full = ["wifi-densepose-nn/onnx", "wifi-densepose-train/tch-backend"]
edge-inference = ["wifi-densepose-nn/edge-inference"]  # NEW: minimal binary for Pi

4.3 交叉编译配置

# .cargo/config.toml (add section)
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustflags = ["-C", "target-cpu=cortex-a53", "-C", "target-feature=+neon"]

5. ESP32 固件修改

5.1 新增文件

  • firmware/esp32-csi-node/main/protocol_v2.h -- 协议 v2 帧打包
  • firmware/esp32-csi-node/main/pca_compress.h -- 用于 CSI 的 PCA 压缩
  • firmware/esp32-csi-node/main/pca_compress.c -- 带 ESP32 SIMD 的 PCA 实现
  • firmware/esp32-csi-node/main/pi_zero_mode.c -- Pi Zero 通信模式(比完整服务器模式更轻量)

5.2 修改文件

  • firmware/esp32-csi-node/main/csi_handler.c -- 在 CSI 回调中添加压缩步骤
  • firmware/esp32-csi-node/main/nvs_config.c -- 在 NVS 中存储 PCA 矩阵
  • firmware/esp32-csi-node/main/Kconfig.projbuild -- 添加 CONFIG_PI_ZERO_MODE、CONFIG_CSI_COMPRESSION 选项

5.3 配置更新

# Provision for Pi Zero mode with PCA-16 compression
python firmware/esp32-csi-node/provision.py \
  --port COM7 \
  --ssid "MyWiFi" \
  --password "secret" \
  --target-ip 192.168.1.50 \  # Pi Zero IP
  --target-port 5555 \
  --compression pca-16 \
  --pca-matrix pca_matrix_16.bin

6. 训练流水线

6.1 训练工作流

Phase 1: Pre-train on public datasets (GPU workstation)
  Dataset: MM-Fi + Wi-Pose (Intel 5300 format, 30 subcarriers)
  Model: WiFlowPose with 30 subcarriers
  Loss: L_keypoint + 0.2 * L_bone + 0.1 * L_physics
  Duration: ~20 hours on single A100

Phase 2: Domain adaptation for ESP32 CSI (GPU workstation)
  Dataset: Self-collected ESP32-S3 data (52 subcarriers)
  Method: Fine-tune all layers with lower learning rate (1e-4)
  Subcarrier interpolation: 30 -> 52 using existing interpolate_subcarriers()
  Duration: ~4 hours

Phase 3: Quantization (CPU workstation)
  Method: Post-training quantization with 1000 calibration samples
  Format: ONNX INT8 (QDQ format)
  Validation: PCK@20 degradation < 2%

Phase 4: Environment calibration (on Pi Zero)
  Method: 60-second empty-room CSI collection
  Output: Room fingerprint + PCA matrix
  Duration: ~2 minutes total

6.2 数据集采集协议

对于自行采集的 ESP32 训练数据:

  1. 设置: 在 4x4m 房间的两个对角放置 2 个 ESP32-S3 节点,Pi Zero 接收
  2. 真值: 智能手机摄像头运行 MediaPipe Pose(30 FPS),通过 NTP 同步
  3. 活动: 站立、行走、坐下、挥手、跌倒、空闲(每项 2 分钟)
  4. 受试者: 5 名以上不同体型的志愿者
  5. 环境: 3 个以上房间(卧室、办公室、走廊)用于泛化
  6. 总目标: 约 100K 同步 CSI-姿态帧对

同步方法: - ESP32 和 Pi Zero 通过 NTP 同步(局域网内精度 < 10ms) - 摄像头帧使用系统时钟打时间戳 - 通过运动信号的互相关进行离线对齐

6.3 迁移学习策略

遵循 DensePose-WiFi 的成熟方法:

L_total = lambda_pose * L_pose
        + lambda_bone * L_bone
        + lambda_transfer * L_transfer
        + lambda_physics * L_physics

L_transfer = MSE(features_student, features_teacher)

其中 features_teacher 来自预训练的基于图像的姿态模型(HRNet 或 ViTPose),features_student 来自 WiFi CSI 模型在相应中间层的特征。

Lambda 计划: - 第 1-20 轮:lambda_transfer = 0.5(强迁移引导) - 第 20-50 轮:lambda_transfer = 0.2(中等引导) - 第 50-100 轮:lambda_transfer = 0.05(微调自由度)

7. 时间表与里程碑

阶段 1:基础(第 1-4 周)

周 动作 交付物
1 动作 1(协议),ADR-069 草稿 协议规范 + 解析器测试
2 动作 2(模型架构,开始) Rust 中的 WiFlowPose 模型定义
2 动作 3(骨骼损失) 损失函数已实现并测试
3 动作 2(模型架构,完成) 完整模型并导出 ONNX
4 动作 4(量化) INT8 模型,精度已验证

里程碑 M1: WiFlowPose 模型在 MM-Fi 上训练,导出为 INT8 ONNX,在验证集上 PCK@20 > 85%。

阶段 2:边缘部署(第 5-8 周)

周 动作 交付物
5 动作 5(边缘引擎,开始) 交叉编译可用,模型可在 Pi 上加载
6 动作 5(边缘引擎,完成) 在 Pi Zero 上以 >= 10 Hz 进行流式推理
6 动作 6(CSI 压缩) 在 ESP32 上进行 PCA 压缩,已验证带宽降低
7 集成测试 ESP32 -> Pi Zero 完整流水线可用
8 性能优化 延迟 < 100ms,内存 < 200 MB

里程碑 M2: 端到端演示:ESP32 捕获 CSI,Pi Zero 以 10+ Hz 输出姿态。

阶段 3:精度与适应(第 9-12 周)

周 动作 交付物
9 数据采集(ESP32-S3 训练数据) 50K+ 同步 CSI-姿态帧
10 域适应训练 ESP32 专用模型,MPJPE < 120mm
11 动作 7(跨环境适应) 房间校准可用
12 验证与文档 ADR-069 定稿,见证包

里程碑 M3: 单人在校准环境中 MPJPE < 100mm,跨环境部署可用,校准时间为 60 秒。

阶段 4:多人与 3D(第 13-20 周)

周 动作 交付物
13-14 动作 8(多人 PAF) 两人姿态分离可用
15-16 动作 9(3D 提升) 基于多节点的 Z 轴估计
17-18 高级优化 模型蒸馏、QAT
19-20 生产加固 OTA 更新、监控、告警

里程碑 M4: 在 Pi Zero 2 W 上以 10 Hz 实现多人 3D 姿态。

8. 风险分析

8.1 技术风险

风险 概率 影响 缓解措施
Pi Zero 2 W 推理过慢(> 100ms) 中 高 回退到活动识别(更小模型);改用 Pi 4
ESP32-S3 CSI 质量不足以用于姿态 低 严重 已在 ADR-028 中验证;如有需要,添加定向天线
INT8 量化导致精度下降 > 5% 中 中 改用 FP16(大小 2 倍,速度慢约 1.5 倍);应用 QAT
跨环境泛化能力差 高 高 房间校准(动作 7);基于模板的模型;持续适应
WiFi 干扰降低 CSI 质量 中 中 相干门控(已实现);信道跳变;5 GHz 回退
ONNX Runtime 二进制文件对 Pi Zero 过大 低 中 使用 OnnxStream(2 MB)替代完整 ONNX Runtime(30 MB)
多人关联错误 高 中 初期限制为 2 人;使用 PAF + 匈牙利算法;AETHER 重识别

8.2 硬件风险

风险 概率 影响 缓解措施
Pi Zero 2 W 供应短缺 中 中 该设计也可用于 Pi 3A+ 或 Pi 4
ESP32-S3 固件不稳定 低 中 现有固件经过实战测试;OTA 回滚
WiFi AP 对 CSI 的干扰 低 低 专用 2.4 GHz 信道;ESP32 信道跳变
电源问题(欠压) 低 中 合适的电源;ESP32 欠压检测

8.3 研究风险

风险 概率 影响 缓解措施
WiFlow 结果无法复现 中 高 回退到 CSI-Former 或 MultiFormer 架构
ESP32 CSI 与 Intel 5300 存在根本差异 中 高 采集 ESP32 专用训练数据;子载波插值
骨骼约束损失未能提升边缘精度 低 低 若无收益则移除;该约束简单且开销低
PCA 压缩丢失关键 CSI 信息 低 中 通过消融实验验证;如有需要,回退到原始 CSI

9. 依赖图(动作顺序)

                    [esp32_csi_capture] (DONE)
                    /                    \
                   v                      v
    [Action 1: Protocol]          [training_pipeline] (DONE)
           |                      /        |        \
           v                     v         v         v
    [Action 6: Compression] [Action 2: Model] [Action 3: Bone Loss]
           |                     |              |
           |                     +------+-------+
           |                            v
           |                   [Action 4: Quantization]
           |                            |
           +---------------+------------+
                           v
                  [Action 5: Edge Engine]
                           |
                           v
                  [Action 7: Cross-Env] (Phase 2)
                           |
                           v
                  [Action 8: Multi-Person] (Phase 2)
                           |
                           v
                  [Action 9: 3D Lifting] (Phase 3)

关键路径: 动作 1 -> 动作 2 -> 动作 4 -> 动作 5 并行路径: 动作 3 可与动作 2 并行执行 并行路径: 动作 6 可与动作 2-4 并行执行

10. 成功标准

阶段 1 退出标准

  • [ ] WiFlowPose 模型在 MM-Fi 数据集上训练至收敛
  • [ ] MM-Fi 验证集上 PCK@20 >= 85%
  • [ ] INT8 ONNX 模型大小 < 5 MB
  • [ ] 骨骼约束损失将物理上不合理的预测减少 > 50%

阶段 2 退出标准

  • [ ] edge_infer 二进制文件可交叉编译为 aarch64,并能在 Pi Zero 2 W 上运行
  • [ ] 端到端延迟 < 150ms(从 CSI 捕获到姿态输出)
  • [ ] 持续推理速率 >= 10 Hz
  • [ ] PCA 压缩在不损失超过 5% 精度的情况下将带宽降低 >= 3 倍
  • [ ] 多节点支持(2 个 ESP32 节点 + 1 个 Pi Zero)可用

阶段 3 退出标准

  • [ ] 在已校准环境中,单人 MPJPE < 100mm
  • [ ] 跨环境部署可通过 60 秒校准正常工作
  • [ ] 系统可连续运行 24 小时而不崩溃
  • [ ] ESP32 OTA 固件更新可用于 CSI 压缩参数

阶段 4 退出标准

  • [ ] 双人姿态分离可用(每人 MPJPE < 150mm)
  • [ ] 从 2 个及以上节点进行 3D 姿态估计(Z 轴误差 < 200mm)
  • [ ] 生产监控和告警已投入运行

11. 与现有 ADR 的关系

ADR 关系
ADR-018 协议 v2(动作 1)扩展了 ADR-018 的二进制帧格式
ADR-024 AETHER 重识别嵌入用于多人跟踪(动作 8)
ADR-027 MERIDIAN 跨环境泛化指导动作 7
ADR-028 ESP32 能力审计验证了 CSI 质量假设
ADR-029 RuvSense 流水线阶段输入到边缘推理(动作 5)
ADR-068 每节点状态流水线直接用于多节点推理

12. 需要新增的 ADR

ADR-069: 在 Raspberry Pi Zero 2 W 上进行边缘推理

本实施计划应正式化为 ADR-069,涵盖: - 协议 v2 规范 - WiFlowPose 架构选择理由 - Pi Zero 部署约束与优化 - INT8 量化策略 - 交叉编译方法 - 环境校准协议

状态:已提议,待本计划批准后生效。

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView