Detour软件架构
概述 / Overview
Detour 是 MDCS 的定位系统:它整合 激光 SLAM、地纹 SLAM、天花板 SLAM、二维码导航 等多种定位手段,输出统一的 6-DoF 位姿给上层(Clumsy 自动驾驶 / SimpleComposer 调度)。Detour 不接受外部插件 —— 它通过 DObject 共享内存订阅 Medulla 发布的传感器数据,并通过 外部反馈接口接收里程计 / IMU / RTK / UWB。
Detour is the MDCS positioning subsystem. It fuses laser SLAM, ground-texture SLAM, ceiling SLAM, QR navigation, and other localisation sources into a unified 6-DoF pose for the upper layers (Clumsy autopilot / SimpleComposer fleet). Detour does not accept plugins — it consumes Medulla sensor publications via DObject, and external poses (odometry / IMU / RTK / UWB) via the external-feed API.
子模块 / Subsystems
| 模块 / Module | 文件 / File | 用途 / Use |
|---|---|---|
| Lidar consumer | `D:\src\Detour\DetourCore\CartDefinition\Lidar.cs:302-311` | 从 Medulla DObject 订阅雷达帧 |
| Tight coupler | `D:\src\Detour\DetourCore\Algorithms\TightCoupler.ExternalCoupler.cs` | 接收外部位姿、做紧耦合融合 |
| Laser SLAM | `D:\src\Detour\DetourCore\Algorithms\LaserSLAM*` | 见 Detour 激光 SLAM 算法详解 |
| Ground-texture SLAM | `D:\src\Detour\DetourCore\Algorithms\GroundTexture*` | 见 地面纹理 SLAM 算法详解 |
| QR / fiducial | `D:\src\Detour\DetourCore\Algorithms\QR*` | 见 二维码识别导航 |
| Multi-source fuser | `TightCoupler` | 见 多定位源的自动综合 |
数据流 / Data flow
Medulla 传感器插件
│ output() → DObject(name)
▼
Detour 订阅:
- LidarConsumer.ReadLidar()
- CameraConsumer (ground-texture / ceiling / QR)
│
▼
各 SLAM 后端 (laser / texture / ceiling / QR)
│ 每个产生一组 观测约束
▼
TightCoupler (位姿图优化)
│ + 外部反馈 (PostExternalFeed)
▼
统一位姿 (x, y, z, th, pitch, roll, tick)
│ 发布到 DObject "pose"
▼
Clumsy / SimpleComposer 订阅
外部反馈 / External feeds
非传感器位姿(轮编里程计 / IMU / RTK / UWB / 二次定位源)通过 外部反馈进入 Detour:
Non-sensor poses (wheel odometry, IMU, RTK, UWB, secondary sources) enter Detour through the external-feed API:
TightCoupler.PostExternalFeed(new ExternalFeed
{
name = "wheel_imu",
counter = tick++,
hasTranslation = true,
hasRotation = true,
is2D = true,
integrated = true, // 积分量 / cumulative
x = odom_x, y = odom_y, th = odom_th
}, "WheelOdom");
字段含义见 `TightCoupler.ExternalCoupler.cs`:`hasTranslation/hasRotation`(包含的自由度)、`integrated`(积分量 vs 单帧量)、`toRemap`(绝对参考系下,需要全局重映射)、`startingTick`(首帧基准)。
Field semantics in `TightCoupler.ExternalCoupler.cs`: `hasTranslation/hasRotation` (DOFs), `integrated` (cumulative vs single-frame), `toRemap` (absolute, needs global remap), `startingTick` (reference baseline).
多 SLAM 共存策略 / Multi-SLAM coexistence
- 并行运行: 默认每种 SLAM 后端都开,各产生自己的观测约束。
- 置信加权: TightCoupler 根据每个后端的协方差矩阵做加权融合。
- 场景切换: 某个后端连续 N 帧置信度 < 阈值 → 临时禁用其约束。
- 硬切换: 用户可在 UI 中强制选择"单一定位源"模式(调试用)。
- All SLAM backends run in parallel by default.
- TightCoupler weights by per-backend covariance.
- A backend that's degraded for N frames is temporarily disabled.
- A user can force single-source mode (debug).
定位输出 / Positioning output
Detour 把当前最优位姿写到 pose 命名的 DObject:
The current best pose is published to a DObject named `pose`:
public struct DetourPose
{
public double x, y, z; // mm
public double th; // 偏航 / yaw rad
public double pitch, roll; // rad
public long tick; // 时间戳 / system tick
public double cov_xy; // 平面协方差 / planar covariance
public double cov_th; // 偏航协方差 / yaw covariance
public string activeBackend; // 当前主用 SLAM 后端
}
与 Medulla 的关系 / Relation to Medulla
Detour 不是 Medulla 的插件;它是独立的 .NET 进程,与 Medulla 同主机但不同进程,二者只通过 DObject 共享内存通讯。这种设计使得 Detour 可以独立部署 / 升级 / 切换 SLAM 算法而不影响 Medulla。
Detour is not a Medulla plugin. It's a separate .NET process on the same host, communicating with Medulla only via DObject shared memory. This decoupling lets Detour deploy / upgrade / swap SLAM algorithms independently.
DetourStandalone 与 DetourLite / Standalone & Lite variants
- DetourStandalone: 完整 Detour,含全部 SLAM + UI。详见 DetourStandalonePluginGuide。
- DetourLite: 精简版,只含必要功能 + 检查表自检。见 DetourLite 检查表。