Compare commits
18
Commits
0843c6ade0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a05d44826 | ||
|
|
4db635ec78 | ||
|
|
96445bd5f1 | ||
|
|
72f407c110 | ||
|
|
56f4b3adb0 | ||
|
|
c710b955b1 | ||
|
|
ef712728e2 | ||
|
|
06237c103a | ||
|
|
4502296915 | ||
|
|
0602144ac5 | ||
|
|
28ac7c488e | ||
|
|
b772174c1c | ||
|
|
b833e6f658 | ||
|
|
55e9456e4a | ||
|
|
9b72f580c3 | ||
|
|
3c3a34c1ed | ||
|
|
ff39d32123 | ||
|
|
3c58a08dad |
No files matched your search
@@ -9,6 +9,31 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 当前定位入口
|
||||||
|
|
||||||
|
默认定位已切换到连续跟踪的 LIO(`field_localization_node`)。Shell 和 Python 启动默认只读加载仓库随附的 `src/sentry_sim/maps/field_full.flmap`,覆盖当前 Gazebo 场地。完整用法、时间/外参约定和局限见 [field_localization](src/field_localization/README.md)。
|
||||||
|
|
||||||
|
`LOCALIZATION=amcl scripts/sentry_up.sh`(或 Python 启动参数 `localization:=amcl`)选择旧方案。下文与 `docs/定位接入AMCL.md` 中的 AMCL 参数/排障说明仅适用于该分支。每次只启动一种定位器发布 `map→odom`,两种方案均保留 Nav2 的 2D map_server。
|
||||||
|
|
||||||
|
## 当前仿真渲染与模型资源
|
||||||
|
|
||||||
|
- **3D 雷达使用 GPU 渲染路径**:模型配置为 `gpu_lidar`,Gazebo Sensors 与场景使用 OGRE2。无界面启动通过 EGL 选择 NVIDIA vendor;具备 NVIDIA 设备和驱动时使用显卡,否则可能回退到 Mesa `llvmpipe` 软件渲染。当前机器的 EGL/NVIDIA 检查和性能数据见 [`docs/Gazebo_GPU评估.md`](docs/Gazebo_GPU评估.md)。GPU 指的是雷达的渲染计算;碰撞与车辆动力学仍由 DART 在 CPU 上计算。
|
||||||
|
- Shell 与 Python 启动入口共享 EGL 和 Gazebo 环境探测。无界面模式使用 Gazebo headless rendering;GUI 和无界面模式均从世界配置使用 OGRE2。
|
||||||
|
- 模型网格引用使用相对路径或 `model://` URI。`tools/gen_sdf.sh` 可从仓库外调用,并依据脚本位置定位工程;它生成 SDF 1.11 与 URDF,按两种产物各自的位置生成相对网格路径,通过校验后才替换产物。启动器按运行位置计算 RViz 所需的 `file://` URI。
|
||||||
|
- `catch_net`、`test_box` 的模型描述与配置统一为 SDF 1.11。模型资源解析和 EGL 启动细节见 [`src/sentry_sim/README.md`](src/sentry_sim/README.md)、[`tools/README.md`](tools/README.md) 与 [`docs/Gazebo_GPU评估.md`](docs/Gazebo_GPU评估.md)。
|
||||||
|
|
||||||
|
## MID-360 与场地点云
|
||||||
|
|
||||||
|
MID-360 使用 **0.10–40 m、360° × 59°(−7° 至 +52°)、40 线、10 Hz**。Gazebo 的规则采样每帧 14,400 点,雷达壳体为 **65 × 65 × 60 mm、265 g**。
|
||||||
|
|
||||||
|
| 话题 | 用途 |
|
||||||
|
|---|---|
|
||||||
|
| `/scan`、`/scan/points` | 原始传感器输出,保留体育馆墙壁和屋顶回波,RViz 使用原始 3D 点云 |
|
||||||
|
| `/scan/points_lio` | 保留场内地面和远端围挡。建图与定位再按 `map` 系场地边界裁剪 |
|
||||||
|
| `/scan/points_filtered`、`/scan2d` | 导航和避障输入,水平距离上限 8 m,障碍标记距离 4.5 m |
|
||||||
|
|
||||||
|
Shell 和 Python 均实测 **10.0 Hz、14,400 点/帧**,原始回波最远分别为 **29.78 m、31.52 m**。34 个测站重建的候选图 `field_full_40m.flmap` 有 **10,583 个体素**,全部落在场地裁剪范围内。Python 全场测试的 70 个代表目标均可规划,13 段导航有 11 段成功、9 段满足全部指标。圆柱复测的终点误差为 **0.082 m**,最小净距为 **0.364 m**。全场验收尚未通过,默认仍加载旧图 `field_full.flmap`,加载时同样裁剪馆外点。详见 [MID-360 接入与验收](docs/MID360-3D雷达接入.md)。
|
||||||
|
|
||||||
## 0. 开发环境
|
## 0. 开发环境
|
||||||
|
|
||||||
### 0.1 操作系统
|
### 0.1 操作系统
|
||||||
@@ -27,15 +52,15 @@
|
|||||||
| Gazebo(ROS vendor) | **10.5.0** | `/opt/ros/lyrical/opt/gz_*_vendor/` |
|
| Gazebo(ROS vendor) | **10.5.0** | `/opt/ros/lyrical/opt/gz_*_vendor/` |
|
||||||
| ros_gz / ros_gz_sim | 3.0.10 | `/opt/ros/lyrical` |
|
| ros_gz / ros_gz_sim | 3.0.10 | `/opt/ros/lyrical` |
|
||||||
| Nav2 | 1.5.2 | `ros-lyrical-navigation2` / `nav2-bringup` |
|
| Nav2 | 1.5.2 | `ros-lyrical-navigation2` / `nav2-bringup` |
|
||||||
| slam_toolbox | 2.10.0 | 备用(当前不用,定位走里程计真值) |
|
| slam_toolbox | 2.10.0 | 备用(当前默认 LIO,AMCL 可选) |
|
||||||
| RViz2 | 15.2.6 | |
|
| RViz2 | 15.2.6 | |
|
||||||
| CMake | 4.2.3 | 系统自带。**本工程不用**(构建全走 xmake) |
|
| CMake | 4.2.3 | 系统自带。**本工程不用**(构建全走 xmake) |
|
||||||
| GCC / G++ | 15.2.0 | |
|
| GCC / G++ | 15.2.0 | |
|
||||||
| GNU Make | 4.4.1 | |
|
| GNU Make | 4.4.1 | |
|
||||||
| Python | 3.14.4 | `/usr/bin/python3`(系统版) |
|
| Python | 3.14.4 | `/usr/bin/python3`(系统版) |
|
||||||
| Git | 2.53.0 | |
|
| Git | 2.53.0 | |
|
||||||
| **C++ 标准** | **C++23** | 仓库根 `xmake.lua` 的 `set_languages("c++23")`<br>⚠️ **下限 C++17**:rclcpp 要 17、PCL 1.15 用 `#error` 硬拦,改成 11/14 **编译不过** ,于是用23 |
|
| **C++ 标准** | **C++23** | 仓库根 `xmake.lua` 的 `set_languages("c++23")`<br>**固定要求 C++23**,不能降为 C++17/20 |
|
||||||
| **xmake** | **3.1.1** | `~/.local/bin/xmake`。**全工程唯一的构建系统**,在仓库根跑 `xmake`(核心库 + 两个节点 + 223 项单测,增量 0.5 秒)。`sentry_sim` 是纯数据包,不需要编译 |
|
| **xmake** | **3.1.1** | `~/.local/bin/xmake`。**全工程唯一的构建系统**,在仓库根跑 `xmake`(导航与定位核心库、节点、离线工具及单元测试)。`sentry_sim` 是纯数据包,不需要编译 |
|
||||||
|
|
||||||
## 1. 目录结构
|
## 1. 目录结构
|
||||||
|
|
||||||
@@ -54,7 +79,7 @@ sentry_nav_dev/ 仓库根(xmake 工程根)
|
|||||||
│ │
|
│ │
|
||||||
│ ├── sentry_nav/ 导航/决策节点(C++,唯一的可编译包)
|
│ ├── sentry_nav/ 导航/决策节点(C++,唯一的可编译包)
|
||||||
│ └── sentry_sim/ 仿真环境(147 MB,其中网格 146 MB)
|
│ └── sentry_sim/ 仿真环境(147 MB,其中网格 146 MB)
|
||||||
├── tools/ 模型转换与调试工具(独立脚本,不参与构建)
|
├── tools/ 日常工具、验收和启动/构建辅助脚本
|
||||||
├── generated/ 运行时产物(可随时删)
|
├── generated/ 运行时产物(可随时删)
|
||||||
├── .vscode/ IDE 配置(不影响仿真)
|
├── .vscode/ IDE 配置(不影响仿真)
|
||||||
└── build/ xmake 构建产物(不入 git)
|
└── build/ xmake 构建产物(不入 git)
|
||||||
@@ -68,7 +93,7 @@ sentry_nav_dev/ 仓库根(xmake 工程根)
|
|||||||
| `src/sentry_nav/` | 算法代码 | 在这块实现算法 |
|
| `src/sentry_nav/` | 算法代码 | 在这块实现算法 |
|
||||||
| `src/sentry_sim/` | 仿真基础设施(模型/参数/启动) | 改模型和调参时动 |
|
| `src/sentry_sim/` | 仿真基础设施(模型/参数/启动) | 改模型和调参时动 |
|
||||||
| `field/` | 官方场地包副本(地图 + 3D 场地) | 官方更新时整包替换 |
|
| `field/` | 官方场地包副本(地图 + 3D 场地) | 官方更新时整包替换 |
|
||||||
| `tools/` | 辅助工具脚本 | 按需加新工具 |
|
| `tools/` | [工具索引](tools/README.md) | 日常命令在顶层,内部脚本与验收分别归档 |
|
||||||
| `docs/` | 技术文档 | 有新发现就补 |
|
| `docs/` | 技术文档 | 有新发现就补 |
|
||||||
| `generated/` | 运行时产物 | 可删 |
|
| `generated/` | 运行时产物 | 可删 |
|
||||||
| `build/` | xmake 产物 | 不入 git |
|
| `build/` | xmake 产物 | 不入 git |
|
||||||
@@ -124,9 +149,9 @@ ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true rviz:=fa
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd ~/Gazebo_projects/sentry_nav_dev
|
cd ~/Gazebo_projects/sentry_nav_dev
|
||||||
HEADLESS=0 scripts/sentry_up.sh # 启动
|
HEADLESS=0 scripts/sentry_up.sh # 启动(日志自动落盘 generated/up.log)
|
||||||
python3 tools/check_stack.py # 体检(只读)
|
python3 tools/check_stack.py # 体检(只读)
|
||||||
build/linux/x86_64/release/nav_client 2.0 2.0 # 发一个导航目标(C++ 版,先 xmake)
|
build/bin/nav_client 0.0 0.0 # 发一个导航目标(先 xmake 编译)
|
||||||
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.5}}" # 手动前进
|
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.5}}" # 手动前进
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -223,18 +248,14 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
|||||||
| `tools/build_vehicle.py` | 整车装配体 → base/wheel 网格 + 布局 json |
|
| `tools/build_vehicle.py` | 整车装配体 → base/wheel 网格 + 布局 json |
|
||||||
| `tools/decimate.py` | 顶点聚类减面(纯 numpy,不依赖 MeshLab) |
|
| `tools/decimate.py` | 顶点聚类减面(纯 numpy,不依赖 MeshLab) |
|
||||||
| `tools/gen_sdf.sh` | URDF(xacro) → Gazebo 用的 model.sdf |
|
| `tools/gen_sdf.sh` | URDF(xacro) → Gazebo 用的 model.sdf |
|
||||||
| `tools/demo.py` | 驱动演示(前进/转向/打印雷达+里程计) |
|
| `nav_client`(xmake 产物) | 发 Nav2 目标(C++ 版,源码 `src/sentry_nav/src/nav_client.cpp`),**发前先查地图预检**(障碍/未知/净空不足直接拦),再打位置/重试/结果与导航耗时。实际路径随平台变,查法 `python3 tools/project_env.py` |
|
||||||
| `build/linux/x86_64/release/nav_client` | 发 Nav2 目标(C++ 版,源码 `src/sentry_nav/src/nav_client.cpp`;原 `tools/nav_client.py` 已删除),**发前先查地图预检**(障碍/未知/净空不足直接拦),再打位置/重试/结果与导航耗时 |
|
| `tools/check_stack.py` | 只读体检:10 个 lifecycle 节点 + 节点总览 + 话题 + TF + 真值对照 |
|
||||||
| `tools/free_goals.py` | 从栅格图算连通安全区,列出可去目标点(不需要起 ROS) |
|
|
||||||
| `tools/tf_watch.py` | 实时盯三条 TF 边 + Gazebo 真值 + 雷达有效率,抓定位瞬移 |
|
|
||||||
| `tools/scan_probe.py` | 雷达质量体检(默认 `/scan2d`,可传话题名) |
|
|
||||||
| `tools/probe_all.py` | 一次性检查 /clock /odom /scan /tf /粒子云 |
|
|
||||||
| `tools/check_stack.py` | 只读体检:7 个 lifecycle 节点 + 话题 + TF + 真值对照 |
|
|
||||||
| `tools/check_dds.sh` | Fast DDS 体检:`/dev/shm` 残留段、残留进程。`--clean` 清残留 |
|
| `tools/check_dds.sh` | Fast DDS 体检:`/dev/shm` 残留段、残留进程。`--clean` 清残留 |
|
||||||
|
| `tools/project_env.py` | 路径/版本探测(ROS 发行版、产物目录、场地包、地图、gz 版本),排查"路径不对"先跑它;被 `launch/` import,是依赖库 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 7. 当前状态(2026-11-16)
|
## 7. 当前状态(2026-11-25 更新)
|
||||||
|
|
||||||
### ✅ 已验证可用
|
### ✅ 已验证可用
|
||||||
|
|
||||||
@@ -262,9 +283,9 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
|||||||
> (`failed to plan from <一个奇怪的位置>`),极容易查错方向。
|
> (`failed to plan from <一个奇怪的位置>`),极容易查错方向。
|
||||||
>
|
>
|
||||||
> 根因与修法:`docs/踩过的坑.md` §G4/§G5、`docs/定位接入AMCL.md` §4.1/§4.2。
|
> 根因与修法:`docs/踩过的坑.md` §G4/§G5、`docs/定位接入AMCL.md` §4.1/§4.2。
|
||||||
> 诊断工具:`python3 tools/tf_watch.py`(抓瞬移)、`python3 tools/free_goals.py`(找安全点)。
|
> 诊断工具:`python3 tools/check_stack.py`(含真值对照)。
|
||||||
|
|
||||||
- **MID-360 已做成 3D 激光**(`/scan/points`,PointCloud2),**垂直视场为真机规格**:
|
- **历史记录:12 m 量程版的 MID-360 点云实测**(2026-11-16)。
|
||||||
|
|
||||||
| 指标 | 实测 |
|
| 指标 | 实测 |
|
||||||
|---|---|
|
|---|---|
|
||||||
@@ -277,8 +298,7 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
|||||||
|
|
||||||
RViz 的「MID360点云」显示项已经配好,打开就能看到。
|
RViz 的「MID360点云」显示项已经配好,打开就能看到。
|
||||||
|
|
||||||
> ⚠️ 量程仍是 **12 m**(真机 40 m),导致 14 m 外的场馆墙打不到、
|
> 当前 40 m 模型的结果见 [MID-360 接入与验收](docs/MID360-3D雷达接入.md)。
|
||||||
> 10 m 天花板差 4 cm 够不着。想改善见 `docs/仿真场地外壳.md` §10。
|
|
||||||
|
|
||||||
### 🆕 2026-11-17 新增
|
### 🆕 2026-11-17 新增
|
||||||
|
|
||||||
@@ -296,13 +316,12 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
|||||||
|
|
||||||
### ⚠️ 仍有局限
|
### ⚠️ 仍有局限
|
||||||
|
|
||||||
1. **定位是"作弊"的**:`map→odom` 是写死的静态平移 (-5.0, 3.0),位置靠 Gazebo 的
|
1. **LIO 是已知初始位姿下的连续跟踪定位**:不会全局重定位;点云配准连续失效或不确定度超限时会报告定位不可用并触发导航保护。地图对称性、几何退化和传感器断流仍可能导致停车。接口、阈值和验证限制见 [`src/field_localization/README.md`](src/field_localization/README.md)。
|
||||||
轮式里程计积分。打滑/被推之后**永远不会自愈**;真机上完全不可用。
|
2. **仿真用固定 40 m 量程和规则采样**,真机的探测距离随反射率变化,扫描图案也不同。
|
||||||
真定位需要:点云转 2D → AMCL(当前 `/scan` 因真机视场已基本失效,
|
|
||||||
得先加 `pointcloud_to_laserscan`)。详见 `docs/仿真场地外壳.md`
|
|
||||||
2. **雷达量程只有 12 m**(真机 40 m):场馆墙(14 m 外)打不到、10 m 天花板差 4 cm
|
|
||||||
3. 质量/惯量为估算值(25 kg / 1.5 kg),物理表现可能与真机有偏差
|
3. 质量/惯量为估算值(25 kg / 1.5 kg),物理表现可能与真机有偏差
|
||||||
4. 云台是刚体(导航不需要转动),自瞄阶段要拆
|
4. 云台 yaw 已拆成独立 link,可 360° 连续转(`gimbal_yaw_link`);pitch 轴还没拆。
|
||||||
|
雷达随云台转动,整帧点云按采样时刻的 TF 转到 IMU 系。
|
||||||
|
细节见 [`src/sentry_sim/urdf/README.md`](src/sentry_sim/urdf/README.md)
|
||||||
5. 场地外壳是纯视觉设施,没有看台/球架/广告牌等赛场道具
|
5. 场地外壳是纯视觉设施,没有看台/球架/广告牌等赛场道具
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -354,11 +373,11 @@ python3 tools/check_stack.py
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| ~~1~~ | ~~修 `patrol` 的朝向~~ | ✅ **已做**(2026-11-17)。原来 `orientation.w` 写死 1.0(永远朝 +X),现在按 `face_mode` 算:默认朝下一个航点,可选顺着来路。角度计算在 `src/core/`,有 190 项单测覆盖 |
|
| ~~1~~ | ~~修 `patrol` 的朝向~~ | ✅ **已做**(2026-11-17)。原来 `orientation.w` 写死 1.0(永远朝 +X),现在按 `face_mode` 算:默认朝下一个航点,可选顺着来路。角度计算在 `src/core/`,有 190 项单测覆盖 |
|
||||||
| 2 | **写决策状态机**(PATROL / ENGAGE / RETREAT) | 还没有。骨架是 `patrol`,纯逻辑该写在 `src/core/` 里配单测(5 ms 跑完,不用起 Gazebo) |
|
| 2 | **写决策状态机**(PATROL / ENGAGE / RETREAT) | 还没有。骨架是 `patrol`,纯逻辑该写在 `src/core/` 里配单测(5 ms 跑完,不用起 Gazebo) |
|
||||||
| 3 | **把定位做成真的** | 现在是**作弊**的:`map→odom` 写死 (-5.0, 3.0),位置靠轮速积分,打滑/被撞永远不会自愈。真做要 `/scan/points` → `pointcloud_to_laserscan` → AMCL |
|
| 3 | **扩展 LIO 验收与场景覆盖** | 当前默认使用全场 `field_full.flmap` 连续跟踪;继续验证新障碍、长时间往返和传感器断流下的定位保护。不要启用全局重定位来处理场地的 180° 对称歧义 |
|
||||||
| 4 | **雷达量程 12 → 20 m** | 现在 14 m 外的场馆墙打不到、10 m 天花板差 4 cm。改法见 `docs/仿真场地外壳.md` |
|
| ~~4~~ | ~~恢复雷达 40 m 量程~~ | 已恢复,体育馆回波在建图、定位和避障中按用途裁剪 |
|
||||||
| 5 | **补真实参数** | 整车质量 25 kg / 轮 1.5 kg 是估的。找机械要 SolidWorks「评估 → 质量属性」(kg·m²) |
|
| 5 | **补真实参数** | 整车质量 25 kg / 轮 1.5 kg 是估的。找机械要 SolidWorks「评估 → 质量属性」(kg·m²) |
|
||||||
| 6 | **障碍测试补齐** | `models/test_box/` 有模型但世界没 include;加进去后曾出现规划失败(车跑到角落出不来),需要查是代价地图被点云糊住还是控制器问题 |
|
| 6 | **障碍测试补齐** | `models/test_box/` 有模型但世界没 include;加进去后曾出现规划失败(车跑到角落出不来),需要查是代价地图被点云糊住还是控制器问题 |
|
||||||
| 7 | **云台拆分**(做自瞄才需要) | 现在云台是刚体。要拆得机械给 yaw / pitch 零件清单,再用 `tools/build_vehicle.py --split-gimbal` |
|
| 7 | ~~**云台拆分**~~ | ✅ **已做**(2026-11-25)。yaw 轴由 5 个同轴件实测在车体中心(**不是** GM6020 电机轴),`gimbal_yaw_link` 用 `continuous` 关节可 360° 转。剩 pitch 轴没拆 |
|
||||||
|
|
||||||
**1 和 2 是真正该动的代码**;3 是中等工程;4~6 是调参和补数据。
|
**1 和 2 是真正该动的代码**;3 是中等工程;4~6 是调参和补数据。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,209 @@
|
|||||||
|
# Gazebo GPU 渲染与物理评估
|
||||||
|
|
||||||
|
最后更新:2026-11-24
|
||||||
|
|
||||||
|
## 实测环境
|
||||||
|
|
||||||
|
Gazebo Sim 10.6.0,SDFormat 16.1.0,ROS 2 Lyrical。DART 继续计算接触、刚体和关节。
|
||||||
|
场地和车辆的可视网格与 `gpu_lidar` 使用 OGRE2。无界面入口通过 EGL 初始化渲染。
|
||||||
|
|
||||||
|
**本文有两组测量,条件和结论不同,不要混用:**
|
||||||
|
|
||||||
|
| 场景 | 进程读到的 OpenGL 设备 | 说明了什么 |
|
||||||
|
|---|---|---|
|
||||||
|
| 隔离环境(`/dev` 只有 14 项,看不到 `/dev/nvidiactl`) | Mesa llvmpipe(LLVM 21.1.8) | 只能测软件渲染,**不代表硬件性能** |
|
||||||
|
| 本机(RTX 5060 Max-Q,`/dev/nvidia0` 与 `/dev/dri/card0` 齐全) | **NVIDIA GeForce RTX 5060** | 见「EGL 修复的验证结果」 |
|
||||||
|
|
||||||
|
「雷达对照」那张 CPU 表来自**隔离环境**,衡量的是软件渲染开销。
|
||||||
|
|
||||||
|
## 为什么无界面入口落到 llvmpipe
|
||||||
|
|
||||||
|
改动前,`generated/up.log` 里**每次运行都有 60 组** `libEGL` 警告:
|
||||||
|
|
||||||
|
```text
|
||||||
|
libEGL warning: pci id for fd 113: 10de:2d59, driver (null)
|
||||||
|
libEGL warning: egl: failed to create dri2 screen
|
||||||
|
```
|
||||||
|
|
||||||
|
`10de:2d59` 是本机的独立显卡(RTX 5060 Max-Q)。**设备节点是通的**(有 fd),
|
||||||
|
失败点是 `driver (null)`:glvnd 在用 Mesa 的 DRI2 加载器找驱动,而 **NVIDIA 不提供
|
||||||
|
Mesa DRI 驱动**,它走自己的 `libEGL_nvidia.so`。查找失败后 EGL 回退到 llvmpipe,
|
||||||
|
`gpu_lidar` 于是在 CPU 上做软件光栅化。
|
||||||
|
|
||||||
|
**关键区分:驱动和节点都没问题。** `nvidia-smi` 报告 `595.99.02` / CUDA 13.2,
|
||||||
|
`/dev/nvidia0`、`/dev/nvidiactl`、`/dev/dri/card0`、`/dev/dri/renderD128` 全在,
|
||||||
|
桌面本身也在用这块卡。唯一的问题是 EGL 的 vendor 选择。
|
||||||
|
|
||||||
|
修法是让 EGL 只挑 NVIDIA 的 vendor 库。规则集中在 `tools/project_env.py` 的
|
||||||
|
`gpu_env()`,两个启动入口共用:
|
||||||
|
|
||||||
|
| 入口 | 用法 |
|
||||||
|
|---|---|
|
||||||
|
| Shell | `env_common.sh` 的 `env_gpu_egl()` 在启动 Gazebo 前 `eval` 出 export |
|
||||||
|
| Python | `sentry_arena.launch.py` 把结果作为 `additional_env` 传给 Gazebo 的 `ExecuteProcess` |
|
||||||
|
|
||||||
|
导出内容:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
|
||||||
|
export NVIDIA_DRIVER_CAPABILITIES=all
|
||||||
|
```
|
||||||
|
|
||||||
|
`EGL_PLATFORM` 不默认设置(让 OGRE2 自己选 device/surfaceless)。只有某些机器
|
||||||
|
确实需要时才用 `SENTRY_EGL_PLATFORM=surfaceless` 追加。
|
||||||
|
|
||||||
|
| 变量 | 行为 |
|
||||||
|
|---|---|
|
||||||
|
| `SENTRY_GPU_EGL=auto`(默认) | 有 `/dev/nvidiactl` 且存在 vendor json 才启用 |
|
||||||
|
| `SENTRY_GPU_EGL=nvidia` | 强制启用;缺 vendor json 直接报错 |
|
||||||
|
| `SENTRY_GPU_EGL=off` | 不动环境(想自己接管时用) |
|
||||||
|
| `SENTRY_EGL_PLATFORM=surfaceless` | 额外导出 `EGL_PLATFORM`(默认不设) |
|
||||||
|
| `SENTRY_EGL_VENDOR_JSON=<路径>` | 覆盖 vendor json 位置(发行版放别处时用) |
|
||||||
|
|
||||||
|
判定结果随时可查,不用起仿真:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/project_env.py --gpu
|
||||||
|
SENTRY_DRY_RUN=1 scripts/sentry_up.sh # 试运行报告里也有一行 GPU EGL
|
||||||
|
```
|
||||||
|
|
||||||
|
### EGL 修复的验证结果
|
||||||
|
|
||||||
|
在本机(`nvidia-smi` 正常、`/dev/nvidia0` 与 `/dev/dri/card0` 都在)验证,三项证据全部成立:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python3 tools/project_env.py --gpu
|
||||||
|
nvidia → __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json NVIDIA_DRIVER_CAPABILITIES=all
|
||||||
|
```
|
||||||
|
|
||||||
|
| 证据 | 修复前 | 修复后 |
|
||||||
|
|---|---|---|
|
||||||
|
| `failed to create dri2 screen`(同一次运行内) | 60 次 | **0 次** |
|
||||||
|
| `[env] GPU EGL → NVIDIA` 日志 | 无 | **有** |
|
||||||
|
| `nvidia-smi` 里的 Gazebo 进程 | 无 | **`gz-sim-main`,Type=`G`,128 MiB** |
|
||||||
|
|
||||||
|
第三项是决定性证据 —— 仿真运行中 `nvidia-smi` 的输出:
|
||||||
|
|
||||||
|
```text
|
||||||
|
| 0 N/A N/A 208686 G .../libexec/gz/sim10/gz-sim-main 128MiB |
|
||||||
|
```
|
||||||
|
|
||||||
|
显存总量也交叉对上了:桌面程序单独占 1,991 MiB,仿真运行中 2,148 MiB,
|
||||||
|
差值 157 MiB 与 Gazebo 的 128 MiB 渲染缓冲一致。
|
||||||
|
|
||||||
|
> **统计 `generated/up.log` 的坑**:这个文件跨多次运行**追加写**,直接
|
||||||
|
> `grep -c` 会把历史记录数进来。要先按最后一次启动切段:
|
||||||
|
>
|
||||||
|
> ```bash
|
||||||
|
> LAST=$(grep -n "sentry_up.*LIO mode=" generated/up.log | tail -1 | cut -d: -f1)
|
||||||
|
> sed -n "${LAST},\$p" generated/up.log | grep -c "failed to create dri2 screen"
|
||||||
|
> ```
|
||||||
|
|
||||||
|
若某台机器上设了 vendor 之后仍出现 `dri2` 警告,先试
|
||||||
|
`SENTRY_EGL_PLATFORM=surfaceless` 再跑一次;仍不行就用 `SENTRY_GPU_EGL=off`
|
||||||
|
保持原来的 llvmpipe 行为。
|
||||||
|
|
||||||
|
### 仍未测量:CPU 收益
|
||||||
|
|
||||||
|
「用上了显卡」已确认,但**省了多少 CPU 还没测**。方法(两组各跑一次):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev
|
||||||
|
|
||||||
|
# A 组(硬件渲染)
|
||||||
|
HEADLESS=1 scripts/sentry_up.sh &
|
||||||
|
# B 组(强制软件渲染)改成:HEADLESS=1 SENTRY_GPU_EGL=off scripts/sentry_up.sh &
|
||||||
|
|
||||||
|
sleep 20 # 等起稳
|
||||||
|
PID=$(pgrep -f "gz-sim-main" | head -1)
|
||||||
|
A=$(awk '{print $14+$15}' /proc/$PID/stat) # utime+stime(时钟滴答)
|
||||||
|
sleep 30
|
||||||
|
B=$(awk '{print $14+$15}' /proc/$PID/stat)
|
||||||
|
awk -v a="$A" -v b="$B" -v c="$(getconf CLK_TCK)" \
|
||||||
|
'BEGIN{printf "gz 平均单核占用 %.1f%%\n", (b-a)/c/30*100}'
|
||||||
|
```
|
||||||
|
|
||||||
|
对照基线见「雷达对照」:CPU 射线 29.7%,OGRE2 + llvmpipe 83.8%。
|
||||||
|
把 A 组数字补进那张表的第三行后,本文的渲染部分才算完整。
|
||||||
|
|
||||||
|
## 雷达对照
|
||||||
|
|
||||||
|
前两种配置各跑两次,均用同一个场地、机器人、DART 和初始位姿 `(-5, 3)`。
|
||||||
|
起稳后按仿真时间发送 4 秒前进、4 秒后退、2 秒停止。前进和后退速度幅值均为
|
||||||
|
0.16 m/s。独立真值显示最大位移落在 0.643–0.650 m。CPU 射线时不启动渲染,
|
||||||
|
OGRE2 雷达通过 EGL 绘制场景。表中 CPU 占用按单核 100% 计,包括 Gazebo 的子进程。
|
||||||
|
|
||||||
|
| 雷达 | 实时因子 | CPU 秒 / 仿真秒 | 平均单核 CPU 占用 | 点云频率(仿真时间) | 每帧点数 |
|
||||||
|
|---|---:|---:|---:|---:|---:|
|
||||||
|
| CPU 射线 | 0.973 | 0.305 | 29.7% | 10.0 Hz | 14,400 |
|
||||||
|
| OGRE2 雷达,llvmpipe | 1.000 | 0.838 | 83.8% | 10.0 Hz | 14,400 |
|
||||||
|
| **OGRE2 雷达,RTX 5060** | 待测 | 待测 | 待测 | 10.0 Hz | 14,400 |
|
||||||
|
|
||||||
|
仿真世界的实时因子目标为 1.0。在这组负载下,OGRE2 + llvmpipe 耗用约 2.75 倍于
|
||||||
|
CPU 射线的 CPU 时间,但实时因子反而更好(1.000 vs 0.973)—— 渲染和物理循环解耦,
|
||||||
|
CPU 射线才会直接阻塞物理更新。**前两行都是软件渲染基线与 CPU 射线,不含硬件加速。**
|
||||||
|
第三行的采样方法见「仍未测量:CPU 收益」。
|
||||||
|
|
||||||
|
## GPU 物理迁移
|
||||||
|
|
||||||
|
当前安装中的可选插件为 DART、Bullet、Bullet Featherstone 和 TPE。PhysX
|
||||||
|
可以通过 Gazebo Physics 接口实现独立引擎插件。候选插件需要提供当前模型用到的
|
||||||
|
关节、碰撞和接触接口,并适配 SDF 载入。PhysX 的 CUDA 刚体支持存在按形状和功能
|
||||||
|
回退 CPU 的情况。 [Gazebo Sim 物理引擎](https://gazebosim.org/api/sim/10/physics.html) · [PhysX GPU 刚体](https://nvidia-omniverse.github.io/PhysX/physx/5.7.0/docs/GPURigidBodies.html)
|
||||||
|
|
||||||
|
| 项目 | 迁移核查 |
|
||||||
|
|---|---|
|
||||||
|
| 四轮关节驱动 | 为 `MecanumDrive` 提供四个旋转关节的速度命令、状态读回和限制。对比直行、倒车、原地转向、停止时的轮速和独立真值。PhysX 的部分关节类型仍需要 CPU 参与。 |
|
||||||
|
| 轮地摩擦 | 匹配 DART 下圆柱轮与地板的静摩擦、滑移和停止距离。需要接触修改时,PhysX 可能使用 CPU 窄相。 |
|
||||||
|
| 场地碰撞 | 保留场地静态网格和车身简化碰撞体。对使用 GPU 碰撞的网格启用 GPU 数据预处理,检查围挡、相交边缘和低矮障碍的接触结果。 |
|
||||||
|
| 接触反馈与时序 | 对比接触点、方向和反馈时序,确认 ROS 时钟、IMU、里程计和独立真值时序。PhysX 的场景查询和部分接触功能仍由 CPU 执行。 |
|
||||||
|
|
||||||
|
默认部署继续使用 DART。渲染部分已在本机确认走 NVIDIA(见「EGL 修复的验证结果」),
|
||||||
|
下一步是在同一运动序列上同时记录硬件渲染的 CPU 占用和 Physics 更新耗时,判断
|
||||||
|
动态接触是不是新的主要开销。若确实如此,再做独立 PhysX 插件原型。单车场景的
|
||||||
|
GPU 物理收益目前未实测,轮地下的误差和场地网格碰撞是迁移验收的重点。
|
||||||
|
|
||||||
|
## 模型资源
|
||||||
|
|
||||||
|
运行 `tools/gen_sdf.sh` 可重新生成 SDF 1.11 和 URDF。网格引用以各自产物目录
|
||||||
|
为基准。用 Gazebo CLI 单独检查含 `model://` 的世界时,为 `SDF_PATH` 提供与
|
||||||
|
启动器相同的两处模型目录。运行时的 RViz `file://` URI 由启动器计算。
|
||||||
|
|
||||||
|
## 启动和导航回归
|
||||||
|
|
||||||
|
Shell 和 Python 的 EGL 启动均持续收到 `/scan` 与 `/scan/points`,两者的帧名为
|
||||||
|
`lidar_link`,仿真频率为 10.0 Hz,点云每帧 14,400 点。虚拟显示上运行的 Gazebo GUI
|
||||||
|
加载了场地、车体和四轮。用 RViz 的资源读取库验证了含空格路径下的两种 STL。
|
||||||
|
|
||||||
|
| 验收 | Nav2 成功 | 最大真值终点误差 | 平移 ATE | 最大 3D 误差 |
|
||||||
|
|---|---:|---:|---:|---:|
|
||||||
|
| Shell 首轮 | 2/3 | 1.892 m(返程取消) | 0.028 m | 0.148 m |
|
||||||
|
| Python | 3/3 | 0.459 m | 0.019 m | 0.087 m |
|
||||||
|
| Shell 复测 | 3/3 | 0.235 m | 0.025 m | 0.111 m |
|
||||||
|
|
||||||
|
各次运行均只有一个 `map → odom` 发布者。首轮 Shell 返程在仿真时间 91.57 s
|
||||||
|
因水平位置 3σ 达 0.521 m 触发保护。Shell 复测启动时遇到一次 Nav2 动作发现超时,
|
||||||
|
原有监管流程重试后全部节点 ACTIVE,`/is_path_valid` 正常响应。Python 的真值终点
|
||||||
|
分别为 0.459、0.341 和 0.071 m,前两段超过了原有的 0.30 m 验收值。
|
||||||
|
|
||||||
|
含空格的临时目录中,生成器从仓库外运行两次,产物一致。5 个模型和 1 个世界通过
|
||||||
|
`gz sdf -k`,生成模型保留用于 Gazebo 坐标帧的 `gz_frame_id` 扩展。
|
||||||
|
`xmake test` 通过 15 项,环境探测和模型生成的 Python 回归测试分别通过 11 项和 3 项
|
||||||
|
(新增的 `test_gpu_egl_matches_shell` 校验 `gpu_env()` 在 CLI 与 Shell 两个入口
|
||||||
|
给出的判定一致)。脚本语法检查、Shell 预演和 Python 启动参数检查通过。
|
||||||
|
其他 Gazebo 版本未实测。
|
||||||
|
|
||||||
|
### EGL 修复后的运行检查
|
||||||
|
|
||||||
|
加 EGL vendor 后的一次无界面 Shell 运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ HEADLESS=1 scripts/sentry_up.sh
|
||||||
|
[env] GPU EGL → NVIDIA(OGRE2 走真显卡;SENTRY_GPU_EGL=off 可关闭)
|
||||||
|
```
|
||||||
|
|
||||||
|
该次运行内 `failed to create dri2 screen` 计数为 **0**(此前每次 60),
|
||||||
|
`field_localization` 的 8 次状态打印全部为 `mode=FULL reason=NONE`,
|
||||||
|
`self_filter` 剔除盒 `x[-0.29,0.37] y[-0.27,0.27] z[-0.05,0.55]` 与车体
|
||||||
|
`0.578 × 0.521` 加上前伸云台的一致,未出现新的启动回归。
|
||||||
|
|
||||||
+72
-59
@@ -1,7 +1,7 @@
|
|||||||
# MID-360 3D 激光雷达接入说明
|
# MID-360 3D 激光雷达接入说明
|
||||||
|
|
||||||
> **状态**:✅ 点云可用,已通过 `self_filter` 接入 Nav2 代价地图
|
> 已接通 40 m 原始点云、场地建图裁剪与 Nav2 避障。新地图继续作为候选图。
|
||||||
> **最后更新**:2026-11-17
|
> 最后更新于 2026-11-25。
|
||||||
> **涉及**:`src/sentry_sim/urdf/sentry.urdf.xacro`(传感器定义)、`src/sentry_nav/`(自滤)
|
> **涉及**:`src/sentry_sim/urdf/sentry.urdf.xacro`(传感器定义)、`src/sentry_nav/`(自滤)
|
||||||
|
|
||||||
## 1. 结论
|
## 1. 结论
|
||||||
@@ -9,13 +9,12 @@
|
|||||||
| 能力 | 状态 |
|
| 能力 | 状态 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 输出 3D 点云 | ✅ **14400 点/帧(360 水平 × 40 垂直)**,10 Hz |
|
| 输出 3D 点云 | ✅ **14400 点/帧(360 水平 × 40 垂直)**,10 Hz |
|
||||||
| 有效点 / 测距 | ⚠️ 约 4950 个有效点(`inf` 占 65.6%),**0.06 ~ 11.68 m** |
|
| 量程 | 0.10–40 m,Shell 和 Python 采样的最远有效点分别为 29.78 m 和 31.52 m |
|
||||||
| 能看到地面 | ✅ 高度 −0.41 ~ +9.31 m(−7° 打地面,+52° 打到顶棚主梁) |
|
| 可见范围 | 场内地面、外部体育馆墙壁、屋顶 |
|
||||||
| RViz 可视化 | ✅ 「MID360点云」显示项(`/scan/points`) |
|
| RViz 可视化 | ✅ 「MID360点云」显示项(`/scan/points`) |
|
||||||
| 接入 Nav2 避障 | ✅ `/scan/points_filtered`(`self_filter` 剔除车身自回波后) |
|
| 接入 Nav2 避障 | ✅ `/scan/points_filtered`(`self_filter` 剔除车身自回波后) |
|
||||||
|
|
||||||
> ⚠️ **最大的限制不是视场,是量程 12 m**。真机是 0.1~40 m,我们只给 12 m,
|
体育馆保持 40 × 28 m、墙高 10 m。原始点云保留体育馆回波,建图和避障分别处理。
|
||||||
> 导致 14 m 外的墙一个点打不到、10 m 天花板差 4 cm 够不着。见 §3。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -27,12 +26,15 @@
|
|||||||
|
|
||||||
| 项 | 值 |
|
| 项 | 值 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 安装位置(ROS) | **(−0.0935, −0.1512, 0.4052)**,外形 84×68×82 mm(装配体实测) |
|
| 安装位置(ROS) | 云台零位时在底盘系 **(−0.0935, −0.1512, 0.4052) m** |
|
||||||
| 类型 | `type="lidar"` + `gz-sim-cpu-lidar-system`(CPU 射线,不依赖 GPU) |
|
| 外形与质量 | **65 × 65 × 60 mm,265 g**。惯量按均质长方体计算,SDF 转换后并入云台 link |
|
||||||
|
| 类型 | `type="gpu_lidar"` + OGRE2 `Sensors` |
|
||||||
| 水平 | 360 点,−π ~ +π |
|
| 水平 | 360 点,−π ~ +π |
|
||||||
| **垂直** | **40 线,−7° ~ +52°**(真机规格;−0.122173 ~ 0.907571 rad) |
|
| **垂直** | **40 线,−7° ~ +52°**(真机规格;−0.122173 ~ 0.907571 rad) |
|
||||||
| 更新率 | 10 Hz |
|
| 更新率 | 10 Hz |
|
||||||
| 量程 | **0.10 ~ 12.0 m**,分辨率 0.01 m,高斯噪声 σ=0.01(真机 0.1~40 m) |
|
| 量程 | **0.10–40 m**,分辨率 0.01 m,高斯噪声 σ=0.01 m |
|
||||||
|
|
||||||
|
40 m 对应官方低反射率规格(10%)。Gazebo 使用固定最大量程和每帧 14,400 点的规则采样。实机的回波距离随反射率变化,扫描图案与仿真不同。[Livox 技术参数](https://www.livoxtech.com/cn/mid-360/specs)
|
||||||
|
|
||||||
### 2.2 话题与桥接
|
### 2.2 话题与桥接
|
||||||
|
|
||||||
@@ -53,40 +55,37 @@
|
|||||||
`worlds/sentry_arena.sdf` 里必须有:
|
`worlds/sentry_arena.sdf` 里必须有:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<plugin filename="gz-sim-cpu-lidar-system" name="gz::sim::systems::CpuLidar" />
|
<plugin filename="gz-sim-sensors-system" name="gz::sim::systems::Sensors">
|
||||||
|
<render_engine>ogre2</render_engine>
|
||||||
|
</plugin>
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2.4 两个必须知道的行为
|
### 2.4 两个必须知道的行为
|
||||||
|
|
||||||
**① 雷达不能被整车碰撞盒包住。**
|
**① GPU 雷达测量渲染场景中的表面。**
|
||||||
Gazebo 的激光是给**碰撞体**做射线求交的。原来 `base_link` 一个盒子包住整车,
|
可见网格和物理碰撞体可能采用不同的几何。修改车身视觉网格或场地模型后,重新核对车身自回波和可用点数。
|
||||||
而雷达在 `z = 0.405`(盒内),射线全打在内壁上,测距只有 0.2~0.4 m。
|
上一版 CPU 雷达的有效点比例是历史测量。
|
||||||
现在拆成两个盒子(`chassis_collision` 下半 + `gimbal_collision` 上半靠前),雷达位置就露出来了。
|
|
||||||
|
|
||||||
**② `/scan`(2D)现在基本不可用,这是预期的。**
|
**② `/scan` 取中间一层。** 约 +22.5° 的仰角会看到体育馆外壳。AMCL 和碰撞监控用自滤后投影的 `/scan2d`,Nav2 代价地图用 3D 点云。
|
||||||
gz 的 `/scan` 取**中间那层**射线,而中间角 = (−7 + 52) / 2 = **+22.5° 仰角**,射向天空。
|
|
||||||
只用 3D 点云;Nav2 代价地图吃的也是点云,不受影响。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. ⚠️ 真正的瓶颈:量程 12 m
|
## 3. 按用途过滤
|
||||||
|
|
||||||
射线是斜的,到目标的**斜距 = 高度 / sin(仰角)**:
|
| 用途 | 坐标系与过滤 |
|
||||||
|
|---|---|
|
||||||
|
| 原始观测 | `/scan` 和 `/scan/points` 在 `lidar_link`,保留硬件模型的 0.10–40 m 射线量程 |
|
||||||
|
| 避障 | `/scan/points_filtered` 在 `base_link`,剔除无效点、车身回波,保留 z 0.02–1.20 m、水平距离 ≤8 m 的点。Nav2 障碍标记仍为 4.5 m,清障为 8 m |
|
||||||
|
| 投影 | `/scan2d` 取底盘系 z 0.05–0.50 m,每个方位取最近回波,AMCL 和碰撞监控使用此话题 |
|
||||||
|
| 建图和定位 | `/scan/points_lio` 保留地面和远端围挡。LIO 配准、地图加载、在线建图和离线测站建图使用场地边界 |
|
||||||
|
|
||||||
| 仰角 | 到天花板下沿(上方 9.49 m) | 到主梁下沿(上方 8.94 m) |
|
比赛场内车体中心距最近馆墙至少 10 m。避障的 8 m 上限能滤除馆墙,1.20 m 的高度上限能滤除斜上方进入 8 m 水平范围的天花板。LIO 需要场内远端围挡,因此另设 `lio_max_range=40.2` m 为水平预滤上限,其中 0.2 m 覆盖雷达相对底盘的偏心。
|
||||||
|---|---|---|
|
|
||||||
| +30° | 18.99 m ❌ | 17.89 m ❌ |
|
|
||||||
| +45.9° | 13.22 m ❌ | 12.46 m ❌ |
|
|
||||||
| **+52°(最大)** | 12.05 m ❌ | 11.35 m ✅ |
|
|
||||||
|
|
||||||
- **天花板下沿需要仰角 ≥ 52.3°**,最高只有 52.0° —— 差 0.3°,够不着
|
地图在 `map` 系使用 [场地点云配置](../src/sentry_sim/config/field_cloud.yaml) 中的 x ±6.4 m、y ±4.4 m、z −0.10 至 0.65 m。配准先用扫描时刻的 IMU 预测位姿裁剪并留 0.20 m 余量。地图加载和写入不加余量,单独的测站建图使用已知测站位姿。
|
||||||
- **主梁下沿需要 ≥ 48.2°** —— 只有最顶上 1~2 条线打到,就是那 81 个点的来源
|
|
||||||
- **墙(最近 14.0 m 水平)斜距永远 ≥ 14 m** —— 任何仰角都超量程,**一个点都打不到**
|
|
||||||
|
|
||||||
换个说法:**量程 12 m 时射线最高只到 `0.4052 + 12·sin(52°) = 9.86 m`**,
|
云台转动时,自滤根据点云时间戳查雷达到底盘的 TF。LIO 和录制再把整帧点云统一到 IMU 系。实机若按方位角去畸变,当前实现需要固定安装的雷达。
|
||||||
而天花板下沿在 9.9 m —— 差 4 cm。
|
|
||||||
|
|
||||||
### 对照实验:量程改 20 m
|
### 历史对照(12 m 和 20 m)
|
||||||
|
|
||||||
| 指标 | 12 m | **20 m** |
|
| 指标 | 12 m | **20 m** |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
@@ -96,39 +95,55 @@ gz 的 `/scan` 取**中间那层**射线,而中间角 = (−7 + 52) / 2 = **+2
|
|||||||
| 天花板点(z>8) | 81 | **4578** |
|
| 天花板点(z>8) | 81 | **4578** |
|
||||||
| 远处墙点(r>12.5) | **0** | **1440** |
|
| 远处墙点(r>12.5) | **0** | **1440** |
|
||||||
|
|
||||||
**改法是两个地方一起改**,否则自滤节点会把新打到的墙点又丢掉:
|
|
||||||
|
|
||||||
1. `urdf/sentry.urdf.xacro` 的 `<ray>` 段 → `max_range` 改成 20.0
|
|
||||||
2. `src/sentry_nav/src/self_filter.cpp` 的 `declare_parameter<double>("max_range", 12.0)` → 20.0
|
|
||||||
|
|
||||||
(实验后已改回 12.0,当前仍是 12 m。)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 4. 实测数据
|
## 4. 40 m 实测
|
||||||
|
|
||||||
2026-11-16,headless + 临时桥 + rclpy 订阅一帧:
|
2026-11-25,在隔离 ROS Domain 和 Gazebo partition 中使用 Gazebo 10.6、OGRE2 和 Mesa llvmpipe。每个入口采样 50 帧。频率按仿真时间计算,测试覆盖软件渲染。
|
||||||
|
|
||||||
```
|
| 启动入口 | 原始点云 | 最远有效斜距 | 自滤后最大水平距离 / 高度 |
|
||||||
点云规格 :14400 点/帧(360 水平 × 40 垂直)
|
|---|---:|---:|---:|
|
||||||
有效点 :4954(inf 占 65.6%)
|
| Shell | 14,400 点/帧,10.0 Hz | 29.78 m | 7.68 m / 0.37 m |
|
||||||
水平测距 :0.06 ~ 11.68 m
|
| Python | 14,400 点/帧,10.0 Hz | 31.52 m | 7.95 m / 0.42 m |
|
||||||
高度范围 :−0.41 ~ +9.31 m ← 上面是顶棚主梁
|
|
||||||
垂直角 :−7.0° ~ +52.0° ← 与真机一致
|
|
||||||
打到天花板的点 :81 个(1.6%)
|
|
||||||
```
|
|
||||||
|
|
||||||
**`inf` 高达 65.6%** 是因为大厅空旷:`0° ~ +38°` 那一段射线什么都打不到。
|
两次原始数据均为 `lidar_link`,`/scan` 报告 `range_max=40.0`,`/scan2d` 报告 `range_max=8.0`。34 个空场测站生成 **10,583 个 0.10 m 体素**,越界数为 0,最高体素点约 0.440 m。轨迹真值来自 Gazebo PosePublisher,仅用于验收。
|
||||||
不是坏了,是真实的「无回波」。
|
|
||||||
|
| 候选图验收 | Nav2 成功 / 实跑 | 满足全部指标 | 平移 ATE | 1 s 平移 RPE | 最大 3D 定位误差 | 圆柱最小净距 |
|
||||||
|
|---|---:|---:|---:|---:|---:|---:|
|
||||||
|
| Shell 全场首测 | 2/3 | 2/3 | 0.026 m | 0.029 m | 0.109 m | — |
|
||||||
|
| Shell 全场复测 | 3/4 | 3/4 | 0.027 m | 0.032 m | 0.132 m | — |
|
||||||
|
| Python 全场 | 11/13 | 9/13 | 0.030 m | 0.035 m | 0.167 m | — |
|
||||||
|
| Python 圆柱首测 | 1/1 | 0/1 | 0.024 m | 0.031 m | 0.093 m | 0.346 m |
|
||||||
|
| Python 圆柱复测 | 1/1 | 1/1 | 0.025 m | 0.028 m | 0.095 m | 0.364 m |
|
||||||
|
|
||||||
|
Shell 和 Python 的 70 个代表目标均可规划。Shell 复测成功跑完 `(0,0) ↔ (5,−3)`,真值终点误差分别为 0.105 m 和 0.229 m。两次 Shell 全场测试分别在约 `(1.19,1.51)` 和 `(1.16,1.50)` 停车,水平 3σ 达到 0.529 m 和 0.5002 m。回放首测失败处的扫描仍可满秩配准,IMU 记录到约 89 m/s² 的短时加速度峰值。
|
||||||
|
|
||||||
|
Python 全场测试在 `(1.63,1.73)` 和 `(5.09,−2.04)` 附近触发 3σ 停车,另有两段报告成功但终点误差为 0.487 m 和 0.351 m。圆柱试验首测终点误差 0.502 m,复测 0.082 m。候选图目前通过了裁剪检查和部分导航路段,全场验收仍未通过。两个入口默认继续使用 `field_full.flmap`,加载时保留 10,112 个场内体素。两套默认启动均确认 12 个受管节点 ACTIVE、`/is_path_valid` 正常、`map → odom` 只有一个发布者。
|
||||||
|
|
||||||
|
单独在原地用 13 个约 0.5 rad 的目标角阶跃跨过一圈。关节 TF 发布为 20 Hz 时 194 次定位心跳中有 116 次无效。改为 100 Hz 后,复测 163 次均有效。新旧数据回放分别处理 379 帧和 426 帧,均成功配准。GCC 15.2 / C++23 构建无警告,`xmake test` 15/15 通过。模型与世界通过 `gz sdf -k`,验证器提示 `gz_frame_id` 是 Gazebo 扩展。
|
||||||
|
|
||||||
|
候选图生成、选用和离线回放命令见 [定位包说明](../src/field_localization/README.md)。
|
||||||
|
|
||||||
自检命令:
|
自检命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 tools/cloud_probe.py # 点数、测距范围、高度范围、距离直方图
|
# 点云规模 / 有效率
|
||||||
python3 tools/scan_probe.py /scan # 3D 雷达中间层(+22.5°,基本失效,仅参考)
|
ros2 topic hz /scan/points
|
||||||
python3 tools/scan_probe.py # 0° 单线雷达 /scan2d(给 AMCL 用)
|
ros2 topic echo /scan/points --once | head -20
|
||||||
|
|
||||||
|
# /scan2d 的束数与取值范围
|
||||||
|
ros2 topic echo /scan2d --once | grep -E 'angle_|range_|count'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> `tools/` 里的 `cloud_probe.py` / `scan_probe.py` 已移除(2026-11-21 精简)。
|
||||||
|
> 上面这两条 `ros2 topic` 能拿到同样的原始信息,缺点是不会替你算直方图和"被车体糊住"的判断。
|
||||||
|
|
||||||
|
> ⚠️ **`/scan2d` 不再是独立传感器**:2026-11-19 起它由 `self_filter` 从过滤后的
|
||||||
|
> 3D 点云投影生成(取 `z ∈ [0.05, 0.50] m`、360 个方位取最小距离),
|
||||||
|
> URDF 里那个 0° 单线雷达已删除。原因见
|
||||||
|
> [`踩过的坑.md`](踩过的坑.md) §G4/§G5 —— 单线雷达装在 0.4052 m,
|
||||||
|
> 看不见场地里 0.42 m 的悬空平板,会把 AMCL 带飞。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 5. 怎么看
|
## 5. 怎么看
|
||||||
@@ -157,9 +172,7 @@ ros2 topic info /scan/points # PointCloud2
|
|||||||
`Collision Ahead - Exiting DriveOnHeading`。抬高 `obstacle_min_range` 到 0.9 m 也不够
|
`Collision Ahead - Exiting DriveOnHeading`。抬高 `obstacle_min_range` 到 0.9 m 也不够
|
||||||
(车身相对传感器最远约 0.65 m)。
|
(车身相对传感器最远约 0.65 m)。
|
||||||
|
|
||||||
**现在的做法**:`src/sentry_nav/` 里的 `self_filter` 节点把点云转到 `base_link`、
|
两个代价地图都订阅 `/scan/points_filtered`。`self_filter` 按时间戳转换到底盘系,执行车身、距离和高度过滤。避障和定位分别发布点云,见 §3。
|
||||||
剔掉车身包围盒内的点,输出 `/scan/points_filtered`,两个代价地图都改吃它。
|
|
||||||
实测 3612 → 1546 点,最近距离 0.10 → 0.87 m。
|
|
||||||
|
|
||||||
参数与用法见 `src/sentry_nav/README.md`;代码分层见 `src/sentry_nav/src/README.md`。
|
参数与用法见 `src/sentry_nav/README.md`;代码分层见 `src/sentry_nav/src/README.md`。
|
||||||
|
|
||||||
@@ -171,7 +184,9 @@ ros2 topic info /scan/points # PointCloud2
|
|||||||
|---|---|
|
|---|---|
|
||||||
| 安装位置 | `urdf/sentry.urdf.xacro` 的 `lidar_x/y/z` |
|
| 安装位置 | `urdf/sentry.urdf.xacro` 的 `lidar_x/y/z` |
|
||||||
| 垂直视场 / 线数 | 同文件 `<vertical>` 的 `samples` / `min_angle` / `max_angle`(弧度) |
|
| 垂直视场 / 线数 | 同文件 `<vertical>` 的 `samples` / `min_angle` / `max_angle`(弧度) |
|
||||||
| 量程、噪声、更新率 | 同文件 `<ray>` 段(改量程记得同时改 `self_filter` 的 `max_range`) |
|
| 量程、噪声、更新率 | 同文件 `gpu_lidar` 传感器的 `<lidar>` 段与 `<update_rate>` |
|
||||||
|
| 建图和定位裁剪 | `src/sentry_sim/config/field_cloud.yaml` |
|
||||||
|
| 避障与清障距离 | `self_filter` 的 `max_range` 和 `nav2_params.yaml` 的 `raytrace_max_range` |
|
||||||
| 碰撞体形状 | 同文件 `chassis_collision` / `gimbal_collision` |
|
| 碰撞体形状 | 同文件 `chassis_collision` / `gimbal_collision` |
|
||||||
| 桥接话题 | `scripts/sentry_up.sh` **和** `scripts/bridge_after_gz.sh` |
|
| 桥接话题 | `scripts/sentry_up.sh` **和** `scripts/bridge_after_gz.sh` |
|
||||||
| 是否参与避障 | `config/nav2_params.yaml` 的 costmap `plugins` 与 `observation_sources` |
|
| 是否参与避障 | `config/nav2_params.yaml` 的 costmap `plugins` 与 `observation_sources` |
|
||||||
@@ -192,9 +207,7 @@ HEADLESS=0 scripts/sentry_up.sh
|
|||||||
| 现象 | 原因 | 处理 |
|
| 现象 | 原因 | 处理 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| 点云全在 0.2~0.4 m | 雷达被整车碰撞盒包住 | 拆成底盘盒 + 云台盒(§2.4①) |
|
| 点云全在 0.2~0.4 m | 雷达被整车碰撞盒包住 | 拆成底盘盒 + 云台盒(§2.4①) |
|
||||||
| `/scan` 全是 `inf` | 改成真机视场后的**预期行为**(中间层 +22.5° 打向天空) | 正常,只用 3D 点云 |
|
| RViz 的原始点云中看到馆墙和屋顶 | 当前 40 m 传感器回波 | 用 `/scan/points_filtered` 查看实际避障输入 |
|
||||||
| 点云上半区一大片空(`inf` 65%) | 同上 + 大厅空旷、量程 12 m 够不到天花板 | 加大量程(§3) |
|
|
||||||
| 天花板只打到 81 个点 | 量程 12 m 下最高只到 9.86 m,天花板在 9.9 m | 量程改 20 m(§3) |
|
|
||||||
| 点云话题收不到 | 只改了 `bridge_after_gz.sh`,实际跑的是 `sentry_up.sh` | 两处都改(§2.2) |
|
| 点云话题收不到 | 只改了 `bridge_after_gz.sh`,实际跑的是 `sentry_up.sh` | 两处都改(§2.2) |
|
||||||
| 接进代价地图后车不动 | 点云含车身自回波 | 已加自滤(§6) |
|
| 接进代价地图后车不动 | 点云含车身自回波 | 已加自滤(§6) |
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -3,17 +3,18 @@
|
|||||||
专项技术文档。**工程总览和目录树在上一层的 [`../README.md`](../README.md)**
|
专项技术文档。**工程总览和目录树在上一层的 [`../README.md`](../README.md)**
|
||||||
——这里只放「怎么做」和「为什么」。
|
——这里只放「怎么做」和「为什么」。
|
||||||
|
|
||||||
## 七份文档
|
## 八份文档
|
||||||
|
|
||||||
| 文档 | 一句话 | 什么时候看 |
|
| 文档 | 一句话 | 什么时候看 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| [`操作手册.md`](操作手册.md) | 启动/收尾、体检、遥控、演示、发目标、航点巡逻、看数据、环境变量、场地坐标 | **要动手操作** |
|
| [`操作手册.md`](操作手册.md) | 启动/收尾、体检、遥控、演示、发目标、航点巡逻、看数据、环境变量、场地坐标 | **要动手操作** |
|
||||||
| [`排错速查.md`](排错速查.md) | 7 类 34 条现象 → 原因 → 处理 | **出问题了**(「现在怎么办」) |
|
| [`排错速查.md`](排错速查.md) | 7 类 34 条现象 → 原因 → 处理 | **出问题了**(「现在怎么办」) |
|
||||||
| [`踩过的坑.md`](踩过的坑.md) | 27 条设计经验,按领域分 7 组(§A–§G) | 想知道**为什么**这么设计(「别再犯」) |
|
| [`踩过的坑.md`](踩过的坑.md) | 27 条设计经验,按领域分 7 组(§A–§G) | 想知道**为什么**这么设计(「别再犯」) |
|
||||||
| [`MID360-3D雷达接入.md`](MID360-3D雷达接入.md) | 传感器配置、话题桥接、实测数据、**量程 12 m 这个瓶颈** | 动雷达 |
|
| [`MID360-3D雷达接入.md`](MID360-3D雷达接入.md) | 40 m 雷达配置、场地点云过滤、地图与导航验收 | 动雷达 |
|
||||||
| [`仿真场地外壳.md`](仿真场地外壳.md) | 体育馆大厅 + 屋顶 + 拦截网的尺寸、取舍、怎么改 | 动场地 |
|
| [`仿真场地外壳.md`](仿真场地外壳.md) | 体育馆大厅 + 屋顶 + 拦截网的尺寸、取舍、怎么改 | 动场地 |
|
||||||
| [`定位接入AMCL.md`](定位接入AMCL.md) | **定位怎么做**:为什么之前是假的、AMCL 需要什么、2D 雷达怎么加、`map→odom` 谁发、已知卡点 | 动定位 |
|
| [`定位接入AMCL.md`](定位接入AMCL.md) | **定位怎么做**:为什么之前是假的、AMCL 需要什么、2D 雷达怎么加、`map→odom` 谁发、已知卡点 | 动定位 |
|
||||||
| [`构建体系与代码分层.md`](构建体系与代码分层.md) | C++23 下限证据、为什么全用 xmake、`src/core/` 分层纪律 | 动构建或代码结构 |
|
| [`构建体系与代码分层.md`](构建体系与代码分层.md) | C++23 下限证据、为什么全用 xmake、`src/core/` 分层纪律 | 动构建或代码结构 |
|
||||||
|
| [`Gazebo_GPU评估.md`](Gazebo_GPU评估.md) | `gpu_lidar` 为什么退到 llvmpipe、**EGL vendor 修法与验证证据**、雷达 CPU 对照、PhysX 迁移核查 | 动渲染 / GPU / 雷达类型 |
|
||||||
|
|
||||||
## 几条常见路径
|
## 几条常见路径
|
||||||
|
|
||||||
@@ -28,6 +29,10 @@
|
|||||||
「车知道自己在哪吗 / 怎么做定位」
|
「车知道自己在哪吗 / 怎么做定位」
|
||||||
→ 定位接入AMCL.md(现状、改动清单、验收、卡点)
|
→ 定位接入AMCL.md(现状、改动清单、验收、卡点)
|
||||||
|
|
||||||
|
「无界面仿真 CPU 吃满了 / 想换 GPU 雷达」
|
||||||
|
→ Gazebo_GPU评估.md(EGL vendor 判定、验证命令、CPU 对照)
|
||||||
|
→ 先跑 python3 tools/project_env.py --gpu
|
||||||
|
|
||||||
「我要加决策状态机」
|
「我要加决策状态机」
|
||||||
→ 构建体系与代码分层 §4(分层)§6(五步流程)
|
→ 构建体系与代码分层 §4(分层)§6(五步流程)
|
||||||
→ 代码本身看 src/sentry_nav/ 下的 README
|
→ 代码本身看 src/sentry_nav/ 下的 README
|
||||||
|
|||||||
+3
-1
@@ -4,12 +4,14 @@
|
|||||||
> **最后更新**:2026-11-17
|
> **最后更新**:2026-11-17
|
||||||
> **涉及模型**:`arena_walls`(新)、`arena_roof`(新)、`catch_net`(停用但保留)
|
> **涉及模型**:`arena_walls`(新)、`arena_roof`(新)、`catch_net`(停用但保留)
|
||||||
|
|
||||||
|
2026-11-25 起原始雷达量程为 40 m,体育馆几何沿用本文的尺寸。下文关于 12 m 和 20 m 的测量是旧版记录。当前观测与场地过滤见 [MID-360 接入与验收](MID360-3D雷达接入.md)。
|
||||||
|
|
||||||
## 1. 一句话结论
|
## 1. 一句话结论
|
||||||
|
|
||||||
> 比赛场地被包在 **40 × 28 m、墙高 10 m** 的体育馆大厅里,头顶是 10 m 的顶棚 + 梁 + 12 条灯带。
|
> 比赛场地被包在 **40 × 28 m、墙高 10 m** 的体育馆大厅里,头顶是 10 m 的顶棚 + 梁 + 12 条灯带。
|
||||||
> 墙、地面、顶棚、梁**都有碰撞体**。雷达视场也已改成真机规格 **−7°~+52° / 40 线**。
|
> 墙、地面、顶棚、梁**都有碰撞体**。雷达视场也已改成真机规格 **−7°~+52° / 40 线**。
|
||||||
>
|
>
|
||||||
> **但外壳目前基本打不到**:墙最近 14.0 m > 量程 12 m;天花板下沿 9.9 m,
|
> **早期 12 m 模型基本扫不到外壳**:墙最近 14.0 m > 量程 12 m;天花板下沿 9.9 m,
|
||||||
> 而量程 12 m 下射线最高只到 9.86 m —— **差 4 cm**。
|
> 而量程 12 m 下射线最高只到 9.86 m —— **差 4 cm**。
|
||||||
> 实测只打到顶棚主梁 **81 个点**,墙 **0 个**。怎么解决见 §6。
|
> 实测只打到顶棚主梁 **81 个点**,墙 **0 个**。怎么解决见 §6。
|
||||||
|
|
||||||
|
|||||||
+23
-3
@@ -1,5 +1,7 @@
|
|||||||
# 定位接入(AMCL)
|
# 定位接入(AMCL)
|
||||||
|
|
||||||
|
> 本文适用于显式选择 `LOCALIZATION=amcl` 的旧定位分支。当前默认 LIO,使用说明见 [field_localization](../src/field_localization/README.md)。不要同时启动两个 map→odom 发布者。
|
||||||
|
|
||||||
> **状态**:🟢 **已修复(2026-11-19)** —— `scan2d` 改为由 `self_filter` 从 3D 点云投影生成
|
> **状态**:🟢 **已修复(2026-11-19)** —— `scan2d` 改为由 `self_filter` 从 3D 点云投影生成
|
||||||
> (取 `z ∈ [0.05, 0.50] m` 车体碰撞带、360 方位取最小距离),消除了「雷达看不见 0.42 m
|
> (取 `z ∈ [0.05, 0.50] m` 车体碰撞带、360 方位取最小距离),消除了「雷达看不见 0.42 m
|
||||||
> 悬空平板、地图却有」的高度失配跑飞。原问题复盘见 §4.1 的更正与
|
> 悬空平板、地图却有」的高度失配跑飞。原问题复盘见 §4.1 的更正与
|
||||||
@@ -266,7 +268,25 @@ ros2 action list | grep -E "^/wait$"
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
SENTRY_ODOM_SCALE=1.15 HEADLESS=1 scripts/sentry_up.sh # 里程计报的距离偏大 15%
|
SENTRY_ODOM_SCALE=1.15 HEADLESS=1 scripts/sentry_up.sh # 里程计报的距离偏大 15%
|
||||||
python3 tools/amcl_drift_demo.py # 对比三列
|
```
|
||||||
|
|
||||||
|
三列数据的读法(三个终端各跑一条,或轮流跑):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# ① AMCL 定位(map -> base_link)
|
||||||
|
ros2 run tf2_ros tf2_echo map base_link
|
||||||
|
# ② 原始里程计(odom -> base_link,被 odom_scale 打了比例误差)
|
||||||
|
ros2 run tf2_ros tf2_echo odom base_link
|
||||||
|
# ③ 真值(Gazebo 世界坐标)
|
||||||
|
GZ_PARTITION=sentry gz model -m sentry --pose
|
||||||
|
```
|
||||||
|
|
||||||
|
想让车自己走一段(**绕过 Nav2**,这样才能制造出打滑/漂移),直接往 `/cmd_vel` 灌速度:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist \
|
||||||
|
"{linear: {x: 0.5}, angular: {z: 0.0}}"
|
||||||
|
# Ctrl+C 停
|
||||||
```
|
```
|
||||||
|
|
||||||
实测(车直线前进,轮子被场内道具挡住后打滑):
|
实测(车直线前进,轮子被场内道具挡住后打滑):
|
||||||
@@ -291,13 +311,13 @@ python3 tools/amcl_drift_demo.py # 对比三列
|
|||||||
|
|
||||||
### ⚠️ 这个演示**不避障**是有意的
|
### ⚠️ 这个演示**不避障**是有意的
|
||||||
|
|
||||||
`amcl_drift_demo.py` 直接往 `/cmd_vel` 发速度,**绕过了 controller / 代价地图 / collision_monitor 整条链**。
|
上面那种 `ros2 topic pub /cmd_vel` 直接往底盘灌速度,**绕过了 controller / 代价地图 / collision_monitor 整条链**。
|
||||||
所以车会撞墙、会卡在场内道具上 —— 这是**预期行为**:
|
所以车会撞墙、会卡在场内道具上 —— 这是**预期行为**:
|
||||||
|
|
||||||
- 走 Nav2 的话,代价地图会把它绕开,就制造不出「轮子转了但车没动」的漂移场景
|
- 走 Nav2 的话,代价地图会把它绕开,就制造不出「轮子转了但车没动」的漂移场景
|
||||||
- 而那个场景(打滑)正是 AMCL 唯一能体现价值的地方
|
- 而那个场景(打滑)正是 AMCL 唯一能体现价值的地方
|
||||||
|
|
||||||
要验证 Nav2 自己的避障,得用 `build/linux/x86_64/release/nav_client x y` 发导航目标。
|
要验证 Nav2 自己的避障,得用 `build/bin/nav_client x y` 发导航目标。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+16
-8
@@ -34,11 +34,11 @@ TF 链(`map→odom` / `odom→base_link` / `map→base_link`),结尾直接
|
|||||||
|
|
||||||
| 现象 | 原因 | 处理 |
|
| 现象 | 原因 | 处理 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| 雷达全是 `inf` | 传感器高于围挡(0.42 m),一圈打不到东西 | `python3 tools/scan_probe.py /scan` 或 `/scan2d` 会提示 |
|
| 雷达全是 `inf` | 传感器高于围挡(0.42 m),一圈打不到东西 | `ros2 topic echo /scan2d --once` 看 ranges 是不是一堆 `inf`/`nan` |
|
||||||
| 点云上半区一大片空(`inf` 65%) | **拦截网默认已停用** + 大厅空旷 + 量程 12 m 够不到天花板 | 当前预期状态;想改善见 `MID360-3D雷达接入.md` §3 |
|
| 点云上半区缺点 | 过滤话题剔除了顶棚,滤除范围随话题而异 | 对照原始 `/scan/points`,见 [MID-360 过滤说明](MID360-3D雷达接入.md) |
|
||||||
| 点云里全是近距离点 | 传感器被车身碰撞盒包住 | 检查碰撞体是否把雷达罩进去(已拆成 `chassis_collision` + `gimbal_collision`) |
|
| 点云里全是近距离点 | 传感器被车身碰撞盒包住 | 检查碰撞体是否把雷达罩进去(已拆成 `chassis_collision` + `gimbal_collision`) |
|
||||||
| 代价地图把车自己标成障碍 | 没跑自滤,或包围盒太小 | 确认 `self_filter` 在跑:`ros2 topic hz /scan/points_filtered` |
|
| 代价地图把车自己标成障碍 | 没跑自滤,或包围盒太小 | 确认 `self_filter` 在跑:`ros2 topic hz /scan/points_filtered` |
|
||||||
| 雷达看不到场馆墙 | 量程只有 **12 m**,墙在 14 m 外 | 见 `仿真场地外壳.md` §6.2 |
|
| 避障点云看不到场馆墙 | 底盘系的水平距离上限为 **8 m** | 用原始 `/scan/points` 查看馆墙回波 |
|
||||||
|
|
||||||
## C. 话题与桥
|
## C. 话题与桥
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ TF 链(`map→odom` / `odom→base_link` / `map→base_link`),结尾直接
|
|||||||
| `Costmap timed out waiting for update` / 代价地图 100×100 | `map_server` 没起(关 AMCL 时最容易发生) | 检查 `ros2 topic hz /map`;`sentry_up.sh` 第 5.7 步专门起它 |
|
| `Costmap timed out waiting for update` / 代价地图 100×100 | `map_server` 没起(关 AMCL 时最容易发生) | 检查 `ros2 topic hz /map`;`sentry_up.sh` 第 5.7 步专门起它 |
|
||||||
| 目标成功但位置偏差大 | 控制器有到达容差,正常 0.1~0.3 m | 调 `goal_checker` 的 `xy_goal_tolerance` |
|
| 目标成功但位置偏差大 | 控制器有到达容差,正常 0.1~0.3 m | 调 `goal_checker` 的 `xy_goal_tolerance` |
|
||||||
| 打滑 / 被撞后位置永远不对 | **定位是「作弊」的**:静态 `map→odom` + 轮速积分,不会自愈 | 见根 `../README.md` §7 |
|
| 打滑 / 被撞后位置永远不对 | **定位是「作弊」的**:静态 `map→odom` + 轮速积分,不会自愈 | 见根 `../README.md` §7 |
|
||||||
| `failed to create plan with tolerance of: 0.500000` | 这条报错**不区分**「目标点在障碍里 / 起点在障碍里 / 中间真没路」,只能靠人排查 | `python3 tools/free_goals.py` 找安全点;`build/linux/x86_64/release/nav_client` 已内置预检会先拦一道 |
|
| `failed to create plan with tolerance of: 0.500000` | 这条报错**不区分**「目标点在障碍里 / 起点在障碍里 / 中间真没路」,只能靠人排查 | `nav_client` 已内置预检会先拦一道;再不行就在 RViz 里看 `/global_costmap/costmap` |
|
||||||
| 导航目标 `ABORTED`,日志是 `failed to plan from (<一个奇怪的位置>)` | **定位瞬移**:AMCL 跑飞后,起点落到障碍格里。报错落在规划器上,真凶在 AMCL | `python3 tools/tf_watch.py --time 60` 一个窗口盯着,另一个窗口发目标;再用 `gz model -m sentry --pose` 对真值 |
|
| 导航目标 `ABORTED`,日志是 `failed to plan from (<一个奇怪的位置>)` | **定位瞬移**:AMCL 跑飞后,起点落到障碍格里。报错落在规划器上,真凶在 AMCL | 对比三个位姿:`ros2 run tf2_ros tf2_echo map base_link`、`ros2 run tf2_ros tf2_echo map odom`、`gz model -m sentry --pose`(真值) |
|
||||||
| `nav_client` 反馈的位置一路平滑,**最后一行 TF 却差好几米** | 同上。另外 `NavigateToPose` 的 `distance_remaining` 在 Nav2 1.5 里**永远返回 0**,别拿它判断进度 | 同上。仿真的已知根因见 [`踩过的坑.md`](踩过的坑.md) §G4 |
|
| `nav_client` 反馈的位置一路平滑,**最后一行 TF 却差好几米** | 同上。另外 `NavigateToPose` 的 `distance_remaining` 在 Nav2 1.5 里**永远返回 0**,别拿它判断进度 | 同上。仿真的已知根因见 [`踩过的坑.md`](踩过的坑.md) §G4 |
|
||||||
| AMCL 认为的位置和 Gazebo 真值差好几米 | `scan2d` 在 0.4052 m,看不见 0.42 m 的悬空平板 → 粒子滤波失配 | 见 [`踩过的坑.md`](踩过的坑.md) §G4/§G5 与 [`定位接入AMCL.md`](定位接入AMCL.md) §4.1 的更正 |
|
| AMCL 认为的位置和 Gazebo 真值差好几米 | `scan2d` 在 0.4052 m,看不见 0.42 m 的悬空平板 → 粒子滤波失配 | 见 [`踩过的坑.md`](踩过的坑.md) §G4/§G5 与 [`定位接入AMCL.md`](定位接入AMCL.md) §4.1 的更正 |
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ TF 链(`map→odom` / `odom→base_link` / `map→base_link`),结尾直接
|
|||||||
| `xmake test` 报 `invalid task: run_tests` | 老文档的错写法 | 用 **`xmake test`** |
|
| `xmake test` 报 `invalid task: run_tests` | 老文档的错写法 | 用 **`xmake test`** |
|
||||||
| `xmake test xxx` 显示 `nothing to test` | 用例名是 `<target>/<testname>` | **`xmake test test_self_filter_core/default`** |
|
| `xmake test xxx` 显示 `nothing to test` | 用例名是 `<target>/<testname>` | **`xmake test test_self_filter_core/default`** |
|
||||||
| `xacro` 报 `environment variable 'SENTRY_SIM_SHARE' is not set` | 手动展开 URDF 没设变量(不用 ament,`$(find pkg)` 查不到包) | `export SENTRY_SIM_SHARE=<仓库>/src/sentry_sim`,或直接用 `tools/gen_sdf.sh` |
|
| `xacro` 报 `environment variable 'SENTRY_SIM_SHARE' is not set` | 手动展开 URDF 没设变量(不用 ament,`$(find pkg)` 查不到包) | `export SENTRY_SIM_SHARE=<仓库>/src/sentry_sim`,或直接用 `tools/gen_sdf.sh` |
|
||||||
| `ros2 run sentry_nav xxx` 报找不到包 | **本工程没有 ament 注册,没有 `ros2 run`** | 直接跑 `build/linux/x86_64/release/xxx` |
|
| `ros2 run sentry_nav xxx` 报找不到包 | **本工程没有 ament 注册,没有 `ros2 run`** | 直接跑 `build/bin/xxx` |
|
||||||
| `-p waypoints:="[1,2]"` 报类型错 | 传了整数数组 | **写 `[1.0, 2.0]`**(浮点) |
|
| `-p waypoints:="[1,2]"` 报类型错 | 传了整数数组 | **写 `[1.0, 2.0]`**(浮点) |
|
||||||
|
|
||||||
## F. 编辑器
|
## F. 编辑器
|
||||||
@@ -98,11 +98,19 @@ TF 链(`map→odom` / `odom→base_link` / `map→base_link`),结尾直接
|
|||||||
|
|
||||||
## G. 还不行:先把日志拿到手
|
## G. 还不行:先把日志拿到手
|
||||||
|
|
||||||
|
**`sentry_up.sh` 现在默认就把日志落盘到 `generated/up.log`**,不用再手动 `| tee`。
|
||||||
|
每次启动会在日志里加一条分隔线(`===== sentry_up 启动 … =====`),历次会话分得清。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
HEADLESS=0 scripts/sentry_up.sh 2>&1 | tee generated/up.log
|
# 先看结果:激活到底走完了没有
|
||||||
|
grep -E 'Managed nodes are active|Failed to change state|Aborting' generated/up.log | tail -20
|
||||||
|
|
||||||
|
# 再看卡在哪个节点上
|
||||||
|
grep -E 'Configuring|Activating|bond' generated/up.log | tail -40
|
||||||
```
|
```
|
||||||
|
|
||||||
日志落进仓库后,别人(包括我)能直接读文件诊断。
|
日志在仓库里,别人(包括我)能直接读文件诊断。
|
||||||
|
关掉自动落盘:`SENTRY_LOG=0`;换位置:`SENTRY_LOG=/path/x.log`。
|
||||||
|
|
||||||
| 想知道 | 看哪 |
|
| 想知道 | 看哪 |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
|||||||
+86
-49
@@ -40,16 +40,16 @@ Gazebo(系统版 10.6)
|
|||||||
| 只起仿真和桥,不起 Nav2 | `NAV2=0 scripts/sentry_up.sh` |
|
| 只起仿真和桥,不起 Nav2 | `NAV2=0 scripts/sentry_up.sh` |
|
||||||
| 不起 RViz(省内存) | `RVIZ=0 scripts/sentry_up.sh` |
|
| 不起 RViz(省内存) | `RVIZ=0 scripts/sentry_up.sh` |
|
||||||
| Wayland 下窗口起不来 | `QT_QPA_PLATFORM=xcb HEADLESS=0 scripts/sentry_up.sh` |
|
| Wayland 下窗口起不来 | `QT_QPA_PLATFORM=xcb HEADLESS=0 scripts/sentry_up.sh` |
|
||||||
| **把日志落进仓库**(方便别人帮你查) | `HEADLESS=0 scripts/sentry_up.sh 2>&1 \| tee generated/up.log` |
|
| **看启动日志** | 已**自动落盘**到 `generated/up.log`(每次启动加一条分隔线)。关掉:`SENTRY_LOG=0`;改位置:`SENTRY_LOG=/path/x.log` |
|
||||||
| 多套仿真并存 | `GZ_PARTITION=fight ROS_DOMAIN_ID=1 …`(两个都要改) |
|
| 多套仿真并存 | `GZ_PARTITION=fight ROS_DOMAIN_ID=1 …`(两个都要改) |
|
||||||
| **用 `ros2 launch` 起**(等价入口) | `ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true rviz:=false` |
|
| **用 `ros2 launch` 起**(等价入口) | `ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true rviz:=false` |
|
||||||
|
|
||||||
**单独跑某个节点**(本工程没有 ament 注册,**没有 `ros2 run`**):
|
**单独跑某个节点**(本工程没有 ament 注册,**没有 `ros2 run`**):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
build/linux/x86_64/release/self_filter --ros-args -p use_sim_time:=true
|
build/bin/self_filter --ros-args -p use_sim_time:=true
|
||||||
build/linux/x86_64/release/patrol --ros-args -p use_sim_time:=true -p loop:=false
|
build/bin/patrol --ros-args -p use_sim_time:=true -p loop:=false
|
||||||
build/linux/x86_64/release/odom_tf --ros-args -p use_sim_time:=true
|
build/bin/odom_tf --ros-args -p use_sim_time:=true
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -89,71 +89,85 @@ ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{}"
|
|||||||
|
|
||||||
明显偏小 → 检查轮子半径 / 麦克纳姆辊子摩擦 / 质量参数。
|
明显偏小 → 检查轮子半径 / 麦克纳姆辊子摩擦 / 质量参数。
|
||||||
|
|
||||||
**演示脚本**:
|
**手动驱动**(`demo.py` / `drive_demo.py` 已移除,用 ros2 原生工具代替):
|
||||||
|
|
||||||
| 脚本 | 做什么 |
|
```bash
|
||||||
|---|---|
|
# 直线前进 0.5 m/s
|
||||||
| `python3 tools/demo.py` | 前进 → 转向 → 再前进,同时打印雷达和里程计真实数据 |
|
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist \
|
||||||
| `python3 tools/drive_demo.py 1.0` | 走 1 m 边长正方形,输出轨迹数据和 SVG(`generated/drive_trajectory.svg`) |
|
"{linear: {x: 0.5}, angular: {z: 0.0}}"
|
||||||
|
# 原地左转 0.8 rad/s(Ctrl+C 停掉上一条再发)
|
||||||
|
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist \
|
||||||
|
"{linear: {x: 0.0}, angular: {z: 0.8}}"
|
||||||
|
```
|
||||||
|
|
||||||
两个都会**自己发 `/cmd_vel`**,所以要先确认 Nav2 没在同时控制车(`NAV2=0` 起最干净)。
|
两条都会**直接发 `/cmd_vel`**,所以要先确认 Nav2 没在同时控制车(`NAV2=0` 起最干净)。
|
||||||
|
想看轨迹就开着 RViz 的 `odom` 显示,或者 `ros2 run tf2_ros tf2_echo odom base_link`。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. 发导航目标
|
## 3. 发导航目标
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
build/linux/x86_64/release/nav_client 2.0 2.0 # 目标 x=2.0 y=2.0(场地坐标,米)
|
build/bin/nav_client 2.0 2.0 # 目标 x=2.0 y=2.0(场地坐标,米)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> 产物固定落在 `build/bin/`(xmake 的 targetdir 被锁死了,见
|
||||||
|
> [`构建体系与代码分层.md`](构建体系与代码分层.md) §7.1)。
|
||||||
|
> 如果你用 `xmake -o <目录>` 换了构建目录,用
|
||||||
|
> `$(python3 tools/project_env.py --bin-dir)/nav_client` 取实际路径。
|
||||||
|
|
||||||
**发之前它会先查地图**,占据值 ≥65、落在未知格、净空 <0.5 m(车体半对角 0.422 m)都直接拦下:
|
**发之前它会先查地图**,占据值 ≥65、落在未知格、净空 <0.5 m(车体半对角 0.422 m)都直接拦下:
|
||||||
|
|
||||||
```
|
```
|
||||||
目标 (3.00, 4.00) -> 栅格 (136, 176) 占据值 100 (障碍) 净空 0.00 m
|
目标 (-2.50, 1.00) -> 栅格 (156, 216) 占据值 100 (障碍) 净空 0.00 m
|
||||||
❌ 这个点不适合当目标(净空需 >= 0.50 m):
|
❌ 这个点不适合当目标(净空需 >= 0.50 m):
|
||||||
点落在障碍格里 —— 规划器必然报 "Failed to create plan with tolerance",换一个点。
|
点落在障碍格里 —— 规划器必然报 "Failed to create plan with tolerance",换一个点。
|
||||||
想找安全点:python3 tools/free_goals.py
|
换一个开阔的点,或先在 RViz 里看一眼 /global_costmap/costmap。
|
||||||
```
|
```
|
||||||
|
|
||||||
**通过预检后**长这样(数值是实测的,位置逐条刷新):
|
发目标前,客户端还会检查 `map → base_link` 的时效。发现 LIO 心跳时,要求最近 0.3 秒内收到有效心跳。`--force` 只跳过静态地图预检。Nav2 返回的错误码和消息会随结果打印,中止、取消和超时均返回非零退出码。
|
||||||
|
|
||||||
|
**通过预检后**长这样(地图行与预检行是实算的,位姿行是格式示意,逐条刷新):
|
||||||
|
|
||||||
```
|
```
|
||||||
地图 512x352 @ 0.025 m/px origin=(-0.40, -0.40)
|
地图 512x352 @ 0.025 m/px origin=(-6.40, -4.40)
|
||||||
目标 (3.11, 1.61) -> 栅格 (140, 80) 占据值 0 (空闲) 净空 1.38 m
|
目标 ( 0.11, 1.61) -> 栅格 (260, 240) 占据值 0 (空闲) 净空 1.60 m
|
||||||
等待 navigate_to_pose 动作服务器...
|
等待 navigate_to_pose 动作服务器...
|
||||||
✅ 动作服务器可用
|
✅ 动作服务器可用
|
||||||
✅ 目标已接受,等待结果...
|
✅ 目标已接受,等待结果...
|
||||||
位置 ( 0.90, 4.00) 重试 0 ← 当前位姿 + 恢复行为重试次数
|
位置 (-5.00, 3.00) 重试 0 ← 当前位姿 + 恢复行为重试次数
|
||||||
位置 ( 1.21, 3.76) 重试 0
|
位置 (-4.62, 2.71) 重试 0
|
||||||
结果: ✅ SUCCEEDED ← 4=成功 5=取消 6=放弃
|
结果: ✅ SUCCEEDED ← 4=成功 5=取消 6=放弃
|
||||||
TF map->base_link: (3.05, 1.58) 离目标 0.07 m field 坐标 (-2.95, -2.42)
|
TF map->base_link: (0.05, 1.58) 离目标 0.07 m field 坐标 (0.05, 1.58)
|
||||||
```
|
```
|
||||||
|
|
||||||
最后那行是**实测到位位置**,不会精确等于目标点(控制器有到达容差,正常偏差 0.1~0.3 m)。
|
最后那行是**实测到位位置**,不会精确等于目标点(控制器有到达容差,正常偏差 0.1~0.3 m)。
|
||||||
|
`map→field` 现在是恒等变换(两者都以场地中心为原点),所以两个坐标数值相同。
|
||||||
|
|
||||||
> ⚠️ **别指望「剩余距离」这类进度数字**。早期版本打印 `feedback.distance_remaining`,
|
> ⚠️ **别指望「剩余距离」这类进度数字**。早期版本打印 `feedback.distance_remaining`,
|
||||||
> 而 Nav2 1.5 根本不填这个字段,永远是 `0.00`,看起来像「车原地不动」。
|
> 而 Nav2 1.5 根本不填这个字段,永远是 `0.00`,看起来像「车原地不动」。
|
||||||
> 现在改用**当前位姿 + 重试次数**跟踪进度。
|
> 现在改用**当前位姿 + 重试次数**跟踪进度。
|
||||||
|
|
||||||
不知道有哪些点可去?先跑(**不需要起 ROS**):
|
不知道有哪些点可去?**在 RViz 里看 `/global_costmap/costmap`** —— 膨胀层会把不可通行的走廊标成高代价值,
|
||||||
|
一眼就能看出哪片是空地。
|
||||||
```bash
|
|
||||||
python3 tools/free_goals.py
|
|
||||||
```
|
|
||||||
|
|
||||||
会打印「从起点连通的安全区」面积、可去目标点(含净空和距离)、以及一张安全通行走廊图。
|
|
||||||
|
|
||||||
- **RViz**:工具栏的 **Nav2 Goal** 点一下选目标
|
- **RViz**:工具栏的 **Nav2 Goal** 点一下选目标
|
||||||
- ❌ **不要用** `tools/send_goal.py` —— 它往 `/goal_pose` 话题发 PoseStamped,
|
- ⚠️ 只有 `nav_client` 和 RViz 的 **Nav2 Goal** 这两条路能发目标。
|
||||||
而 Nav2 **没有任何节点订阅这个话题**(`bt_navigator` 二进制里连这个字符串都没有),发了等于空炮
|
往 `/goal_pose` **话题**发是没有用的 —— Nav2 没有任何节点订阅它
|
||||||
|
(`bt_navigator` 二进制里连这个字符串都没有),发了等于空炮
|
||||||
|
|
||||||
**目标莫名 `ABORTED`、或最后一行 TF 突然跳好几米**(定位跑飞,不是避障问题):
|
**目标莫名 `ABORTED`、或最后一行 TF 突然跳好几米**(定位跑飞,不是避障问题):
|
||||||
另开一个窗口盯着,再发目标:
|
把三个位姿摆在一起看,差异一眼就出来:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 tools/tf_watch.py --time 60
|
ros2 run tf2_ros tf2_echo map base_link # AMCL 认为车在哪
|
||||||
|
ros2 run tf2_ros tf2_echo map odom # AMCL 对里程计的修正量(跳变就出在这条边上)
|
||||||
|
GZ_PARTITION=sentry gz model -m sentry --pose # 物理真值
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`map→odom` 单帧跳变超过 0.25 m 就是定位瞬移,根因见
|
||||||
|
[`踩过的坑.md`](踩过的坑.md) §G4。
|
||||||
|
|
||||||
它同时打 `map→odom` / `odom→base_link` / `map→base_link` 三条 TF 边和 Gazebo 真值,
|
它同时打 `map→odom` / `odom→base_link` / `map→base_link` 三条 TF 边和 Gazebo 真值,
|
||||||
任一单帧跳变超过 0.25 m 就标 ⚠️,还会统计 `/scan2d` 的有效返回率。
|
任一单帧跳变超过 0.25 m 就标 ⚠️,还会统计 `/scan2d` 的有效返回率。
|
||||||
|
|
||||||
@@ -162,7 +176,7 @@ python3 tools/tf_watch.py --time 60
|
|||||||
## 4. 航点巡逻(跑自己编的节点)
|
## 4. 航点巡逻(跑自己编的节点)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
build/linux/x86_64/release/patrol --ros-args \
|
build/bin/patrol --ros-args \
|
||||||
-p loop:=false -p waypoints:="[2.0, 2.0, 4.0, 3.0, 3.0, 5.0]"
|
-p loop:=false -p waypoints:="[2.0, 2.0, 4.0, 3.0, 3.0, 5.0]"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -192,8 +206,8 @@ ros2 topic hz /scan # 2D 雷达
|
|||||||
ros2 topic hz /scan/points # MID-360 点云(约 10 Hz)
|
ros2 topic hz /scan/points # MID-360 点云(约 10 Hz)
|
||||||
ros2 topic hz /scan/points_filtered # 自滤后
|
ros2 topic hz /scan/points_filtered # 自滤后
|
||||||
ros2 run tf2_ros tf2_echo map base_link # 定位位姿
|
ros2 run tf2_ros tf2_echo map base_link # 定位位姿
|
||||||
python3 tools/scan_probe.py # 雷达质量(默认 /scan2d;可传话题名)
|
ros2 topic echo /scan2d --once | grep -E 'count|range_' # 雷达束数与量程
|
||||||
python3 tools/probe_all.py # 一次性检查多个话题有没有数据
|
python3 tools/check_stack.py # 一次性检查节点/话题/TF/真值
|
||||||
```
|
```
|
||||||
|
|
||||||
**RViz 里已配好的显示项**(`src/sentry_sim/config/sentry.rviz`):
|
**RViz 里已配好的显示项**(`src/sentry_sim/config/sentry.rviz`):
|
||||||
@@ -213,6 +227,13 @@ python3 tools/probe_all.py # 一次性检查多个话题有没有
|
|||||||
|
|
||||||
## 6. 环境变量
|
## 6. 环境变量
|
||||||
|
|
||||||
|
Shell 和 Python 的路径与版本探测都由 `tools/project_env.py` 实现。
|
||||||
|
用 `python3 tools/project_env.py` 查看探测结果,或运行 `SENTRY_DRY_RUN=1 scripts/sentry_up.sh` 预演启动。
|
||||||
|
单项查询成功返回 `0`,探测失败返回 `1`,参数错误返回 `2`。失败时 stdout 为空,错误写入 stderr。
|
||||||
|
未构建时 `--bin-dir` 仍返回预期的 `build/bin`,已加载 ROS 时 `--ros-setup` 返回空值。
|
||||||
|
|
||||||
|
### 行为开关
|
||||||
|
|
||||||
| 变量 | 默认 | 说明 |
|
| 变量 | 默认 | 说明 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `HEADLESS` | `0` | `1` = 不显示界面(`gz sim -s`) |
|
| `HEADLESS` | `0` | `1` = 不显示界面(`gz sim -s`) |
|
||||||
@@ -220,11 +241,33 @@ python3 tools/probe_all.py # 一次性检查多个话题有没有
|
|||||||
| `RVIZ` | `1` | `0` = 不起 RViz |
|
| `RVIZ` | `1` | `0` = 不起 RViz |
|
||||||
| `ROS_DOMAIN_ID` | `0` | 两个终端必须一致才能互相看到话题 |
|
| `ROS_DOMAIN_ID` | `0` | 两个终端必须一致才能互相看到话题 |
|
||||||
| `GZ_PARTITION` | `sentry` | Gazebo 分区,多套仿真隔离用 |
|
| `GZ_PARTITION` | `sentry` | Gazebo 分区,多套仿真隔离用 |
|
||||||
| `SENTRY_FIELD_ROOT` | 仓库内 `field/RMUL2027_map_transfer_20261016_STEP_R1` | 场地模型/地图目录(找不到才退回 `~/Gazebo_projects/` 下的旧路径) |
|
| `BRIDGE_WAIT_TIMEOUT` | `120` | 等待 Gazebo 发布 `/clock` 的秒数。单次查询至多 2 秒,等不到时启动失败 |
|
||||||
| `SENTRY_MAP_YAML` | 上面路径下的 `maps/rmul_2027/rmul_2027.yaml` | 想换地图时直接指这个 |
|
| `SENTRY_DRY_RUN` | `0` | `1` = 只打印探测结果然后退出,不启动任何进程 |
|
||||||
| `NAV_BIN_DIR` | `<仓库根>/build/linux/x86_64/release` | xmake 产物目录,想用别处的二进制时覆盖 |
|
| `SENTRY_LOG` | `1` | 启动日志自动写 `generated/up.log`(每次加分隔线)。`0` = 关闭,`<路径>` = 换位置 |
|
||||||
| `SENTRY_SIM_SHARE` | 仓库内 `src/sentry_sim` | 数据包位置,同时导出给 `xacro` 解析网格路径 |
|
| `SENTRY_SIM_SHARE` | 仓库内 `src/sentry_sim` | 数据包位置,同时导出给 `xacro` 解析网格路径 |
|
||||||
|
|
||||||
|
### 路径(不设就自动探测)
|
||||||
|
|
||||||
|
| 变量 | 自动探测规则 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `SENTRY_FIELD_ROOT` | 优先仓库内场地包,再查 `~/Gazebo_projects/*map_transfer*/` | 覆盖值必须是现有目录 |
|
||||||
|
| `SENTRY_MAP_YAML` | 依次查标准位置的 `rmul_2027.yaml`、按路径排序的同名文件、按路径排序的第一个普通 YAML 文件 | 覆盖值必须是普通文件 |
|
||||||
|
| `SENTRY_BIN_DIR` | `build/bin` → 旧布局 `release` → 旧布局 `debug`。同一模式按平台和架构路径排序,目录须有已知可执行产物 | 覆盖值必须是现有目录,优先于旧变量 `NAV_BIN_DIR` |
|
||||||
|
|
||||||
|
### 版本(不设就自动探测)
|
||||||
|
|
||||||
|
| 变量 | 自动探测规则 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `ROS_SETUP` | — | 直接指定要 source 的 `setup.bash` 全路径 |
|
||||||
|
| `ROS_DISTRO` | 优先使用对应发行版。需自动扫描时按 ROS 安装目录名自然排序,选择最后一个 | ROS 已加载时沿用当前环境 |
|
||||||
|
| `ROS_INSTALL_ROOT` | — | 非 `/opt/ros` 的 ROS 安装前缀(源码编译) |
|
||||||
|
| `ROS_PREFIX` | — | **只给 `xmake` 用**:ROS 安装前缀。都不设时 xmake 依次看 `AMENT_PREFIX_PATH` → `ROS_DISTRO` → 报错 |
|
||||||
|
| `GZ_BIN` | `/usr/bin/gz` → `/usr/local/bin/gz` → `/opt/gz/bin/gz` → `PATH` | 覆盖值必须指向可执行的普通文件 |
|
||||||
|
| `GZ_FORCE_VERSION` | 用选中的 Gazebo 查询主版本,最多等待 5 秒 | 查询失败时警告并继续使用 Gazebo 默认版本。设置此变量可跳过查询 |
|
||||||
|
|
||||||
|
Python 入口使用已加载的 ROS 环境。`field_root:=` 和 `map:=` 优先于对应的环境变量。只指定场地时,会在该场地目录下自动找地图。
|
||||||
|
`ROS_PREFIX` 用于 xmake 构建。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 7. 场地坐标速查
|
## 7. 场地坐标速查
|
||||||
@@ -258,22 +301,16 @@ ros2 run tf2_ros tf2_echo map field
|
|||||||
# 现在 map→field 是恒等变换:translation = (0.000, 0.000, 0.000)
|
# 现在 map→field 是恒等变换:translation = (0.000, 0.000, 0.000)
|
||||||
```
|
```
|
||||||
|
|
||||||
**方法二:RViz 里画出来(推荐,能肉眼比对)**
|
**方法二:RViz 里看地图本身**
|
||||||
|
|
||||||
|
`mark_field_center.py` 已移除。现在的做法更直接 —— 在 RViz 里把 **Fixed Frame 设成 `map`**
|
||||||
|
并打开 `/map` 显示:地图中心的十字交叉就是 (0,0),而 `map→field` 是恒等变换,
|
||||||
|
所以在 `field` 帧下同一个点还是 (0,0)。想看数值:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 tools/mark_field_center.py # 另开一个终端,仿真跑着时执行
|
ros2 run tf2_ros tf2_echo map field # translation 必须是 (0.000, 0.000, 0.000)
|
||||||
```
|
```
|
||||||
|
|
||||||
然后 RViz 里 **Add → By topic → `/field_center_marker` → Marker**。会看到:
|
|
||||||
|
|
||||||
| 画出什么 | 含义 |
|
|
||||||
|---|---|
|
|
||||||
| 🟡 黄色线框 | 场地内圈 12×8 边界(map 系 x[-6,6] y[-4,4]) |
|
|
||||||
| 🔵 蓝色十字 | 场地中线,交点在中心 |
|
|
||||||
| 🔴 红色圆柱 | 用 **map** 帧画的中心 (0.0, 0.0) |
|
|
||||||
| 🟢 绿色球 | 用 **field** 帧画的中心 (0.0, 0.0) |
|
|
||||||
| 文字标签 | `field(0,0) = map(0,0)` |
|
|
||||||
|
|
||||||
**红圆柱和绿球必须完全重合** —— 重合就说明 `map→field` 这条变换是对的。
|
**红圆柱和绿球必须完全重合** —— 重合就说明 `map→field` 这条变换是对的。
|
||||||
黄框应该正好套在 RViz 地图里场地围挡的内沿上。
|
黄框应该正好套在 RViz 地图里场地围挡的内沿上。
|
||||||
|
|
||||||
@@ -299,7 +336,7 @@ ros2 run ros_gz_sim create -world rmul_arena -name center_check \
|
|||||||
**用 field 系发目标**:
|
**用 field 系发目标**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
build/linux/x86_64/release/patrol --ros-args \
|
build/bin/patrol --ros-args \
|
||||||
-p frame_id:=field -p loop:=false \
|
-p frame_id:=field -p loop:=false \
|
||||||
-p waypoints:="[-4.0, -2.0, -2.0, -2.0, 0.0, 0.0]" # 走到场地中心
|
-p waypoints:="[-4.0, -2.0, -2.0, -2.0, 0.0, 0.0]" # 走到场地中心
|
||||||
```
|
```
|
||||||
|
|||||||
+20
-3
@@ -94,8 +94,8 @@ add_linkgroups(libs, {group = true}) -- → -Wl,--start-group … -Wl,--end-
|
|||||||
|
|
||||||
| 失去的东西 | 现在的替代做法 |
|
| 失去的东西 | 现在的替代做法 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `ros2 run sentry_nav self_filter` | 直接跑 `build/linux/x86_64/release/self_filter` |
|
| `ros2 run sentry_nav self_filter` | 直接跑 `build/bin/self_filter` |
|
||||||
| `ros2 run sentry_sim odom_tf.py` | `build/linux/x86_64/release/odom_tf` |
|
| `ros2 run sentry_sim odom_tf.py` | `build/bin/odom_tf` |
|
||||||
| `ros2 pkg prefix sentry_sim` | `SENTRY_SIM_SHARE` 环境变量(默认 `<仓库>/src/sentry_sim`) |
|
| `ros2 pkg prefix sentry_sim` | `SENTRY_SIM_SHARE` 环境变量(默认 `<仓库>/src/sentry_sim`) |
|
||||||
| `xacro` 的 `$(find sentry_sim)` | 改成 `$(env SENTRY_SIM_SHARE)`;不设变量会明确报错 |
|
| `xacro` 的 `$(find sentry_sim)` | 改成 `$(env SENTRY_SIM_SHARE)`;不设变量会明确报错 |
|
||||||
| `ros2 launch sentry_sim …`(备用入口) | 只保留 `scripts/sentry_up.sh`(本来就是主入口) |
|
| `ros2 launch sentry_sim …`(备用入口) | 只保留 `scripts/sentry_up.sh`(本来就是主入口) |
|
||||||
@@ -187,7 +187,24 @@ src/sentry_nav/
|
|||||||
| `cannot find -lxxx` | 那个包是 header-only | 用 `os.isfile()` 过滤,别直接 `add_links` |
|
| `cannot find -lxxx` | 那个包是 header-only | 用 `os.isfile()` 过滤,别直接 `add_links` |
|
||||||
| `xmake test` 报 `invalid task: run_tests` | 老写法 | 用 **`xmake test`** |
|
| `xmake test` 报 `invalid task: run_tests` | 老写法 | 用 **`xmake test`** |
|
||||||
| `xmake test xxx` 显示 `nothing to test` | 用例名是 `<target>/<testname>` | **`xmake test test_xxx/default`** |
|
| `xmake test xxx` 显示 `nothing to test` | 用例名是 `<target>/<testname>` | **`xmake test test_xxx/default`** |
|
||||||
| `attempt to index a nil value (local 't')` | 公共配置函数带了参数 | 改成无参,在 `target()` 块内调用 |
|
| `attempt to index a nil value (local 't')` | 公共配置函数带了参数,或想在 `target()` 块**外面**拿目标实例 | xmake 的 API **只在 `target()` 块内部有效**。`target(name)` 也**不返回实例**(返回 nil),所以写不出 `set_targetdir` 的包装函数 |
|
||||||
| VS Code 报 `xxx.hpp file not found` | 根 `compile_commands.json` 过期 | 跑一次 `xmake`,再重启 clangd |
|
| VS Code 报 `xxx.hpp file not found` | 根 `compile_commands.json` 过期 | 跑一次 `xmake`,再重启 clangd |
|
||||||
|
|
||||||
|
### 7.1 产物目录固定成 `build/bin/`
|
||||||
|
|
||||||
|
**结论**:每个 target 里写一行 `set_targetdir("$(builddir)/bin")`,**不用 xmake 默认的
|
||||||
|
`build/<平台>/<架构>/<模式>/`**。
|
||||||
|
|
||||||
|
**为什么**:那串平台三元组(`build/linux/x86_64/release/…`)会被抄进文档、脚本、
|
||||||
|
报错提示里。换架构 / 换 OS / 换 release↔debug,**全仓 29 处引用一起失效** ——
|
||||||
|
本工程已经在这上面翻过一次车。固定成 `build/bin/` 后,文档里可以永远写
|
||||||
|
`build/bin/nav_client`。
|
||||||
|
|
||||||
|
**代价**:release 和 debug 落同一层、互相覆盖。要并行保留就用 `xmake -o <目录>`。
|
||||||
|
|
||||||
|
**⚠️ 新增 target 时必须自己补那一行**,否则它会掉回默认目录、和其它的分家。
|
||||||
|
|
||||||
|
`tools/project_env.py --bin-dir` 和 `scripts/env_common.sh` 的 `env_bin_dir()`
|
||||||
|
都按「找某个已知产物的实际位置」定位,所以**新老两套布局都能兼容**。
|
||||||
|
|
||||||
更多见 `排错速查.md` §E。
|
更多见 `排错速查.md` §E。
|
||||||
+21
-7
@@ -24,9 +24,10 @@
|
|||||||
<axis><xyz>0 1 0</xyz><limit lower="-1e16" upper="1e16" effort="10" velocity="100"/></axis>
|
<axis><xyz>0 1 0</xyz><limit lower="-1e16" upper="1e16" effort="10" velocity="100"/></axis>
|
||||||
```
|
```
|
||||||
|
|
||||||
### A3. `cpu_lidar` 不是合法 SDF sensor 类型
|
### A3. GPU 雷达依赖世界的渲染系统
|
||||||
|
|
||||||
CPU 雷达写 `type="lidar"` + `gz-sim-cpu-lidar-system` 插件。写 `type="cpu_lidar"` 会创建失败。
|
模型使用 `type="gpu_lidar"`,世界加载 OGRE2 `Sensors`。服务端无界面运行时使用
|
||||||
|
`--headless-rendering`。若 `/clock` 有数据而 `/scan/points` 无数据,先检查 Sensors 和 EGL 初始化日志。
|
||||||
|
|
||||||
### A4. 百万面级网格会让 Gazebo 卡死
|
### A4. 百万面级网格会让 Gazebo 卡死
|
||||||
|
|
||||||
@@ -63,8 +64,7 @@ export GZ_SIM_SYSTEM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/gz-sim-10/plugins
|
|||||||
本机还有个特例:`gz sim --version` 报 **10.5.0**,apt 装的却是 **10.6.0**。
|
本机还有个特例:`gz sim --version` 报 **10.5.0**,apt 装的却是 **10.6.0**。
|
||||||
原因是 `gz-sim-main` 的 **RUNPATH** 烧进了 vendor 路径,清 `LD_LIBRARY_PATH` 也改不掉 →
|
原因是 `gz-sim-main` 的 **RUNPATH** 烧进了 vendor 路径,清 `LD_LIBRARY_PATH` 也改不掉 →
|
||||||
「10.6 的插件 + 10.5 的核心」混着跑。`scripts/run_gz.sh` 就是为此存在的包装
|
「10.6 的插件 + 10.5 的核心」混着跑。`scripts/run_gz.sh` 就是为此存在的包装
|
||||||
(清掉 `LD_LIBRARY_PATH` 再调 `/usr/bin/gz`,否则连系统版 gz 也会加载 vendor 库,
|
(清掉 `LD_LIBRARY_PATH` 再调 `/usr/bin/gz`,确保系统 gz 使用与自身匹配的库和插件)。
|
||||||
而 vendor 没有 cpu-lidar 插件,雷达会创建失败)。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ velocity_smoother collision_monitor docking_server following_server
|
|||||||
排查 Nav2 起不来时,我在隔离沙箱里看到过**三种不同**的失败
|
排查 Nav2 起不来时,我在隔离沙箱里看到过**三种不同**的失败
|
||||||
(keepout 的 `/get_state` 等不到、`is_path_valid` 60 秒拿不到、controller bond 4 秒超时)——
|
(keepout 的 `/get_state` 等不到、`is_path_valid` 60 秒拿不到、controller bond 4 秒超时)——
|
||||||
每次失败点都不一样,而同一张图里另开探针却能看到**全部 227 个服务**。
|
每次失败点都不一样,而同一张图里另开探针却能看到**全部 227 个服务**。
|
||||||
最后在真机跑 `check_stack.py`,**七个节点全 ACTIVE**。
|
最后在真机跑 `check_stack.py`,**全部节点 ACTIVE**(当时探针还只查 7 个,现在是 10 个)。
|
||||||
|
|
||||||
**教训**:容器/沙箱/CI 里的网络与共享内存行为可能和真机完全不同。
|
**教训**:容器/沙箱/CI 里的网络与共享内存行为可能和真机完全不同。
|
||||||
这种环境里的结论,要么标明「在 X 环境下观察到」,要么先在真机验一遍。
|
这种环境里的结论,要么标明「在 X 环境下观察到」,要么先在真机验一遍。
|
||||||
@@ -194,6 +194,13 @@ gazebo 只报 `Unable to find uri[model://xxx]`,不会告诉你路径写错了
|
|||||||
|
|
||||||
> 这一节全是 2026-11-19 一天内踩出来的。**起因**:导航目标 `ABORTED`,
|
> 这一节全是 2026-11-19 一天内踩出来的。**起因**:导航目标 `ABORTED`,
|
||||||
> 而报错信息一直指向规划器,真正崩掉的却是 AMCL。
|
> 而报错信息一直指向规划器,真正崩掉的却是 AMCL。
|
||||||
|
>
|
||||||
|
> ⚠️ **坐标注记**:本节所有坐标都是**平移前**的旧坐标系(官方定义「西南内角 = (0,0)」,
|
||||||
|
> 内场 0..12 × 0..8)。同一天稍后世界与地图整体平移了 **(−6, −4)**:
|
||||||
|
> 现在 `map` 本身就以场地中心为原点(`rmul_2027.yaml` 的 `origin` = `[-6.4, −4.4]`,
|
||||||
|
> 内场 x[−6,6] y[−4,4])。**旧坐标 (x, y) → 新坐标 (x−6, y−4)。**
|
||||||
|
> 例:本节的真值 `(2.210, 3.792)` → 新坐标 `(−3.790, −0.208)`。
|
||||||
|
> 平移不改变任何形状和结论,只是数字整体挪了位置。
|
||||||
|
|
||||||
### G1. 「地图画错了」——先怀疑自己的对拍程序
|
### G1. 「地图画错了」——先怀疑自己的对拍程序
|
||||||
|
|
||||||
@@ -298,6 +305,13 @@ scan2d 光平面 z = 0.4052 m → 从 0.42 m 平板底下钻过去,零回
|
|||||||
> 顺带一个对照数据:现有 `scan2d` 和「在 0.4052 m 切的图」是 **100% 吻合(273/273)**,
|
> 顺带一个对照数据:现有 `scan2d` 和「在 0.4052 m 切的图」是 **100% 吻合(273/273)**,
|
||||||
> 和官方图只有 74.4%。**雷达没坏,地图没错,它俩描述的是不同高度的东西。**
|
> 和官方图只有 74.4%。**雷达没坏,地图没错,它俩描述的是不同高度的东西。**
|
||||||
|
|
||||||
|
**✅ 已落地**:`src/sentry_nav/src/self_filter.cpp` 现在把过滤后的点云按
|
||||||
|
`z ∈ [0.05, 0.50]`、360 个方位取最小距离,直接发布 `/scan2d`(帧 `base_link`)——
|
||||||
|
不新增进程、不新增话题桥,用的是本来就在跑的那份过滤结果。
|
||||||
|
URDF 里那个单线 `scan2d` 传感器和两处 gz→ROS 桥都已删除,
|
||||||
|
`nav2_params.yaml` 的 `laser_min_range` 也跟着从 `0.6` 降到 `0.15`。
|
||||||
|
细节见 [`定位接入AMCL.md`](定位接入AMCL.md) §4.2。
|
||||||
|
|
||||||
### G6. `NavigateToPose` 的 `distance_remaining` 永远是 0
|
### G6. `NavigateToPose` 的 `distance_remaining` 永远是 0
|
||||||
|
|
||||||
写导航客户端时打印了这个字段,刷了 20 行 `剩余 0.00 m`,看起来像「车原地不动」。
|
写导航客户端时打印了这个字段,刷了 20 行 `剩余 0.00 m`,看起来像「车原地不动」。
|
||||||
@@ -350,9 +364,9 @@ env -u LD_LIBRARY_PATH GZ_PARTITION=sentry gz topic -e -t /scan2d -n 1
|
|||||||
|
|
||||||
而这条报错**不区分**「目标在障碍里」和「起点在障碍里」和「中间没路」,只能靠人排查。
|
而这条报错**不区分**「目标在障碍里」和「起点在障碍里」和「中间没路」,只能靠人排查。
|
||||||
|
|
||||||
**现在的做法**:`build/linux/x86_64/release/nav_client` 发目标前先读 `/map`,检查
|
**现在的做法**:`nav_client` 发目标前先读 `/map`,检查
|
||||||
**占据值 / 是否未知格 / 净空是否 ≥ 0.5 m**(车体半对角 0.422 m),不合格直接拦下并说明原因。
|
**占据值 / 是否未知格 / 净空是否 ≥ 0.5 m**(车体半对角 0.422 m),不合格直接拦下并说明原因。
|
||||||
找安全点用 `tools/free_goals.py`(直读 `rmul_2027.yaml` + `.pgm`,不需要起 ROS)。
|
想提前知道哪里能走,在 RViz 里看 `/global_costmap/costmap`(膨胀层会把不可通行走廊标出来)。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ xmake f -c && xmake # 清掉配置重来
|
|||||||
产物(注意在**仓库根**,不在 `src/sentry_nav/` 下):
|
产物(注意在**仓库根**,不在 `src/sentry_nav/` 下):
|
||||||
|
|
||||||
```
|
```
|
||||||
build/linux/x86_64/release/
|
build/bin/
|
||||||
├── self_filter 点云自滤节点
|
├── self_filter 点云自滤节点
|
||||||
├── patrol 航点巡逻节点
|
├── patrol 航点巡逻节点
|
||||||
├── libsentry_nav_core.a 纯算法静态库
|
├── libsentry_nav_core.a 纯算法静态库
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
# 哨兵 200W 超电底盘“功率—最大速度”限制与遥测系统 (`chassis_power`)
|
||||||
|
|
||||||
|
本项目为哨兵机器人 200W 超电底盘软实时功率限速与状态监控模块,专为 **ROS 2 Jazzy + Nav2 MPPIController** 与 **`xmake` + C++23** 构建体系设计。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、 系统架构设计与职责边界
|
||||||
|
|
||||||
|
系统采用 **「Python 离线微标定 + 零依赖纯 C++23 核心库 + 轻量 ROS 2 接入节点」** 三层解耦架构:
|
||||||
|
|
||||||
|
1. **强实时($\ge 100\sim 1000\text{Hz}$ 硬限流/防扣血/超电防过放)归电控下位机**:
|
||||||
|
- PM02 裁判系统动态限额和 60J 缓冲能量闭环完全由底盘电控(STM32 C板)强实时掌管;一旦超电耗尽或突发大负载,电控自身做毫秒级限流(PID/功率限幅),绝对不把防扣血的生命线寄托在 Linux 上位机上。
|
||||||
|
2. **软实时($10\sim 20\text{Hz}$ 轨迹前馈/速度天花板规划)归上位机**:
|
||||||
|
- 上位机只负责**“战略级巡航限速”**,避免 Nav2 MPPI 控制器规划出 200W 也跑不到的脱离物理实际的轨迹。
|
||||||
|
3. **串口遥测频率对齐为 20Hz**:
|
||||||
|
- 超电能量和底盘总功率属于宏观能量积分量(秒级变化),下调至 20Hz 极简上行(有效载荷仅 8 字节),完全消除跨滑环 CAN1 和串口带宽负担。
|
||||||
|
4. **完全解耦底盘编码器**:
|
||||||
|
- 彻底剥离下位机轮速解算负担,上位机 100% 依赖已在 `field_localization` 发布的 `base_link` 绝对真值速度 `twist`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、 产物一览
|
||||||
|
|
||||||
|
编译产物统一输出至 `build/bin/`:
|
||||||
|
|
||||||
|
| 产物二进制 | 类型 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `build/bin/libchassis_power_core.a` | 静态库 | 零 ROS 依赖核心算法库(串口协议状态机、四重包络解析解、超电能量平滑放电规划、在线 $\kappa_P$ 因子) |
|
||||||
|
| `build/bin/chassis_uart_node` | ROS 2 节点 | 实车 NUC / Xavier NX 原生 POSIX 串口网关(921600 8N1,低延迟模式) |
|
||||||
|
| `build/bin/chassis_power_node` | ROS 2 节点 | 实车与仿真通用限速节点(订阅遥测与真值速度,发布 `/speed_limit` 给 Nav2) |
|
||||||
|
| `build/bin/chassis_power_sim_node` | ROS 2 节点 | Gazebo 虚拟超电模拟器(用于脱离硬件的整车全链路仿真) |
|
||||||
|
| `build/bin/test_*` | 单元测试 | 3 套算法单元测试套件(毫秒级单测,`xmake test` 驱动) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、 串口通信协议约定 (`UART1`, 921600 8N1)
|
||||||
|
|
||||||
|
### 1. 通用帧外壳(小端序)
|
||||||
|
- `sof` (`0xA5`): 1 字节帧头
|
||||||
|
- `cmd_id`: 1 字节命令 ID
|
||||||
|
- `0x01`: 自瞄上行
|
||||||
|
- `0x02`: 底盘与超电遥测上行 (20Hz)
|
||||||
|
- `0x11`: 自瞄下行
|
||||||
|
- `0x12`: 导航底盘指令下行 (10~50Hz)
|
||||||
|
- `payload_len`: 1 字节载荷长度 $N$
|
||||||
|
- `payload`: $N$ 字节载荷数据
|
||||||
|
- `crc16`: 2 字节 DJI 标准 CRC16-CCITT 校验码
|
||||||
|
|
||||||
|
### 2. 底盘与超电遥测载荷 (`cmd_id = 0x02`, 20Hz, 8 Bytes)
|
||||||
|
```cpp
|
||||||
|
struct __attribute__((packed)) UartChassisPowerUpPayload {
|
||||||
|
uint16_t cap_stored_energy_j; // 超电当前存储能量 (J, 0 表示无超电/耗尽)
|
||||||
|
uint16_t cap_max_energy_j; // 超电标称最大可用能量 (J, 如 1500~2000J)
|
||||||
|
uint16_t chassis_power_out_w; // 底盘当前总电功率实测值 (W, 电控滤波平滑值)
|
||||||
|
uint8_t status_flags; // bit0: 超电在线; bit1: 比赛开始(冲点触发); bit2: 小陀螺激活
|
||||||
|
uint8_t reserved; // 对齐预留
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. ROS 2 话题映射
|
||||||
|
- **输入遥测**:`/chassis_power/telemetry` (`sensor_msgs/msg/BatteryState`, 20Hz)
|
||||||
|
- **输入真值速度**:`/field_localization/odometry` (`nav_msgs/msg/Odometry`, 100Hz, `twist.twist`)
|
||||||
|
- **输出 Nav2 调速**:`/speed_limit` (`nav2_msgs/msg/SpeedLimit`, 20Hz, `percentage = false`)
|
||||||
|
- **底盘控制指令**:`/model/sentry/cmd_vel` (`geometry_msgs/msg/Twist`) -> 下发 `cmd_id = 0x12`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、 实车部署与排障指南
|
||||||
|
|
||||||
|
### 1. Intel NUC (`USB-TTL`)
|
||||||
|
- FTDI / CP2102 驱动默认存在 16ms 缓冲延迟。`posix_uart_port` 会自动调用 `ioctl(TIOCSSERIAL)` 开启 `ASYNC_LOW_LATENCY` 压至 1ms。
|
||||||
|
- 建议配置 udev 规则固定别名,防止插入激光雷达或 IMU 时串口号漂移:
|
||||||
|
```bash
|
||||||
|
# /etc/udev/rules.d/99-sentry-chassis-serial.rules
|
||||||
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="sentry_chassis_uart", MODE="0666"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. NVIDIA Jetson Xavier NX (`/dev/ttyTHS0`)
|
||||||
|
- **接线防烧警告**:严禁连接 4 针 GH1.25 端子中的 5V 引脚!只接 `1 (RXD)、2 (TXD)、3 (GND)`,并确认 3.3V 电平匹配。
|
||||||
|
- **防止终端抢占**:
|
||||||
|
```bash
|
||||||
|
sudo systemctl disable --now nvgetty
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 跨滑环 CAN1 带宽保护
|
||||||
|
- 底盘 C 板(C板-S/C)向云台 C 板(C板-S/G)转发底盘超电与比赛状态时,必须降频至 20~100Hz 聚合转发,切勿原样透传 1kHz CAN2 报文,避免挤占 6020 云台电机控制带宽。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、 快速测试与验证
|
||||||
|
|
||||||
|
### 1. 运行所有单元测试
|
||||||
|
```bash
|
||||||
|
xmake test test_power_velocity_model test_uart_protocol test_supercap_estimator
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 离线非负最小二乘拟合工具测试
|
||||||
|
```bash
|
||||||
|
python3 src/chassis_power/src/tools/fit_power_curve.py --test-synthetic
|
||||||
|
```
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# ==============================================================================
|
||||||
|
# 哨兵 200W 超电底盘“功率—最大速度”动力学模型与系统参数配置
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
chassis_power_node:
|
||||||
|
ros__parameters:
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# 1. 物理几何与电机先验参数 (DJI M3508 + C620 + 19.2:1 减速比 + 6寸麦轮)
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
wheel_radius_m: 0.0762 # 麦轮有效半径 R (m)
|
||||||
|
half_wheelbase_plus_track_m: 0.3793 # 半轴距与半轮距之和 Lx + Ly (m)
|
||||||
|
motor_rad_s_per_volt: 2.103 # 482 rpm @ 24V -> 50.47 rad/s (空载转速电压常数)
|
||||||
|
|
||||||
|
# 传动有效利用率 (真实地速 / 轮速)
|
||||||
|
eta_x: 0.95 # 纵向差速行进传动效率
|
||||||
|
eta_y: 0.82 # 横向传动效率 (辊子滚动与内耗)
|
||||||
|
eta_wz: 0.90 # 原地自旋传动效率
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# 2. 二次多项式功率拟合系数
|
||||||
|
# P = kappa_p * (A * v^2 + B * |v| + C2 * wz^2 + C1 * |wz| + P_static) + P_margin
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
a_x: 4.5 # 纵向二次项系数 (铜损主导)
|
||||||
|
a_y: 11.0 # 横向二次项系数 (辊子高速自转内耗)
|
||||||
|
b_x: 12.0 # 纵向一次项系数 (减速箱粘性与滚动阻力)
|
||||||
|
b_y: 26.0 # 横向一次项系数
|
||||||
|
c_wz_lin: 2.5 # 自旋一次项系数
|
||||||
|
c_wz_quad: 1.2 # 自旋二次项系数
|
||||||
|
p_static: 6.0 # 4 个 C620 待机静态功耗 (W)
|
||||||
|
p_accel_margin: 25.0 # 动态加速与爬坡功率余量预留 (W)
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# 3. 抓地力与速度安全约束
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
vx_slip_cap_diff: 3.4 # 差速模式防打滑上限 (m/s)
|
||||||
|
vx_slip_cap_spin: 2.0 # 小陀螺模式防打滑甩尾上限 (m/s)
|
||||||
|
safe_decel_m_s2: 2.2 # 开局 200W 抢点制动安全减速度 (m/s^2)
|
||||||
|
min_crawl_speed: 0.35 # 超电见底时的保底脱困爬行速度 (m/s)
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# 4. 超电容量与能量池放电规划
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
max_supercap_power_w: 200.0 # 超电极速冲刺满功率预算 (W)
|
||||||
|
cruise_power_w: 80.0 # 超电耗尽后的标称巡航功率预算 (W)
|
||||||
|
energy_threshold_low_j: 300.0 # 超电低电量衰减阈值 (J)
|
||||||
|
kappa_filter_alpha: 0.05 # 在线功率因子低通滤波时间常数平滑度
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# 5. 战术行为控制
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
force_opening_sprint: false # 是否强制常开 200W 极速冲点
|
||||||
|
combat_spin: false # 是否开启小陀螺周期平均阻力模型
|
||||||
|
opening_sprint_duration_s: 5.0 # 开局冲点最长单次持续时间 (s)
|
||||||
|
|
||||||
|
chassis_uart_node:
|
||||||
|
ros__parameters:
|
||||||
|
device: "/dev/ttyUSB0" # NUC 上推荐 udev 别名,NX 推荐 /dev/ttyTHS0
|
||||||
|
baud_rate: 921600 # 8N1 极简 20Hz 遥测
|
||||||
|
cmd_vel_topic: "/model/sentry/cmd_vel"
|
||||||
|
telemetry_topic: "/chassis_power/telemetry"
|
||||||
|
|
||||||
|
chassis_power_sim_node:
|
||||||
|
ros__parameters:
|
||||||
|
max_energy_j: 1800.0 # 10s @ 200W 保守标称能量
|
||||||
|
initial_energy_j: 1800.0
|
||||||
|
recharge_power_w: 60.0 # 裁判系统标称补能功率
|
||||||
|
nominal_voltage_v: 24.0
|
||||||
|
start_sprint_on_start: false
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 哨兵底盘战术运动模态
|
||||||
|
*/
|
||||||
|
enum class TacticalMode : uint8_t {
|
||||||
|
kOpeningSprint, ///< 开局 200W 极速冲点 (纯差速前向,吃满功率预算,启用终点制动减速包络)
|
||||||
|
kDiffCruise, ///< 常规差速巡航 (纯差速 vy=0,根据超电剩余容量平滑限速)
|
||||||
|
kCombatSpin, ///< 占点/交战边走边小陀螺 (自旋周期平均阻力 + 扣减自旋功耗与最不利轮速余量)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 底盘与 M3508 物理先验及二次功率模型参数
|
||||||
|
*
|
||||||
|
* 单轮电功率损耗二次展开:
|
||||||
|
* P = kappa_p * (A * v^2 + B * |v| + C2 * wz^2 + C1 * |wz| + P_static) + P_margin
|
||||||
|
*/
|
||||||
|
struct PowerModelParams {
|
||||||
|
// 几何与电机转速极限 (DJI M3508 + 19.2:1 减速箱 + 6 寸麦轮)
|
||||||
|
double wheel_radius_m{0.0762}; ///< 轮半径 R (m)
|
||||||
|
double half_wheelbase_plus_track_m{0.3793}; ///< 半轴距 + 半轮距 Lx + Ly (m)
|
||||||
|
double motor_rad_s_per_volt{2.103}; ///< 482 rpm @ 24V -> 50.47 rad/s (空载转速电压常数)
|
||||||
|
|
||||||
|
// 传动有效利用率 (真实地速 / 轮速)
|
||||||
|
double eta_x{0.95}; ///< 纵向有效传动效率
|
||||||
|
double eta_y{0.82}; ///< 横向传动效率 (辊子滚动与内部内力耗损)
|
||||||
|
double eta_wz{0.90}; ///< 自旋有效利用率
|
||||||
|
|
||||||
|
// 二次功率拟合系数
|
||||||
|
double a_x{4.5}; ///< 纵向二次项系数 (铜损 + 高速流体阻力)
|
||||||
|
double a_y{11.0}; ///< 横向二次项系数
|
||||||
|
double b_x{12.0}; ///< 纵向一次项系数 (库仑摩擦 + 减速箱粘性损耗)
|
||||||
|
double b_y{26.0}; ///< 横向一次项系数
|
||||||
|
double c_wz_lin{2.5}; ///< 自旋一次项系数
|
||||||
|
double c_wz_quad{1.2}; ///< 自旋二次项系数
|
||||||
|
double p_static{6.0}; ///< 4 个 C620 待机静态底盘功耗 (W)
|
||||||
|
double p_accel_margin{25.0}; ///< 机动加速功率余量预留 (W)
|
||||||
|
|
||||||
|
// 安全限制
|
||||||
|
double vx_slip_cap_diff{3.4}; ///< 纯差速防打滑物理极速截断 (m/s)
|
||||||
|
double vx_slip_cap_spin{2.0}; ///< 小陀螺防甩尾防打滑极速截断 (m/s)
|
||||||
|
double safe_decel_m_s2{2.2}; ///< 开局极速刹车安全减速度 (m/s^2)
|
||||||
|
double min_crawl_speed{0.35}; ///< 超电耗尽/极低可用功率时的最低脱困爬行速度 (m/s)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 功率反解查询结构体
|
||||||
|
*/
|
||||||
|
struct PowerQuery {
|
||||||
|
TacticalMode mode{TacticalMode::kDiffCruise}; ///< 战术模态
|
||||||
|
double available_power_w{80.0}; ///< 当前分配给底盘平移的可用功率预算 (W, 如 45~200W)
|
||||||
|
double bus_voltage_v{24.0}; ///< 底盘母线供电电压 (V, 默认 24.0V)
|
||||||
|
double active_wz_rad_s{0.0}; ///< 当前或目标自旋角速度 (rad/s, 差速转向或小陀螺转速)
|
||||||
|
double power_scale_kappa{1.0}; ///< 在线功率自适应修正因子 kappa_P (平稳行驶实测/预测比)
|
||||||
|
double goal_distance_m{-1.0}; ///< 距目标终点距离 (m, <=0 表示不启用终点制动包络)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 综合包络反解限速结果
|
||||||
|
*/
|
||||||
|
struct SpeedLimitResult {
|
||||||
|
double vx_max{0.0}; ///< 最终输出给 Nav2 的最大前向速度 (m/s)
|
||||||
|
double v_power_bound{0.0}; ///< 净可用功率求解上限 (m/s)
|
||||||
|
double v_kinematic_bound{0.0}; ///< 母线反电动势电机物理转速上限 (m/s)
|
||||||
|
double v_slip_bound{0.0}; ///< 模态抓地力防打滑上限 (m/s)
|
||||||
|
double v_brake_bound{0.0}; ///< 终点制动防冲过头上限 (m/s)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 纯 C++23 功率—最大速度数学反解器 (零第三方与 ROS 依赖)
|
||||||
|
*/
|
||||||
|
class PowerVelocityModel {
|
||||||
|
public:
|
||||||
|
explicit constexpr PowerVelocityModel(const PowerModelParams ¶ms = {}) noexcept
|
||||||
|
: params_(params) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 根据给定功率预算、自旋角速度与母线电压,四重包络解析反解最大前向速度
|
||||||
|
*/
|
||||||
|
[[nodiscard]] SpeedLimitResult compute_limit(const PowerQuery &query) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 正向模型:预测给定线速度与角速度下所需的稳态电功率 (W)
|
||||||
|
*/
|
||||||
|
[[nodiscard]] double predict_power(TacticalMode mode, double vx, double wz,
|
||||||
|
double kappa_p = 1.0) const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] const PowerModelParams ¶ms() const noexcept { return params_; }
|
||||||
|
void set_params(const PowerModelParams ¶ms) noexcept { params_ = params; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
PowerModelParams params_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "chassis_power/core/power_velocity_model.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
struct EstimatorConfig {
|
||||||
|
double max_supercap_power_w{200.0}; ///< 超电冲刺满功率 (W)
|
||||||
|
double cruise_power_w{80.0}; ///< 超电耗尽后的标称巡航功率 (W)
|
||||||
|
double energy_threshold_low_j{300.0}; ///< 超电低电量衰减阈值 (J, 低于此值开始线性降至 cruise_power)
|
||||||
|
double kappa_filter_alpha{0.05}; ///< 在线功率因子低通滤波平滑系数 (20Hz 下平滑时间常数约 1s)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 超电剩余功率规划器与在线功率因子自适应器
|
||||||
|
*/
|
||||||
|
class SupercapEstimator {
|
||||||
|
public:
|
||||||
|
explicit SupercapEstimator(const EstimatorConfig &cfg = {}) noexcept : cfg_(cfg) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 根据超电剩余能量计算当前上位机应给出的功率预算 (W)
|
||||||
|
*
|
||||||
|
* @param cap_energy_j 超电当前储存能量 (J)
|
||||||
|
* @param is_opening_sprint 是否处于开局抢点阶段
|
||||||
|
* @return double 可用功率预算 (W)
|
||||||
|
*/
|
||||||
|
[[nodiscard]] double compute_available_power(double cap_energy_j,
|
||||||
|
bool is_opening_sprint) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 在线更新动力学功率修正因子 kappa_P
|
||||||
|
*
|
||||||
|
* @param actual_power_w 电控实测底盘功率 (W)
|
||||||
|
* @param predicted_power_w 动力学模型预测功率 (W)
|
||||||
|
* @param current_speed_m_s 真实车速 (m/s, 只有速度大于一定阈值才更新,避免静止除零)
|
||||||
|
*/
|
||||||
|
void update_kappa(double actual_power_w, double predicted_power_w,
|
||||||
|
double current_speed_m_s) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] double kappa_p() const noexcept { return kappa_p_; }
|
||||||
|
void reset_kappa() noexcept { kappa_p_ = 1.0; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
EstimatorConfig cfg_;
|
||||||
|
double kappa_p_{1.0};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
// 串口通信常量
|
||||||
|
inline constexpr uint8_t kFrameHeaderSof = 0xA5;
|
||||||
|
inline constexpr uint8_t kCmdIdAimIn = 0x01;
|
||||||
|
inline constexpr uint8_t kCmdIdChassisPowerIn = 0x02;
|
||||||
|
inline constexpr uint8_t kCmdIdAimOut = 0x11;
|
||||||
|
inline constexpr uint8_t kCmdIdChassisNavOut = 0x12;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 921600 串口通用帧头
|
||||||
|
*/
|
||||||
|
struct FrameHeader {
|
||||||
|
uint8_t sof{kFrameHeaderSof};
|
||||||
|
uint8_t cmd_id{0};
|
||||||
|
uint8_t payload_len{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 下位机 -> 上位机:底盘与超电遥测载荷 (20Hz, 8 Bytes 极简设计)
|
||||||
|
*/
|
||||||
|
struct UartChassisPowerUpPayload {
|
||||||
|
uint16_t cap_stored_energy_j; ///< 超电当前存储能量 (J, 0 表示无超电/超电耗尽)
|
||||||
|
uint16_t cap_max_energy_j; ///< 超电标称最大可用能量 (J, 如 1500~2000 J)
|
||||||
|
uint16_t chassis_power_out_w; ///< 底盘当前总电功率实测值 (W, 电控滤波平滑值)
|
||||||
|
uint8_t status_flags; ///< bit0: 超电就绪; bit1: 比赛开始(game_progress==4); bit2: 小陀螺使能
|
||||||
|
uint8_t reserved; ///< 对齐预留
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 上位机 -> 下位机:底盘控制指令载荷 (10~50Hz, 6 Bytes)
|
||||||
|
*/
|
||||||
|
struct UartChassisNavDownPayload {
|
||||||
|
int16_t vx_mm_s; ///< 车体 X 轴线速度 (mm/s)
|
||||||
|
int16_t vy_mm_s; ///< 车体 Y 轴线速度 (mm/s, 差速模式下固定为 0)
|
||||||
|
int16_t wz_mrad_s; ///< 车体 Z 轴角速度 (0.001 rad/s)
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DJI 标准 CRC16-CCITT 校验工具
|
||||||
|
*/
|
||||||
|
[[nodiscard]] uint16_t calculate_crc16(std::span<const uint8_t> data, uint16_t init_val = 0xFFFF) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 打包带有 SOF、CMD_ID 与 CRC16 的完整二进制帧
|
||||||
|
*/
|
||||||
|
[[nodiscard]] std::vector<uint8_t> serialize_frame(uint8_t cmd_id, std::span<const uint8_t> payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 串口流式字节解包器(内部状态机,自动处理断包与粘包)
|
||||||
|
*/
|
||||||
|
class StreamDecoder {
|
||||||
|
public:
|
||||||
|
enum class State {
|
||||||
|
kWaitSof,
|
||||||
|
kWaitCmdId,
|
||||||
|
kWaitLen,
|
||||||
|
kWaitPayload,
|
||||||
|
kWaitCrcLow,
|
||||||
|
kWaitCrcHigh,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DecodedFrame {
|
||||||
|
uint8_t cmd_id{0};
|
||||||
|
std::vector<uint8_t> payload;
|
||||||
|
};
|
||||||
|
|
||||||
|
StreamDecoder() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 输入一个字节,如果凑齐一个完整有效帧则返回该帧,否则返回 std::nullopt
|
||||||
|
*/
|
||||||
|
[[nodiscard]] std::optional<DecodedFrame> feed_byte(uint8_t byte) noexcept;
|
||||||
|
|
||||||
|
void reset() noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
State state_{State::kWaitSof};
|
||||||
|
uint8_t cmd_id_{0};
|
||||||
|
uint8_t payload_len_{0};
|
||||||
|
std::vector<uint8_t> buffer_;
|
||||||
|
uint16_t received_crc_{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
class PosixUartPort {
|
||||||
|
public:
|
||||||
|
PosixUartPort() = default;
|
||||||
|
~PosixUartPort();
|
||||||
|
|
||||||
|
PosixUartPort(const PosixUartPort &) = delete;
|
||||||
|
PosixUartPort &operator=(const PosixUartPort &) = delete;
|
||||||
|
PosixUartPort(PosixUartPort &&other) noexcept;
|
||||||
|
PosixUartPort &operator=(PosixUartPort &&other) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 打开指定串口并按 8N1 配置波特率与低延迟模式
|
||||||
|
*
|
||||||
|
* @param device 串口设备路径 (例如 /dev/ttyUSB0, /dev/ttyTHS0)
|
||||||
|
* @param baud_rate 波特率 (默认 921600)
|
||||||
|
* @return true 打开并配置成功
|
||||||
|
* @return false 失败
|
||||||
|
*/
|
||||||
|
bool open(std::string_view device, int baud_rate = 921600);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 关闭串口
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查串口是否已成功打开
|
||||||
|
*/
|
||||||
|
[[nodiscard]] bool is_open() const noexcept { return fd_ >= 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 非阻塞读取可用数据
|
||||||
|
*
|
||||||
|
* @param buffer 目标缓冲区
|
||||||
|
* @param max_len 最大读取字节数
|
||||||
|
* @return ssize_t 实际读取字节数,0 表示无数据,-1 表示错误
|
||||||
|
*/
|
||||||
|
[[nodiscard]] ssize_t read_bytes(uint8_t *buffer, size_t max_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发送指定字节序列
|
||||||
|
*
|
||||||
|
* @param data 发送数据指针
|
||||||
|
* @param len 发送字节数
|
||||||
|
* @return ssize_t 实际写入字节数,-1 表示错误
|
||||||
|
*/
|
||||||
|
[[nodiscard]] ssize_t write_bytes(const uint8_t *data, size_t len);
|
||||||
|
|
||||||
|
[[nodiscard]] const std::string &device_path() const noexcept { return device_path_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int fd_{-1};
|
||||||
|
std::string device_path_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "chassis_power/core/power_velocity_model.hpp"
|
||||||
|
#include "chassis_power/core/supercap_estimator.hpp"
|
||||||
|
|
||||||
|
#include <geometry_msgs/msg/pose_stamped.hpp>
|
||||||
|
#include <nav2_msgs/msg/speed_limit.hpp>
|
||||||
|
#include <nav_msgs/msg/odometry.hpp>
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <sensor_msgs/msg/battery_state.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
class PowerLimiterNode : public rclcpp::Node {
|
||||||
|
public:
|
||||||
|
explicit PowerLimiterNode(const rclcpp::NodeOptions &options = rclcpp::NodeOptions{});
|
||||||
|
~PowerLimiterNode() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void load_parameters();
|
||||||
|
void on_telemetry(sensor_msgs::msg::BatteryState::ConstSharedPtr msg);
|
||||||
|
void on_odometry(nav_msgs::msg::Odometry::ConstSharedPtr msg);
|
||||||
|
void on_goal_pose(geometry_msgs::msg::PoseStamped::ConstSharedPtr msg);
|
||||||
|
void update_speed_limit();
|
||||||
|
|
||||||
|
core::PowerVelocityModel model_;
|
||||||
|
core::SupercapEstimator estimator_;
|
||||||
|
|
||||||
|
std::mutex mutex_;
|
||||||
|
std::optional<sensor_msgs::msg::BatteryState> last_telemetry_;
|
||||||
|
std::optional<nav_msgs::msg::Odometry> last_odom_;
|
||||||
|
std::optional<geometry_msgs::msg::PoseStamped> current_goal_;
|
||||||
|
|
||||||
|
rclcpp::Subscription<sensor_msgs::msg::BatteryState>::SharedPtr telemetry_sub_;
|
||||||
|
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr odom_sub_;
|
||||||
|
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
|
||||||
|
rclcpp::Publisher<nav2_msgs::msg::SpeedLimit>::SharedPtr speed_limit_pub_;
|
||||||
|
rclcpp::TimerBase::SharedPtr timer_;
|
||||||
|
|
||||||
|
// 参数配置
|
||||||
|
bool force_opening_sprint_{false};
|
||||||
|
bool combat_spin_enabled_{false};
|
||||||
|
double opening_sprint_duration_s_{5.0};
|
||||||
|
rclcpp::Time sprint_start_time_{0, 0, RCL_ROS_TIME};
|
||||||
|
bool sprint_active_{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "chassis_power/core/uart_protocol.hpp"
|
||||||
|
#include "chassis_power/ros/posix_uart_port.hpp"
|
||||||
|
|
||||||
|
#include <geometry_msgs/msg/twist.hpp>
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <sensor_msgs/msg/battery_state.hpp>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
class UartBridgeNode : public rclcpp::Node {
|
||||||
|
public:
|
||||||
|
explicit UartBridgeNode(const rclcpp::NodeOptions &options = rclcpp::NodeOptions{});
|
||||||
|
~UartBridgeNode() override = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void poll_uart();
|
||||||
|
void on_cmd_vel(geometry_msgs::msg::Twist::ConstSharedPtr msg);
|
||||||
|
void try_reconnect();
|
||||||
|
|
||||||
|
PosixUartPort port_;
|
||||||
|
core::StreamDecoder decoder_;
|
||||||
|
|
||||||
|
std::string device_path_{"/dev/ttyUSB0"};
|
||||||
|
int baud_rate_{921600};
|
||||||
|
std::string cmd_vel_topic_{"/model/sentry/cmd_vel"};
|
||||||
|
std::string telemetry_topic_{"/chassis_power/telemetry"};
|
||||||
|
|
||||||
|
rclcpp::Publisher<sensor_msgs::msg::BatteryState>::SharedPtr telemetry_pub_;
|
||||||
|
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr cmd_vel_sub_;
|
||||||
|
rclcpp::TimerBase::SharedPtr poll_timer_;
|
||||||
|
rclcpp::TimerBase::SharedPtr reconnect_timer_;
|
||||||
|
|
||||||
|
std::array<uint8_t, 256> rx_buffer_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
#include "chassis_power/core/power_velocity_model.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// 辅助函数:安全解一元二次方程 A * v^2 + B * v - DeltaP = 0 的正根
|
||||||
|
// 满足 A > 0, B >= 0, DeltaP >= 0
|
||||||
|
[[nodiscard]] constexpr double solve_quadratic_positive_root(double a, double b,
|
||||||
|
double delta_p) noexcept {
|
||||||
|
if (delta_p <= 0.0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
if (a <= 1e-6) {
|
||||||
|
// 退化为线性方程: B * v = DeltaP
|
||||||
|
return (b > 1e-6) ? (delta_p / b) : 0.0;
|
||||||
|
}
|
||||||
|
const double discriminant = b * b + 4.0 * a * delta_p;
|
||||||
|
return (-b + std::sqrt(discriminant)) / (2.0 * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
SpeedLimitResult PowerVelocityModel::compute_limit(const PowerQuery &query) const noexcept {
|
||||||
|
SpeedLimitResult result{};
|
||||||
|
|
||||||
|
const double abs_wz = std::abs(query.active_wz_rad_s);
|
||||||
|
const double kappa = std::clamp(query.power_scale_kappa, 0.5, 2.0);
|
||||||
|
|
||||||
|
// 1. 模态动力学等效系数
|
||||||
|
double eff_a = params_.a_x;
|
||||||
|
double eff_b = params_.b_x;
|
||||||
|
double gamma_mode = 1.0 / std::max(params_.eta_x, 1e-3);
|
||||||
|
double slip_cap = params_.vx_slip_cap_diff;
|
||||||
|
|
||||||
|
if (query.mode == TacticalMode::kCombatSpin) {
|
||||||
|
// 小陀螺自旋周期平均阻力模型
|
||||||
|
// 麦轮周期积分: 平均二次项 = (a_x + a_y) / 2, 平均一次项 = (2 / pi) * (b_x + b_y)
|
||||||
|
eff_a = 0.5 * (params_.a_x + params_.a_y);
|
||||||
|
eff_b = (2.0 / std::numbers::pi) * (params_.b_x + params_.b_y);
|
||||||
|
|
||||||
|
// 最不利相位 (45度方向麦轮速度投影系数): sqrt(2)/2 * (1/eta_x + 1/eta_y)
|
||||||
|
const double inv_eta_sum = (1.0 / std::max(params_.eta_x, 1e-3)) +
|
||||||
|
(1.0 / std::max(params_.eta_y, 1e-3));
|
||||||
|
gamma_mode = std::numbers::sqrt2 * 0.5 * inv_eta_sum;
|
||||||
|
slip_cap = params_.vx_slip_cap_spin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 功率包络解析解 (v_power_bound)
|
||||||
|
// 计算自旋旋转功耗与静态功耗
|
||||||
|
const double rot_power = params_.c_wz_lin * abs_wz + params_.c_wz_quad * (abs_wz * abs_wz);
|
||||||
|
const double fixed_power = params_.p_static + rot_power;
|
||||||
|
|
||||||
|
// 净可用平移功率预算: DeltaP = max(0.0, (P_avail - P_margin)/kappa - fixed_power)
|
||||||
|
const double net_p_budget =
|
||||||
|
std::max(0.0, (query.available_power_w - params_.p_accel_margin) / kappa - fixed_power);
|
||||||
|
result.v_power_bound = solve_quadratic_positive_root(eff_a, eff_b, net_p_budget);
|
||||||
|
|
||||||
|
// 3. 电机母线电压转速包络 (v_kinematic_bound)
|
||||||
|
// 电机在母线电压下的空载角速度上限: omega_max = motor_rad_s_per_volt * V_bus
|
||||||
|
// 单轮速度约束: gamma_mode * v_x + (L / eta_wz) * |wz| <= R * omega_max
|
||||||
|
const double max_wheel_speed =
|
||||||
|
params_.wheel_radius_m * (params_.motor_rad_s_per_volt * std::max(query.bus_voltage_v, 1.0));
|
||||||
|
const double rot_wheel_speed =
|
||||||
|
(params_.half_wheelbase_plus_track_m / std::max(params_.eta_wz, 1e-3)) * abs_wz;
|
||||||
|
const double remaining_wheel_speed = std::max(0.0, max_wheel_speed - rot_wheel_speed);
|
||||||
|
result.v_kinematic_bound = remaining_wheel_speed / std::max(gamma_mode, 1e-3);
|
||||||
|
|
||||||
|
// 4. 防打滑包络 (v_slip_bound)
|
||||||
|
result.v_slip_bound = slip_cap;
|
||||||
|
|
||||||
|
// 5. 抢点制动包络 (v_brake_bound)
|
||||||
|
if (query.mode == TacticalMode::kOpeningSprint && query.goal_distance_m >= 0.0) {
|
||||||
|
result.v_brake_bound =
|
||||||
|
std::sqrt(2.0 * params_.safe_decel_m_s2 * std::max(0.0, query.goal_distance_m));
|
||||||
|
} else {
|
||||||
|
result.v_brake_bound = 100.0; // 极大值,不构成约束
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 四重包络综合取小,并应用最低爬行速度保底 (保证低功耗下不卡死)
|
||||||
|
const double v_candidate = std::max(result.v_power_bound, params_.min_crawl_speed);
|
||||||
|
result.vx_max = std::min({v_candidate, result.v_kinematic_bound, result.v_slip_bound,
|
||||||
|
result.v_brake_bound});
|
||||||
|
|
||||||
|
// 严格确保不会超过物理极限
|
||||||
|
result.vx_max = std::max(0.0, std::min(result.vx_max, result.v_kinematic_bound));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
double PowerVelocityModel::predict_power(TacticalMode mode, double vx, double wz,
|
||||||
|
double kappa_p) const noexcept {
|
||||||
|
const double abs_vx = std::abs(vx);
|
||||||
|
const double abs_wz = std::abs(wz);
|
||||||
|
const double kappa = std::clamp(kappa_p, 0.5, 2.0);
|
||||||
|
|
||||||
|
double eff_a = params_.a_x;
|
||||||
|
double eff_b = params_.b_x;
|
||||||
|
|
||||||
|
if (mode == TacticalMode::kCombatSpin) {
|
||||||
|
eff_a = 0.5 * (params_.a_x + params_.a_y);
|
||||||
|
eff_b = (2.0 / std::numbers::pi) * (params_.b_x + params_.b_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
const double p_trans = eff_a * (abs_vx * abs_vx) + eff_b * abs_vx;
|
||||||
|
const double p_rot = params_.c_wz_lin * abs_wz + params_.c_wz_quad * (abs_wz * abs_wz);
|
||||||
|
|
||||||
|
return kappa * (p_trans + p_rot + params_.p_static) + params_.p_accel_margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include "chassis_power/core/supercap_estimator.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
double SupercapEstimator::compute_available_power(double cap_energy_j,
|
||||||
|
bool is_opening_sprint) const noexcept {
|
||||||
|
if (cap_energy_j <= 0.0) {
|
||||||
|
return cfg_.cruise_power_w;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_opening_sprint) {
|
||||||
|
// 开局冲点阶段:只要电量还在安全阈值以上,全额释放 200W
|
||||||
|
if (cap_energy_j >= cfg_.energy_threshold_low_j) {
|
||||||
|
return cfg_.max_supercap_power_w;
|
||||||
|
}
|
||||||
|
// 电量不足时平滑线性过渡回巡航功率
|
||||||
|
const double ratio = std::clamp(cap_energy_j / cfg_.energy_threshold_low_j, 0.0, 1.0);
|
||||||
|
return cfg_.cruise_power_w + ratio * (cfg_.max_supercap_power_w - cfg_.cruise_power_w);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 常规巡航阶段:根据超电储能按比例平滑使用
|
||||||
|
if (cap_energy_j >= cfg_.energy_threshold_low_j) {
|
||||||
|
// 超电能量充足,按 120W 高效巡航
|
||||||
|
return std::min(cfg_.max_supercap_power_w, cfg_.cruise_power_w * 1.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
const double ratio = std::clamp(cap_energy_j / cfg_.energy_threshold_low_j, 0.0, 1.0);
|
||||||
|
return cfg_.cruise_power_w + ratio * (cfg_.cruise_power_w * 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SupercapEstimator::update_kappa(double actual_power_w, double predicted_power_w,
|
||||||
|
double current_speed_m_s) noexcept {
|
||||||
|
// 仅在车体处于有效运动状态 (v > 0.4 m/s) 且预测功率有意义时更新
|
||||||
|
if (current_speed_m_s < 0.4 || predicted_power_w < 10.0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const double instant_kappa =
|
||||||
|
std::clamp(actual_power_w / predicted_power_w, 0.6, 1.8);
|
||||||
|
|
||||||
|
// 一阶低通平滑滤波: kappa = (1 - alpha) * kappa + alpha * instant_kappa
|
||||||
|
kappa_p_ = (1.0 - cfg_.kappa_filter_alpha) * kappa_p_ +
|
||||||
|
cfg_.kappa_filter_alpha * instant_kappa;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
#include "chassis_power/core/uart_protocol.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace chassis_power::core {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// CRC16-CCITT 查找表 (Poly: 0x1021)
|
||||||
|
constexpr std::array<uint16_t, 256> kCrc16Table = []() consteval {
|
||||||
|
std::array<uint16_t, 256> table{};
|
||||||
|
for (uint32_t i = 0; i < 256; ++i) {
|
||||||
|
uint16_t cur = static_cast<uint16_t>(i << 8);
|
||||||
|
for (int j = 0; j < 8; ++j) {
|
||||||
|
if ((cur & 0x8000) != 0) {
|
||||||
|
cur = static_cast<uint16_t>((cur << 1) ^ 0x1021);
|
||||||
|
} else {
|
||||||
|
cur = static_cast<uint16_t>(cur << 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table[i] = cur;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}();
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
uint16_t calculate_crc16(std::span<const uint8_t> data, uint16_t init_val) noexcept {
|
||||||
|
uint16_t crc = init_val;
|
||||||
|
for (const uint8_t byte : data) {
|
||||||
|
crc = static_cast<uint16_t>((crc << 8) ^ kCrc16Table[((crc >> 8) ^ byte) & 0xFF]);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> serialize_frame(uint8_t cmd_id, std::span<const uint8_t> payload) {
|
||||||
|
std::vector<uint8_t> frame;
|
||||||
|
frame.reserve(3 + payload.size() + 2);
|
||||||
|
|
||||||
|
frame.push_back(kFrameHeaderSof);
|
||||||
|
frame.push_back(cmd_id);
|
||||||
|
frame.push_back(static_cast<uint8_t>(payload.size()));
|
||||||
|
frame.insert(frame.end(), payload.begin(), payload.end());
|
||||||
|
|
||||||
|
const uint16_t crc = calculate_crc16(frame);
|
||||||
|
frame.push_back(static_cast<uint8_t>(crc & 0xFF));
|
||||||
|
frame.push_back(static_cast<uint8_t>((crc >> 8) & 0xFF));
|
||||||
|
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StreamDecoder::reset() noexcept {
|
||||||
|
state_ = State::kWaitSof;
|
||||||
|
cmd_id_ = 0;
|
||||||
|
payload_len_ = 0;
|
||||||
|
buffer_.clear();
|
||||||
|
received_crc_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<StreamDecoder::DecodedFrame> StreamDecoder::feed_byte(uint8_t byte) noexcept {
|
||||||
|
switch (state_) {
|
||||||
|
case State::kWaitSof:
|
||||||
|
if (byte == kFrameHeaderSof) {
|
||||||
|
buffer_.clear();
|
||||||
|
buffer_.push_back(byte);
|
||||||
|
state_ = State::kWaitCmdId;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::kWaitCmdId:
|
||||||
|
cmd_id_ = byte;
|
||||||
|
buffer_.push_back(byte);
|
||||||
|
state_ = State::kWaitLen;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::kWaitLen:
|
||||||
|
payload_len_ = byte;
|
||||||
|
buffer_.push_back(byte);
|
||||||
|
if (payload_len_ == 0) {
|
||||||
|
state_ = State::kWaitCrcLow;
|
||||||
|
} else {
|
||||||
|
buffer_.reserve(3 + payload_len_ + 2);
|
||||||
|
state_ = State::kWaitPayload;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::kWaitPayload:
|
||||||
|
buffer_.push_back(byte);
|
||||||
|
if (buffer_.size() == static_cast<size_t>(3 + payload_len_)) {
|
||||||
|
state_ = State::kWaitCrcLow;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::kWaitCrcLow:
|
||||||
|
received_crc_ = byte;
|
||||||
|
state_ = State::kWaitCrcHigh;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::kWaitCrcHigh: {
|
||||||
|
received_crc_ |= static_cast<uint16_t>(byte << 8);
|
||||||
|
const uint16_t calc_crc = calculate_crc16(buffer_);
|
||||||
|
if (calc_crc == received_crc_) {
|
||||||
|
DecodedFrame result{
|
||||||
|
.cmd_id = cmd_id_,
|
||||||
|
.payload = std::vector<uint8_t>(buffer_.begin() + 3, buffer_.end()),
|
||||||
|
};
|
||||||
|
reset();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// CRC 校验失败,重置状态机
|
||||||
|
reset();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::core
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
#include "chassis_power/ros/posix_uart_port.hpp"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/serial.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
speed_t to_baud_constant(int baud_rate) {
|
||||||
|
switch (baud_rate) {
|
||||||
|
case 9600:
|
||||||
|
return B9600;
|
||||||
|
case 19200:
|
||||||
|
return B19200;
|
||||||
|
case 38400:
|
||||||
|
return B38400;
|
||||||
|
case 57600:
|
||||||
|
return B57600;
|
||||||
|
case 115200:
|
||||||
|
return B115200;
|
||||||
|
case 230400:
|
||||||
|
return B230400;
|
||||||
|
#ifdef B460800
|
||||||
|
case 460800:
|
||||||
|
return B460800;
|
||||||
|
#endif
|
||||||
|
#ifdef B921600
|
||||||
|
case 921600:
|
||||||
|
return B921600;
|
||||||
|
#endif
|
||||||
|
#ifdef B1000000
|
||||||
|
case 1000000:
|
||||||
|
return B1000000;
|
||||||
|
#endif
|
||||||
|
#ifdef B1500000
|
||||||
|
case 1500000:
|
||||||
|
return B1500000;
|
||||||
|
#endif
|
||||||
|
#ifdef B2000000
|
||||||
|
case 2000000:
|
||||||
|
return B2000000;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return B921600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
PosixUartPort::~PosixUartPort() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
PosixUartPort::PosixUartPort(PosixUartPort &&other) noexcept
|
||||||
|
: fd_(other.fd_), device_path_(std::move(other.device_path_)) {
|
||||||
|
other.fd_ = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PosixUartPort &PosixUartPort::operator=(PosixUartPort &&other) noexcept {
|
||||||
|
if (this != &other) {
|
||||||
|
close();
|
||||||
|
fd_ = other.fd_;
|
||||||
|
device_path_ = std::move(other.device_path_);
|
||||||
|
other.fd_ = -1;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PosixUartPort::open(std::string_view device, int baud_rate) {
|
||||||
|
close();
|
||||||
|
device_path_ = std::string(device);
|
||||||
|
|
||||||
|
fd_ = ::open(device_path_.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||||
|
if (fd_ < 0) {
|
||||||
|
std::cerr << "[PosixUartPort] Failed to open " << device_path_ << ": "
|
||||||
|
<< std::strerror(errno) << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct termios tty{};
|
||||||
|
if (tcgetattr(fd_, &tty) != 0) {
|
||||||
|
std::cerr << "[PosixUartPort] tcgetattr error on " << device_path_ << ": "
|
||||||
|
<< std::strerror(errno) << "\n";
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设为原始模式 (Raw mode),禁用任何终端控制字符与回显
|
||||||
|
cfmakeraw(&tty);
|
||||||
|
|
||||||
|
// 8N1 配置
|
||||||
|
tty.c_cflag &= ~PARENB; // 无奇偶校验
|
||||||
|
tty.c_cflag &= ~CSTOPB; // 1 位停止位
|
||||||
|
tty.c_cflag &= ~CSIZE;
|
||||||
|
tty.c_cflag |= CS8; // 8 位数据位
|
||||||
|
tty.c_cflag &= ~CRTSCTS; // 无硬件流控
|
||||||
|
tty.c_cflag |= (CLOCAL | CREAD); // 忽略调制解调器状态线,使能接收
|
||||||
|
|
||||||
|
// 禁用软件流控
|
||||||
|
tty.c_iflag &= ~(IXON | IXOFF | IXANY);
|
||||||
|
|
||||||
|
// 非阻塞或极短超时控制
|
||||||
|
tty.c_cc[VMIN] = 0;
|
||||||
|
tty.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
|
speed_t baud = to_baud_constant(baud_rate);
|
||||||
|
cfsetispeed(&tty, baud);
|
||||||
|
cfsetospeed(&tty, baud);
|
||||||
|
|
||||||
|
if (tcsetattr(fd_, TCSANOW, &tty) != 0) {
|
||||||
|
std::cerr << "[PosixUartPort] tcsetattr error on " << device_path_ << ": "
|
||||||
|
<< std::strerror(errno) << "\n";
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试为 FTDI / CP210x 等 USB 虚拟串口开启 ASYNC_LOW_LATENCY (将 16ms 缓冲延迟压至 1ms)
|
||||||
|
struct serial_struct serial{};
|
||||||
|
if (ioctl(fd_, TIOCGSERIAL, &serial) == 0) {
|
||||||
|
serial.flags |= ASYNC_LOW_LATENCY;
|
||||||
|
if (ioctl(fd_, TIOCSSERIAL, &serial) == 0) {
|
||||||
|
std::cout << "[PosixUartPort] ASYNC_LOW_LATENCY enabled for " << device_path_ << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空现有输入输出缓冲区
|
||||||
|
tcflush(fd_, TCIOFLUSH);
|
||||||
|
|
||||||
|
std::cout << "[PosixUartPort] Successfully opened " << device_path_
|
||||||
|
<< " at " << baud_rate << " baud (8N1)\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PosixUartPort::close() {
|
||||||
|
if (fd_ >= 0) {
|
||||||
|
::close(fd_);
|
||||||
|
fd_ = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t PosixUartPort::read_bytes(uint8_t *buffer, size_t max_len) {
|
||||||
|
if (fd_ < 0 || buffer == nullptr || max_len == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t n = ::read(fd_, buffer, max_len);
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
return 0; // 正常非阻塞无数据
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t PosixUartPort::write_bytes(const uint8_t *data, size_t len) {
|
||||||
|
if (fd_ < 0 || data == nullptr || len == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t total_written = 0;
|
||||||
|
while (static_cast<size_t>(total_written) < len) {
|
||||||
|
ssize_t n = ::write(fd_, data + total_written, len - total_written);
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
|
// 短暂重试或让出
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
total_written += n;
|
||||||
|
}
|
||||||
|
return total_written;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
#include "chassis_power/ros/power_limiter_node.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
PowerLimiterNode::PowerLimiterNode(const rclcpp::NodeOptions &options)
|
||||||
|
: Node("chassis_power_node", options) {
|
||||||
|
load_parameters();
|
||||||
|
|
||||||
|
telemetry_sub_ = create_subscription<sensor_msgs::msg::BatteryState>(
|
||||||
|
"/chassis_power/telemetry", rclcpp::QoS(1),
|
||||||
|
[this](sensor_msgs::msg::BatteryState::ConstSharedPtr msg) { on_telemetry(msg); });
|
||||||
|
|
||||||
|
odom_sub_ = create_subscription<nav_msgs::msg::Odometry>(
|
||||||
|
"/field_localization/odometry", rclcpp::QoS(1),
|
||||||
|
[this](nav_msgs::msg::Odometry::ConstSharedPtr msg) { on_odometry(msg); });
|
||||||
|
|
||||||
|
goal_sub_ = create_subscription<geometry_msgs::msg::PoseStamped>(
|
||||||
|
"/goal_pose", rclcpp::QoS(1),
|
||||||
|
[this](geometry_msgs::msg::PoseStamped::ConstSharedPtr msg) { on_goal_pose(msg); });
|
||||||
|
|
||||||
|
speed_limit_pub_ =
|
||||||
|
create_publisher<nav2_msgs::msg::SpeedLimit>("/speed_limit", rclcpp::QoS(1));
|
||||||
|
|
||||||
|
// 20Hz 软实时规划周期 (50ms)
|
||||||
|
timer_ = create_wall_timer(50ms, [this]() { update_speed_limit(); });
|
||||||
|
|
||||||
|
RCLCPP_INFO(get_logger(),
|
||||||
|
"chassis_power_node started. 20Hz speed limiter active on /speed_limit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerLimiterNode::load_parameters() {
|
||||||
|
core::PowerModelParams p;
|
||||||
|
p.wheel_radius_m = declare_parameter<double>("wheel_radius_m", 0.0762);
|
||||||
|
p.half_wheelbase_plus_track_m =
|
||||||
|
declare_parameter<double>("half_wheelbase_plus_track_m", 0.3793);
|
||||||
|
p.motor_rad_s_per_volt = declare_parameter<double>("motor_rad_s_per_volt", 2.103);
|
||||||
|
p.eta_x = declare_parameter<double>("eta_x", 0.95);
|
||||||
|
p.eta_y = declare_parameter<double>("eta_y", 0.82);
|
||||||
|
p.eta_wz = declare_parameter<double>("eta_wz", 0.90);
|
||||||
|
p.a_x = declare_parameter<double>("a_x", 4.5);
|
||||||
|
p.a_y = declare_parameter<double>("a_y", 11.0);
|
||||||
|
p.b_x = declare_parameter<double>("b_x", 12.0);
|
||||||
|
p.b_y = declare_parameter<double>("b_y", 26.0);
|
||||||
|
p.c_wz_lin = declare_parameter<double>("c_wz_lin", 2.5);
|
||||||
|
p.c_wz_quad = declare_parameter<double>("c_wz_quad", 1.2);
|
||||||
|
p.p_static = declare_parameter<double>("p_static", 6.0);
|
||||||
|
p.p_accel_margin = declare_parameter<double>("p_accel_margin", 25.0);
|
||||||
|
p.vx_slip_cap_diff = declare_parameter<double>("vx_slip_cap_diff", 3.4);
|
||||||
|
p.vx_slip_cap_spin = declare_parameter<double>("vx_slip_cap_spin", 2.0);
|
||||||
|
p.safe_decel_m_s2 = declare_parameter<double>("safe_decel_m_s2", 2.2);
|
||||||
|
p.min_crawl_speed = declare_parameter<double>("min_crawl_speed", 0.35);
|
||||||
|
model_.set_params(p);
|
||||||
|
|
||||||
|
core::EstimatorConfig ec;
|
||||||
|
ec.max_supercap_power_w = declare_parameter<double>("max_supercap_power_w", 200.0);
|
||||||
|
ec.cruise_power_w = declare_parameter<double>("cruise_power_w", 80.0);
|
||||||
|
ec.energy_threshold_low_j = declare_parameter<double>("energy_threshold_low_j", 300.0);
|
||||||
|
ec.kappa_filter_alpha = declare_parameter<double>("kappa_filter_alpha", 0.05);
|
||||||
|
estimator_ = core::SupercapEstimator(ec);
|
||||||
|
|
||||||
|
force_opening_sprint_ = declare_parameter<bool>("force_opening_sprint", false);
|
||||||
|
combat_spin_enabled_ = declare_parameter<bool>("combat_spin", false);
|
||||||
|
opening_sprint_duration_s_ =
|
||||||
|
declare_parameter<double>("opening_sprint_duration_s", 5.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerLimiterNode::on_telemetry(sensor_msgs::msg::BatteryState::ConstSharedPtr msg) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
// 检测比赛开始标志 (bit1) 触发开局冲点
|
||||||
|
if (!sprint_active_ && (msg->power_supply_status & 0x02)) {
|
||||||
|
sprint_active_ = true;
|
||||||
|
sprint_start_time_ = now();
|
||||||
|
RCLCPP_INFO(get_logger(), "Opening sprint mode triggered by telemetry status!");
|
||||||
|
}
|
||||||
|
last_telemetry_ = *msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerLimiterNode::on_odometry(nav_msgs::msg::Odometry::ConstSharedPtr msg) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
last_odom_ = *msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerLimiterNode::on_goal_pose(geometry_msgs::msg::PoseStamped::ConstSharedPtr msg) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
current_goal_ = *msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PowerLimiterNode::update_speed_limit() {
|
||||||
|
std::optional<sensor_msgs::msg::BatteryState> telem;
|
||||||
|
std::optional<nav_msgs::msg::Odometry> odom;
|
||||||
|
std::optional<geometry_msgs::msg::PoseStamped> goal;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
telem = last_telemetry_;
|
||||||
|
odom = last_odom_;
|
||||||
|
goal = current_goal_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开局抢点时长超时判定
|
||||||
|
if (sprint_active_) {
|
||||||
|
const double elapsed = (now() - sprint_start_time_).seconds();
|
||||||
|
if (elapsed > opening_sprint_duration_s_) {
|
||||||
|
sprint_active_ = false;
|
||||||
|
RCLCPP_INFO(get_logger(), "Opening sprint timeout (%.1fs). Returned to cruise.", elapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遥测数据提取与超时安全保底
|
||||||
|
double cap_energy_j = 0.0;
|
||||||
|
double bus_voltage = 24.0;
|
||||||
|
double actual_power = 0.0;
|
||||||
|
bool is_spin_flag = false;
|
||||||
|
|
||||||
|
if (telem.has_value()) {
|
||||||
|
cap_energy_j = telem->charge;
|
||||||
|
bus_voltage = telem->voltage > 5.0 ? telem->voltage : 24.0;
|
||||||
|
actual_power = telem->current * telem->voltage;
|
||||||
|
is_spin_flag = (telem->power_supply_status & 0x04) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 速度提取 (来自 field_localization base_link 绝对真值地速)
|
||||||
|
double vx_lio = 0.0;
|
||||||
|
double wz_lio = 0.0;
|
||||||
|
double dist_to_goal = -1.0;
|
||||||
|
|
||||||
|
if (odom.has_value()) {
|
||||||
|
vx_lio = odom->twist.twist.linear.x;
|
||||||
|
wz_lio = odom->twist.twist.angular.z;
|
||||||
|
|
||||||
|
if (goal.has_value()) {
|
||||||
|
const double dx = goal->pose.position.x - odom->pose.pose.position.x;
|
||||||
|
const double dy = goal->pose.position.y - odom->pose.pose.position.y;
|
||||||
|
dist_to_goal = std::hypot(dx, dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定战术模态
|
||||||
|
core::TacticalMode mode = core::TacticalMode::kDiffCruise;
|
||||||
|
if (force_opening_sprint_ || sprint_active_) {
|
||||||
|
mode = core::TacticalMode::kOpeningSprint;
|
||||||
|
} else if (combat_spin_enabled_ || is_spin_flag) {
|
||||||
|
mode = core::TacticalMode::kCombatSpin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在线动力学功率修正因子 kappa_P 更新
|
||||||
|
const double predicted_power =
|
||||||
|
model_.predict_power(mode, vx_lio, wz_lio, estimator_.kappa_p());
|
||||||
|
if (telem.has_value() && odom.has_value()) {
|
||||||
|
estimator_.update_kappa(actual_power, predicted_power, std::abs(vx_lio));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算上位机可用功率预算
|
||||||
|
const double p_avail = estimator_.compute_available_power(
|
||||||
|
cap_energy_j, mode == core::TacticalMode::kOpeningSprint);
|
||||||
|
|
||||||
|
// 反解四重包络限速
|
||||||
|
core::PowerQuery query{
|
||||||
|
.mode = mode,
|
||||||
|
.available_power_w = p_avail,
|
||||||
|
.bus_voltage_v = bus_voltage,
|
||||||
|
.active_wz_rad_s = wz_lio,
|
||||||
|
.power_scale_kappa = estimator_.kappa_p(),
|
||||||
|
.goal_distance_m = dist_to_goal,
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto result = model_.compute_limit(query);
|
||||||
|
|
||||||
|
// 发布 Nav2 SpeedLimit 消息
|
||||||
|
nav2_msgs::msg::SpeedLimit limit_msg;
|
||||||
|
limit_msg.header.stamp = now();
|
||||||
|
limit_msg.header.frame_id = "base_link";
|
||||||
|
limit_msg.percentage = false;
|
||||||
|
limit_msg.speed_limit = static_cast<double>(result.vx_max);
|
||||||
|
speed_limit_pub_->publish(limit_msg);
|
||||||
|
|
||||||
|
// 每秒输出一次诊断日志
|
||||||
|
RCLCPP_INFO_THROTTLE(
|
||||||
|
get_logger(), *get_clock(), 1000,
|
||||||
|
"Mode: %d | P_avail: %.1fW | Stored: %.0fJ | v_max: %.2fm/s (P:%.2f, K:%.2f, "
|
||||||
|
"S:%.2f, B:%.2f) | kappa_P: %.2f",
|
||||||
|
static_cast<int>(mode), p_avail, cap_energy_j, result.vx_max, result.v_power_bound,
|
||||||
|
result.v_kinematic_bound, result.v_slip_bound, result.v_brake_bound,
|
||||||
|
estimator_.kappa_p());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
rclcpp::init(argc, argv);
|
||||||
|
auto node = std::make_shared<chassis_power::ros::PowerLimiterNode>();
|
||||||
|
rclcpp::spin(node);
|
||||||
|
rclcpp::shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
#include "chassis_power/core/power_velocity_model.hpp"
|
||||||
|
|
||||||
|
#include <nav_msgs/msg/odometry.hpp>
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <sensor_msgs/msg/battery_state.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
class PowerSimNode : public rclcpp::Node {
|
||||||
|
public:
|
||||||
|
explicit PowerSimNode(const rclcpp::NodeOptions &options = rclcpp::NodeOptions{})
|
||||||
|
: Node("chassis_power_sim_node", options) {
|
||||||
|
load_parameters();
|
||||||
|
|
||||||
|
odom_sub_ = create_subscription<nav_msgs::msg::Odometry>(
|
||||||
|
"/field_localization/odometry", rclcpp::QoS(1),
|
||||||
|
[this](nav_msgs::msg::Odometry::ConstSharedPtr msg) { on_odometry(msg); });
|
||||||
|
|
||||||
|
telemetry_pub_ =
|
||||||
|
create_publisher<sensor_msgs::msg::BatteryState>("/chassis_power/telemetry", 10);
|
||||||
|
|
||||||
|
last_time_ = now();
|
||||||
|
// 20Hz 遥测发布与能量仿真积分
|
||||||
|
timer_ = create_wall_timer(50ms, [this]() { update_simulation(); });
|
||||||
|
|
||||||
|
RCLCPP_INFO(get_logger(),
|
||||||
|
"chassis_power_sim_node started. Cap energy: %.0f J, recharge: %.1f W.",
|
||||||
|
current_energy_j_, recharge_power_w_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void load_parameters() {
|
||||||
|
max_energy_j_ = declare_parameter<double>("max_energy_j", 1800.0);
|
||||||
|
current_energy_j_ = declare_parameter<double>("initial_energy_j", 1800.0);
|
||||||
|
recharge_power_w_ = declare_parameter<double>("recharge_power_w", 60.0);
|
||||||
|
voltage_v_ = declare_parameter<double>("nominal_voltage_v", 24.0);
|
||||||
|
start_sprint_on_start_ = declare_parameter<bool>("start_sprint_on_start", false);
|
||||||
|
|
||||||
|
core::PowerModelParams p;
|
||||||
|
p.wheel_radius_m = declare_parameter<double>("wheel_radius_m", 0.0762);
|
||||||
|
p.half_wheelbase_plus_track_m =
|
||||||
|
declare_parameter<double>("half_wheelbase_plus_track_m", 0.3793);
|
||||||
|
p.a_x = declare_parameter<double>("a_x", 4.5);
|
||||||
|
p.a_y = declare_parameter<double>("a_y", 11.0);
|
||||||
|
p.b_x = declare_parameter<double>("b_x", 12.0);
|
||||||
|
p.b_y = declare_parameter<double>("b_y", 26.0);
|
||||||
|
p.c_wz_lin = declare_parameter<double>("c_wz_lin", 2.5);
|
||||||
|
p.c_wz_quad = declare_parameter<double>("c_wz_quad", 1.2);
|
||||||
|
p.p_static = declare_parameter<double>("p_static", 6.0);
|
||||||
|
p.p_accel_margin = declare_parameter<double>("p_accel_margin", 25.0);
|
||||||
|
model_.set_params(p);
|
||||||
|
|
||||||
|
if (start_sprint_on_start_) {
|
||||||
|
sprint_active_ = true;
|
||||||
|
sprint_start_time_ = now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_odometry(nav_msgs::msg::Odometry::ConstSharedPtr msg) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
vx_ = msg->twist.twist.linear.x;
|
||||||
|
wz_ = msg->twist.twist.angular.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_simulation() {
|
||||||
|
const auto current_time = now();
|
||||||
|
const double dt = std::clamp((current_time - last_time_).seconds(), 0.001, 0.2);
|
||||||
|
last_time_ = current_time;
|
||||||
|
|
||||||
|
double vx = 0.0;
|
||||||
|
double wz = 0.0;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
vx = vx_;
|
||||||
|
wz = wz_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模式判定
|
||||||
|
core::TacticalMode mode = core::TacticalMode::kDiffCruise;
|
||||||
|
if (sprint_active_) {
|
||||||
|
if ((current_time - sprint_start_time_).seconds() > 5.0) {
|
||||||
|
sprint_active_ = false;
|
||||||
|
} else {
|
||||||
|
mode = core::TacticalMode::kOpeningSprint;
|
||||||
|
}
|
||||||
|
} else if (std::abs(wz) > 1.5) {
|
||||||
|
mode = core::TacticalMode::kCombatSpin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 估算底盘当前实测电功率 (正向模型)
|
||||||
|
const double chassis_power = model_.predict_power(mode, vx, wz, 1.0);
|
||||||
|
|
||||||
|
// 能量积分: dE = (P_recharge - P_chassis) * dt
|
||||||
|
const double net_power = recharge_power_w_ - chassis_power;
|
||||||
|
current_energy_j_ =
|
||||||
|
std::clamp(current_energy_j_ + net_power * dt, 0.0, max_energy_j_);
|
||||||
|
|
||||||
|
// 打包并发布遥测消息
|
||||||
|
sensor_msgs::msg::BatteryState msg;
|
||||||
|
msg.header.stamp = current_time;
|
||||||
|
msg.header.frame_id = "base_link";
|
||||||
|
msg.voltage = static_cast<float>(voltage_v_);
|
||||||
|
msg.current = static_cast<float>(chassis_power / voltage_v_);
|
||||||
|
msg.charge = static_cast<float>(current_energy_j_);
|
||||||
|
msg.capacity = static_cast<float>(max_energy_j_);
|
||||||
|
msg.design_capacity = static_cast<float>(max_energy_j_);
|
||||||
|
msg.percentage = max_energy_j_ > 0 ? static_cast<float>(current_energy_j_ / max_energy_j_)
|
||||||
|
: 0.0f;
|
||||||
|
msg.present = true;
|
||||||
|
|
||||||
|
uint8_t flags = 0x01; // bit0: 超电在线
|
||||||
|
if (sprint_active_) {
|
||||||
|
flags |= 0x02; // bit1: 比赛开始冲点
|
||||||
|
}
|
||||||
|
if (mode == core::TacticalMode::kCombatSpin) {
|
||||||
|
flags |= 0x04; // bit2: 小陀螺
|
||||||
|
}
|
||||||
|
msg.power_supply_status = flags;
|
||||||
|
|
||||||
|
telemetry_pub_->publish(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
core::PowerVelocityModel model_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
double vx_{0.0};
|
||||||
|
double wz_{0.0};
|
||||||
|
|
||||||
|
double max_energy_j_{1800.0};
|
||||||
|
double current_energy_j_{1800.0};
|
||||||
|
double recharge_power_w_{60.0};
|
||||||
|
double voltage_v_{24.0};
|
||||||
|
bool start_sprint_on_start_{false};
|
||||||
|
|
||||||
|
bool sprint_active_{false};
|
||||||
|
rclcpp::Time sprint_start_time_{0, 0, RCL_ROS_TIME};
|
||||||
|
rclcpp::Time last_time_{0, 0, RCL_ROS_TIME};
|
||||||
|
|
||||||
|
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr odom_sub_;
|
||||||
|
rclcpp::Publisher<sensor_msgs::msg::BatteryState>::SharedPtr telemetry_pub_;
|
||||||
|
rclcpp::TimerBase::SharedPtr timer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
rclcpp::init(argc, argv);
|
||||||
|
auto node = std::make_shared<chassis_power::ros::PowerSimNode>();
|
||||||
|
rclcpp::spin(node);
|
||||||
|
rclcpp::shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
#include "chassis_power/ros/uart_bridge_node.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
namespace chassis_power::ros {
|
||||||
|
|
||||||
|
UartBridgeNode::UartBridgeNode(const rclcpp::NodeOptions &options)
|
||||||
|
: Node("chassis_uart_node", options) {
|
||||||
|
device_path_ = declare_parameter<std::string>("device", "/dev/ttyUSB0");
|
||||||
|
baud_rate_ = declare_parameter<int>("baud_rate", 921600);
|
||||||
|
cmd_vel_topic_ = declare_parameter<std::string>("cmd_vel_topic", "/model/sentry/cmd_vel");
|
||||||
|
telemetry_topic_ = declare_parameter<std::string>("telemetry_topic", "/chassis_power/telemetry");
|
||||||
|
|
||||||
|
telemetry_pub_ = create_publisher<sensor_msgs::msg::BatteryState>(telemetry_topic_, 10);
|
||||||
|
|
||||||
|
cmd_vel_sub_ = create_subscription<geometry_msgs::msg::Twist>(
|
||||||
|
cmd_vel_topic_, rclcpp::QoS(1),
|
||||||
|
[this](geometry_msgs::msg::Twist::ConstSharedPtr msg) { on_cmd_vel(msg); });
|
||||||
|
|
||||||
|
// 尝试打开串口
|
||||||
|
try_reconnect();
|
||||||
|
|
||||||
|
// 10ms (100Hz) 高频轮询读取串口数据,防止内核缓冲区堆积
|
||||||
|
poll_timer_ = create_wall_timer(10ms, [this]() { poll_uart(); });
|
||||||
|
|
||||||
|
// 1s 定时重连检测
|
||||||
|
reconnect_timer_ = create_wall_timer(1000ms, [this]() {
|
||||||
|
if (!port_.is_open()) {
|
||||||
|
try_reconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RCLCPP_INFO(get_logger(),
|
||||||
|
"chassis_uart_node initialized. Device: %s @ %d baud, cmd_vel: %s, telemetry: %s",
|
||||||
|
device_path_.c_str(), baud_rate_, cmd_vel_topic_.c_str(), telemetry_topic_.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridgeNode::try_reconnect() {
|
||||||
|
if (!port_.is_open()) {
|
||||||
|
if (port_.open(device_path_, baud_rate_)) {
|
||||||
|
RCLCPP_INFO(get_logger(), "Connected to serial port %s", device_path_.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridgeNode::poll_uart() {
|
||||||
|
if (!port_.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t n = port_.read_bytes(rx_buffer_.data(), rx_buffer_.size());
|
||||||
|
if (n < 0) {
|
||||||
|
RCLCPP_WARN(get_logger(), "Serial read error on %s. Closing port.", device_path_.c_str());
|
||||||
|
port_.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ssize_t i = 0; i < n; ++i) {
|
||||||
|
auto frame_opt = decoder_.feed_byte(rx_buffer_[static_cast<size_t>(i)]);
|
||||||
|
if (frame_opt.has_value()) {
|
||||||
|
const auto &frame = *frame_opt;
|
||||||
|
if (frame.cmd_id == core::kCmdIdChassisPowerIn &&
|
||||||
|
frame.payload.size() >= sizeof(core::UartChassisPowerUpPayload)) {
|
||||||
|
core::UartChassisPowerUpPayload payload{};
|
||||||
|
std::memcpy(&payload, frame.payload.data(), sizeof(payload));
|
||||||
|
|
||||||
|
sensor_msgs::msg::BatteryState msg;
|
||||||
|
msg.header.stamp = now();
|
||||||
|
msg.header.frame_id = "base_link";
|
||||||
|
msg.voltage = 24.0f;
|
||||||
|
msg.current = static_cast<float>(payload.chassis_power_out_w) / 24.0f;
|
||||||
|
msg.charge = static_cast<float>(payload.cap_stored_energy_j);
|
||||||
|
msg.capacity = static_cast<float>(payload.cap_max_energy_j);
|
||||||
|
msg.design_capacity = static_cast<float>(payload.cap_max_energy_j);
|
||||||
|
msg.percentage = payload.cap_max_energy_j > 0
|
||||||
|
? (static_cast<float>(payload.cap_stored_energy_j) /
|
||||||
|
static_cast<float>(payload.cap_max_energy_j))
|
||||||
|
: 0.0f;
|
||||||
|
msg.present = (payload.status_flags & 0x01) != 0;
|
||||||
|
msg.power_supply_status = payload.status_flags;
|
||||||
|
|
||||||
|
telemetry_pub_->publish(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridgeNode::on_cmd_vel(geometry_msgs::msg::Twist::ConstSharedPtr msg) {
|
||||||
|
if (!port_.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::isfinite(msg->linear.x) || !std::isfinite(msg->linear.y) ||
|
||||||
|
!std::isfinite(msg->angular.z)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
core::UartChassisNavDownPayload payload{
|
||||||
|
.vx_mm_s = static_cast<int16_t>(
|
||||||
|
std::clamp(msg->linear.x * 1000.0, -32768.0, 32767.0)),
|
||||||
|
.vy_mm_s = static_cast<int16_t>(
|
||||||
|
std::clamp(msg->linear.y * 1000.0, -32768.0, 32767.0)),
|
||||||
|
.wz_mrad_s = static_cast<int16_t>(
|
||||||
|
std::clamp(msg->angular.z * 1000.0, -32768.0, 32767.0)),
|
||||||
|
};
|
||||||
|
|
||||||
|
std::span<const uint8_t> payload_span(reinterpret_cast<const uint8_t *>(&payload),
|
||||||
|
sizeof(payload));
|
||||||
|
auto frame = core::serialize_frame(core::kCmdIdChassisNavOut, payload_span);
|
||||||
|
(void)port_.write_bytes(frame.data(), frame.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chassis_power::ros
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
rclcpp::init(argc, argv);
|
||||||
|
auto node = std::make_shared<chassis_power::ros::UartBridgeNode>();
|
||||||
|
rclcpp::spin(node);
|
||||||
|
rclcpp::shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
哨兵底盘“功率—速度”二次多项式参数拟合工具
|
||||||
|
|
||||||
|
功能:
|
||||||
|
1. 从实车走廊/台架采集的 CSV 或 ROS2 数据中读取真实地速 (vx, wz) 与实测底盘总电功率 P_chassis
|
||||||
|
2. 使用非负约束最小二乘法 (NNLS) 拟合阻力参数 (a_x, b_x, c_1, c_2, P_static)
|
||||||
|
3. 评估拟合优度 R^2 并输出拟合参数建议,可直接写入 chassis_power.yaml
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from typing import Tuple
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def fit_diff_model(
|
||||||
|
vx: np.ndarray, wz: np.ndarray, p_meas: np.ndarray, p_margin: float = 25.0
|
||||||
|
) -> Tuple[dict, float]:
|
||||||
|
"""
|
||||||
|
拟合模型:
|
||||||
|
P_meas - P_margin = a_x * vx^2 + b_x * |vx| + c_wz_lin * |wz| + c_wz_quad * wz^2 + p_static
|
||||||
|
"""
|
||||||
|
vx_abs = np.abs(vx)
|
||||||
|
wz_abs = np.abs(wz)
|
||||||
|
y = np.maximum(0.0, p_meas - p_margin)
|
||||||
|
|
||||||
|
# 构造设计矩阵 A
|
||||||
|
# [vx^2, |vx|, |wz|, wz^2, 1]
|
||||||
|
A = np.column_stack([vx_abs**2, vx_abs, wz_abs, wz_abs**2, np.ones_like(vx)])
|
||||||
|
|
||||||
|
try:
|
||||||
|
from scipy.optimize import nnls
|
||||||
|
|
||||||
|
coefs, rnorm = nnls(A, y)
|
||||||
|
except ImportError:
|
||||||
|
# 回退至带有非负截断的普通最小二乘
|
||||||
|
coefs, _, _, _ = np.linalg.lstsq(A, y, rcond=None)
|
||||||
|
coefs = np.maximum(0.0, coefs)
|
||||||
|
|
||||||
|
a_x, b_x, c_lin, c_quad, p_static = coefs
|
||||||
|
|
||||||
|
y_pred = A @ coefs
|
||||||
|
ss_tot = np.sum((y - np.mean(y)) ** 2)
|
||||||
|
ss_res = np.sum((y - y_pred) ** 2)
|
||||||
|
r2 = 1.0 - (ss_res / ss_tot) if ss_tot > 1e-6 else 1.0
|
||||||
|
|
||||||
|
fitted_params = {
|
||||||
|
"a_x": float(a_x),
|
||||||
|
"b_x": float(b_x),
|
||||||
|
"c_wz_lin": float(c_lin),
|
||||||
|
"c_wz_quad": float(c_quad),
|
||||||
|
"p_static": float(p_static),
|
||||||
|
"p_accel_margin": float(p_margin),
|
||||||
|
}
|
||||||
|
|
||||||
|
return fitted_params, float(r2)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_synthetic_data(n_samples: int = 500) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
|
||||||
|
"""生成走廊加减速与原地小陀螺的合成数据用于校验"""
|
||||||
|
np.random.seed(42)
|
||||||
|
vx = np.random.uniform(0.0, 3.5, n_samples)
|
||||||
|
wz = np.random.uniform(0.0, 2.5, n_samples)
|
||||||
|
|
||||||
|
# 理论先验真值
|
||||||
|
true_ax = 4.5
|
||||||
|
true_bx = 12.0
|
||||||
|
true_clin = 2.5
|
||||||
|
true_cquad = 1.2
|
||||||
|
true_pstat = 6.0
|
||||||
|
p_margin = 25.0
|
||||||
|
|
||||||
|
noise = np.random.normal(0.0, 3.0, n_samples)
|
||||||
|
p = (
|
||||||
|
true_ax * (vx**2)
|
||||||
|
+ true_bx * np.abs(vx)
|
||||||
|
+ true_clin * np.abs(wz)
|
||||||
|
+ true_cquad * (wz**2)
|
||||||
|
+ true_pstat
|
||||||
|
+ p_margin
|
||||||
|
+ noise
|
||||||
|
)
|
||||||
|
p = np.maximum(true_pstat, p)
|
||||||
|
return vx, wz, p
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="Chassis Power-Velocity Curve Fitter")
|
||||||
|
parser.add_argument("--csv", type=str, help="Path to input CSV file (columns: vx, wz, power)")
|
||||||
|
parser.add_argument("--p-margin", type=float, default=25.0, help="Acceleration power margin (W)")
|
||||||
|
parser.add_argument("--test-synthetic", action="store_true", help="Run test on synthetic test bench data")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.test_synthetic or not args.csv:
|
||||||
|
print("[INFO] No CSV provided or --test-synthetic specified. Running synthetic bench calibration...")
|
||||||
|
vx, wz, p = generate_synthetic_data()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
data = np.genfromtxt(args.csv, delimiter=",", names=True)
|
||||||
|
vx = data["vx"]
|
||||||
|
wz = data["wz"]
|
||||||
|
p = data["power"]
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[ERROR] Failed to load CSV {args.csv}: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f"[INFO] Loaded {len(vx)} data samples.")
|
||||||
|
params, r2 = fit_diff_model(vx, wz, p, p_margin=args.p_margin)
|
||||||
|
|
||||||
|
print("=" * 60)
|
||||||
|
print("底盘功率—最大速度拟合结果 (Fit Results)")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"R^2 拟合优度: {r2:.4f}")
|
||||||
|
for k, v in params.items():
|
||||||
|
print(f" {k:16s}: {v:8.4f}")
|
||||||
|
print("=" * 60)
|
||||||
|
print("可直接将上述参数复制到 config/chassis_power.yaml 对应的项中!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#include "chassis_power/core/power_velocity_model.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace chassis_power::core;
|
||||||
|
|
||||||
|
void test_monotonicity() {
|
||||||
|
PowerVelocityModel model;
|
||||||
|
|
||||||
|
// 1. 随着可用功率增加,解出的最大速度必须单调递增
|
||||||
|
PowerQuery q1{.mode = TacticalMode::kDiffCruise, .available_power_w = 60.0};
|
||||||
|
PowerQuery q2{.mode = TacticalMode::kDiffCruise, .available_power_w = 120.0};
|
||||||
|
PowerQuery q3{.mode = TacticalMode::kDiffCruise, .available_power_w = 200.0};
|
||||||
|
|
||||||
|
auto r1 = model.compute_limit(q1);
|
||||||
|
auto r2 = model.compute_limit(q2);
|
||||||
|
auto r3 = model.compute_limit(q3);
|
||||||
|
|
||||||
|
assert(r1.vx_max > 0.35);
|
||||||
|
assert(r2.vx_max > r1.vx_max);
|
||||||
|
assert(r3.vx_max > r2.vx_max);
|
||||||
|
assert(r3.vx_max <= model.params().vx_slip_cap_diff);
|
||||||
|
|
||||||
|
std::cout << "[PASS] Monotonicity: 60W->" << r1.vx_max << " m/s, 120W->" << r2.vx_max
|
||||||
|
<< " m/s, 200W->" << r3.vx_max << " m/s\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_combat_spin_penalty() {
|
||||||
|
PowerVelocityModel model;
|
||||||
|
|
||||||
|
// 2. 相同功率下,小陀螺模式的前向极速必须显著低于纯差速
|
||||||
|
PowerQuery q_diff{.mode = TacticalMode::kDiffCruise,
|
||||||
|
.available_power_w = 150.0,
|
||||||
|
.active_wz_rad_s = 0.0};
|
||||||
|
PowerQuery q_spin{.mode = TacticalMode::kCombatSpin,
|
||||||
|
.available_power_w = 150.0,
|
||||||
|
.active_wz_rad_s = 3.0};
|
||||||
|
|
||||||
|
auto r_diff = model.compute_limit(q_diff);
|
||||||
|
auto r_spin = model.compute_limit(q_spin);
|
||||||
|
|
||||||
|
assert(r_spin.vx_max < r_diff.vx_max);
|
||||||
|
assert(r_spin.vx_max <= model.params().vx_slip_cap_spin);
|
||||||
|
|
||||||
|
std::cout << "[PASS] CombatSpin Penalty: Diff " << r_diff.vx_max
|
||||||
|
<< " m/s vs Spin " << r_spin.vx_max << " m/s\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_braking_envelope() {
|
||||||
|
PowerVelocityModel model;
|
||||||
|
|
||||||
|
// 3. 开局冲点刹车包络测试:距终点越近,限速越低
|
||||||
|
PowerQuery q_far{.mode = TacticalMode::kOpeningSprint,
|
||||||
|
.available_power_w = 200.0,
|
||||||
|
.goal_distance_m = 5.0};
|
||||||
|
PowerQuery q_near{.mode = TacticalMode::kOpeningSprint,
|
||||||
|
.available_power_w = 200.0,
|
||||||
|
.goal_distance_m = 0.2};
|
||||||
|
|
||||||
|
auto r_far = model.compute_limit(q_far);
|
||||||
|
auto r_near = model.compute_limit(q_near);
|
||||||
|
|
||||||
|
assert(r_near.vx_max < r_far.vx_max);
|
||||||
|
double expected_near_brake = std::sqrt(2.0 * model.params().safe_decel_m_s2 * 0.2);
|
||||||
|
assert(std::abs(r_near.vx_max - expected_near_brake) < 0.1);
|
||||||
|
|
||||||
|
std::cout << "[PASS] Braking Envelope: 5m->" << r_far.vx_max << " m/s, 0.2m->"
|
||||||
|
<< r_near.vx_max << " m/s (expected brake bound: " << expected_near_brake << ")\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
test_monotonicity();
|
||||||
|
test_combat_spin_penalty();
|
||||||
|
test_braking_envelope();
|
||||||
|
std::cout << "All test_power_velocity_model passed!\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#include "chassis_power/core/supercap_estimator.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace chassis_power::core;
|
||||||
|
|
||||||
|
void test_supercap_power_allocation() {
|
||||||
|
EstimatorConfig cfg{
|
||||||
|
.max_supercap_power_w = 200.0,
|
||||||
|
.cruise_power_w = 80.0,
|
||||||
|
.energy_threshold_low_j = 300.0,
|
||||||
|
.kappa_filter_alpha = 0.1,
|
||||||
|
};
|
||||||
|
SupercapEstimator estimator(cfg);
|
||||||
|
|
||||||
|
// 1. 开局冲点模式,高电量下必须分配 200W
|
||||||
|
double p_sprint_full = estimator.compute_available_power(1000.0, true);
|
||||||
|
assert(p_sprint_full == 200.0);
|
||||||
|
|
||||||
|
// 2. 开局冲点模式,低电量下平滑过渡 (如 150J 对应 80 + 0.5 * 120 = 140W)
|
||||||
|
double p_sprint_low = estimator.compute_available_power(150.0, true);
|
||||||
|
assert(p_sprint_low == 140.0);
|
||||||
|
|
||||||
|
// 3. 超电耗尽 (0 J),回退至标称巡航功率 80W
|
||||||
|
double p_empty = estimator.compute_available_power(0.0, true);
|
||||||
|
assert(p_empty == 80.0);
|
||||||
|
|
||||||
|
std::cout << "[PASS] Supercap power allocation: Full->" << p_sprint_full
|
||||||
|
<< "W, Low->" << p_sprint_low << "W, Empty->" << p_empty << "W\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_kappa_adaptation() {
|
||||||
|
SupercapEstimator estimator;
|
||||||
|
assert(estimator.kappa_p() == 1.0);
|
||||||
|
|
||||||
|
// 模拟小车在光滑地面出现微滑移,实测功率高于理论预测值 (actual=100W, pred=80W -> ratio=1.25)
|
||||||
|
for (int i = 0; i < 20; ++i) {
|
||||||
|
estimator.update_kappa(100.0, 80.0, 1.2 /* v=1.2 m/s */);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 滤波后 kappa_p 必须上升,从而让功率反解限速主动下调
|
||||||
|
assert(estimator.kappa_p() > 1.15);
|
||||||
|
std::cout << "[PASS] Kappa adaptation filtered value: " << estimator.kappa_p() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
test_supercap_power_allocation();
|
||||||
|
test_kappa_adaptation();
|
||||||
|
std::cout << "All test_supercap_estimator passed!\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
#include "chassis_power/core/uart_protocol.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace chassis_power::core;
|
||||||
|
|
||||||
|
void test_crc16() {
|
||||||
|
const uint8_t test_data[] = {0x01, 0x02, 0x03, 0x04, 0x05};
|
||||||
|
uint16_t crc = calculate_crc16(test_data);
|
||||||
|
assert(crc != 0);
|
||||||
|
|
||||||
|
// 校验一致性
|
||||||
|
uint16_t crc2 = calculate_crc16(test_data);
|
||||||
|
assert(crc == crc2);
|
||||||
|
std::cout << "[PASS] CRC16 calculation\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_serialize_and_decode() {
|
||||||
|
UartChassisPowerUpPayload payload{
|
||||||
|
.cap_stored_energy_j = 1200,
|
||||||
|
.cap_max_energy_j = 1800,
|
||||||
|
.chassis_power_out_w = 115,
|
||||||
|
.status_flags = 0x03,
|
||||||
|
.reserved = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::span<const uint8_t> payload_span(reinterpret_cast<const uint8_t*>(&payload),
|
||||||
|
sizeof(payload));
|
||||||
|
auto frame_bytes = serialize_frame(kCmdIdChassisPowerIn, payload_span);
|
||||||
|
|
||||||
|
assert(frame_bytes.size() == 3 + sizeof(payload) + 2);
|
||||||
|
assert(frame_bytes[0] == kFrameHeaderSof);
|
||||||
|
assert(frame_bytes[1] == kCmdIdChassisPowerIn);
|
||||||
|
assert(frame_bytes[2] == sizeof(payload));
|
||||||
|
|
||||||
|
// 流式单字节喂入解码
|
||||||
|
StreamDecoder decoder;
|
||||||
|
std::optional<StreamDecoder::DecodedFrame> decoded;
|
||||||
|
|
||||||
|
// 故意在前边塞几个噪声杂质字节,测试前导噪声容错能力
|
||||||
|
(void)decoder.feed_byte(0xFF);
|
||||||
|
(void)decoder.feed_byte(0x00);
|
||||||
|
(void)decoder.feed_byte(0x55);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < frame_bytes.size(); ++i) {
|
||||||
|
decoded = decoder.feed_byte(frame_bytes[i]);
|
||||||
|
if (i < frame_bytes.size() - 1) {
|
||||||
|
assert(!decoded.has_value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(decoded.has_value());
|
||||||
|
assert(decoded->cmd_id == kCmdIdChassisPowerIn);
|
||||||
|
assert(decoded->payload.size() == sizeof(payload));
|
||||||
|
|
||||||
|
UartChassisPowerUpPayload received_payload{};
|
||||||
|
std::memcpy(&received_payload, decoded->payload.data(), sizeof(payload));
|
||||||
|
|
||||||
|
assert(received_payload.cap_stored_energy_j == 1200);
|
||||||
|
assert(received_payload.cap_max_energy_j == 1800);
|
||||||
|
assert(received_payload.chassis_power_out_w == 115);
|
||||||
|
assert(received_payload.status_flags == 0x03);
|
||||||
|
|
||||||
|
std::cout << "[PASS] Serialize and Stream Decode with leading noise\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
test_crc16();
|
||||||
|
test_serialize_and_decode();
|
||||||
|
std::cout << "All test_uart_protocol passed!\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
if not make_ros_config then
|
||||||
|
includes("../../xmake/ros2.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
add_cxxflags("-Wall", "-Wextra")
|
||||||
|
if is_mode("release") then
|
||||||
|
set_optimize("faster")
|
||||||
|
end
|
||||||
|
|
||||||
|
local ros_common = make_ros_config({
|
||||||
|
"rclcpp",
|
||||||
|
"sensor_msgs",
|
||||||
|
"nav_msgs",
|
||||||
|
"geometry_msgs",
|
||||||
|
"nav2_msgs",
|
||||||
|
}, {
|
||||||
|
"sensor_msgs",
|
||||||
|
"nav_msgs",
|
||||||
|
"geometry_msgs",
|
||||||
|
"nav2_msgs",
|
||||||
|
"std_msgs",
|
||||||
|
"builtin_interfaces",
|
||||||
|
"rosgraph_msgs",
|
||||||
|
"rcl_interfaces",
|
||||||
|
"service_msgs",
|
||||||
|
"type_description_interfaces",
|
||||||
|
"statistics_msgs",
|
||||||
|
})
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
-- 1. chassis_power_core: 纯 C++23 核心算法静态库 (零 ROS 依赖)
|
||||||
|
-- ============================================================================
|
||||||
|
|
||||||
|
target("chassis_power_core")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("static")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("src/core/*.cpp")
|
||||||
|
add_cxxflags("-fPIC")
|
||||||
|
|
||||||
|
add_includedirs("include", {public = true})
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
-- 2. 核心算法单元测试 (毫秒级回归验证,无需 ROS 2 与硬件)
|
||||||
|
-- ============================================================================
|
||||||
|
|
||||||
|
target("test_power_velocity_model")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("tests/test_power_velocity_model.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
|
||||||
|
add_tests("default", {group = "unit"})
|
||||||
|
|
||||||
|
target("test_uart_protocol")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("tests/test_uart_protocol.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
|
||||||
|
add_tests("default", {group = "unit"})
|
||||||
|
|
||||||
|
target("test_supercap_estimator")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("tests/test_supercap_estimator.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
|
||||||
|
add_tests("default", {group = "unit"})
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
-- 3. 在线 ROS 2 接入节点 (产物固定输出至 build/bin/)
|
||||||
|
-- ============================================================================
|
||||||
|
|
||||||
|
-- 产物 1: build/bin/chassis_uart_node (实车 NUC / Xavier NX 串口网关)
|
||||||
|
target("chassis_uart_node")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("src/ros/posix_uart_port.cpp")
|
||||||
|
add_files("src/ros/uart_bridge_main.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
add_includedirs("include", {public = true})
|
||||||
|
ros_common()
|
||||||
|
|
||||||
|
-- 产物 2: build/bin/chassis_power_node (实车与仿真通用核心限速节点)
|
||||||
|
target("chassis_power_node")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("src/ros/power_limiter_main.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
add_includedirs("include", {public = true})
|
||||||
|
ros_common()
|
||||||
|
|
||||||
|
-- 产物 3: build/bin/chassis_power_sim_node (Gazebo 虚拟超电模拟器)
|
||||||
|
target("chassis_power_sim_node")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
|
||||||
|
add_files("src/ros/power_sim_main.cpp")
|
||||||
|
add_deps("chassis_power_core")
|
||||||
|
add_includedirs("include", {public = true})
|
||||||
|
ros_common()
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
# 场地 LiDAR–IMU 定位
|
||||||
|
|
||||||
|
本包使用 C++23、标准库和 Eigen 3.4;core 完全不依赖 ROS。在线流程为 IMU 中值传播、扫描去畸变、体素地图点到面残差和 18 维迭代误差状态滤波。没有全局重定位、回环或多假设初始化。初始位姿必须已知,且 map 始终以场地中心为原点。
|
||||||
|
|
||||||
|
## 构建与测试
|
||||||
|
|
||||||
|
在仓库根配置已有 ROS 环境,然后运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
xmake
|
||||||
|
xmake test
|
||||||
|
```
|
||||||
|
|
||||||
|
编译使用 GCC 15.2、`-std=c++23 -Wall -Wextra`,release 核心启用 `-O2`。Eigen 通过系统 pkg-config 发现;不会从网络安装算法依赖。所有产物位于 `build/bin/`。项目二进制直接执行,不使用 ament、colcon 或 `ros2 run` 注册。
|
||||||
|
|
||||||
|
测试使用现有计数框架的 `CHECK/CHECK_NEAR` 包装,release 下也执行。`test_eskf` 和 `test_lio_synthetic` 默认把五组随机种子的收敛数据写到 `/tmp/field_lio_bias_filter.csv` 和 `/tmp/field_lio_bias_end_to_end.csv`;直接执行时可用第一个位置参数指定 CSV 路径。
|
||||||
|
|
||||||
|
## 建图、保存与只读定位
|
||||||
|
|
||||||
|
当前 Gazebo 场地可直接用 `scripts/sentry_up.sh` 启动。两个入口默认只读加载 `src/sentry_sim/maps/field_full.flmap`。需要自建地图时可单独写入新路径:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
LIO_MODE=mapping scripts/sentry_up.sh
|
||||||
|
# 在机器人处于已知初始位姿后开始移动;保存当前地图:
|
||||||
|
ros2 service call /field_localization/save_map std_srvs/srv/Trigger '{}'
|
||||||
|
# 停止上一套进程;正常退出也会执行最终地图导出。
|
||||||
|
LIO_MAP="$PWD/generated/field_mapping.flmap" scripts/sentry_up.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Shell 默认 `LOCALIZATION=lio`、`LIO_MODE=localization`,缺失地图立即报错。建图模式默认写入 `generated/field_mapping.flmap`。可显式用 `LOCALIZATION=amcl` 选择旧方案;不自动回退。两个分支都保留 Nav2 的 2D map_server,但只有 AMCL 分支启动 AMCL。`NAV2=0` 不启动导航,仍可运行 LIO 建图。
|
||||||
|
|
||||||
|
Python 启动入口在仿真时钟和 odom/base/lidar TF 就绪后,通过与 shell 相同的独立启动进程运行 Nav2,具有对应参数:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ros2 launch src/sentry_sim/launch/sentry_arena.launch.py lio_mode:=mapping
|
||||||
|
ros2 launch src/sentry_sim/launch/sentry_arena.launch.py lio_map:="$PWD/generated/field_mapping.flmap"
|
||||||
|
ros2 launch src/sentry_sim/launch/sentry_arena.launch.py localization:=amcl
|
||||||
|
```
|
||||||
|
|
||||||
|
默认初始 base_link 位姿为 `(-5,3,0)`、零 RPY,与当前世界出生点对应。Shell 使用 `LIO_INITIAL_X/Y/Z/YAW`,Python 使用 `lio_initial_x/y/z/yaw`,节点另外支持 `initial_roll/pitch`。改变出生点必须同时更新初始位姿。首帧只用来建立已知位姿下的种子地图,不能从单帧猜测其全局位置。
|
||||||
|
|
||||||
|
只读定位绝不往地图插点。建图只在无退化、质量门槛通过后插入关键帧,位移必须严格大于 0.5 m,或旋转严格大于 10°。初始化种子帧是唯一例外。配准失败不写图。
|
||||||
|
|
||||||
|
两个启动入口和录制工具读取 [场地点云配置](../sentry_sim/config/field_cloud.yaml)。`map` 系的保留范围为 `x=[−6.4,6.4]`、`y=[−4.4,4.4]`、`z=[−0.10,0.65]` m。定位用扫描时刻的预测位姿裁剪,并在各边留 0.20 m 余量。读图、写入关键帧和测站建图使用严格边界。默认地图文件有 17,002 个体素,启动时只加载其中 10,112 个场内体素。裁剪依赖已知初始位姿和 IMU 预测,可适应小幅位姿误差。
|
||||||
|
|
||||||
|
### 单独生成全场 Gazebo 地图
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/capture_lio.py --profile mapping --full-field \
|
||||||
|
--output generated/full_survey --map generated/field_full_40m.flmap
|
||||||
|
python3 tools/validation/validate_lio_navigation.py --full-field --launcher shell \
|
||||||
|
--map generated/field_full_40m.flmap --output generated/full_shell
|
||||||
|
```
|
||||||
|
|
||||||
|
该模式在隔离的 Gazebo 空场沿重叠测站采集实际雷达扫描。测站坐标由命令指定,Gazebo 真值只核对到位误差。全场图包含南走廊的地面回波,为 LIO 提供垂直方向约束。避障用的 `/scan/points_filtered` 和 `/scan2d` 继续沿用原有的地面滤除规则。全场图对应当前仿真模型和雷达外参,改场地或更换外参后应重新采集和验收。
|
||||||
|
|
||||||
|
仓库随附的 `src/sentry_sim/maps/field_full_40m.flmap` 有 10,583 个体素,仍是候选图。Shell 可用 `LIO_MAP` 指定,Python 可传 `lio_map:=`。检查所有路段时可加 `--continue-on-failure`,让脚本在恢复后测试后续目标,失败路段仍计入总结果。见 [40 m 地图实测](../../docs/MID360-3D雷达接入.md)。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
LIO_MAP="$PWD/src/sentry_sim/maps/field_full_40m.flmap" HEADLESS=1 scripts/sentry_up.sh
|
||||||
|
ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true \
|
||||||
|
lio_map:="$PWD/src/sentry_sim/maps/field_full_40m.flmap"
|
||||||
|
```
|
||||||
|
|
||||||
|
## ROS 接口与坐标约定
|
||||||
|
|
||||||
|
- 默认输入:`point_cloud_topic=/scan/points`、`imu_topic=/imu`。Shell、Python 启动和录制工具均使用 `/scan/points_lio`。旧版地图可配合 `LIO_POINT_CLOUD_TOPIC=/scan/points_filtered` 显式录制或启动,Python 也可传 `lio_point_cloud_topic:=/scan/points_filtered`。
|
||||||
|
- 原始云在 `lidar_link`,自滤云在 `base_link`。瞬时点云按消息时间戳转换到 `imu_link`,包含云台角度和偏心位移。两个仿真入口的关节 TF 发布频率设为 100 Hz。
|
||||||
|
- 默认坐标系为 `map/odom/base_link/imu_link/lidar_link`,可通过同名 frame 参数配置。方位角去畸变在原生雷达坐标系计算,要求雷达与 IMU 刚性连接。
|
||||||
|
- 内部状态原点为 IMU,`q` 将 IMU 坐标旋转到 map,`v/g` 在 map 系。误差顺序为 `p,v,theta,bg,ba,g`,右扰动态度误差。
|
||||||
|
- `get_pose()` 返回 `map → base_link`;`get_snapshot()` 在一把互斥锁内返回配套的位姿、滤波状态、协方差与状态时间。
|
||||||
|
- 只发布 TF `map → odom`:`T_map_odom = T_map_base × inverse(T_odom_base)`,两个变换使用同一时间。`publish_map_to_odom=false` 可关闭;不能与 AMCL 同时发布。
|
||||||
|
- `/field_localization/odometry` 为 map 系车体位姿(含 6×6 位姿协方差)以及 `base_link` 系车体线速度/角速度 `twist`(已扣除陀螺零偏与 IMU 偏心安装杆臂速度,含 6×6 速度协方差);也可直接通过 core 快照或 `get_twist()` 读取。不额外广播 body TF。
|
||||||
|
- 每 5 秒打印模式、降级原因、有效点数、残差 RMSE、内点数/比例、退化维数与子空间基、关键帧数和地图点数,同时输出 `/field_localization/status` 摘要。
|
||||||
|
- 支持 `--ros-args -p use_sim_time:=true`。只有消息/ROS 仿真时间参与状态计算。检测到 `/clock` 回跳后停止输出;必须显式调用 `/field_localization/reset` 或重启,以配置的已知初始位姿重新开始。
|
||||||
|
|
||||||
|
`process_imu/process_point_cloud` 的 bool 表示输入是否被接受,不等于完成 LiDAR 更新。`TrackingMode::FULL` 表示当前存在有效 LiDAR 约束,仍可能有部分退化;具体退化方向由状态中的矩阵列表示,不能直接当作三个欧拉角轴。`IMU_ONLY` 表示仅预测。
|
||||||
|
|
||||||
|
## 时间、噪声与退化
|
||||||
|
|
||||||
|
Gazebo 的 IMU 传感器配置无噪声;正式回放使用原始数据,不人为加噪。滤波过程噪声仍可配置,用于表达模型和状态不确定性。默认 gyro/accel 噪声密度为 0.003 rad/s/√Hz 和 0.03 m/s²/√Hz,零偏随机游走为 `1e-5/1e-4`。这些参数不代表修改传感器数据。
|
||||||
|
|
||||||
|
默认 `scan_timing=instantaneous`,整帧按 header 同刻处理,不给仿真点云制造滚动扫描畸变。可选 `azimuth`,参数为 `scan_period_sec=0.1`、`scan_start_angle_rad=-pi`、`scan_counterclockwise=true`、`scan_stamp_at_end=true`。必须与设备真实扫描约定匹配。纯 core 还支持真实逐点绝对时间戳模式。
|
||||||
|
|
||||||
|
去畸变包含初速度、重力、旋转、平移和固定杆臂。保留最近 2 秒 IMU/状态,延迟扫描在对应时刻更新后重传播,不把旧量测直接作用于当前状态。ROS 扫描队列最多 5 帧,等待 IMU 覆盖最多 0.2 秒仿真时间。
|
||||||
|
|
||||||
|
默认地图和扫描体素为 0.1 m,邻域 0.5 m;最多 10 次迭代,至少 50 个内点、内点率 20%、残差 RMSE 不超过 0.1 m。Huber 阈值 0.05 m。信息矩阵按内点数归一化,以 1 m 特征长度统一平移/旋转尺度;SVD 相对阈值 `1e-4`、绝对阈值 `1e-6`。不可观位姿增益和修正被投影掉,并使用投影后增益执行 Joseph 协方差更新。
|
||||||
|
|
||||||
|
## 离线数据、回放与独立真值
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/capture_lio.py --profile mapping --output generated/lio_mapping --map generated/field_mapping.flmap --duration 120
|
||||||
|
python3 tools/capture_lio.py --profile evaluation --output generated/lio_evaluation --map src/sentry_sim/maps/field_full.flmap --duration 120
|
||||||
|
build/bin/field_localization_replay --dataset generated/lio_evaluation --mode localization --map src/sentry_sim/maps/field_full.flmap --output generated/lio_metrics
|
||||||
|
```
|
||||||
|
|
||||||
|
采集前需要已有 ROS Python 环境。脚本使用独立 Gazebo partition 和 ROS domain,只清理由自己创建的进程树;创建输出目录中的 `STOP` 文件可请求停止。控制器仅用轮速里程计走西北走廊路线,真值只进入记录器。两次采集使用不同路线,地图与定位序列分开。
|
||||||
|
|
||||||
|
独立真值来自 Gazebo 自带 PosePublisher,100 Hz,桥接至 `/evaluation/ground_truth` 的 PoseStamped。模型原点与 base_link 重合,世界与 map 原点一致。真值不进入定位器,不发布到 TF,也不用 `/odom` 代替真值。
|
||||||
|
|
||||||
|
新录制的 `config.txt` 附带 `cloud_frame imu_link` 和场地裁剪范围,回放重用该范围。旧数据缺少这两项时仍按原来的雷达系、固定外参及扫描时间模型读取。FLPC v1 和 FLMAP v1 的二进制格式保持不变。`imu.csv` 保存 IMU 系原始测量,`scans.csv` 索引 `clouds/*.flpc`,`truth.tum` 保存世界系真值。
|
||||||
|
|
||||||
|
回放工具不依赖 ROS,不读取轮速作为定位量测。输出 `trajectory.tum/status.csv/metrics.txt`;报告未对齐的平移 ATE、旋转测地角 ATE、1 秒相对位姿 RPE,旋转以度报告。真值线性平移/四元数 slerp 插值,最大真值间隔 0.05 秒。没有真值或足够对应关系时不能声称验证精度。
|
||||||
|
|
||||||
|
## 已知局限与失败行为
|
||||||
|
|
||||||
|
- 初始位姿错误、机器人被搬移、大幅时间/外参错误可能失锁;不做全局重定位。显式 reset 也只回到配置的已知初始位姿。
|
||||||
|
- 平面、走廊、重复结构可能不可观;仅更新可观方向,其他方向靠 IMU 并逐渐漂移。全部约束失败进入 IMU_ONLY。
|
||||||
|
- 同时估计重力和加计零偏需要运动激励。六轴收敛只对有充分三维激励的带噪合成测试验收,不能由平面、零噪声仿真推导出来。
|
||||||
|
- 超过 0.3 秒无有效 LiDAR 更新进入 IMU_ONLY;无效云立即降级。IMU 间隔超过 0.05 秒不跨缺口积分,持位并增大不确定度。状态过期 0.1 秒或缺少同刻 odom TF 时停止广播过时位姿。
|
||||||
|
- 地图没有回环优化、动态物体剔除或在线外参标定,建图可积累漂移。固定地图改变后不会自动重建。
|
||||||
|
- 方位角去畸变是缺少真实逐点时间时的近似;错误扫描方向、起始角和 header 语义会引入伪畸变。
|
||||||
|
- 本次实测路线覆盖西北走廊;不能据此声称全场每处、真机噪声、绑架恢复或快速运动已验证。
|
||||||
|
|
||||||
|
## 本机验收记录(2026-11-22)
|
||||||
|
|
||||||
|
GCC 15.2 清洁重构建零警告,11 套 xmake 测试通过。五组带噪合成端到端测试各 600 帧均通过零偏门槛。独立的 120 秒 Gazebo 定位序列包含 1,034 帧有效扫描,未做事后轨迹对齐:平移 ATE RMSE 0.005279 m,旋转 ATE RMSE 0.191335°;1 秒 RPE 为 0.005358 m / 0.099086°。FULL 比例与真值匹配覆盖率均为 100%,地图文件哈希不变。此精度仅代表本次西北走廊、零噪声 IMU 条件。
|
||||||
|
|
||||||
|
在同一录制数据的独立故障注入回放中,把相对第 30–32 秒的 17 帧点云替换为空云,17 帧全部进入 IMU_ONLY,后续恢复 FULL,未执行全局搜索;全段平移 ATE RMSE 增至 0.014314 m。
|
||||||
|
|
||||||
|
完整 Nav2 启动检查命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/validation/verify_lio_stack.py --map src/sentry_sim/maps/field_full.flmap --output generated/lio_stack_check
|
||||||
|
```
|
||||||
|
|
||||||
|
实测 9 个所需生命周期节点均 ACTIVE,AMCL 不存在,map→odom 仅一个发布者,没有 map→base_link 发布。交付数据中附带原始序列、收敛曲线 CSV、轨迹、逐帧状态、TF/生命周期检查 JSON 与构建日志。
|
||||||
|
|
||||||
|
Python 入口可用 `tools/validation/verify_lio_stack.py --launcher python` 做同样的完整启动检查;验证器等待生命周期管理器报告激活完成,并继续观察稳定状态,避免在 bond 握手结束前退出。
|
||||||
|
|
||||||
|
### 导航有效性与失效保护
|
||||||
|
|
||||||
|
`/field_localization/navigation_valid` 以 10 Hz 发布,状态切换时立即更新。启动与失效后的恢复都需要连续五帧成功配准。最近成功配准超过 0.3 秒,或水平位置最大主方向的 3σ 超过 0.5 m、航向 3σ 超过 15° 时,停止更新 `map → odom`。IMU 传播与诊断里程计保留。长时间纯 IMU 传播的结果可能继续漂移,不能作为导航位姿使用。
|
||||||
|
|
||||||
|
导航时,车端转发节点仅接收碰撞监控器的最终 `/cmd_vel`。LIO 心跳失效或超时触发零速度与目标取消。速度命令自身超时也触发零速度,恢复行为中的正常等待可以继续。解除定位失效后需要重新发送已取消的目标。Shell 的 `NAV2=0` 和 Python 的 `nav2:=false` 都可通过 `MANUAL_CMD_VEL_TOPIC` 设置手动输入。
|
||||||
|
|
||||||
|
两个仿真入口启用点云可靠传输。独立运行定位节点时可用 `reliable_clouds` 匹配发布者。指定 `LIO_TRACE_PATH` 可记录每帧的预测、候选和最终状态、协方差、信息矩阵及拒绝原因,这会增加磁盘 I/O。已知初始位姿仍是连续跟踪的前提。动态障碍遮挡全部可用结构、场地退化或传感器断流时,导航将停止。
|
||||||
|
|
||||||
|
### 复现导航验收
|
||||||
|
|
||||||
|
两个入口都可运行相同的隔离验收。域编号可用 `--domain` 显式保留给并行测试;如域已有导航或定位节点,启动器会拒绝启动。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/validation/run_lio_matrix.py --launcher shell --map src/sentry_sim/maps/field_full.flmap --output generated/lio_matrix_shell
|
||||||
|
python3 tools/validation/run_lio_matrix.py --launcher python --map src/sentry_sim/maps/field_full.flmap --output generated/lio_matrix_python
|
||||||
|
python3 tools/validation/validate_lio_navigation.py --launcher shell --scenario lidar_loss --goal 0 0 \
|
||||||
|
--map src/sentry_sim/maps/field_full.flmap --output generated/lio_lidar_loss
|
||||||
|
```
|
||||||
|
|
||||||
|
默认矩阵各跑三次空场和三次圆柱绕行,再跑一次堵塞。默认圆柱在 `(-4, -1.5)`,半径 0.22 m、高 0.8 m。每次保留启动与目标日志、录制数据、TF 发布者数、最小圆柱净距及无需轨迹对齐的 3D ATE 和 1 秒 RPE。堵塞场景要求 Nav2 返回明确中止。断流场景只停止试验自己创建的自滤节点,并用执行器收到的零速度测量停车延迟。实测位姿来自 Gazebo PosePublisher,只参与评估。
|
||||||
|
|
||||||
|
### 复现连续往返失效
|
||||||
|
|
||||||
|
`--round-trip-regression` 在同一个仿真实例中连续发送五个目标,复现中间停留的时间。支持 `clear` 和 `cylinder`,每段保存单独的目标日志、真值终点误差和轨迹指标。总报告包含停留期间的定位误差和首次定位失效时间。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 tools/validation/validate_lio_navigation.py --launcher shell --scenario clear \
|
||||||
|
--map generated/field.flmap --output generated/lio_round_trip_clear --round-trip-regression
|
||||||
|
```
|
||||||
|
|
||||||
|
用 `--launcher python` 切换入口。每次使用新的输出目录。跟踪 CSV 在原有字段后附加配准阶段和拒绝原因,以及初始与末次匹配的候选平面、支撑范围拒绝、面距离拒绝和内点数。可对同一条瞬时扫描离线比较预测位姿和独立真值附近的地图支持。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
build/bin/field_localization_replay --dataset generated/lio_round_trip_clear/dataset \
|
||||||
|
--mode localization --map generated/field.flmap --output generated/lio_inspect \
|
||||||
|
--inspect-scan 108.7
|
||||||
|
```
|
||||||
|
|
||||||
|
将 108.7 替换为数据集 scans.csv 中要检查的时间戳。回放继续使用估计位姿运行滤波器。真值只用于对照匹配和评估轨迹。
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# field_localization/include/
|
||||||
|
|
||||||
|
C++ 头文件的根目录。和 `sentry_nav/include/` 一样**按包名建子目录**,
|
||||||
|
include 时写成 `#include "field_localization/core/xxx.hpp"`,不会和其他工程的同名头文件撞车。
|
||||||
|
|
||||||
|
```
|
||||||
|
include/
|
||||||
|
├── README.md 本文件
|
||||||
|
└── field_localization/ ← 真正的头文件都在这层
|
||||||
|
├── README.md 公共头文件总表
|
||||||
|
├── core/ 纯算法层接口(8 个头,零 ROS)
|
||||||
|
│ ├── README.md
|
||||||
|
│ ├── types.hpp ImuData / PointXYZI / PointCloud / Pose3D
|
||||||
|
│ ├── imu_integration.hpp 旋转数学、IMU 积分、点云去畸变
|
||||||
|
│ ├── eskf.hpp 18 维误差状态卡尔曼滤波
|
||||||
|
│ ├── registration.hpp 体素地图、点到面配准、退化检测
|
||||||
|
│ ├── map_io.hpp 地图文件读写、关键帧判定
|
||||||
|
│ ├── localization_core.hpp 定位主流程
|
||||||
|
│ ├── dataset.hpp 数据集读写、ATE/RPE 评估、调优轨迹 CSV
|
||||||
|
│ └── tracking_health.hpp 定位有效性(导航联锁的依据)
|
||||||
|
└── ros/ ROS 适配层接口(2 个头,依赖 rclcpp)
|
||||||
|
├── README.md
|
||||||
|
├── conversion.hpp PointCloud2 / Transform 与 core 类型互转
|
||||||
|
└── localization_node.hpp 定位节点
|
||||||
|
```
|
||||||
|
|
||||||
|
## 两个子目录,依赖不一样
|
||||||
|
|
||||||
|
| 目录 | 能 include 什么 | 编进哪个 target |
|
||||||
|
|---|---|---|
|
||||||
|
| `field_localization/core/` | 只有 C++ 标准库和 Eigen | `field_localization_core`(静态库) |
|
||||||
|
| `field_localization/ros/` | 在 core 之上再加 `rclcpp` / `tf2_ros` / 消息类型 | `field_localization_ros`(动态库) |
|
||||||
|
|
||||||
|
`xmake.lua` 里 `field_localization_core` 把 `include/` 设成了 `public` 头目录,
|
||||||
|
所以依赖它的 target(节点、录制工具、回放工具、全部测试)都直接写
|
||||||
|
`#include "field_localization/..."`,不用各自再加 include 路径。
|
||||||
|
|
||||||
|
## 硬规则:`core/` 的头不许 include ROS
|
||||||
|
|
||||||
|
`field_localization_core` 是独立静态库,它的 include 路径里没有 ROS 头文件,编译和链接时也不碰 ROS。
|
||||||
|
本包 12 个测试里有 11 个、离线工具 `field_localization_replay` 也只依赖这个库。
|
||||||
|
|
||||||
|
**往 `core/` 的头里加一行 `#include <rclcpp/...>`,这些测试和工具就全部编不过。**
|
||||||
|
|
||||||
|
判据和 `sentry_nav` 一样:这个头需要 `rclcpp` / `tf2` / 消息类型吗?
|
||||||
|
不需要就放 `core/`,需要就放 `ros/`。
|
||||||
|
|
||||||
|
## 加头文件时要改哪里
|
||||||
|
|
||||||
|
| 加什么 | 要不要改 `xmake.lua` |
|
||||||
|
|---|---|
|
||||||
|
| 头文件(放 `core/` 或 `ros/`) | **不用**,`include/` 已经是 public 头目录 |
|
||||||
|
| `core/` 的实现 | **不用**,`src/core/*.cpp` 是通配 |
|
||||||
|
| `ros/` 的实现 | **要**,`field_localization_ros` 是逐个文件列的 |
|
||||||
|
|
||||||
|
## 这个包的写法
|
||||||
|
|
||||||
|
- 头文件保护统一用 `#pragma once`(没有 include guard 宏)
|
||||||
|
- 符号放在 `field_localization::core` 或 `field_localization::ros`,不往全局命名空间塞东西
|
||||||
|
- 类型名大驼峰(`LocalizationCore`、`ErrorStateFilter`),函数名小写下划线(`scan_to_map`、`process_imu`),枚举一律 `enum class`
|
||||||
|
- 注释中英文都有,跟随所在文件
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 公共头文件总表:[`field_localization/README.md`](field_localization/README.md)
|
||||||
|
- 实现:[`../src/README.md`](../src/README.md)
|
||||||
|
- 同样的规矩在兄弟包里的版本:[`../../sentry_nav/include/README.md`](../../sentry_nav/include/README.md)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# include/field_localization/ (公共头文件)
|
||||||
|
|
||||||
|
包对外的头文件目录,10 个头,分两层。
|
||||||
|
|
||||||
|
| 层 | 头文件 | 实现 | 提供什么 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| core | `core/types.hpp` | 只有头文件 | `ImuData` / `PointXYZI` / `PointCloud` / `Pose3D` |
|
||||||
|
| core | `core/imu_integration.hpp` | `../../src/core/imu_integration.cpp` | 旋转数学、`MotionState`、IMU 积分、`deskew` |
|
||||||
|
| core | `core/eskf.hpp` | `../../src/core/eskf.cpp` | `ErrorStateFilter`:18 维误差状态滤波 |
|
||||||
|
| core | `core/registration.hpp` | `../../src/core/registration.cpp` | `VoxelMap`、`scan_to_map`、`detect_degeneracy` |
|
||||||
|
| core | `core/map_io.hpp` | `../../src/core/map_io.cpp` | `save_map` / `read_map`(FLMAP v1)、`new_keyframe` |
|
||||||
|
| core | `core/localization_core.hpp` | `../../src/core/localization_core.cpp` | `LocalizationCore`:定位主流程 |
|
||||||
|
| core | `core/dataset.hpp` | `../../src/core/dataset.cpp` | FLPC 点云、数据集配置、TUM 轨迹、ATE/RPE、调优 CSV |
|
||||||
|
| core | `core/tracking_health.hpp` | 只有头文件 | `TrackingHealth`:定位能否用于导航 |
|
||||||
|
| ros | `ros/conversion.hpp` | `../../src/ros/conversion.cpp` | ROS 消息 ⇄ core 类型 |
|
||||||
|
| ros | `ros/localization_node.hpp` | `../../src/ros/localization_node.cpp` | `LocalizationNode`:定位节点 |
|
||||||
|
|
||||||
|
## 两层怎么分工
|
||||||
|
|
||||||
|
| | `core/` | `ros/` |
|
||||||
|
|---|---|---|
|
||||||
|
| 能 include 什么 | 只有 C++ 标准库和 Eigen | 在 core 之上再加 `rclcpp` / `tf2_ros` / 消息类型 |
|
||||||
|
| 编进哪个 target | `field_localization_core`(静态库) | `field_localization_ros`(动态库) |
|
||||||
|
| 能不能脱离 ROS 测 | 能(11 个测试) | 只有 `test_ros_conversion` 测到 `conversion.hpp` |
|
||||||
|
|
||||||
|
## 头文件之间的依赖
|
||||||
|
|
||||||
|
`core/` 是一条链,上游在前,**没有环**:
|
||||||
|
|
||||||
|
```
|
||||||
|
types → imu_integration → eskf → registration → map_io → localization_core → dataset
|
||||||
|
└→ tracking_health
|
||||||
|
```
|
||||||
|
|
||||||
|
`ros/` 两个头在这条链的顶端:
|
||||||
|
|
||||||
|
- `ros/conversion.hpp` include `core/dataset.hpp`
|
||||||
|
- `ros/localization_node.hpp` include `ros/conversion.hpp` 和 `core/tracking_health.hpp`
|
||||||
|
|
||||||
|
## 加新头文件
|
||||||
|
|
||||||
|
放对应的层,命名 `xxx.hpp`,在 `.cpp` 里 `#include "field_localization/core/xxx.hpp"`。
|
||||||
|
**不用改 `xmake.lua`**:`include/` 已经是 `field_localization_core` 的 public 头目录。
|
||||||
|
|
||||||
|
先确认它该放哪一层:这个头需要 `rclcpp` / `tf2` / 消息类型吗?
|
||||||
|
不需要就放 `core/`,并配上不依赖 ROS 的测试;需要才放 `ros/`。
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- core 逐个头的说明和默认值:[`core/README.md`](core/README.md)
|
||||||
|
- ros 逐个头的说明:[`ros/README.md`](ros/README.md)
|
||||||
|
- 这层目录的规矩(`#pragma once`、命名空间、命名):[`../README.md`](../README.md)
|
||||||
|
- 实现:[`../../src/README.md`](../../src/README.md)
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
# include/field_localization/core/ (纯算法层接口)
|
||||||
|
|
||||||
|
**这 8 个头只 include C++ 标准库和 Eigen,不 include 任何 ROS / PCL / tf2 头文件。**
|
||||||
|
|
||||||
|
它们属于静态库 `field_localization_core`。11 个测试和离线工具 `field_localization_replay`
|
||||||
|
只链接这个库,所以不开 Gazebo、不 source ROS 也能跑。
|
||||||
|
|
||||||
|
依赖是一条链,上游在前,**没有环**:
|
||||||
|
|
||||||
|
```
|
||||||
|
types → imu_integration → eskf → registration → map_io → localization_core → dataset
|
||||||
|
└→ tracking_health
|
||||||
|
```
|
||||||
|
|
||||||
|
加新头时别把它插成环。
|
||||||
|
|
||||||
|
## `types.hpp`(只有头文件)
|
||||||
|
|
||||||
|
后面所有头都用的四个基础结构:
|
||||||
|
|
||||||
|
| 类型 | 字段 | 注意 |
|
||||||
|
|---|---|---|
|
||||||
|
| `ImuData` | `timestamp_sec`、`frame_id`、`angular_velocity`、`linear_acceleration` | 单位 rad/s、m/s² |
|
||||||
|
| `PointXYZI` | `timestamp_sec`、`position`、`intensity` | `position` 是 **float**(`Eigen::Vector3f`) |
|
||||||
|
| `PointCloud` | `timestamp_sec`、`frame_id`、`points` | |
|
||||||
|
| `Pose3D` | `rotation`(`Eigen::Quaterniond`)、`translation` | 表示「子坐标系 → 父坐标系」的变换 |
|
||||||
|
| `Twist3D` | `linear`、`angular`(均为 `Eigen::Vector3d`) | 车体坐标系下的三维线速度(m/s)与角速度(rad/s) |
|
||||||
|
|
||||||
|
**所有时间戳的单位都是秒**(`double`),不是 ROS 的纳秒。
|
||||||
|
|
||||||
|
## `imu_integration.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/imu_integration.cpp`。
|
||||||
|
|
||||||
|
| 符号 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `skew(v)` / `exp_so3(v)` / `log_so3(q)` | 反对称矩阵、旋转向量 ⇄ 四元数 |
|
||||||
|
| `compose(a, b)` / `inverse(p)` | 位姿复合与求逆 |
|
||||||
|
| `base_twist(state, raw_w, base_from_imu)` | 扣除陀螺零偏与 IMU 偏心安装杆臂效应,求 `base_link` 刚体线速度与角速度 |
|
||||||
|
| `valid_imu(imu)` | 时间戳合法、数值全部有限 |
|
||||||
|
| `interpolate_imu(samples, time)` | 在相邻两个 IMU 样本之间线性插值 |
|
||||||
|
| `integrate_midpoint(state, a, b)` | 中值积分,推进一步 |
|
||||||
|
| `integrate_trajectory(samples, initial, end)` | 从 `initial` 积到 `end`,返回整条状态轨迹 |
|
||||||
|
| `preintegrate(samples, start, end, bg, ba)` | 零重力的预积分。**目前只有 `test_imu_integration` 在用**,滤波器走的是 `integrate_midpoint` |
|
||||||
|
| `interpolate_motion(trajectory, time)` | 在状态轨迹上插值:旋转 slerp,平移三次 Hermite(用两端速度) |
|
||||||
|
| `scan_window(cloud, options)` | 这一帧扫描的起止时间 |
|
||||||
|
| `deskew(cloud, trajectory, options)` | 把一帧内的点统一到扫描结束时刻;输出仍在传感器系 |
|
||||||
|
|
||||||
|
`MotionState` 是滤波器的状态:`timestamp_sec`、`pose`、`velocity`、`gyro_bias`、`accel_bias`、`gravity`(默认 `(0, 0, -9.81)`)。
|
||||||
|
**位姿和速度都以 IMU 原点为参考,`pose.rotation` 把 IMU 系转到 map 系**,不是车体系。
|
||||||
|
|
||||||
|
`ScanTiming` 三种扫描时间模型:
|
||||||
|
|
||||||
|
| 取值 | 每个点的采集时刻 | 什么时候用 |
|
||||||
|
|---|---|---|
|
||||||
|
| `INSTANTANEOUS`(默认) | 整帧同一个时刻,不去畸变 | 仿真点云,header 是整帧一个时间戳 |
|
||||||
|
| `AZIMUTH` | 从 `start_angle_rad` 起,按方位角在 `period_sec` 内扫完 | 真机没有逐点时间戳 |
|
||||||
|
| `POINT_TIMESTAMPS` | 每个点自己的 `timestamp_sec` | 真机给了逐点时间戳;ROS 节点目前没开放这个选项 |
|
||||||
|
|
||||||
|
`DeskewOptions` 默认 `period_sec = 0.1`、`start_angle_rad = -π`、`counterclockwise = true`、`stamp_at_end = true`。
|
||||||
|
`imu_from_sensor` 默认是恒等变换,实际必须按真实安装关系填(ROS 节点从 TF 读)。
|
||||||
|
|
||||||
|
## `eskf.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/eskf.cpp`。误差状态卡尔曼滤波,18 维。
|
||||||
|
|
||||||
|
| 类型 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `NoiseOptions` | 连续时间噪声密度、零偏随机游走、`integration_error_scale`、`maximum_imu_gap` |
|
||||||
|
| `FilterSnapshot` | `state`(`MotionState`)+ 18×18 `covariance`,可以整体 `restore()` 回去 |
|
||||||
|
| `InnovationCheck` | `FINAL`(过门限)或 `TRIAL`(配准迭代的中间步,不过门限) |
|
||||||
|
| `ErrorStateFilter` | 滤波器本体 |
|
||||||
|
|
||||||
|
误差状态的顺序是**位置、速度、姿态误差(右扰动)、陀螺零偏、加计零偏、重力**,每段 3 维。
|
||||||
|
|
||||||
|
| 方法 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `initialize(state)` | 设状态,协方差对角线设成固定初值:位置 0.01、速度 1、姿态 0.01、陀螺零偏 0.01、加计零偏 0.25、重力 0.01 |
|
||||||
|
| `propagate(a, b)` | 用两个 IMU 样本做中值积分,同时传播协方差。间隔超过 `maximum_imu_gap` 或时间戳对不上返回 `false` |
|
||||||
|
| `correct_pose(measurement, noise, projector)` | 直接用一位姿量测更新;`projector` 挑出哪些方向可观 |
|
||||||
|
| `correct_information(prior, linearization, information, gradient, projector, model_covariance, check)` | 固定先验的迭代更新:残差的 Hessian(`information`)和梯度由调用方给。配准用它 |
|
||||||
|
| `last_nis()` / `measurement_rank()` | 上一次更新的归一化新息平方和、量测秩 |
|
||||||
|
| `snapshot()` / `restore(snapshot)` | 取 / 设整体状态 |
|
||||||
|
| `inject(state, error)` / `difference(a, b)` | 把误差注入状态、两个状态求差(静态函数) |
|
||||||
|
|
||||||
|
## `registration.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/registration.cpp`。扫描到地图的点到面配准。
|
||||||
|
|
||||||
|
| 符号 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `VoxelMap` | 体素哈希地图,每个体素只留一个点;`plane(point, radius)` 拟合该点邻域的平面并缓存 |
|
||||||
|
| `Plane` | `center`、`normal`、`support_radius`、`valid` |
|
||||||
|
| `voxel_downsample(cloud, resolution)` | 扫描体素降采样,每个体素留第一个点 |
|
||||||
|
| `detect_degeneracy(h, options)` | 对 6×6 信息矩阵做 SVD,分出可观方向(`projector`)和退化方向(`null_basis`) |
|
||||||
|
| `scan_to_map(cloud, imu_from_sensor, map, prediction, noise, options)` | 迭代配准,返回 `RegistrationResult`,成功时 `estimate` 是更新后的滤波状态 |
|
||||||
|
| `inspect_scan_support(...)` | 只统计某个位姿下的关联计数,不更新。回放工具的 `--inspect-scan` 用它 |
|
||||||
|
|
||||||
|
`VoxelMap::plane()` 判定平面的条件:邻域里至少 5 个点,取最近的至多 20 个做主成分分析,
|
||||||
|
最小特征值与第二小特征值之比小于 0.03。
|
||||||
|
**有限大的平面不是无限延伸的墙**:查询点在平面内的投影超出 `support_radius` 一个体素以上,
|
||||||
|
就不算这个平面的对应(计入 `outside_support`)。
|
||||||
|
|
||||||
|
`scan_to_map()` 的阶段和失败原因:
|
||||||
|
|
||||||
|
| 阶段(`RegistrationStage`) | 做什么 | 可能的失败(`RegistrationFailure`) |
|
||||||
|
|---|---|---|
|
||||||
|
| `INITIAL_MATCH` | 在预测位姿处找点到面对应 | `NO_CORRESPONDENCES`(内点少于 `minimum_inliers`);`DEGENERATE`(六个方向全退化) |
|
||||||
|
| `ITERATION` | 最多迭代 `maximum_iterations` 次,每次在私有滤波器里做一步不过门限的试更新 | `INNOVATION`;`QUALITY`(相对先验的修正达到 0.5 m 或 0.35 rad) |
|
||||||
|
| `FINAL_FUSION` | 用收敛后的对应关系,对原始先验做一次**过门限**的正式更新 | `INNOVATION`;`QUALITY`(内点率、RMSE 或修正幅度不达标,阶段停在 `FINAL_FUSION`) |
|
||||||
|
| `COMPLETE` | 成功,`failure == NONE` | 无 |
|
||||||
|
|
||||||
|
`AssociationCounts` 把每一帧的关联过程记成五个数:
|
||||||
|
`sampled` → `candidate_planes` → `outside_support` / `plane_distance_rejected` / `inliers`。
|
||||||
|
`RegistrationResult` 里存了初始和最后一次的计数,`test_registration.cpp` 断言它们满足
|
||||||
|
`candidate_planes == outside_support + plane_distance_rejected + inliers`。
|
||||||
|
|
||||||
|
`map_translation_sigma` / `map_rotation_sigma` 是**地图和关联本身的不确定度**,
|
||||||
|
不随扫描点数增加而缩小,防止把几百个相关的点残差当成几百个独立的绝对位姿观测。
|
||||||
|
要求精确地图的单测(合成地图)会显式把它们设成 0。
|
||||||
|
|
||||||
|
## `map_io.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/map_io.cpp`。
|
||||||
|
|
||||||
|
| 符号 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `save_map(map, path, error)` | 写 FLMAP v1。先写 `path.tmp` 再改名,拒绝保存空地图 |
|
||||||
|
| `read_map(path, error)` | 读 FLMAP v1,带完整性检查 |
|
||||||
|
| `new_keyframe(previous, current)` | 位移超过 0.5 m **或** 旋转超过 10° 才算新关键帧(都是严格大于) |
|
||||||
|
|
||||||
|
FLMAP v1 的布局(小端):8 字节魔数 `FLMAP0001`、`uint32` 版本号、`double` 体素边长、
|
||||||
|
`uint64` 点数,然后每个点 3 个 `double`。`read_map` 会核对文件长度恰好等于 `28 + 24 × 点数`,
|
||||||
|
并拒绝超过 500 万点、非有限坐标、坐标绝对值与体素边长之比超过 1e12 的点。
|
||||||
|
|
||||||
|
## `localization_core.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/localization_core.cpp`。定位主流程,把上面几样串起来。
|
||||||
|
|
||||||
|
| 类型 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `MapMode` | `MAPPING`(边走边建图)或 `LOCALIZATION`(只读地图,默认) |
|
||||||
|
| `CoreOptions` | 模式、分辨率、`RegistrationOptions`、`NoiseOptions`、已知初始位姿、`base_from_imu`、`DeskewOptions` |
|
||||||
|
| `TrackingMode` | `FULL`(当前有有效的激光约束)或 `IMU_ONLY`(只有预测) |
|
||||||
|
| `FailureReason` | 没进 `FULL` 的原因:`INITIALIZING`、`NO_VALID_POINTS`、`INVALID_INPUT`、`TIME_ORDER`、`IMU_GAP`、`IMU_COVERAGE`、`REGISTRATION_FAILED`、`LIDAR_TIMEOUT`、`MAP_UNAVAILABLE` |
|
||||||
|
| `LocalizationStatus` | 模式、原因、各种计数、最近一次配准的残差 / 内点 / 退化方向、关键帧数、地图点数 |
|
||||||
|
| `LocalizationSnapshot` | `pose` + `filter` + `status`,在**同一把锁**里一起取出来 |
|
||||||
|
| `LocalizationCore` | 本体:`process_imu` / `process_point_cloud` / `get_snapshot` / `load_map` / `export_map` / `set_pose` / `reset` |
|
||||||
|
|
||||||
|
几条约定:
|
||||||
|
|
||||||
|
- **所有公有方法都上锁**,可以从 ROS 回调线程和定时器线程同时调
|
||||||
|
- `get_pose()` 和 `LocalizationSnapshot::pose` 是 **map → base_link**;滤波器内部状态的原点是 IMU
|
||||||
|
- `process_imu` / `process_point_cloud` 的返回值只表示「这份输入收下了没有」,**不等于完成了一次激光更新**。要看 `status.mode` 和 `accepted_corrections`
|
||||||
|
- 必须已知初始位姿:没有全局重定位,`reset()` 也只回到 `CoreOptions::initial_pose`
|
||||||
|
- `reset()` 只在 `MAPPING` 模式下清空地图
|
||||||
|
|
||||||
|
## `dataset.hpp`
|
||||||
|
|
||||||
|
实现:`src/core/dataset.cpp`。离线数据的读写和打分,在线定位不用。
|
||||||
|
|
||||||
|
| 符号 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `write_cloud` / `read_cloud` | FLPC v1 点云文件(`.flpc`) |
|
||||||
|
| `write_dataset_config` / `read_dataset_config` | 数据集目录里的 `config.txt`:已知初始位姿、两组固定外参、扫描时间模型 |
|
||||||
|
| `read_trajectory` / `write_trajectory_sample` / `trajectory_pose` | TUM 文本轨迹及其插值(真值间隔超过上限时拒绝插值) |
|
||||||
|
| `evaluate(estimate, truth)` | 未对齐的 ATE(平移 / 旋转)和 1 秒相对位姿误差 RPE |
|
||||||
|
| `write_filter_trace_header` / `write_filter_trace` | 每帧三行的调优 CSV:状态、18×18 协方差、6×6 信息矩阵、梯度、奇异值、配准阶段和关联计数 |
|
||||||
|
| `mode_name` / `reason_name` | 枚举转字符串,日志用 |
|
||||||
|
|
||||||
|
FLPC v1 的布局(小端):8 字节魔数 `FLPC0001`、`uint32` 版本号、`double` 帧时间戳、
|
||||||
|
`uint32` 点数,然后每个点 1 个 `double` 时间戳 + 3 个 `float` 坐标 + 1 个 `float` 强度。
|
||||||
|
文件长度必须是 `24 + 24 × 点数`,单帧最多 100 万点。
|
||||||
|
|
||||||
|
两种二进制格式都逐个字段序列化,不直接写 Eigen 对象的内存。
|
||||||
|
|
||||||
|
## `tracking_health.hpp`(只有头文件)
|
||||||
|
|
||||||
|
定位结果能不能拿去导航。`ros/localization_node.cpp` 用它决定是否继续发布 `map → odom`
|
||||||
|
和 `/field_localization/navigation_valid`,后者是 `sentry_nav` 的 `cmd_vel_relay` 的联锁输入。
|
||||||
|
|
||||||
|
`TrackingHealth::update(snapshot, base_from_imu, now)` 返回当前是否有效。规则(`HealthOptions` 默认值):
|
||||||
|
|
||||||
|
| 条件 | 限值 |
|
||||||
|
|---|---|
|
||||||
|
| 最近一次成功配准距今 | ≤ 0.3 s |
|
||||||
|
| IMU 状态距今 | ≤ 0.1 s(允许 `now` 比状态时间戳早 0.05 s,容忍时钟投递偏差) |
|
||||||
|
| 水平位置 3σ(取 xy 协方差块的最大特征值方向) | ≤ 0.5 m |
|
||||||
|
| 航向 3σ | ≤ 15° |
|
||||||
|
| 恢复有效 | 连续 **5 帧**成功配准。数的是 `accepted_corrections`,不是定时器节拍 |
|
||||||
|
|
||||||
|
任何一条不满足就立刻失效并把连续计数清零;`accepted_corrections` 倒退(被 reset)也判失效。
|
||||||
|
|
||||||
|
`base_pose_covariance()` 与 `base_twist_covariance()` 分别通过 6×18 解析雅可比把 IMU 原点的位姿/速度/零偏协方差换算到 `base_link`(其中速度协方差额外叠加单步陀螺采样白噪声),`update()` 和 ROS 节点都用它们。
|
||||||
|
|
||||||
|
## 默认值速查
|
||||||
|
|
||||||
|
以头文件为准,改了默认值记得同步这里:
|
||||||
|
|
||||||
|
| 项 | 默认值 | 在哪 |
|
||||||
|
|---|---|---|
|
||||||
|
| 地图 / 扫描体素 | 0.1 m | `CoreOptions::map_resolution`、`RegistrationOptions::scan_voxel` |
|
||||||
|
| 邻域半径 | 0.5 m | `RegistrationOptions::neighborhood_radius` |
|
||||||
|
| 点量测 σ | 0.02 m | `RegistrationOptions::measurement_sigma` |
|
||||||
|
| Huber 阈值 | 0.025 m | `RegistrationOptions::huber_threshold` |
|
||||||
|
| 点到面距离上限 | 0.12 m | `RegistrationOptions::max_plane_distance` |
|
||||||
|
| 地图平移 / 旋转不确定度 | 0.03 m / 0.002 rad | `RegistrationOptions::map_translation_sigma` / `map_rotation_sigma` |
|
||||||
|
| 最多迭代 | 10 次 | `RegistrationOptions::maximum_iterations` |
|
||||||
|
| 成功门槛 | 内点 ≥ 50、内点率 ≥ 20%、RMSE ≤ 0.1 m | `RegistrationOptions` |
|
||||||
|
| 退化判定 | 相对 1e-4、绝对 1e-6 | `RegistrationOptions::degeneracy_relative` / `degeneracy_absolute` |
|
||||||
|
| 陀螺 / 加计噪声密度 | 0.003 rad/s/√Hz、0.03 m/s²/√Hz | `NoiseOptions::gyro` / `accel` |
|
||||||
|
| 陀螺 / 加计零偏随机游走 | 1e-5、1e-4 | `NoiseOptions::gyro_bias_walk` / `accel_bias_walk` |
|
||||||
|
| 积分误差尺度 | 1.4 | `NoiseOptions::integration_error_scale` |
|
||||||
|
| IMU 最大间隔 | 0.05 s | `NoiseOptions::maximum_imu_gap` |
|
||||||
|
| IMU 相对 base_link 的位置 | z = 0.15 m | `CoreOptions::base_from_imu`(ROS 节点会用 TF 覆盖) |
|
||||||
|
| 新息门限 | 按量测秩取卡方 99.9% 分位 | `eskf.cpp` 里的 `gates[]` |
|
||||||
|
| 新关键帧 | 位移 > 0.5 m 或旋转 > 10° | `map_io.cpp` 的 `new_keyframe()` |
|
||||||
|
| 导航有效性 | 配准超时 0.3 s、IMU 超时 0.1 s、位置 3σ 0.5 m、航向 3σ 15°、恢复 5 帧 | `HealthOptions` |
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 实现细节:[`../../../src/core/README.md`](../../../src/core/README.md)
|
||||||
|
- 上层的 ROS 接口:[`../ros/README.md`](../ros/README.md)
|
||||||
|
- 测试:[`../../../tests/README.md`](../../../tests/README.md)
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/localization_core.hpp"
|
||||||
|
namespace field_localization::core {
|
||||||
|
// Versioned little-endian scalar encoding; never serializes Eigen object memory.
|
||||||
|
void write_cloud(const PointCloud &cloud,const std::filesystem::path &path);
|
||||||
|
PointCloud read_cloud(const std::filesystem::path &path,const std::string &frame="lidar_link");
|
||||||
|
void write_dataset_config(const CoreOptions &options,const std::filesystem::path &path,
|
||||||
|
const std::string &cloud_frame="lidar_link");
|
||||||
|
CoreOptions read_dataset_config(const std::filesystem::path &path,std::string *cloud_frame=nullptr);
|
||||||
|
struct TrajectorySample { double time; Pose3D pose; };
|
||||||
|
std::vector<TrajectorySample> read_trajectory(const std::filesystem::path &path);
|
||||||
|
void write_trajectory_sample(std::ostream &out,const TrajectorySample &sample);
|
||||||
|
std::optional<Pose3D> trajectory_pose(std::span<const TrajectorySample> trajectory,double time,
|
||||||
|
double maximum_gap=0.05);
|
||||||
|
struct Evaluation {
|
||||||
|
std::size_t total{0},matched{0},relative_pairs{0};
|
||||||
|
double ate_translation{0},ate_rotation_rad{0},rpe_translation{0},rpe_rotation_rad{0};
|
||||||
|
};
|
||||||
|
Evaluation evaluate(std::span<const TrajectorySample> estimate,std::span<const TrajectorySample> truth);
|
||||||
|
void write_filter_trace_header(std::ostream &out);
|
||||||
|
void write_filter_trace(std::ostream &out,double time,const char *phase,const FilterSnapshot &filter,
|
||||||
|
const LocalizationStatus &status);
|
||||||
|
const char *mode_name(TrackingMode mode);
|
||||||
|
const char *reason_name(FailureReason reason);
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/imu_integration.hpp"
|
||||||
|
namespace field_localization::core {
|
||||||
|
using Matrix18 = Eigen::Matrix<double,18,18>;
|
||||||
|
using Vector18 = Eigen::Matrix<double,18,1>;
|
||||||
|
using Matrix6 = Eigen::Matrix<double,6,6>;
|
||||||
|
using Vector6 = Eigen::Matrix<double,6,1>;
|
||||||
|
struct NoiseOptions {
|
||||||
|
// Continuous-time noise densities, configurable even with noiseless simulated sensors.
|
||||||
|
double gyro{0.003};
|
||||||
|
double accel{0.03};
|
||||||
|
double gyro_bias_walk{1e-5};
|
||||||
|
double accel_bias_walk{1e-4};
|
||||||
|
double gravity_walk{0.0};
|
||||||
|
// Quadrature/model error for unresolved between-sample dynamics, separate from sensor noise.
|
||||||
|
double integration_error_scale{1.4};
|
||||||
|
double maximum_imu_gap{0.05};
|
||||||
|
};
|
||||||
|
struct FilterSnapshot {
|
||||||
|
MotionState state;
|
||||||
|
// Error order: position, velocity, right attitude error, gyro bias, accel bias, gravity.
|
||||||
|
Matrix18 covariance{Matrix18::Identity()};
|
||||||
|
};
|
||||||
|
enum class InnovationCheck { FINAL, TRIAL };
|
||||||
|
|
||||||
|
class ErrorStateFilter {
|
||||||
|
public:
|
||||||
|
explicit ErrorStateFilter(const NoiseOptions &noise = {});
|
||||||
|
void initialize(const MotionState &state);
|
||||||
|
bool propagate(const ImuData &a, const ImuData &b);
|
||||||
|
bool correct_pose(const Pose3D &measurement, const Matrix6 &noise,
|
||||||
|
const Matrix6 &projector = Matrix6::Identity());
|
||||||
|
// Fixed-prior iterated update. Hessian/gradient are from current point-plane residuals.
|
||||||
|
bool correct_information(const FilterSnapshot &prior, const MotionState &linearization,
|
||||||
|
const Matrix6 &information, const Vector6 &gradient,
|
||||||
|
const Matrix6 &projector, const Matrix6 &model_covariance = Matrix6::Zero(),
|
||||||
|
InnovationCheck check = InnovationCheck::FINAL);
|
||||||
|
double last_nis() const { return last_nis_; }
|
||||||
|
int measurement_rank() const { return measurement_rank_; }
|
||||||
|
const FilterSnapshot &snapshot() const { return estimate_; }
|
||||||
|
void restore(const FilterSnapshot &snapshot) { estimate_=snapshot; }
|
||||||
|
static MotionState inject(const MotionState &state, const Vector18 &error);
|
||||||
|
static Vector18 difference(const MotionState &reference, const MotionState &state);
|
||||||
|
private:
|
||||||
|
bool update(const FilterSnapshot &prior, const Eigen::Matrix<double,6,18> &h,
|
||||||
|
const Vector6 &innovation, const Matrix6 &noise, const Matrix6 &projector,
|
||||||
|
InnovationCheck check = InnovationCheck::FINAL);
|
||||||
|
double last_nis_{0};
|
||||||
|
int measurement_rank_{0};
|
||||||
|
NoiseOptions noise_;
|
||||||
|
FilterSnapshot estimate_;
|
||||||
|
};
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/types.hpp"
|
||||||
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
Eigen::Matrix3d skew(const Eigen::Vector3d &v);
|
||||||
|
Eigen::Quaterniond exp_so3(const Eigen::Vector3d &v);
|
||||||
|
Eigen::Vector3d log_so3(const Eigen::Quaterniond &q);
|
||||||
|
Pose3D compose(const Pose3D &a, const Pose3D &b);
|
||||||
|
Pose3D inverse(const Pose3D &p);
|
||||||
|
|
||||||
|
// Pose and velocity refer to the IMU origin; rotation maps IMU to map.
|
||||||
|
struct MotionState {
|
||||||
|
double timestamp_sec{0.0};
|
||||||
|
Pose3D pose;
|
||||||
|
Eigen::Vector3d velocity{Eigen::Vector3d::Zero()};
|
||||||
|
Eigen::Vector3d gyro_bias{Eigen::Vector3d::Zero()};
|
||||||
|
Eigen::Vector3d accel_bias{Eigen::Vector3d::Zero()};
|
||||||
|
Eigen::Vector3d gravity{0.0, 0.0, -9.81};
|
||||||
|
};
|
||||||
|
// Body-frame (base_link) linear and angular velocity with gyro-bias and lever-arm compensation.
|
||||||
|
Twist3D base_twist(const MotionState &state, const Eigen::Vector3d &raw_angular_velocity,
|
||||||
|
const Pose3D &base_from_imu);
|
||||||
|
struct Preintegration {
|
||||||
|
Eigen::Quaterniond dR{Eigen::Quaterniond::Identity()};
|
||||||
|
Eigen::Vector3d dv{Eigen::Vector3d::Zero()};
|
||||||
|
Eigen::Vector3d dp{Eigen::Vector3d::Zero()};
|
||||||
|
double dt{0.0};
|
||||||
|
};
|
||||||
|
bool valid_imu(const ImuData &imu);
|
||||||
|
std::optional<ImuData> interpolate_imu(std::span<const ImuData> samples, double time);
|
||||||
|
MotionState integrate_midpoint(const MotionState &state, const ImuData &a,
|
||||||
|
const ImuData &b);
|
||||||
|
std::optional<std::vector<MotionState>> integrate_trajectory(
|
||||||
|
std::span<const ImuData> samples, const MotionState &initial, double end);
|
||||||
|
std::optional<Preintegration> preintegrate(std::span<const ImuData> samples,
|
||||||
|
double start, double end, const Eigen::Vector3d &bg = Eigen::Vector3d::Zero(),
|
||||||
|
const Eigen::Vector3d &ba = Eigen::Vector3d::Zero());
|
||||||
|
std::optional<MotionState> interpolate_motion(std::span<const MotionState> trajectory,
|
||||||
|
double time);
|
||||||
|
enum class ScanTiming { INSTANTANEOUS, AZIMUTH, POINT_TIMESTAMPS };
|
||||||
|
struct DeskewOptions {
|
||||||
|
ScanTiming timing{ScanTiming::INSTANTANEOUS};
|
||||||
|
double period_sec{0.1};
|
||||||
|
double start_angle_rad{-3.14159265358979323846};
|
||||||
|
bool counterclockwise{true};
|
||||||
|
bool stamp_at_end{true};
|
||||||
|
Pose3D imu_from_sensor;
|
||||||
|
};
|
||||||
|
// Output is in the same sensor frame, at scan end. Input timestamps are unchanged.
|
||||||
|
std::optional<PointCloud> deskew(const PointCloud &cloud,
|
||||||
|
std::span<const MotionState> trajectory, const DeskewOptions &options);
|
||||||
|
std::pair<double, double> scan_window(const PointCloud &cloud, const DeskewOptions &options);
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -1,13 +1,33 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "field_localization/core/types.hpp"
|
#include "field_localization/core/map_io.hpp"
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace field_localization::core {
|
namespace field_localization::core {
|
||||||
|
|
||||||
|
enum class TrackingMode { IMU_ONLY, FULL };
|
||||||
|
enum class FailureReason { INITIALIZING, NONE, NO_VALID_POINTS, INVALID_INPUT, TIME_ORDER,
|
||||||
|
IMU_GAP, IMU_COVERAGE, REGISTRATION_FAILED, LIDAR_TIMEOUT, MAP_UNAVAILABLE };
|
||||||
struct LocalizationStatus {
|
struct LocalizationStatus {
|
||||||
|
TrackingMode mode{TrackingMode::IMU_ONLY};
|
||||||
|
FailureReason reason{FailureReason::INITIALIZING};
|
||||||
|
double state_timestamp{0.0};
|
||||||
|
double last_correction_timestamp{-1};
|
||||||
|
std::size_t accepted_corrections{0};
|
||||||
|
bool registration_residual_available{false};
|
||||||
|
RegistrationResult registration;
|
||||||
|
FilterSnapshot registration_prediction;
|
||||||
|
double registration_rmse{0.0};
|
||||||
|
std::size_t inlier_count{0};
|
||||||
|
double inlier_ratio{0.0};
|
||||||
|
int degenerate_dimensions{6};
|
||||||
|
Matrix6 degenerate_basis{Matrix6::Identity()};
|
||||||
|
Vector6 information_singular_values{Vector6::Zero()};
|
||||||
|
std::size_t keyframe_count{0};
|
||||||
|
std::size_t map_point_count{0};
|
||||||
bool has_imu{false};
|
bool has_imu{false};
|
||||||
bool has_point_cloud{false};
|
bool has_point_cloud{false};
|
||||||
|
|
||||||
@@ -23,9 +43,34 @@ struct LocalizationStatus {
|
|||||||
std::size_t last_point_count{0};
|
std::size_t last_point_count{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class MapMode { MAPPING, LOCALIZATION };
|
||||||
|
struct CoreOptions {
|
||||||
|
MapMode map_mode{MapMode::LOCALIZATION};
|
||||||
|
double map_resolution{0.1};
|
||||||
|
RegistrationOptions registration;
|
||||||
|
NoiseOptions noise;
|
||||||
|
Pose3D initial_pose;
|
||||||
|
Pose3D base_from_imu{Eigen::Quaterniond::Identity(), Eigen::Vector3d{0,0,0.15}};
|
||||||
|
DeskewOptions deskew;
|
||||||
|
std::optional<MapBounds> map_bounds;
|
||||||
|
};
|
||||||
|
inline constexpr double map_association_margin=0.20;
|
||||||
|
struct LocalizationSnapshot {
|
||||||
|
Pose3D pose;
|
||||||
|
FilterSnapshot filter;
|
||||||
|
LocalizationStatus status;
|
||||||
|
Twist3D twist{};
|
||||||
|
Eigen::Vector3d raw_angular_velocity{Eigen::Vector3d::Zero()};
|
||||||
|
double imu_dt{0.0};
|
||||||
|
};
|
||||||
class LocalizationCore {
|
class LocalizationCore {
|
||||||
public:
|
public:
|
||||||
LocalizationCore() = default;
|
LocalizationCore();
|
||||||
|
explicit LocalizationCore(const CoreOptions &options);
|
||||||
|
[[nodiscard]] LocalizationSnapshot get_snapshot() const;
|
||||||
|
void set_map_points(std::span<const Eigen::Vector3d> points);
|
||||||
|
bool load_map(const std::filesystem::path &path,std::string &error);
|
||||||
|
bool export_map(const std::filesystem::path &path,std::string &error) const;
|
||||||
|
|
||||||
// 接收 IMU 数据
|
// 接收 IMU 数据
|
||||||
bool process_imu(const ImuData &imu);
|
bool process_imu(const ImuData &imu);
|
||||||
@@ -36,6 +81,9 @@ public:
|
|||||||
// 获取当前位姿
|
// 获取当前位姿
|
||||||
[[nodiscard]] Pose3D get_pose() const;
|
[[nodiscard]] Pose3D get_pose() const;
|
||||||
|
|
||||||
|
// 获取当前车体坐标系(base_link)线速度与角速度
|
||||||
|
[[nodiscard]] Twist3D get_twist() const;
|
||||||
|
|
||||||
// 设置位姿(用于初始化和后续算法集成)
|
// 设置位姿(用于初始化和后续算法集成)
|
||||||
void set_pose(const Pose3D &pose);
|
void set_pose(const Pose3D &pose);
|
||||||
|
|
||||||
@@ -48,8 +96,18 @@ public:
|
|||||||
private:
|
private:
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
|
|
||||||
|
const CoreOptions options_;
|
||||||
|
VoxelMap map_;
|
||||||
|
double last_correction_time_{-1.0};
|
||||||
|
std::optional<Pose3D> last_keyframe_;
|
||||||
|
ErrorStateFilter filter_;
|
||||||
|
std::optional<ImuData> previous_imu_;
|
||||||
|
std::vector<ImuData> imu_history_;
|
||||||
|
std::vector<FilterSnapshot> state_history_;
|
||||||
Pose3D pose_{};
|
Pose3D pose_{};
|
||||||
|
Twist3D twist_{};
|
||||||
|
double last_imu_dt_{0.0};
|
||||||
LocalizationStatus status_{};
|
LocalizationStatus status_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace field_localization::core
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/registration.hpp"
|
||||||
|
#include <filesystem>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
namespace field_localization::core {
|
||||||
|
struct MapBounds {
|
||||||
|
Eigen::Vector3d min;
|
||||||
|
Eigen::Vector3d max;
|
||||||
|
bool valid() const;
|
||||||
|
bool contains(const Eigen::Vector3d &point,double margin=0.0) const;
|
||||||
|
};
|
||||||
|
PointCloud crop_to_map(const PointCloud &cloud,const Pose3D &map_from_sensor,
|
||||||
|
const MapBounds &bounds,double margin=0.0);
|
||||||
|
bool save_map(const VoxelMap &map,const std::filesystem::path &path,std::string &error);
|
||||||
|
std::optional<VoxelMap> read_map(const std::filesystem::path &path,std::string &error,
|
||||||
|
const std::optional<MapBounds> &bounds={});
|
||||||
|
bool new_keyframe(const Pose3D &previous,const Pose3D ¤t);
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/eskf.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
struct VoxelKey {
|
||||||
|
std::int64_t x{},y{},z{};
|
||||||
|
bool operator==(const VoxelKey &) const = default;
|
||||||
|
};
|
||||||
|
struct VoxelHash { std::size_t operator()(const VoxelKey &k) const; };
|
||||||
|
struct Plane {
|
||||||
|
Eigen::Vector3d center{Eigen::Vector3d::Zero()};
|
||||||
|
Eigen::Vector3d normal{Eigen::Vector3d::Zero()};
|
||||||
|
double support_radius{0};
|
||||||
|
bool valid{false};
|
||||||
|
};
|
||||||
|
class VoxelMap {
|
||||||
|
public:
|
||||||
|
explicit VoxelMap(double resolution=0.1);
|
||||||
|
void insert(const Eigen::Vector3d &point);
|
||||||
|
void insert(const PointCloud &cloud,const Pose3D &map_from_sensor);
|
||||||
|
void clear();
|
||||||
|
std::size_t size() const { return points_.size(); }
|
||||||
|
double resolution() const { return resolution_; }
|
||||||
|
std::vector<Eigen::Vector3d> points() const;
|
||||||
|
Plane plane(const Eigen::Vector3d &point,double radius) const;
|
||||||
|
private:
|
||||||
|
VoxelKey key(const Eigen::Vector3d &point) const;
|
||||||
|
double resolution_;
|
||||||
|
std::unordered_map<VoxelKey,Eigen::Vector3d,VoxelHash> points_;
|
||||||
|
mutable std::unordered_map<VoxelKey,Plane,VoxelHash> planes_;
|
||||||
|
mutable double cached_radius_{-1};
|
||||||
|
};
|
||||||
|
PointCloud voxel_downsample(const PointCloud &cloud,double resolution);
|
||||||
|
struct RegistrationOptions {
|
||||||
|
double scan_voxel{0.1};
|
||||||
|
double neighborhood_radius{0.5};
|
||||||
|
double measurement_sigma{0.02};
|
||||||
|
// Shared map/association uncertainty does not shrink with the number of scan points.
|
||||||
|
double map_translation_sigma{0.03};
|
||||||
|
double map_rotation_sigma{0.002};
|
||||||
|
double huber_threshold{0.025};
|
||||||
|
double max_plane_distance{0.12};
|
||||||
|
double max_rmse{0.1};
|
||||||
|
double minimum_inlier_ratio{0.2};
|
||||||
|
std::size_t minimum_inliers{50};
|
||||||
|
int maximum_iterations{10};
|
||||||
|
double degeneracy_relative{1e-4};
|
||||||
|
double degeneracy_absolute{1e-6};
|
||||||
|
};
|
||||||
|
struct Degeneracy {
|
||||||
|
Matrix6 projector{Matrix6::Zero()};
|
||||||
|
Matrix6 null_basis{Matrix6::Identity()};
|
||||||
|
Vector6 singular_values{Vector6::Zero()};
|
||||||
|
int dimensions{6};
|
||||||
|
};
|
||||||
|
Degeneracy detect_degeneracy(const Matrix6 &normalized_information,const RegistrationOptions &options={});
|
||||||
|
enum class RegistrationFailure { NONE, NO_CORRESPONDENCES, DEGENERATE, INNOVATION, QUALITY };
|
||||||
|
enum class RegistrationStage { NOT_RUN, INITIAL_MATCH, ITERATION, FINAL_FUSION, COMPLETE };
|
||||||
|
|
||||||
|
struct AssociationCounts {
|
||||||
|
std::size_t sampled{0};
|
||||||
|
std::size_t candidate_planes{0};
|
||||||
|
std::size_t outside_support{0};
|
||||||
|
std::size_t plane_distance_rejected{0};
|
||||||
|
std::size_t inliers{0};
|
||||||
|
};
|
||||||
|
const char *registration_stage_name(RegistrationStage stage);
|
||||||
|
const char *registration_failure_name(RegistrationFailure failure);
|
||||||
|
struct RegistrationResult {
|
||||||
|
bool success{false};
|
||||||
|
FilterSnapshot estimate;
|
||||||
|
RegistrationFailure failure{RegistrationFailure::NO_CORRESPONDENCES};
|
||||||
|
Matrix6 information{Matrix6::Zero()};
|
||||||
|
Vector6 gradient{Vector6::Zero()};
|
||||||
|
double nis{0};
|
||||||
|
int measurement_rank{0};
|
||||||
|
bool residual_available{false};
|
||||||
|
double rmse{0};
|
||||||
|
std::size_t inliers{0};
|
||||||
|
double inlier_ratio{0};
|
||||||
|
Degeneracy degeneracy;
|
||||||
|
RegistrationStage stage{RegistrationStage::NOT_RUN};
|
||||||
|
AssociationCounts initial_associations;
|
||||||
|
AssociationCounts last_associations;
|
||||||
|
};
|
||||||
|
AssociationCounts inspect_scan_support(const PointCloud &cloud,const Pose3D &imu_from_sensor,
|
||||||
|
const VoxelMap &map,const Pose3D &map_from_imu,const RegistrationOptions &options={});
|
||||||
|
RegistrationResult scan_to_map(const PointCloud &cloud,const Pose3D &imu_from_sensor,
|
||||||
|
const VoxelMap &map,const FilterSnapshot &prediction,const NoiseOptions &noise={},
|
||||||
|
const RegistrationOptions &options={});
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/localization_core.hpp"
|
||||||
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
inline Matrix6 base_pose_covariance(const LocalizationSnapshot &s,const Pose3D &base_from_imu) {
|
||||||
|
Eigen::Matrix<double,6,18> j=Eigen::Matrix<double,6,18>::Zero();
|
||||||
|
j.block<3,3>(0,0).setIdentity();
|
||||||
|
j.block<3,3>(0,6)=-s.filter.state.pose.rotation.toRotationMatrix()*skew(inverse(base_from_imu).translation);
|
||||||
|
j.block<3,3>(3,6)=base_from_imu.rotation.toRotationMatrix();
|
||||||
|
return j*s.filter.covariance*j.transpose();
|
||||||
|
}
|
||||||
|
inline Matrix6 base_twist_covariance(const LocalizationSnapshot &s,const Pose3D &base_from_imu,
|
||||||
|
double gyro_noise_density=0.0) {
|
||||||
|
const Eigen::Matrix3d r_bi=base_from_imu.rotation.normalized().toRotationMatrix();
|
||||||
|
const Eigen::Matrix3d r_mi=s.filter.state.pose.rotation.normalized().toRotationMatrix();
|
||||||
|
const Eigen::Matrix3d lever_r=skew(base_from_imu.translation)*r_bi;
|
||||||
|
Eigen::Matrix<double,6,18> j=Eigen::Matrix<double,6,18>::Zero();
|
||||||
|
j.block<3,3>(0,3)=r_bi*r_mi.transpose();
|
||||||
|
j.block<3,3>(0,6)=r_bi*skew(r_mi.transpose()*s.filter.state.velocity);
|
||||||
|
j.block<3,3>(0,9)=-lever_r;
|
||||||
|
j.block<3,3>(3,9)=-r_bi;
|
||||||
|
Matrix6 cov=j*s.filter.covariance*j.transpose();
|
||||||
|
if(gyro_noise_density>0.0 && s.imu_dt>1e-6) {
|
||||||
|
const double sample_var=(gyro_noise_density*gyro_noise_density)/s.imu_dt;
|
||||||
|
Eigen::Matrix<double,6,3> g;
|
||||||
|
g.topRows<3>()=-lever_r;
|
||||||
|
g.bottomRows<3>()=-r_bi;
|
||||||
|
cov.noalias()+=sample_var*(g*g.transpose());
|
||||||
|
}
|
||||||
|
return 0.5*(cov+cov.transpose());
|
||||||
|
}
|
||||||
|
struct HealthOptions {
|
||||||
|
double correction_timeout{0.3},imu_timeout{0.1},clock_tolerance{0.05};
|
||||||
|
double position_three_sigma{0.5},yaw_three_sigma{15*std::numbers::pi/180};
|
||||||
|
std::size_t recovery_scans{5};
|
||||||
|
};
|
||||||
|
// Independent of ROS and of publication frequency: count accepted scans, not timer ticks.
|
||||||
|
class TrackingHealth {
|
||||||
|
public:
|
||||||
|
explicit TrackingHealth(const HealthOptions &options={}):options_(options) {}
|
||||||
|
bool update(const LocalizationSnapshot &s,const Pose3D &base_from_imu,double now) {
|
||||||
|
const auto &status=s.status;
|
||||||
|
const Matrix6 p=base_pose_covariance(s,base_from_imu);
|
||||||
|
const double horizontal=0.5*(p(0,0)+p(1,1)+std::hypot(p(0,0)-p(1,1),2*p(0,1)));
|
||||||
|
Eigen::Vector3d yaw_j;
|
||||||
|
auto yaw=[](const Eigen::Quaterniond &q) {
|
||||||
|
return std::atan2(2*(q.w()*q.z()+q.x()*q.y()),1-2*(q.y()*q.y()+q.z()*q.z()));
|
||||||
|
};
|
||||||
|
for(int i=0;i<3;++i) {
|
||||||
|
Eigen::Vector3d d=Eigen::Vector3d::Zero();d[i]=1e-6;
|
||||||
|
const double a=yaw(s.pose.rotation*exp_so3(d)),b=yaw(s.pose.rotation*exp_so3(-d));
|
||||||
|
yaw_j[i]=std::remainder(a-b,2*std::numbers::pi)/2e-6;
|
||||||
|
}
|
||||||
|
const double yaw_variance=yaw_j.dot(p.bottomRightCorner<3,3>()*yaw_j);
|
||||||
|
position_sigma_=3*std::sqrt(std::max(0.0,horizontal)); yaw_sigma_=3*std::sqrt(std::max(0.0,yaw_variance));
|
||||||
|
const bool bounded=p.allFinite() && horizontal>=0 && yaw_variance>=0 &&
|
||||||
|
3*std::sqrt(horizontal)<=options_.position_three_sigma &&
|
||||||
|
3*std::sqrt(yaw_variance)<=options_.yaw_three_sigma;
|
||||||
|
const bool fresh=std::isfinite(now) && status.has_imu && status.last_correction_timestamp>=0 &&
|
||||||
|
now>=status.state_timestamp-options_.clock_tolerance && now-status.state_timestamp<=options_.imu_timeout &&
|
||||||
|
now>=status.last_correction_timestamp-options_.clock_tolerance && now-status.last_correction_timestamp<=options_.correction_timeout;
|
||||||
|
if(!fresh || !bounded) { valid_=false; consecutive_=0; }
|
||||||
|
if(status.mode!=TrackingMode::FULL) consecutive_=0;
|
||||||
|
if(status.accepted_corrections<last_accepted_) { valid_=false; consecutive_=0; }
|
||||||
|
if(status.accepted_corrections!=last_accepted_) {
|
||||||
|
if(fresh && bounded && status.mode==TrackingMode::FULL) ++consecutive_;
|
||||||
|
else consecutive_=0;
|
||||||
|
last_accepted_=status.accepted_corrections;
|
||||||
|
}
|
||||||
|
if(fresh && bounded && consecutive_>=options_.recovery_scans) valid_=true;
|
||||||
|
return valid_;
|
||||||
|
}
|
||||||
|
double position_three_sigma() const { return position_sigma_; }
|
||||||
|
double yaw_three_sigma() const { return yaw_sigma_; }
|
||||||
|
void reset() { valid_=false; consecutive_=0; last_accepted_=0; }
|
||||||
|
private:
|
||||||
|
HealthOptions options_;
|
||||||
|
double position_sigma_{0},yaw_sigma_{0};
|
||||||
|
bool valid_{false};
|
||||||
|
std::size_t consecutive_{0},last_accepted_{0};
|
||||||
|
};
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -39,4 +39,10 @@ struct Pose3D {
|
|||||||
Eigen::Vector3d translation{Eigen::Vector3d::Zero()};
|
Eigen::Vector3d translation{Eigen::Vector3d::Zero()};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace field_localization::core
|
struct Twist3D {
|
||||||
|
Eigen::Vector3d linear{Eigen::Vector3d::Zero()};
|
||||||
|
|
||||||
|
Eigen::Vector3d angular{Eigen::Vector3d::Zero()};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# include/field_localization/ros/ (ROS 适配层接口)
|
||||||
|
|
||||||
|
两个头,是 core 和 ROS 之间需要碰 `rclcpp` 的地方。编进 `field_localization_ros`(动态库)。
|
||||||
|
|
||||||
|
| 头文件 | 实现 | 提供什么 |
|
||||||
|
|---|---|---|
|
||||||
|
| `conversion.hpp` | `src/ros/conversion.cpp` | ROS 消息和 core 类型互转 |
|
||||||
|
| `localization_node.hpp` | `src/ros/localization_node.cpp` | `LocalizationNode` 类声明 |
|
||||||
|
|
||||||
|
## `conversion.hpp`
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
namespace field_localization::ros {
|
||||||
|
core::PointCloud convert_cloud(const sensor_msgs::msg::PointCloud2 &msg);
|
||||||
|
core::Pose3D from_transform(const geometry_msgs::msg::Transform &transform);
|
||||||
|
geometry_msgs::msg::Transform to_transform(const core::Pose3D &pose);
|
||||||
|
geometry_msgs::msg::Twist to_twist(const core::Twist3D &twist);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
三个函数都是纯函数,只依赖消息类型,不碰节点,所以 `tests/test_ros_conversion.cpp`
|
||||||
|
能不起节点直接测。
|
||||||
|
|
||||||
|
`convert_cloud()` 被两个可执行文件用到:定位节点和录制工具 `field_localization_record`。
|
||||||
|
它的要求(不满足就抛 `std::runtime_error`):
|
||||||
|
|
||||||
|
| 检查 | 要求 |
|
||||||
|
|---|---|
|
||||||
|
| 字段 | `x` / `y` / `z` 必须有,`intensity` 可选;类型必须是 `FLOAT32`,偏移不能越过 `point_step` |
|
||||||
|
| 布局 | `point_step` 不为 0,`width × point_step ≤ row_step`,`row_step × height ≤ data 长度`,总点数 ≤ 100 万 |
|
||||||
|
| 字节序 | 按 `is_bigendian` 转到本机字节序,行尾的填充字节会被跳过 |
|
||||||
|
| 单点 | 坐标或强度非有限的点直接丢掉,不抛异常 |
|
||||||
|
|
||||||
|
输出的点在消息自己的 `frame_id` 下,时间戳取 header,单位换成秒。
|
||||||
|
|
||||||
|
## `localization_node.hpp`
|
||||||
|
|
||||||
|
`LocalizationNode` 的成员列表。对外只有构造函数和析构函数,其余全是私有回调。
|
||||||
|
参数、话题、服务这些「怎么用」的内容在 [`../../../src/ros/README.md`](../../../src/ros/README.md)。
|
||||||
|
|
||||||
|
它继承 `rclcpp::Node`,头文件里带着 `tf2_ros` 的 Buffer / Listener / Broadcaster、
|
||||||
|
`TrackingHealth` 和调优 CSV 的 `std::ofstream`。
|
||||||
|
**只有 `src/ros/localization_node.cpp` 和 `src/ros/main.cpp` include 它。**
|
||||||
|
外部代码不要 include,按话题和服务对接就行。
|
||||||
|
|
||||||
|
## 加新东西放哪
|
||||||
|
|
||||||
|
| 要加的 | 放哪 |
|
||||||
|
|---|---|
|
||||||
|
| 新的消息 ⇄ core 转换函数 | `conversion.hpp` + `conversion.cpp`,写成纯函数,在 `test_ros_conversion` 里补用例 |
|
||||||
|
| 新的订阅 / 发布 / 服务 | `localization_node.hpp` + `localization_node.cpp` |
|
||||||
|
| 不依赖 ROS 的逻辑 | 不放这里,放 `core/` |
|
||||||
|
|
||||||
|
`src/ros/` 下的 `.cpp` 在 `xmake.lua` 里是逐个列出来的(不是通配),
|
||||||
|
加新的实现文件必须去 `field_localization_ros` 的文件列表里补一行。
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 怎么用这个节点:[`../../../src/ros/README.md`](../../../src/ros/README.md)
|
||||||
|
- 被适配的 core:[`../core/README.md`](../core/README.md)
|
||||||
|
- 测试:[`../../../tests/README.md`](../../../tests/README.md)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "field_localization/core/dataset.hpp"
|
||||||
|
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||||
|
#include <geometry_msgs/msg/transform.hpp>
|
||||||
|
#include <geometry_msgs/msg/twist.hpp>
|
||||||
|
#include <tf2_ros/buffer.hpp>
|
||||||
|
namespace rclcpp { class Node; }
|
||||||
|
namespace field_localization::ros {
|
||||||
|
core::PointCloud convert_cloud(const sensor_msgs::msg::PointCloud2 &msg);
|
||||||
|
core::PointCloud convert_cloud_in_frame(const sensor_msgs::msg::PointCloud2 &msg,
|
||||||
|
const std::string &frame,const tf2_ros::Buffer &buffer);
|
||||||
|
std::optional<core::MapBounds> declare_map_bounds(rclcpp::Node &node);
|
||||||
|
core::Pose3D from_transform(const geometry_msgs::msg::Transform &transform);
|
||||||
|
geometry_msgs::msg::Transform to_transform(const core::Pose3D &pose);
|
||||||
|
geometry_msgs::msg::Twist to_twist(const core::Twist3D &twist);
|
||||||
|
} // namespace field_localization::ros
|
||||||
@@ -1,42 +1,52 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "field_localization/ros/conversion.hpp"
|
||||||
#include "field_localization/core/localization_core.hpp"
|
|
||||||
#include "field_localization/core/types.hpp"
|
|
||||||
|
|
||||||
#include <rclcpp/rclcpp.hpp>
|
#include <rclcpp/rclcpp.hpp>
|
||||||
#include <sensor_msgs/msg/imu.hpp>
|
#include <sensor_msgs/msg/imu.hpp>
|
||||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
#include <nav_msgs/msg/odometry.hpp>
|
||||||
|
#include <std_msgs/msg/string.hpp>
|
||||||
#include <cstddef>
|
#include <std_srvs/srv/trigger.hpp>
|
||||||
#include <functional>
|
#include <tf2_ros/buffer.hpp>
|
||||||
#include <string>
|
#include <tf2_ros/transform_listener.hpp>
|
||||||
|
#include <tf2_ros/transform_broadcaster.hpp>
|
||||||
|
#include <deque>
|
||||||
|
#include <fstream>
|
||||||
|
#include <std_msgs/msg/bool.hpp>
|
||||||
|
#include "field_localization/core/tracking_health.hpp"
|
||||||
|
|
||||||
namespace field_localization::ros {
|
namespace field_localization::ros {
|
||||||
|
class LocalizationNode:public rclcpp::Node {
|
||||||
class LocalizationNode : public rclcpp::Node {
|
|
||||||
public:
|
public:
|
||||||
explicit LocalizationNode(
|
explicit LocalizationNode(const rclcpp::NodeOptions &options=rclcpp::NodeOptions());
|
||||||
const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
|
~LocalizationNode() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool ensure_core();
|
||||||
void on_point_cloud(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
|
void on_point_cloud(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
|
||||||
|
|
||||||
void on_imu(sensor_msgs::msg::Imu::ConstSharedPtr msg);
|
void on_imu(sensor_msgs::msg::Imu::ConstSharedPtr msg);
|
||||||
|
void drain_scans();
|
||||||
|
void publish_estimate();
|
||||||
void print_localization_status();
|
void print_localization_status();
|
||||||
|
bool check_clock();
|
||||||
rclcpp::TimerBase::SharedPtr status_timer_;
|
bool navigation_valid();
|
||||||
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr
|
void publish_health(bool heartbeat=false);
|
||||||
point_cloud_sub_;
|
core::CoreOptions core_options_;
|
||||||
|
std::unique_ptr<core::LocalizationCore> core_;
|
||||||
|
std::unique_ptr<tf2_ros::Buffer> tf_buffer_;
|
||||||
|
std::unique_ptr<tf2_ros::TransformListener> tf_listener_;
|
||||||
|
std::unique_ptr<tf2_ros::TransformBroadcaster> broadcaster_;
|
||||||
|
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr point_cloud_sub_;
|
||||||
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr imu_sub_;
|
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr imu_sub_;
|
||||||
|
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odometry_pub_;
|
||||||
std::string point_cloud_topic_;
|
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr status_pub_;
|
||||||
std::string imu_topic_;
|
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr save_service_,reset_service_;
|
||||||
core::LocalizationCore core_;
|
rclcpp::TimerBase::SharedPtr status_timer_,health_timer_;
|
||||||
|
rclcpp::Publisher<std_msgs::msg::Bool>::SharedPtr navigation_valid_pub_;
|
||||||
std::size_t point_cloud_count_{0};
|
core::TrackingHealth health_;
|
||||||
std::size_t imu_count_{0};
|
bool last_health_{false};
|
||||||
|
std::ofstream trace_;
|
||||||
|
std::deque<core::PointCloud> scans_;
|
||||||
|
std::deque<core::LocalizationSnapshot> pending_tf_;
|
||||||
|
std::string map_frame_,odom_frame_,base_frame_,imu_frame_,lidar_frame_,map_path_,export_path_;
|
||||||
|
bool publish_map_to_odom_{false},clock_rewound_{false};
|
||||||
|
double last_clock_{-1},last_published_{-1};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace field_localization::ros
|
} // namespace field_localization::ros
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# field_localization/src/ (实现文件)
|
||||||
|
|
||||||
|
C++ 实现的根目录,分三块:**纯算法核心**(`core/`)、**ROS 适配**(`ros/`)、**离线工具**(`tools/`)。
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── core/ ★ 纯算法核心(零 ROS,只用标准库和 Eigen)
|
||||||
|
│ ├── README.md
|
||||||
|
│ ├── imu_integration.cpp 旋转数学、IMU 积分、去畸变
|
||||||
|
│ ├── eskf.cpp 18 维误差状态滤波
|
||||||
|
│ ├── registration.cpp 体素地图、点到面配准、退化检测
|
||||||
|
│ ├── map_io.cpp 地图文件读写、关键帧判定
|
||||||
|
│ ├── localization_core.cpp 定位主流程
|
||||||
|
│ └── dataset.cpp 数据集读写、ATE/RPE、调优轨迹 CSV
|
||||||
|
├── ros/ ROS 适配
|
||||||
|
│ ├── README.md
|
||||||
|
│ ├── main.cpp 定位节点的入口
|
||||||
|
│ ├── localization_node.cpp 定位节点
|
||||||
|
│ └── conversion.cpp ROS 消息 ⇄ core 类型
|
||||||
|
└── tools/ 命令行工具
|
||||||
|
├── README.md
|
||||||
|
├── record.cpp 录数据集(ROS 节点)
|
||||||
|
└── replay.cpp 离线回放打分(不依赖 ROS)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 哪个文件编进哪个 target
|
||||||
|
|
||||||
|
定义都在 [`../xmake.lua`](../xmake.lua),产物统一落在 `build/bin/`。
|
||||||
|
|
||||||
|
| target | 类型 | 用到的文件 | 依赖 ROS |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `field_localization_core` | 静态库 | `core/*.cpp`(**通配**) | 否 |
|
||||||
|
| `field_localization_ros` | 动态库 | `ros/localization_node.cpp`、`ros/conversion.cpp`(逐个列出) | 是 |
|
||||||
|
| `field_localization_node` | 可执行 | `ros/main.cpp` | 是 |
|
||||||
|
| `field_localization_record` | 可执行 | `tools/record.cpp` | 是 |
|
||||||
|
| `field_localization_replay` | 可执行 | `tools/replay.cpp` | 否 |
|
||||||
|
|
||||||
|
此外还有 12 个测试 target,每个对应 `tests/` 里的一个 `test_*.cpp`,
|
||||||
|
除 `test_ros_conversion` 外都只依赖 `field_localization_core`。
|
||||||
|
|
||||||
|
## 构建和运行
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev # 仓库根
|
||||||
|
xmake # 编译,先 source ROS 环境
|
||||||
|
xmake test # 单元测试
|
||||||
|
```
|
||||||
|
|
||||||
|
本工程不用 ament / colcon,没有 `ros2 run`,产物直接按路径执行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
build/bin/field_localization_node --ros-args -p use_sim_time:=true ...
|
||||||
|
build/bin/field_localization_replay --dataset <目录> --mode localization --map <地图> --output <目录>
|
||||||
|
```
|
||||||
|
|
||||||
|
平时不用手敲:`scripts/sentry_up.sh` 和
|
||||||
|
[`sentry_arena.launch.py`](../../sentry_sim/launch/sentry_arena.launch.py) 会带好参数把节点拉起来。
|
||||||
|
|
||||||
|
## 这三层各管什么
|
||||||
|
|
||||||
|
| 层 | 该写 | 不该写 |
|
||||||
|
|---|---|---|
|
||||||
|
| `core/` | 滤波、积分、配准、地图、文件格式、有效性判定 | 订阅话题、读 ROS 参数、查 TF |
|
||||||
|
| `ros/` | 参数、话题、服务、TF、扫描排队、QoS | 数学和状态逻辑 |
|
||||||
|
| `tools/` | 命令行参数解析、文件输出、打印 | 算法(调用 core 就行) |
|
||||||
|
|
||||||
|
判据和 `sentry_nav` 相同:**这段代码去掉 `rclcpp` 还能写出来吗?** 能就放 `core/`。
|
||||||
|
|
||||||
|
## 加文件时要改哪里
|
||||||
|
|
||||||
|
| 加什么 | 放哪 | 改不改 `xmake.lua` |
|
||||||
|
|---|---|---|
|
||||||
|
| 新算法 | `core/xxx.cpp` | 不用(通配) |
|
||||||
|
| ROS 适配的新实现 | `ros/xxx.cpp` | **要**,加进 `field_localization_ros` 的文件列表 |
|
||||||
|
| 新的可执行文件 | `ros/` 或 `tools/` | **要**,新开一个 target |
|
||||||
|
| 新测试 | `tests/test_xxx.cpp` | **要**,新开一个 target 并 `add_tests` |
|
||||||
|
|
||||||
|
新开 target 时记得抄上 `set_targetdir("$(builddir)/bin")`,
|
||||||
|
否则产物会落到 xmake 默认的 `build/<平台>/<架构>/<模式>/`,和文档、脚本里的路径对不上。
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 算法细节:[`core/README.md`](core/README.md)
|
||||||
|
- 节点怎么用:[`ros/README.md`](ros/README.md)
|
||||||
|
- 工具怎么用:[`tools/README.md`](tools/README.md)
|
||||||
|
- 接口:[`../include/README.md`](../include/README.md)
|
||||||
|
- 测试:[`../tests/README.md`](../tests/README.md)
|
||||||
|
- 包总览:[`../README.md`](../README.md)
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
# field_localization/src/core/ (纯算法核心)
|
||||||
|
|
||||||
|
**这里的一切都必须能在没有 ROS、没有 Gazebo 的情况下编译和测试。**
|
||||||
|
|
||||||
|
六个实现文件编成静态库 `field_localization_core`,只依赖 C++ 标准库和
|
||||||
|
Eigen 3.4(系统 pkg-config 的 `eigen3`)。
|
||||||
|
接口在 [`../../include/field_localization/core/`](../../include/field_localization/core/README.md),
|
||||||
|
其中 `types.hpp` 和 `tracking_health.hpp` 只有头文件,没有对应的 `.cpp`。
|
||||||
|
|
||||||
|
```
|
||||||
|
core/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── imu_integration.cpp 旋转数学、IMU 中值积分、轨迹插值、点云去畸变
|
||||||
|
├── eskf.cpp 18 维误差状态滤波
|
||||||
|
├── registration.cpp 体素地图、点到面配准、退化检测
|
||||||
|
├── map_io.cpp FLMAP 地图读写、关键帧判定
|
||||||
|
├── localization_core.cpp 定位主流程(IMU 预测 + 激光更新)
|
||||||
|
└── dataset.cpp FLPC 点云、数据集配置、TUM 轨迹、ATE/RPE、调优 CSV
|
||||||
|
```
|
||||||
|
|
||||||
|
## 唯一的硬规则
|
||||||
|
|
||||||
|
> **不许 `#include` 任何 `rclcpp` / `tf2` / ROS 消息类型,也不许用 PCL。**
|
||||||
|
> 只允许 C++ 标准库和 Eigen。
|
||||||
|
|
||||||
|
`field_localization_core` 的 include 路径里没有 ROS 头文件,链接时也不碰 ROS,
|
||||||
|
所以违反了这条直接编不过。
|
||||||
|
|
||||||
|
本包 12 个测试里有 11 个、离线工具 `field_localization_replay` 都只链接这个库,
|
||||||
|
所以能用 `xmake test` 在不开 Gazebo 的情况下验证算法。
|
||||||
|
输入输出只用 `types.hpp` 里的几个结构体(`ImuData` / `PointCloud` / `Pose3D`),
|
||||||
|
ROS 消息的转换全部留在 `../ros/conversion.cpp`。
|
||||||
|
|
||||||
|
## 一帧数据走一遍的流程
|
||||||
|
|
||||||
|
`localization_core.cpp` 是入口,其余五个文件各管一段:
|
||||||
|
|
||||||
|
```
|
||||||
|
IMU 样本 ──▶ process_imu
|
||||||
|
├─ eskf.cpp propagate:中值积分推进一步,传播协方差
|
||||||
|
└─ 记进最近 2 秒的历史(imu_history_ / state_history_)
|
||||||
|
|
||||||
|
点云 ──────▶ process_point_cloud
|
||||||
|
├─ imu_integration.cpp scan_window + deskew:按 IMU 轨迹把点统一到扫描结束时刻
|
||||||
|
├─ eskf.cpp 重建「扫描结束时刻」的滤波状态 at_scan
|
||||||
|
├─ registration.cpp scan_to_map:在体素地图上做点到面迭代配准
|
||||||
|
│ └─ eskf.cpp correct_information:更新 at_scan
|
||||||
|
├─ eskf.cpp 从扫描结束时刻把状态重新传播到最新的 IMU
|
||||||
|
└─ map_io.cpp MAPPING 模式下,够新且无退化才插关键帧
|
||||||
|
```
|
||||||
|
|
||||||
|
## 六个文件各管什么
|
||||||
|
|
||||||
|
### `imu_integration.cpp`
|
||||||
|
|
||||||
|
- **旋转数学**:`skew`、`exp_so3`、`log_so3`,以及位姿的 `compose` / `inverse`
|
||||||
|
- `integrate_midpoint()`:两个样本的角速度和比力取平均、减零偏;姿态先用半步旋转更新,
|
||||||
|
再用更新后的姿态把比力转到 map 系,累加速度和位置
|
||||||
|
- `integrate_trajectory()`:沿一组 IMU 样本从初始状态积到 `end`,首尾用 `interpolate_imu()` 对齐到精确时刻
|
||||||
|
- `interpolate_motion()`:旋转 slerp,平移用三次 Hermite 插值(带上两端速度),匀加速运动插值不出错
|
||||||
|
- `deskew()`:取扫描结束时刻的位姿作参考,把每个点按它自己采集时刻的传感器位姿变换过去。
|
||||||
|
非有限的点直接丢
|
||||||
|
- `preintegrate()`:目前只有 `test_imu_integration` 在用,滤波器走的是 `integrate_midpoint`
|
||||||
|
|
||||||
|
### `eskf.cpp`
|
||||||
|
|
||||||
|
18 维误差状态:位置 3、速度 3、姿态误差 3(右扰动)、陀螺零偏 3、加计零偏 3、重力 3。
|
||||||
|
|
||||||
|
- `propagate()`:状态转移矩阵取到二阶(`I + F·dt + ½F²·dt²`),过程噪声 `½·dt·(Qc + Φ·Qc·Φᵀ)`。
|
||||||
|
**再加一项积分误差**:相邻两个样本的加速度、角速度差得越多,这一步注入的不确定度越大
|
||||||
|
(`integration_error_scale`)。有了这一项,无噪声仿真里的接触冲击不会被误当成加计零偏
|
||||||
|
- `update()`:`S = H·P·Hᵀ + R`,新息门限按**实际量测秩**查卡方 99.9% 分位表;
|
||||||
|
协方差用 Joseph 形式更新,姿态误差注入后用右雅可比重置;
|
||||||
|
更新完检查协方差正定,不正定就整步放弃
|
||||||
|
- `correct_pose()`:先把不可观的方向从量测里投影掉再算增益。只投影增益的位姿行不行,
|
||||||
|
不可观的新息会顺着相关性污染速度和零偏
|
||||||
|
- `correct_information()`:把 6×6 信息矩阵白化成等效量测。迭代过程中线性化点在变,
|
||||||
|
切空间要用右雅可比搬到固定先验的坐标下
|
||||||
|
- 所有入口遇到非有限输入、非法时间间隔都返回 `false`,不抛异常
|
||||||
|
|
||||||
|
### `registration.cpp`
|
||||||
|
|
||||||
|
- `VoxelMap`:体素哈希表,每个体素只留第一个点。`plane()` 的拟合结果按体素缓存,
|
||||||
|
地图一变(`insert()` / `clear()`)缓存作废
|
||||||
|
- `VoxelMap::plane()`:在 `radius` 邻域里找点,至少 5 个,取最近的至多 20 个做主成分分析;
|
||||||
|
最小特征值与第二小特征值之比小于 0.03 才算平面
|
||||||
|
- `linearize()`(文件内私有):对每个点找对应平面、算点到面残差和 Huber 权重,
|
||||||
|
累加 6×6 的 Hessian 和梯度,同时数出 `AssociationCounts`
|
||||||
|
- `detect_degeneracy()`:对信息矩阵做 SVD,奇异值低于阈值的方向是退化方向,其余是可观方向(`projector`)。
|
||||||
|
配准只更新可观方向
|
||||||
|
- `scan_to_map()`:迭代配准。阶段和失败原因见接口说明里的
|
||||||
|
[`registration.hpp`](../../include/field_localization/core/README.md)
|
||||||
|
- Hessian 按内点数归一化之后才做退化检测
|
||||||
|
|
||||||
|
### `map_io.cpp`
|
||||||
|
|
||||||
|
- `save_map()` / `read_map()`:FLMAP v1 二进制地图。保存是先写临时文件再改名;
|
||||||
|
读取时核对魔数、版本号和文件长度
|
||||||
|
- `new_keyframe()`:位移严格大于 0.5 m 或旋转严格大于 10° 才算新关键帧
|
||||||
|
|
||||||
|
### `localization_core.cpp`
|
||||||
|
|
||||||
|
定位主流程,把上面几样串起来。
|
||||||
|
|
||||||
|
- 构造:用已知初始位姿和 `base_from_imu` 初始化滤波器
|
||||||
|
- `process_imu()`:输入检查 → 传播 → 记历史。
|
||||||
|
IMU 断档(间隔超过 `maximum_imu_gap`)时把协方差对角线加 1.0 并清空历史,报 `IMU_GAP`;
|
||||||
|
IMU 时间比最近一帧点云晚 0.3 s 以上,报 `LIDAR_TIMEOUT`
|
||||||
|
- `process_point_cloud()`:输入检查 → 等 IMU 覆盖整个扫描窗口 → 去畸变 → 配准 → 成功后重新传播、
|
||||||
|
更新位姿、必要时插关键帧。配准失败只记原因,不动状态
|
||||||
|
- 地图点数少于 5 个时:`MAPPING` 模式拿这一帧直接播种(第一个关键帧),`LOCALIZATION` 模式报 `MAP_UNAVAILABLE`
|
||||||
|
- `set_pose()` / `reset()`:回到已知初始位姿,清空历史,等新的 IMU。没有全局搜索
|
||||||
|
|
||||||
|
### `dataset.cpp`
|
||||||
|
|
||||||
|
- `write_cloud()` / `read_cloud()`:FLPC v1 点云文件,读取时核对魔数、版本号和文件长度
|
||||||
|
- `write_dataset_config()` / `read_dataset_config()`:数据集目录里的 `config.txt`
|
||||||
|
- `read_trajectory()` / `trajectory_pose()`:TUM 文本轨迹;真值间隔超过上限时拒绝插值
|
||||||
|
- `evaluate()`:未对齐的 ATE(平移、旋转)和 1 秒相对位姿误差 RPE
|
||||||
|
- `write_filter_trace_header()` / `write_filter_trace()`:调优 CSV,每帧把状态、18×18 协方差、
|
||||||
|
6×6 信息矩阵、梯度、奇异值、配准阶段和关联计数都写出来
|
||||||
|
- `mode_name()` / `reason_name()`:枚举转字符串
|
||||||
|
|
||||||
|
## 加新算法的流程
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# ① 头文件(别 include ROS)
|
||||||
|
vim include/field_localization/core/xxx.hpp
|
||||||
|
|
||||||
|
# ② 实现(放这里,xmake.lua 不用改)
|
||||||
|
vim src/core/xxx.cpp
|
||||||
|
|
||||||
|
# ③ 测试
|
||||||
|
vim tests/test_xxx.cpp # 同时到 xmake.lua 加一个 target
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev && xmake test
|
||||||
|
```
|
||||||
|
|
||||||
|
**这三步不需要 Gazebo。** 跑通了再接 ROS:在 `../ros/localization_node.cpp` 里读参数、订阅话题、调用它。
|
||||||
|
|
||||||
|
## 判据(写代码时问自己一句)
|
||||||
|
|
||||||
|
> **这段逻辑需要 `#include <rclcpp/...>` 吗?**
|
||||||
|
>
|
||||||
|
> - 不需要 → 放这儿,配不依赖 ROS 的测试
|
||||||
|
> - 需要 → 放 `../ros/`,靠跑仿真验证
|
||||||
|
|
||||||
|
| 逻辑 | 放哪 | 为什么 |
|
||||||
|
|---|---|---|
|
||||||
|
| 点到面残差、Huber 权重 | **这里** | 纯数学 |
|
||||||
|
| 把 `PointCloud2` 转成 `PointCloud` | `../ros/conversion.cpp` | 要消息类型 |
|
||||||
|
| 判断定位能否用于导航 | **这里**(`tracking_health.hpp`) | 只看协方差和时间戳 |
|
||||||
|
| 查 `odom → base_link` 的 TF 再合成 `map → odom` | `../ros/localization_node.cpp` | 要 TF |
|
||||||
|
| 地图文件格式 | **这里** | 只读写文件 |
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 接口和默认值速查:[`../../include/field_localization/core/README.md`](../../include/field_localization/core/README.md)
|
||||||
|
- 测试:[`../../tests/README.md`](../../tests/README.md)
|
||||||
|
- ROS 适配:[`../ros/README.md`](../ros/README.md)
|
||||||
|
- 包总览:[`../../README.md`](../../README.md)
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
#include "field_localization/core/dataset.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <bit>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
namespace {
|
||||||
|
template<class T> void write(std::ostream &out,T value) {
|
||||||
|
auto bytes=std::bit_cast<std::array<char,sizeof(T)>>(value);
|
||||||
|
if constexpr(std::endian::native==std::endian::big) std::reverse(bytes.begin(),bytes.end());
|
||||||
|
out.write(bytes.data(),bytes.size());
|
||||||
|
}
|
||||||
|
template<class T> T read(std::istream &in) {
|
||||||
|
std::array<char,sizeof(T)> bytes{}; in.read(bytes.data(),bytes.size());
|
||||||
|
if (!in) throw std::runtime_error("truncated cloud");
|
||||||
|
if constexpr(std::endian::native==std::endian::big) std::reverse(bytes.begin(),bytes.end());
|
||||||
|
return std::bit_cast<T>(bytes);
|
||||||
|
}
|
||||||
|
Pose3D parse_pose(std::istream &in) {
|
||||||
|
Pose3D p; double x=0,y=0,z=0,w=0;
|
||||||
|
in>>p.translation.x()>>p.translation.y()>>p.translation.z()>>x>>y>>z>>w;
|
||||||
|
p.rotation=Eigen::Quaterniond{w,x,y,z};
|
||||||
|
if (!in || !p.translation.allFinite() || !p.rotation.coeffs().allFinite() || p.rotation.norm()<1e-12)
|
||||||
|
throw std::runtime_error("invalid pose record");
|
||||||
|
p.rotation.normalize(); return p;
|
||||||
|
}
|
||||||
|
void pose_fields(std::ostream &out,const Pose3D &p) {
|
||||||
|
out<<std::setprecision(17)<<p.translation.x()<<' '<<p.translation.y()<<' '<<p.translation.z()<<' '
|
||||||
|
<<p.rotation.x()<<' '<<p.rotation.y()<<' '<<p.rotation.z()<<' '<<p.rotation.w();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void write_cloud(const PointCloud &cloud,const std::filesystem::path &path) {
|
||||||
|
if (!std::isfinite(cloud.timestamp_sec) || cloud.points.size()>1000000) throw std::runtime_error("invalid cloud record");
|
||||||
|
std::ofstream out(path,std::ios::binary); out.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
out.write("FLPC0001",8); write<std::uint32_t>(out,1); write<double>(out,cloud.timestamp_sec);
|
||||||
|
write<std::uint32_t>(out,static_cast<std::uint32_t>(cloud.points.size()));
|
||||||
|
for (const auto &p:cloud.points) {
|
||||||
|
write<double>(out,p.timestamp_sec);
|
||||||
|
for (int j=0;j<3;++j) write<float>(out,p.position[j]);
|
||||||
|
write<float>(out,p.intensity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PointCloud read_cloud(const std::filesystem::path &path,const std::string &frame) {
|
||||||
|
std::ifstream in(path,std::ios::binary); std::array<char,8> magic{};
|
||||||
|
in.read(magic.data(),magic.size());
|
||||||
|
if (std::string(magic.data(),magic.size())!="FLPC0001" || read<std::uint32_t>(in)!=1)
|
||||||
|
throw std::runtime_error("unsupported cloud format");
|
||||||
|
PointCloud cloud; cloud.frame_id=frame; cloud.timestamp_sec=read<double>(in);
|
||||||
|
const auto count=read<std::uint32_t>(in);
|
||||||
|
if (!std::isfinite(cloud.timestamp_sec) || count>1000000 || std::filesystem::file_size(path)!=24+std::uint64_t(count)*24)
|
||||||
|
throw std::runtime_error("invalid cloud size");
|
||||||
|
cloud.points.reserve(count);
|
||||||
|
for (std::uint32_t i=0;i<count;++i) {
|
||||||
|
PointXYZI p; p.timestamp_sec=read<double>(in);
|
||||||
|
for (int j=0;j<3;++j) p.position[j]=read<float>(in);
|
||||||
|
p.intensity=read<float>(in);
|
||||||
|
cloud.points.push_back(p);
|
||||||
|
}
|
||||||
|
return cloud;
|
||||||
|
}
|
||||||
|
void write_dataset_config(const CoreOptions &o,const std::filesystem::path &path,const std::string &cloud_frame) {
|
||||||
|
std::ofstream out(path); out.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
out<<"FIELD_LIO_DATASET 1\ninitial_pose "; pose_fields(out,o.initial_pose);
|
||||||
|
out<<"\nbase_from_imu "; pose_fields(out,o.base_from_imu);
|
||||||
|
out<<"\nimu_from_lidar "; pose_fields(out,o.deskew.imu_from_sensor);
|
||||||
|
out<<"\nscan_timing "<<static_cast<int>(o.deskew.timing)<<' '<<o.deskew.period_sec<<' '
|
||||||
|
<<o.deskew.start_angle_rad<<' '<<o.deskew.counterclockwise<<' '<<o.deskew.stamp_at_end<<'\n';
|
||||||
|
// Version 1 originally assumed lidar_link and the legacy field name denotes the recorded scan extrinsic.
|
||||||
|
if (cloud_frame!="lidar_link") out<<"cloud_frame "<<cloud_frame<<'\n';
|
||||||
|
if (o.map_bounds) out<<"map_bounds "<<o.map_bounds->min.transpose()<<' '<<o.map_bounds->max.transpose()<<'\n';
|
||||||
|
}
|
||||||
|
CoreOptions read_dataset_config(const std::filesystem::path &path,std::string *cloud_frame) {
|
||||||
|
std::ifstream in(path); std::string token; int version=0;
|
||||||
|
in>>token>>version;
|
||||||
|
if (!in || token!="FIELD_LIO_DATASET" || version!=1) throw std::runtime_error("unsupported dataset");
|
||||||
|
CoreOptions o;
|
||||||
|
auto named_pose=[&](const char *name) { in>>token; if (token!=name) throw std::runtime_error("invalid dataset extrinsics"); return parse_pose(in); };
|
||||||
|
o.initial_pose=named_pose("initial_pose"); o.base_from_imu=named_pose("base_from_imu");
|
||||||
|
o.deskew.imu_from_sensor=named_pose("imu_from_lidar");
|
||||||
|
int timing=0; in>>token>>timing>>o.deskew.period_sec>>o.deskew.start_angle_rad>>o.deskew.counterclockwise>>o.deskew.stamp_at_end;
|
||||||
|
if (!in || token!="scan_timing" || timing<0 || timing>2 || !std::isfinite(o.deskew.period_sec) || o.deskew.period_sec<=0)
|
||||||
|
throw std::runtime_error("invalid dataset timing");
|
||||||
|
o.deskew.timing=static_cast<ScanTiming>(timing);
|
||||||
|
std::string frame="lidar_link";
|
||||||
|
bool frame_set=false;
|
||||||
|
while (in>>token) {
|
||||||
|
if (token=="cloud_frame" && !frame_set && in>>frame) {
|
||||||
|
frame_set=true;
|
||||||
|
} else if (token=="map_bounds" && !o.map_bounds) {
|
||||||
|
MapBounds bounds;
|
||||||
|
for (int axis=0;axis<3;++axis) in>>bounds.min[axis];
|
||||||
|
for (int axis=0;axis<3;++axis) in>>bounds.max[axis];
|
||||||
|
if (!in || !bounds.valid()) throw std::runtime_error("invalid dataset map bounds");
|
||||||
|
o.map_bounds=bounds;
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("invalid dataset field: "+token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cloud_frame) *cloud_frame=frame;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
void write_trajectory_sample(std::ostream &out,const TrajectorySample &sample) {
|
||||||
|
out<<std::setprecision(17)<<sample.time<<' '; pose_fields(out,sample.pose); out<<'\n';
|
||||||
|
}
|
||||||
|
std::vector<TrajectorySample> read_trajectory(const std::filesystem::path &path) {
|
||||||
|
std::ifstream in(path); if (!in) throw std::runtime_error("cannot open trajectory: "+path.string());
|
||||||
|
std::vector<TrajectorySample> result; std::string line;
|
||||||
|
while (std::getline(in,line)) {
|
||||||
|
if (line.empty() || line[0]=='#') continue;
|
||||||
|
std::istringstream row(line); double time=0; row>>time; auto pose=parse_pose(row);
|
||||||
|
if (!std::isfinite(time) || (!result.empty() && time<=result.back().time)) throw std::runtime_error("trajectory time order");
|
||||||
|
result.push_back({time,pose});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
std::optional<Pose3D> trajectory_pose(std::span<const TrajectorySample> samples,double time,double gap) {
|
||||||
|
const auto b=std::lower_bound(samples.begin(),samples.end(),time,[](const auto &s,double t) { return s.time<t; });
|
||||||
|
if (b==samples.end()) return std::nullopt;
|
||||||
|
if (std::abs(b->time-time)<1e-9) return b->pose;
|
||||||
|
if (b==samples.begin()) return std::nullopt;
|
||||||
|
const auto &a=*(b-1);
|
||||||
|
if (b->time-a.time>gap+1e-9) return std::nullopt;
|
||||||
|
const double u=(time-a.time)/(b->time-a.time);
|
||||||
|
return Pose3D{a.pose.rotation.slerp(u,b->pose.rotation),(1-u)*a.pose.translation+u*b->pose.translation};
|
||||||
|
}
|
||||||
|
Evaluation evaluate(std::span<const TrajectorySample> estimate,std::span<const TrajectorySample> truth) {
|
||||||
|
Evaluation result; result.total=estimate.size();
|
||||||
|
for (const auto &s:estimate) {
|
||||||
|
const auto gt=trajectory_pose(truth,s.time); if (!gt) continue;
|
||||||
|
result.ate_translation+=(s.pose.translation-gt->translation).squaredNorm();
|
||||||
|
result.ate_rotation_rad+=log_so3(gt->rotation.conjugate()*s.pose.rotation).squaredNorm(); ++result.matched;
|
||||||
|
const auto next_est=trajectory_pose(estimate,s.time+1.0,0.15),next_gt=trajectory_pose(truth,s.time+1.0);
|
||||||
|
if (!next_est || !next_gt) continue;
|
||||||
|
const Pose3D relative_truth=compose(inverse(*gt),*next_gt),relative_est=compose(inverse(s.pose),*next_est);
|
||||||
|
const Pose3D error=compose(inverse(relative_truth),relative_est);
|
||||||
|
result.rpe_translation+=error.translation.squaredNorm(); result.rpe_rotation_rad+=log_so3(error.rotation).squaredNorm();
|
||||||
|
++result.relative_pairs;
|
||||||
|
}
|
||||||
|
if (result.matched) { result.ate_translation=std::sqrt(result.ate_translation/result.matched); result.ate_rotation_rad=std::sqrt(result.ate_rotation_rad/result.matched); }
|
||||||
|
if (result.relative_pairs) { result.rpe_translation=std::sqrt(result.rpe_translation/result.relative_pairs); result.rpe_rotation_rad=std::sqrt(result.rpe_rotation_rad/result.relative_pairs); }
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
void write_filter_trace_header(std::ostream &out) {
|
||||||
|
out<<"scan_time,phase,px,py,pz,vx,vy,vz,qx,qy,qz,qw,bgx,bgy,bgz,bax,bay,baz,gx,gy,gz,mode,reason,registration_failure,nis,rank,residual_available,rmse,inliers,degenerate";
|
||||||
|
for(int i=0;i<18;++i) for(int j=0;j<18;++j) out<<",P"<<i<<"_"<<j;
|
||||||
|
for(int i=0;i<6;++i) for(int j=0;j<6;++j) out<<",H"<<i<<"_"<<j;
|
||||||
|
for(int i=0;i<6;++i) out<<",gradient"<<i;
|
||||||
|
for(int i=0;i<6;++i) out<<",singular"<<i;
|
||||||
|
out<<",registration_stage,registration_failure_name";
|
||||||
|
for (const char *phase:{"initial","last"}) {
|
||||||
|
for (const char *field:{"sampled","planes","outside_support","distance_rejected","inliers"})
|
||||||
|
out<<','<<phase<<'_'<<field;
|
||||||
|
}
|
||||||
|
out<<'\n';
|
||||||
|
}
|
||||||
|
void write_filter_trace(std::ostream &out,double time,const char *phase,const FilterSnapshot &f,const LocalizationStatus &status) {
|
||||||
|
const auto &s=f.state; out<<std::setprecision(17)<<time<<','<<phase;
|
||||||
|
for(const auto &v:{s.pose.translation,s.velocity}) for(int i=0;i<3;++i) out<<','<<v[i];
|
||||||
|
for(int i=0;i<4;++i) out<<','<<s.pose.rotation.coeffs()[i];
|
||||||
|
for(const auto &v:{s.gyro_bias,s.accel_bias,s.gravity}) for(int i=0;i<3;++i) out<<','<<v[i];
|
||||||
|
out<<','<<mode_name(status.mode)<<','<<reason_name(status.reason)<<','<<static_cast<int>(status.registration.failure)
|
||||||
|
<<','<<status.registration.nis<<','<<status.registration.measurement_rank<<','<<status.registration_residual_available
|
||||||
|
<<','<<status.registration_rmse<<','<<status.inlier_count<<','<<status.degenerate_dimensions;
|
||||||
|
for(int i=0;i<18;++i) for(int j=0;j<18;++j) out<<','<<f.covariance(i,j);
|
||||||
|
for(int i=0;i<6;++i) for(int j=0;j<6;++j) out<<','<<status.registration.information(i,j);
|
||||||
|
for(int i=0;i<6;++i) out<<','<<status.registration.gradient[i];
|
||||||
|
for(int i=0;i<6;++i) out<<','<<status.information_singular_values[i];
|
||||||
|
const auto ®=status.registration;
|
||||||
|
out<<','<<registration_stage_name(reg.stage)<<','<<registration_failure_name(reg.failure);
|
||||||
|
for (const auto &counts:{reg.initial_associations,reg.last_associations})
|
||||||
|
out<<','<<counts.sampled<<','<<counts.candidate_planes<<','<<counts.outside_support
|
||||||
|
<<','<<counts.plane_distance_rejected<<','<<counts.inliers;
|
||||||
|
out<<'\n';
|
||||||
|
}
|
||||||
|
const char *mode_name(TrackingMode mode) { return mode==TrackingMode::FULL ? "FULL" : "IMU_ONLY"; }
|
||||||
|
const char *reason_name(FailureReason reason) {
|
||||||
|
switch(reason) {
|
||||||
|
case FailureReason::INITIALIZING:return "INITIALIZING"; case FailureReason::NONE:return "NONE";
|
||||||
|
case FailureReason::NO_VALID_POINTS:return "NO_VALID_POINTS"; case FailureReason::INVALID_INPUT:return "INVALID_INPUT";
|
||||||
|
case FailureReason::TIME_ORDER:return "TIME_ORDER"; case FailureReason::IMU_GAP:return "IMU_GAP";
|
||||||
|
case FailureReason::IMU_COVERAGE:return "IMU_COVERAGE"; case FailureReason::REGISTRATION_FAILED:return "REGISTRATION_FAILED";
|
||||||
|
case FailureReason::LIDAR_TIMEOUT:return "LIDAR_TIMEOUT"; case FailureReason::MAP_UNAVAILABLE:return "MAP_UNAVAILABLE";
|
||||||
|
}
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
#include "field_localization/core/eskf.hpp"
|
||||||
|
#include <Eigen/Cholesky>
|
||||||
|
#include <Eigen/Eigenvalues>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
namespace {
|
||||||
|
Eigen::Matrix3d right_jacobian(const Eigen::Vector3d &v) {
|
||||||
|
const double t=v.norm(); const Eigen::Matrix3d a=skew(v);
|
||||||
|
if(t<1e-5) return Eigen::Matrix3d::Identity()-0.5*a+(1.0/6.0)*a*a;
|
||||||
|
return Eigen::Matrix3d::Identity()-(1-std::cos(t))/(t*t)*a+(t-std::sin(t))/(t*t*t)*a*a;
|
||||||
|
}
|
||||||
|
bool valid_state(const MotionState &s) {
|
||||||
|
return std::isfinite(s.timestamp_sec) && s.pose.translation.allFinite() &&
|
||||||
|
s.pose.rotation.coeffs().allFinite() && std::abs(s.pose.rotation.norm()-1)<1e-8 &&
|
||||||
|
s.velocity.allFinite() && s.gyro_bias.allFinite() && s.accel_bias.allFinite() && s.gravity.allFinite();
|
||||||
|
}
|
||||||
|
Eigen::Matrix<double,6,18> pose_selector() {
|
||||||
|
Eigen::Matrix<double,6,18> h=Eigen::Matrix<double,6,18>::Zero();
|
||||||
|
h.block<3,3>(0,0).setIdentity(); h.block<3,3>(3,6).setIdentity(); return h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ErrorStateFilter::ErrorStateFilter(const NoiseOptions &noise):noise_(noise) {
|
||||||
|
for (const double value:{noise.gyro,noise.accel,noise.gyro_bias_walk,noise.accel_bias_walk,noise.gravity_walk,noise.integration_error_scale})
|
||||||
|
if (!std::isfinite(value) || value<0) throw std::invalid_argument("invalid IMU noise density");
|
||||||
|
if (!std::isfinite(noise.maximum_imu_gap) || noise.maximum_imu_gap<=0)
|
||||||
|
throw std::invalid_argument("invalid maximum IMU gap");
|
||||||
|
initialize({});
|
||||||
|
}
|
||||||
|
void ErrorStateFilter::initialize(const MotionState &state) {
|
||||||
|
estimate_.state=state; estimate_.state.pose.rotation.normalize();
|
||||||
|
estimate_.covariance.setZero();
|
||||||
|
estimate_.covariance.diagonal() << 0.01,0.01,0.01, 1,1,1, 0.01,0.01,0.01,
|
||||||
|
0.01,0.01,0.01, 0.25,0.25,0.25, 0.01,0.01,0.01;
|
||||||
|
}
|
||||||
|
bool ErrorStateFilter::propagate(const ImuData &a, const ImuData &b) {
|
||||||
|
const double dt=b.timestamp_sec-a.timestamp_sec;
|
||||||
|
if (!valid_imu(a) || !valid_imu(b) || dt<=0 || dt>noise_.maximum_imu_gap ||
|
||||||
|
std::abs(a.timestamp_sec-estimate_.state.timestamp_sec)>1e-8) return false;
|
||||||
|
const auto &s=estimate_.state;
|
||||||
|
const Eigen::Vector3d w=0.5*(a.angular_velocity+b.angular_velocity)-s.gyro_bias;
|
||||||
|
const Eigen::Vector3d acc=0.5*(a.linear_acceleration+b.linear_acceleration)-s.accel_bias;
|
||||||
|
const Eigen::Matrix3d r=(s.pose.rotation*exp_so3(0.5*dt*w)).toRotationMatrix();
|
||||||
|
Matrix18 f=Matrix18::Zero();
|
||||||
|
f.block<3,3>(0,3).setIdentity();
|
||||||
|
f.block<3,3>(3,6)=-r*skew(acc); f.block<3,3>(3,12)=-r; f.block<3,3>(3,15).setIdentity();
|
||||||
|
f.block<3,3>(6,6)=-skew(w); f.block<3,3>(6,9)=-Eigen::Matrix3d::Identity();
|
||||||
|
const Matrix18 phi=Matrix18::Identity()+f*dt+0.5*f*f*dt*dt;
|
||||||
|
Matrix18 qc=Matrix18::Zero();
|
||||||
|
qc.block<3,3>(3,3).diagonal().setConstant(noise_.accel*noise_.accel);
|
||||||
|
qc.block<3,3>(6,6).diagonal().setConstant(noise_.gyro*noise_.gyro);
|
||||||
|
qc.block<3,3>(9,9).diagonal().setConstant(noise_.gyro_bias_walk*noise_.gyro_bias_walk);
|
||||||
|
qc.block<3,3>(12,12).diagonal().setConstant(noise_.accel_bias_walk*noise_.accel_bias_walk);
|
||||||
|
qc.block<3,3>(15,15).diagonal().setConstant(noise_.gravity_walk*noise_.gravity_walk);
|
||||||
|
Matrix18 covariance=phi*estimate_.covariance*phi.transpose()+0.5*dt*(qc+phi*qc*phi.transpose());
|
||||||
|
// Noiseless samples can still alias fast contact/jerk dynamics. Do not let a
|
||||||
|
// trapezoidal velocity error masquerade as an observable accelerometer bias.
|
||||||
|
Eigen::Matrix<double,18,6> quadrature=Eigen::Matrix<double,18,6>::Zero();
|
||||||
|
quadrature.block<3,3>(0,0)=0.5*dt*r; quadrature.block<3,3>(3,0)=r;
|
||||||
|
quadrature.block<3,3>(6,3).setIdentity();
|
||||||
|
Vector6 variation;
|
||||||
|
variation << b.linear_acceleration-a.linear_acceleration,b.angular_velocity-a.angular_velocity;
|
||||||
|
const Vector6 variance=(noise_.integration_error_scale*dt*variation).array().square().matrix();
|
||||||
|
covariance.noalias()+=quadrature*variance.asDiagonal()*quadrature.transpose();
|
||||||
|
const auto next=integrate_midpoint(s,a,b);
|
||||||
|
if (!covariance.allFinite() || !valid_state(next)) return false;
|
||||||
|
estimate_.state=next;
|
||||||
|
estimate_.covariance=0.5*(covariance+covariance.transpose()).eval();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
MotionState ErrorStateFilter::inject(const MotionState &s,const Vector18 &e) {
|
||||||
|
MotionState out=s;
|
||||||
|
out.pose.translation+=e.segment<3>(0); out.velocity+=e.segment<3>(3);
|
||||||
|
out.pose.rotation=(s.pose.rotation*exp_so3(e.segment<3>(6))).normalized();
|
||||||
|
out.gyro_bias+=e.segment<3>(9); out.accel_bias+=e.segment<3>(12); out.gravity+=e.segment<3>(15);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
Vector18 ErrorStateFilter::difference(const MotionState &a,const MotionState &b) {
|
||||||
|
Vector18 d;
|
||||||
|
d << b.pose.translation-a.pose.translation,b.velocity-a.velocity,
|
||||||
|
log_so3(a.pose.rotation.conjugate()*b.pose.rotation),b.gyro_bias-a.gyro_bias,
|
||||||
|
b.accel_bias-a.accel_bias,b.gravity-a.gravity;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
bool ErrorStateFilter::update(const FilterSnapshot &prior,const Eigen::Matrix<double,6,18> &h,
|
||||||
|
const Vector6 &innovation,const Matrix6 &noise,const Matrix6 &projector,InnovationCheck gate) {
|
||||||
|
if(!h.allFinite() || !innovation.allFinite() || !noise.allFinite() || !projector.allFinite()) return false;
|
||||||
|
const Eigen::SelfAdjointEigenSolver<Matrix6> spectrum(h*h.transpose());
|
||||||
|
if(spectrum.info()!=Eigen::Success) return false;
|
||||||
|
measurement_rank_=0;
|
||||||
|
for(double v:spectrum.eigenvalues()) if(v>1e-10*std::max(1.0,spectrum.eigenvalues().maxCoeff())) ++measurement_rank_;
|
||||||
|
if(measurement_rank_==0) return false;
|
||||||
|
const Matrix6 s=h*prior.covariance*h.transpose()+noise;
|
||||||
|
const Eigen::LDLT<Matrix6> solver(s);
|
||||||
|
if (solver.info()!=Eigen::Success || !solver.isPositive()) return false;
|
||||||
|
last_nis_=innovation.dot(solver.solve(innovation));
|
||||||
|
// Chi-square 99.9% bounds for the retained measurement rank, not always six DOF.
|
||||||
|
constexpr double gates[]{0,10.827566,13.815511,16.266236,18.466827,20.515006,22.457744};
|
||||||
|
if(!std::isfinite(last_nis_) || (gate==InnovationCheck::FINAL && last_nis_>gates[measurement_rank_])) return false;
|
||||||
|
Eigen::Matrix<double,18,6> k=prior.covariance*h.transpose()*solver.solve(Matrix6::Identity());
|
||||||
|
const auto selector=pose_selector();
|
||||||
|
const Eigen::Matrix<double,6,6> pose_k=projector*(selector*k);
|
||||||
|
k.block<3,6>(0,0)=pose_k.topRows<3>(); k.block<3,6>(6,0)=pose_k.bottomRows<3>();
|
||||||
|
const Vector18 correction=k*innovation;
|
||||||
|
if (!correction.allFinite()) return false;
|
||||||
|
Matrix18 a=Matrix18::Identity()-k*h;
|
||||||
|
Matrix18 p=a*prior.covariance*a.transpose()+k*noise*k.transpose();
|
||||||
|
Matrix18 reset=Matrix18::Identity(); reset.block<3,3>(6,6)=right_jacobian(correction.segment<3>(6));
|
||||||
|
p=reset*p*reset.transpose();
|
||||||
|
p=0.5*(p+p.transpose()).eval();
|
||||||
|
if (!p.allFinite() || p.diagonal().minCoeff() < -1e-10) return false;
|
||||||
|
const auto next=inject(prior.state,correction);
|
||||||
|
if (!valid_state(next)) return false;
|
||||||
|
const Eigen::LDLT<Matrix18> check(p);
|
||||||
|
if(check.info()!=Eigen::Success || check.vectorD().minCoeff() < -1e-10) return false;
|
||||||
|
estimate_={next,p}; return true;
|
||||||
|
}
|
||||||
|
bool ErrorStateFilter::correct_pose(const Pose3D &measurement,const Matrix6 &noise,const Matrix6 &projector) {
|
||||||
|
if (!measurement.translation.allFinite() || !measurement.rotation.coeffs().allFinite() ||
|
||||||
|
measurement.rotation.norm()<1e-12 || !noise.allFinite()) return false;
|
||||||
|
Vector6 innovation;
|
||||||
|
innovation << measurement.translation-estimate_.state.pose.translation,
|
||||||
|
log_so3(estimate_.state.pose.rotation.conjugate()*measurement.rotation);
|
||||||
|
// Remove unavailable measurements before computing ANY state gain. Projecting only
|
||||||
|
// pose rows of K lets unobserved innovations corrupt correlated velocity and biases.
|
||||||
|
const Matrix6 r=projector*noise*projector.transpose()+Matrix6::Identity()-projector;
|
||||||
|
return update(estimate_,projector*pose_selector(),projector*innovation,r,projector);
|
||||||
|
}
|
||||||
|
bool ErrorStateFilter::correct_information(const FilterSnapshot &prior,const MotionState &linearization,
|
||||||
|
const Matrix6 &information,const Vector6 &gradient,const Matrix6 &projector,const Matrix6 &model_covariance,InnovationCheck gate) {
|
||||||
|
const Matrix6 retained_information=projector*information*projector.transpose();
|
||||||
|
const Vector6 retained_gradient=projector*gradient;
|
||||||
|
const Eigen::SelfAdjointEigenSolver<Matrix6> eig(retained_information);
|
||||||
|
if (eig.info()!=Eigen::Success || !gradient.allFinite()) return false;
|
||||||
|
const Vector6 d=pose_selector()*difference(prior.state,linearization);
|
||||||
|
Matrix6 whitening=Matrix6::Zero(); Vector6 innovation=Vector6::Zero();
|
||||||
|
for (int i=0;i<6;++i) {
|
||||||
|
const double value=eig.eigenvalues()[i];
|
||||||
|
if (value<=1e-9) continue;
|
||||||
|
whitening.row(i)=std::sqrt(value)*eig.eigenvectors().col(i).transpose();
|
||||||
|
innovation[i]=whitening.row(i).dot(d)-eig.eigenvectors().col(i).dot(retained_gradient)/std::sqrt(value);
|
||||||
|
}
|
||||||
|
Matrix18 tangent=Matrix18::Identity();
|
||||||
|
tangent.block<3,3>(6,6)=right_jacobian(d.tail<3>());
|
||||||
|
const Eigen::Matrix<double,6,18> h=whitening*pose_selector()*tangent;
|
||||||
|
// Recompute the retained pose subspace in the fixed prior's tangent coordinates.
|
||||||
|
const Matrix6 pose_information=h*pose_selector().transpose();
|
||||||
|
const Eigen::SelfAdjointEigenSolver<Matrix6> observable(pose_information.transpose()*pose_information);
|
||||||
|
if(observable.info()!=Eigen::Success) return false;
|
||||||
|
Matrix6 prior_projector=Matrix6::Zero();
|
||||||
|
for(int i=0;i<6;++i) if(observable.eigenvalues()[i]>1e-10*std::max(1.0,observable.eigenvalues().maxCoeff()))
|
||||||
|
prior_projector.noalias()+=observable.eigenvectors().col(i)*observable.eigenvectors().col(i).transpose();
|
||||||
|
return update(prior,h,innovation,Matrix6::Identity()+whitening*model_covariance*whitening.transpose(),prior_projector,gate);
|
||||||
|
}
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
#include "field_localization/core/imu_integration.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
Eigen::Matrix3d skew(const Eigen::Vector3d &v) {
|
||||||
|
Eigen::Matrix3d m;
|
||||||
|
m << 0.0, -v.z(), v.y(), v.z(), 0.0, -v.x(), -v.y(), v.x(), 0.0;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
Eigen::Quaterniond exp_so3(const Eigen::Vector3d &v) {
|
||||||
|
const double angle = v.norm();
|
||||||
|
if (angle < 1e-10) return Eigen::Quaterniond(1.0, v.x()/2, v.y()/2, v.z()/2).normalized();
|
||||||
|
return Eigen::Quaterniond(Eigen::AngleAxisd(angle, v / angle));
|
||||||
|
}
|
||||||
|
Eigen::Vector3d log_so3(const Eigen::Quaterniond &q) {
|
||||||
|
Eigen::Quaterniond n = q.normalized();
|
||||||
|
if (n.w() < 0) n.coeffs() *= -1;
|
||||||
|
const Eigen::AngleAxisd a(n);
|
||||||
|
return a.angle() * a.axis();
|
||||||
|
}
|
||||||
|
Pose3D compose(const Pose3D &a, const Pose3D &b) {
|
||||||
|
return {(a.rotation * b.rotation).normalized(), a.translation + a.rotation * b.translation};
|
||||||
|
}
|
||||||
|
Pose3D inverse(const Pose3D &p) {
|
||||||
|
const Eigen::Quaterniond q = p.rotation.conjugate();
|
||||||
|
return {q, -(q * p.translation)};
|
||||||
|
}
|
||||||
|
Twist3D base_twist(const MotionState &state, const Eigen::Vector3d &raw_angular_velocity,
|
||||||
|
const Pose3D &base_from_imu) {
|
||||||
|
const Eigen::Matrix3d r_bi = base_from_imu.rotation.normalized().toRotationMatrix();
|
||||||
|
const Eigen::Matrix3d r_mi = state.pose.rotation.normalized().toRotationMatrix();
|
||||||
|
const Eigen::Vector3d omega_b = r_bi * (raw_angular_velocity - state.gyro_bias);
|
||||||
|
const Eigen::Vector3d v_imu_in_b = r_bi * (r_mi.transpose() * state.velocity);
|
||||||
|
return {v_imu_in_b - omega_b.cross(base_from_imu.translation), omega_b};
|
||||||
|
}
|
||||||
|
bool valid_imu(const ImuData &imu) {
|
||||||
|
return std::isfinite(imu.timestamp_sec) && imu.timestamp_sec >= 0 &&
|
||||||
|
imu.angular_velocity.allFinite() && imu.linear_acceleration.allFinite();
|
||||||
|
}
|
||||||
|
std::optional<ImuData> interpolate_imu(std::span<const ImuData> samples, double time) {
|
||||||
|
if (!std::isfinite(time) || samples.empty() || time < samples.front().timestamp_sec ||
|
||||||
|
time > samples.back().timestamp_sec) return std::nullopt;
|
||||||
|
const auto b = std::lower_bound(samples.begin(), samples.end(), time,
|
||||||
|
[](const ImuData &s, double t) { return s.timestamp_sec < t; });
|
||||||
|
if (b == samples.end()) return std::nullopt;
|
||||||
|
if (b->timestamp_sec == time) return *b;
|
||||||
|
if (b == samples.begin()) return std::nullopt;
|
||||||
|
const auto &a = *(b - 1);
|
||||||
|
const double u = (time - a.timestamp_sec) / (b->timestamp_sec - a.timestamp_sec);
|
||||||
|
ImuData result = a;
|
||||||
|
result.timestamp_sec = time;
|
||||||
|
result.angular_velocity = (1-u)*a.angular_velocity + u*b->angular_velocity;
|
||||||
|
result.linear_acceleration = (1-u)*a.linear_acceleration + u*b->linear_acceleration;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
MotionState integrate_midpoint(const MotionState &state, const ImuData &a, const ImuData &b) {
|
||||||
|
MotionState out = state;
|
||||||
|
const double dt = b.timestamp_sec - a.timestamp_sec;
|
||||||
|
const Eigen::Vector3d omega = 0.5*(a.angular_velocity+b.angular_velocity)-state.gyro_bias;
|
||||||
|
const Eigen::Vector3d acc = 0.5*(a.linear_acceleration+b.linear_acceleration)-state.accel_bias;
|
||||||
|
const Eigen::Quaterniond mid = state.pose.rotation * exp_so3(0.5*dt*omega);
|
||||||
|
const Eigen::Vector3d world_acc = mid*acc + state.gravity;
|
||||||
|
out.pose.translation += dt*state.velocity + 0.5*dt*dt*world_acc;
|
||||||
|
out.velocity += dt*world_acc;
|
||||||
|
out.pose.rotation = (state.pose.rotation*exp_so3(dt*omega)).normalized();
|
||||||
|
out.timestamp_sec = b.timestamp_sec;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
std::optional<std::vector<MotionState>> integrate_trajectory(
|
||||||
|
std::span<const ImuData> samples, const MotionState &initial, double end) {
|
||||||
|
if (!std::isfinite(end) || end < initial.timestamp_sec) return std::nullopt;
|
||||||
|
for (std::size_t i=0; i<samples.size(); ++i) {
|
||||||
|
if (!valid_imu(samples[i]) || (i && samples[i].timestamp_sec <= samples[i-1].timestamp_sec))
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
auto a = interpolate_imu(samples, initial.timestamp_sec);
|
||||||
|
const auto finish = interpolate_imu(samples, end);
|
||||||
|
if (!a || !finish) return std::nullopt;
|
||||||
|
std::vector<MotionState> result{initial};
|
||||||
|
for (const auto &s : samples) {
|
||||||
|
if (s.timestamp_sec <= initial.timestamp_sec || s.timestamp_sec >= end) continue;
|
||||||
|
result.push_back(integrate_midpoint(result.back(), *a, s));
|
||||||
|
a = s;
|
||||||
|
}
|
||||||
|
if (end > initial.timestamp_sec) result.push_back(integrate_midpoint(result.back(), *a, *finish));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
std::optional<Preintegration> preintegrate(std::span<const ImuData> samples,
|
||||||
|
double start, double end, const Eigen::Vector3d &bg, const Eigen::Vector3d &ba) {
|
||||||
|
MotionState initial;
|
||||||
|
initial.timestamp_sec = start;
|
||||||
|
initial.gravity.setZero();
|
||||||
|
initial.gyro_bias = bg;
|
||||||
|
initial.accel_bias = ba;
|
||||||
|
const auto states = integrate_trajectory(samples, initial, end);
|
||||||
|
if (!states) return std::nullopt;
|
||||||
|
const auto &last = states->back();
|
||||||
|
return Preintegration{last.pose.rotation, last.velocity, last.pose.translation, end-start};
|
||||||
|
}
|
||||||
|
std::optional<MotionState> interpolate_motion(std::span<const MotionState> trajectory, double time) {
|
||||||
|
if (trajectory.empty() || !std::isfinite(time) || time < trajectory.front().timestamp_sec-1e-9 ||
|
||||||
|
time > trajectory.back().timestamp_sec+1e-9) return std::nullopt;
|
||||||
|
const auto b = std::lower_bound(trajectory.begin(), trajectory.end(), time,
|
||||||
|
[](const MotionState &s, double t) { return s.timestamp_sec < t; });
|
||||||
|
if (b == trajectory.end()) return trajectory.back();
|
||||||
|
if (b == trajectory.begin() || std::abs(b->timestamp_sec-time) < 1e-12) return *b;
|
||||||
|
const auto &a = *(b-1);
|
||||||
|
const double dt = b->timestamp_sec-a.timestamp_sec;
|
||||||
|
const double u = (time-a.timestamp_sec)/dt;
|
||||||
|
MotionState s = a;
|
||||||
|
s.timestamp_sec = time;
|
||||||
|
s.pose.rotation = a.pose.rotation.slerp(u,b->pose.rotation).normalized();
|
||||||
|
// Cubic Hermite translation preserves endpoint velocities and constant acceleration.
|
||||||
|
s.pose.translation = (2*u*u*u-3*u*u+1)*a.pose.translation + (u*u*u-2*u*u+u)*dt*a.velocity
|
||||||
|
+ (-2*u*u*u+3*u*u)*b->pose.translation + (u*u*u-u*u)*dt*b->velocity;
|
||||||
|
s.velocity = (1-u)*a.velocity+u*b->velocity;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
std::pair<double,double> scan_window(const PointCloud &cloud, const DeskewOptions &o) {
|
||||||
|
if (o.timing == ScanTiming::INSTANTANEOUS) return {cloud.timestamp_sec,cloud.timestamp_sec};
|
||||||
|
if (o.timing == ScanTiming::POINT_TIMESTAMPS) {
|
||||||
|
double start=cloud.timestamp_sec, end=cloud.timestamp_sec;
|
||||||
|
for (const auto &p:cloud.points) if (std::isfinite(p.timestamp_sec) && p.position.allFinite()) {
|
||||||
|
start=std::min(start,p.timestamp_sec); end=std::max(end,p.timestamp_sec);
|
||||||
|
}
|
||||||
|
return {start,end};
|
||||||
|
}
|
||||||
|
return o.stamp_at_end ? std::pair{cloud.timestamp_sec-o.period_sec,cloud.timestamp_sec}
|
||||||
|
: std::pair{cloud.timestamp_sec,cloud.timestamp_sec+o.period_sec};
|
||||||
|
}
|
||||||
|
std::optional<PointCloud> deskew(const PointCloud &cloud,
|
||||||
|
std::span<const MotionState> trajectory, const DeskewOptions &o) {
|
||||||
|
if (!std::isfinite(cloud.timestamp_sec) || !std::isfinite(o.period_sec) || o.period_sec <= 0)
|
||||||
|
return std::nullopt;
|
||||||
|
const auto [start,end] = scan_window(cloud,o);
|
||||||
|
const auto ref=interpolate_motion(trajectory,end);
|
||||||
|
if (!ref || !interpolate_motion(trajectory,start)) return std::nullopt;
|
||||||
|
const Pose3D sensor_from_world=inverse(compose(ref->pose,o.imu_from_sensor));
|
||||||
|
PointCloud result{end,cloud.frame_id,{}};
|
||||||
|
result.points.reserve(cloud.points.size());
|
||||||
|
for (const auto &p:cloud.points) {
|
||||||
|
if (!p.position.allFinite() || !std::isfinite(p.intensity) || !std::isfinite(p.timestamp_sec)) continue;
|
||||||
|
double time=cloud.timestamp_sec;
|
||||||
|
if (o.timing == ScanTiming::POINT_TIMESTAMPS) time=p.timestamp_sec;
|
||||||
|
if (o.timing == ScanTiming::AZIMUTH) {
|
||||||
|
const double sign=o.counterclockwise ? 1.0 : -1.0;
|
||||||
|
double phase=std::fmod(sign*(std::atan2(p.position.y(),p.position.x())-o.start_angle_rad),2*std::numbers::pi);
|
||||||
|
if (phase < 0) phase+=2*std::numbers::pi;
|
||||||
|
time=start+o.period_sec*phase/(2*std::numbers::pi);
|
||||||
|
}
|
||||||
|
const auto state=interpolate_motion(trajectory,time);
|
||||||
|
if (!state) return std::nullopt;
|
||||||
|
const Pose3D transform=compose(sensor_from_world,compose(state->pose,o.imu_from_sensor));
|
||||||
|
PointXYZI out=p;
|
||||||
|
out.position=(transform.rotation*p.position.cast<double>()+transform.translation).cast<float>();
|
||||||
|
result.points.push_back(out);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -2,8 +2,39 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace field_localization::core {
|
namespace field_localization::core {
|
||||||
|
LocalizationCore::LocalizationCore():LocalizationCore(CoreOptions{}) {}
|
||||||
|
LocalizationCore::LocalizationCore(const CoreOptions &options):options_(options),map_(options.map_resolution),filter_(options.noise) {
|
||||||
|
if (options_.map_bounds && !options_.map_bounds->valid()) throw std::invalid_argument("invalid map bounds");
|
||||||
|
MotionState initial;
|
||||||
|
initial.pose=compose(options.initial_pose,options.base_from_imu);
|
||||||
|
filter_.initialize(initial); pose_=options.initial_pose;
|
||||||
|
}
|
||||||
|
bool LocalizationCore::load_map(const std::filesystem::path &path,std::string &error) {
|
||||||
|
auto map=read_map(path,error,options_.map_bounds);
|
||||||
|
if (!map) return false;
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
map_=std::move(*map); status_.map_point_count=map_.size(); return true;
|
||||||
|
}
|
||||||
|
bool LocalizationCore::export_map(const std::filesystem::path &path,std::string &error) const {
|
||||||
|
VoxelMap copy;
|
||||||
|
{ std::lock_guard<std::mutex> lock(mutex_); copy=map_; }
|
||||||
|
return save_map(copy,path,error);
|
||||||
|
}
|
||||||
|
void LocalizationCore::set_map_points(std::span<const Eigen::Vector3d> points) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
map_.clear();
|
||||||
|
for (const auto &point:points) if (!options_.map_bounds || options_.map_bounds->contains(point)) map_.insert(point);
|
||||||
|
status_.map_point_count=map_.size();
|
||||||
|
}
|
||||||
|
LocalizationSnapshot LocalizationCore::get_snapshot() const {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
return {pose_,filter_.snapshot(),status_,twist_,
|
||||||
|
previous_imu_ ? previous_imu_->angular_velocity : Eigen::Vector3d::Zero(),last_imu_dt_};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LocalizationCore::process_imu(const ImuData &imu) {
|
bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
@@ -11,6 +42,7 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
|||||||
// 时间戳必须有效
|
// 时间戳必须有效
|
||||||
if (!std::isfinite(imu.timestamp_sec) || imu.timestamp_sec < 0.0) {
|
if (!std::isfinite(imu.timestamp_sec) || imu.timestamp_sec < 0.0) {
|
||||||
++status_.rejected_imu_count;
|
++status_.rejected_imu_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::INVALID_INPUT;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,15 +50,45 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
|||||||
if (!imu.angular_velocity.allFinite() ||
|
if (!imu.angular_velocity.allFinite() ||
|
||||||
!imu.linear_acceleration.allFinite()) {
|
!imu.linear_acceleration.allFinite()) {
|
||||||
++status_.rejected_imu_count;
|
++status_.rejected_imu_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::INVALID_INPUT;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拒绝乱序或重复数据
|
// 拒绝乱序或重复数据
|
||||||
if (status_.has_imu && imu.timestamp_sec <= status_.last_imu_timestamp) {
|
if (status_.has_imu && imu.timestamp_sec <= status_.last_imu_timestamp) {
|
||||||
++status_.rejected_imu_count;
|
++status_.rejected_imu_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previous_imu_) {
|
||||||
|
const double dt=imu.timestamp_sec-previous_imu_->timestamp_sec;
|
||||||
|
if (!filter_.propagate(*previous_imu_,imu)) {
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::IMU_GAP;
|
||||||
|
auto snapshot=filter_.snapshot(); snapshot.state.timestamp_sec=imu.timestamp_sec;
|
||||||
|
snapshot.covariance.diagonal().array()+=1.0;
|
||||||
|
filter_.restore(snapshot); imu_history_.clear(); state_history_.clear();
|
||||||
|
last_imu_dt_=0.0;
|
||||||
|
} else {
|
||||||
|
last_imu_dt_=dt;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto snapshot=filter_.snapshot(); snapshot.state.timestamp_sec=imu.timestamp_sec;
|
||||||
|
filter_.restore(snapshot);
|
||||||
|
last_imu_dt_=0.0;
|
||||||
|
}
|
||||||
|
if (status_.has_point_cloud && imu.timestamp_sec-status_.last_point_cloud_timestamp>0.3) {
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::LIDAR_TIMEOUT;
|
||||||
|
}
|
||||||
|
previous_imu_=imu;
|
||||||
|
imu_history_.push_back(imu); state_history_.push_back(filter_.snapshot());
|
||||||
|
while (imu_history_.size()>1 && imu.timestamp_sec-imu_history_[1].timestamp_sec>2.0) {
|
||||||
|
imu_history_.erase(imu_history_.begin()); state_history_.erase(state_history_.begin());
|
||||||
|
}
|
||||||
|
const auto current_state=filter_.snapshot().state;
|
||||||
|
pose_=compose(current_state.pose,inverse(options_.base_from_imu));
|
||||||
|
twist_=base_twist(current_state,imu.angular_velocity,options_.base_from_imu);
|
||||||
|
status_.state_timestamp=imu.timestamp_sec;
|
||||||
status_.has_imu = true;
|
status_.has_imu = true;
|
||||||
status_.last_imu_timestamp = imu.timestamp_sec;
|
status_.last_imu_timestamp = imu.timestamp_sec;
|
||||||
++status_.imu_count;
|
++status_.imu_count;
|
||||||
@@ -39,6 +101,7 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
|||||||
|
|
||||||
if (!std::isfinite(cloud.timestamp_sec) || cloud.timestamp_sec < 0.0) {
|
if (!std::isfinite(cloud.timestamp_sec) || cloud.timestamp_sec < 0.0) {
|
||||||
++status_.rejected_point_cloud_count;
|
++status_.rejected_point_cloud_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,9 +109,15 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
|||||||
if (status_.has_point_cloud &&
|
if (status_.has_point_cloud &&
|
||||||
cloud.timestamp_sec <= status_.last_point_cloud_timestamp) {
|
cloud.timestamp_sec <= status_.last_point_cloud_timestamp) {
|
||||||
++status_.rejected_point_cloud_count;
|
++status_.rejected_point_cloud_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_.has_point_cloud=true;
|
||||||
|
status_.last_point_cloud_timestamp=cloud.timestamp_sec;
|
||||||
|
status_.registration_residual_available=false;
|
||||||
|
status_.registration={}; status_.registration_rmse=0; status_.inlier_count=0; status_.inlier_ratio=0;
|
||||||
|
status_.degenerate_dimensions=6; status_.degenerate_basis=Matrix6::Identity(); status_.information_singular_values.setZero();
|
||||||
// 统计有效点数量
|
// 统计有效点数量
|
||||||
const auto valid_point_count = std::count_if(
|
const auto valid_point_count = std::count_if(
|
||||||
cloud.points.begin(), cloud.points.end(), [](const PointXYZI &point) {
|
cloud.points.begin(), cloud.points.end(), [](const PointXYZI &point) {
|
||||||
@@ -57,6 +126,7 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (valid_point_count == 0) {
|
if (valid_point_count == 0) {
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::NO_VALID_POINTS;
|
||||||
++status_.rejected_point_cloud_count;
|
++status_.rejected_point_cloud_count;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -66,7 +136,97 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
|||||||
status_.last_point_count = static_cast<std::size_t>(valid_point_count);
|
status_.last_point_count = static_cast<std::size_t>(valid_point_count);
|
||||||
|
|
||||||
++status_.point_cloud_count;
|
++status_.point_cloud_count;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY;
|
||||||
|
const auto [start,end]=scan_window(cloud,options_.deskew);
|
||||||
|
if (imu_history_.empty() || start<imu_history_.front().timestamp_sec ||
|
||||||
|
end>imu_history_.back().timestamp_sec || end<=last_correction_time_) {
|
||||||
|
status_.reason=FailureReason::IMU_COVERAGE; return true;
|
||||||
|
}
|
||||||
|
auto it=std::upper_bound(imu_history_.begin(),imu_history_.end(),start,
|
||||||
|
[](double t,const ImuData &s) { return t<s.timestamp_sec; });
|
||||||
|
const auto index=static_cast<std::size_t>(std::distance(imu_history_.begin(),it)-1);
|
||||||
|
const auto trajectory=integrate_trajectory(imu_history_,state_history_[index].state,end);
|
||||||
|
if (!trajectory) { status_.reason=FailureReason::IMU_COVERAGE; return true; }
|
||||||
|
const auto corrected=deskew(cloud,*trajectory,options_.deskew);
|
||||||
|
if (!corrected) { status_.reason=FailureReason::IMU_COVERAGE; return true; }
|
||||||
|
// Reconstruct the covariance at exactly the same scan end as the deskew reference.
|
||||||
|
ErrorStateFilter at_scan(options_.noise); at_scan.restore(state_history_[index]);
|
||||||
|
auto a=interpolate_imu(imu_history_,at_scan.snapshot().state.timestamp_sec);
|
||||||
|
for (const auto &s:imu_history_) {
|
||||||
|
if (s.timestamp_sec<=a->timestamp_sec || s.timestamp_sec>=end) continue;
|
||||||
|
if (!at_scan.propagate(*a,s)) { status_.reason=FailureReason::IMU_GAP; return true; }
|
||||||
|
a=s;
|
||||||
|
}
|
||||||
|
const auto finish=interpolate_imu(imu_history_,end);
|
||||||
|
if (end>a->timestamp_sec && !at_scan.propagate(*a,*finish)) {
|
||||||
|
status_.reason=FailureReason::IMU_GAP; return true;
|
||||||
|
}
|
||||||
|
const auto map_from_sensor_at=[&](const Pose3D &map_from_imu) {
|
||||||
|
return compose(map_from_imu,options_.deskew.imu_from_sensor);
|
||||||
|
};
|
||||||
|
const auto map_scan=[&](const Pose3D &map_from_sensor) {
|
||||||
|
return options_.map_bounds ? crop_to_map(*corrected,map_from_sensor,*options_.map_bounds) : *corrected;
|
||||||
|
};
|
||||||
|
const auto predicted_sensor=map_from_sensor_at(at_scan.snapshot().state.pose);
|
||||||
|
if (map_.size()<5) {
|
||||||
|
if (options_.map_mode==MapMode::MAPPING) {
|
||||||
|
const auto points=map_scan(predicted_sensor);
|
||||||
|
if (points.points.size()<options_.registration.minimum_inliers) {
|
||||||
|
status_.reason=FailureReason::NO_VALID_POINTS; return true;
|
||||||
|
}
|
||||||
|
map_.insert(voxel_downsample(points,options_.map_resolution),predicted_sensor);
|
||||||
|
last_keyframe_=compose(at_scan.snapshot().state.pose,inverse(options_.base_from_imu));
|
||||||
|
status_.keyframe_count=1; status_.map_point_count=map_.size();
|
||||||
|
status_.reason=FailureReason::INITIALIZING;
|
||||||
|
} else status_.reason=FailureReason::MAP_UNAVAILABLE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
status_.registration_prediction=at_scan.snapshot();
|
||||||
|
std::optional<PointCloud> cropped;
|
||||||
|
if (options_.map_bounds)
|
||||||
|
cropped=crop_to_map(*corrected,predicted_sensor,*options_.map_bounds,map_association_margin);
|
||||||
|
const auto registration=scan_to_map(cropped ? *cropped : *corrected,options_.deskew.imu_from_sensor,map_,
|
||||||
|
at_scan.snapshot(),options_.noise,options_.registration);
|
||||||
|
status_.registration=registration;
|
||||||
|
status_.registration_residual_available=registration.residual_available;
|
||||||
|
status_.registration_rmse=registration.rmse; status_.inlier_count=registration.inliers;
|
||||||
|
status_.inlier_ratio=registration.inlier_ratio;
|
||||||
|
status_.degenerate_dimensions=registration.degeneracy.dimensions;
|
||||||
|
status_.degenerate_basis=registration.degeneracy.null_basis;
|
||||||
|
status_.information_singular_values=registration.degeneracy.singular_values;
|
||||||
|
if (!registration.success) { status_.reason=FailureReason::REGISTRATION_FAILED; return true; }
|
||||||
|
ErrorStateFilter replay(options_.noise); replay.restore(registration.estimate);
|
||||||
|
auto corrected_imus=imu_history_; auto corrected_states=state_history_;
|
||||||
|
// Insert a correction checkpoint even when scan time lies between IMU samples.
|
||||||
|
auto at=std::lower_bound(corrected_imus.begin(),corrected_imus.end(),end,
|
||||||
|
[](const ImuData &s,double t) { return s.timestamp_sec<t; });
|
||||||
|
std::size_t slot=static_cast<std::size_t>(std::distance(corrected_imus.begin(),at));
|
||||||
|
if (at==corrected_imus.end() || at->timestamp_sec!=end) {
|
||||||
|
corrected_imus.insert(at,*finish); corrected_states.insert(corrected_states.begin()+static_cast<std::ptrdiff_t>(slot),registration.estimate);
|
||||||
|
} else corrected_states[slot]=registration.estimate;
|
||||||
|
for (std::size_t i=slot+1;i<corrected_imus.size();++i) {
|
||||||
|
if (!replay.propagate(corrected_imus[i-1],corrected_imus[i])) {
|
||||||
|
status_.reason=FailureReason::IMU_GAP; return true;
|
||||||
|
}
|
||||||
|
corrected_states[i]=replay.snapshot();
|
||||||
|
}
|
||||||
|
imu_history_.swap(corrected_imus); state_history_.swap(corrected_states);
|
||||||
|
filter_.restore(replay.snapshot());
|
||||||
|
const Pose3D scan_base=compose(registration.estimate.state.pose,inverse(options_.base_from_imu));
|
||||||
|
if (options_.map_mode==MapMode::MAPPING && registration.degeneracy.dimensions==0 &&
|
||||||
|
(!last_keyframe_ || new_keyframe(*last_keyframe_,scan_base))) {
|
||||||
|
const auto posterior_sensor=map_from_sensor_at(registration.estimate.state.pose);
|
||||||
|
const auto points=map_scan(posterior_sensor);
|
||||||
|
if (!points.points.empty()) {
|
||||||
|
map_.insert(voxel_downsample(points,options_.map_resolution),posterior_sensor);
|
||||||
|
last_keyframe_=scan_base; ++status_.keyframe_count; status_.map_point_count=map_.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status_.last_correction_timestamp=end; ++status_.accepted_corrections;
|
||||||
|
last_correction_time_=end; status_.mode=TrackingMode::FULL; status_.reason=FailureReason::NONE;
|
||||||
|
const auto posterior_state=filter_.snapshot().state;
|
||||||
|
pose_=compose(posterior_state.pose,inverse(options_.base_from_imu));
|
||||||
|
if (previous_imu_) twist_=base_twist(posterior_state,previous_imu_->angular_velocity,options_.base_from_imu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +235,11 @@ Pose3D LocalizationCore::get_pose() const {
|
|||||||
return pose_;
|
return pose_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Twist3D LocalizationCore::get_twist() const {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
return twist_;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalizationCore::set_pose(const Pose3D &pose) {
|
void LocalizationCore::set_pose(const Pose3D &pose) {
|
||||||
if (!pose.translation.allFinite() || !pose.rotation.coeffs().allFinite() ||
|
if (!pose.translation.allFinite() || !pose.rotation.coeffs().allFinite() ||
|
||||||
pose.rotation.norm() < 1e-12) {
|
pose.rotation.norm() < 1e-12) {
|
||||||
@@ -85,6 +250,13 @@ void LocalizationCore::set_pose(const Pose3D &pose) {
|
|||||||
|
|
||||||
pose_ = pose;
|
pose_ = pose;
|
||||||
pose_.rotation.normalize();
|
pose_.rotation.normalize();
|
||||||
|
twist_ = Twist3D{};
|
||||||
|
last_imu_dt_ = 0.0;
|
||||||
|
MotionState initial; initial.pose=compose(pose_,options_.base_from_imu);
|
||||||
|
filter_.initialize(initial); last_correction_time_=-1; previous_imu_.reset();
|
||||||
|
imu_history_.clear(); state_history_.clear(); status_.has_imu=false;
|
||||||
|
status_.last_correction_timestamp=-1; status_.accepted_corrections=0;
|
||||||
|
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::INITIALIZING;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalizationStatus LocalizationCore::get_status() const {
|
LocalizationStatus LocalizationCore::get_status() const {
|
||||||
@@ -95,8 +267,14 @@ LocalizationStatus LocalizationCore::get_status() const {
|
|||||||
void LocalizationCore::reset() {
|
void LocalizationCore::reset() {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
pose_ = Pose3D{};
|
pose_ = options_.initial_pose;
|
||||||
status_ = LocalizationStatus{};
|
twist_ = Twist3D{};
|
||||||
|
last_imu_dt_ = 0.0;
|
||||||
|
MotionState initial; initial.pose=compose(pose_,options_.base_from_imu);
|
||||||
|
filter_.initialize(initial); last_correction_time_=-1; previous_imu_.reset(); imu_history_.clear(); state_history_.clear();
|
||||||
|
if (options_.map_mode==MapMode::MAPPING) map_.clear();
|
||||||
|
last_keyframe_.reset();
|
||||||
|
status_ = LocalizationStatus{}; status_.map_point_count=map_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace field_localization::core
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include "field_localization/core/map_io.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <bit>
|
||||||
|
#include <fstream>
|
||||||
|
#include <numbers>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
namespace {
|
||||||
|
constexpr std::array<char,8> magic{'F','L','M','A','P','0','0','1'};
|
||||||
|
template<class T> void write(std::ostream &out,T value) {
|
||||||
|
auto bytes=std::bit_cast<std::array<char,sizeof(T)>>(value);
|
||||||
|
if constexpr(std::endian::native==std::endian::big) std::reverse(bytes.begin(),bytes.end());
|
||||||
|
out.write(bytes.data(),bytes.size());
|
||||||
|
}
|
||||||
|
template<class T> T read(std::istream &in) {
|
||||||
|
std::array<char,sizeof(T)> bytes{}; in.read(bytes.data(),bytes.size());
|
||||||
|
if (!in) throw std::runtime_error("truncated map");
|
||||||
|
if constexpr(std::endian::native==std::endian::big) std::reverse(bytes.begin(),bytes.end());
|
||||||
|
return std::bit_cast<T>(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool MapBounds::valid() const {
|
||||||
|
return min.allFinite() && max.allFinite() && (min.array()<max.array()).all();
|
||||||
|
}
|
||||||
|
bool MapBounds::contains(const Eigen::Vector3d &point,double margin) const {
|
||||||
|
return (point.array()>=min.array()-margin).all() && (point.array()<=max.array()+margin).all();
|
||||||
|
}
|
||||||
|
PointCloud crop_to_map(const PointCloud &cloud,const Pose3D &map_from_sensor,
|
||||||
|
const MapBounds &bounds,double margin) {
|
||||||
|
PointCloud cropped{cloud.timestamp_sec,cloud.frame_id,{}};
|
||||||
|
cropped.points.reserve(cloud.points.size());
|
||||||
|
for (const auto &point:cloud.points) {
|
||||||
|
const Eigen::Vector3d mapped=map_from_sensor.rotation*point.position.cast<double>()+
|
||||||
|
map_from_sensor.translation;
|
||||||
|
if (bounds.contains(mapped,margin)) cropped.points.push_back(point);
|
||||||
|
}
|
||||||
|
return cropped;
|
||||||
|
}
|
||||||
|
bool new_keyframe(const Pose3D &previous,const Pose3D ¤t) {
|
||||||
|
return (current.translation-previous.translation).norm()>0.5 ||
|
||||||
|
log_so3(previous.rotation.conjugate()*current.rotation).norm()>10*std::numbers::pi/180;
|
||||||
|
}
|
||||||
|
bool save_map(const VoxelMap &map,const std::filesystem::path &path,std::string &error) {
|
||||||
|
error.clear(); const auto temporary=std::filesystem::path(path.string()+".tmp");
|
||||||
|
try {
|
||||||
|
if (map.size()==0) throw std::runtime_error("cannot save an empty map");
|
||||||
|
std::ofstream out(temporary,std::ios::binary|std::ios::trunc);
|
||||||
|
out.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
out.write(magic.data(),magic.size()); write<std::uint32_t>(out,1);
|
||||||
|
write<double>(out,map.resolution()); write<std::uint64_t>(out,map.size());
|
||||||
|
for (const auto &p:map.points()) for (int i=0;i<3;++i) write<double>(out,p[i]);
|
||||||
|
out.close(); std::filesystem::rename(temporary,path); return true;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
error=e.what(); std::error_code ignored; std::filesystem::remove(temporary,ignored); return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::optional<VoxelMap> read_map(const std::filesystem::path &path,std::string &error,
|
||||||
|
const std::optional<MapBounds> &bounds) {
|
||||||
|
error.clear();
|
||||||
|
try {
|
||||||
|
std::ifstream in(path,std::ios::binary);
|
||||||
|
if (!in) throw std::runtime_error("cannot open map: "+path.string());
|
||||||
|
std::array<char,8> signature{}; in.read(signature.data(),signature.size());
|
||||||
|
if (signature!=magic || read<std::uint32_t>(in)!=1) throw std::runtime_error("unsupported map format");
|
||||||
|
const double resolution=read<double>(in); const auto count=read<std::uint64_t>(in);
|
||||||
|
if (count==0 || count>5000000 || std::filesystem::file_size(path)!=28+count*24)
|
||||||
|
throw std::runtime_error("invalid map point count or length");
|
||||||
|
VoxelMap map(resolution);
|
||||||
|
for (std::uint64_t i=0;i<count;++i) {
|
||||||
|
Eigen::Vector3d p; for (int j=0;j<3;++j) p[j]=read<double>(in);
|
||||||
|
if (!p.allFinite() || p.cwiseAbs().maxCoeff()/resolution>1e12)
|
||||||
|
throw std::runtime_error("invalid map coordinate");
|
||||||
|
if (!bounds || bounds->contains(p)) map.insert(p);
|
||||||
|
}
|
||||||
|
if (map.size()==0) throw std::runtime_error("empty voxel map after applying map bounds");
|
||||||
|
return map;
|
||||||
|
} catch (const std::exception &e) { error=e.what(); return std::nullopt; }
|
||||||
|
}
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
#include "field_localization/core/registration.hpp"
|
||||||
|
#include <Eigen/Eigenvalues>
|
||||||
|
#include <Eigen/SVD>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
namespace field_localization::core {
|
||||||
|
std::size_t VoxelHash::operator()(const VoxelKey &k) const {
|
||||||
|
auto mix=[](std::uint64_t x) { x=(x^(x>>30))*0xbf58476d1ce4e5b9ULL;
|
||||||
|
x=(x^(x>>27))*0x94d049bb133111ebULL; return x^(x>>31); };
|
||||||
|
return static_cast<std::size_t>(mix(static_cast<std::uint64_t>(k.x))^
|
||||||
|
(mix(static_cast<std::uint64_t>(k.y))<<1)^(mix(static_cast<std::uint64_t>(k.z))<<2));
|
||||||
|
}
|
||||||
|
VoxelMap::VoxelMap(double resolution):resolution_(resolution) {
|
||||||
|
if (!std::isfinite(resolution) || resolution<=0) throw std::invalid_argument("invalid voxel resolution");
|
||||||
|
}
|
||||||
|
VoxelKey VoxelMap::key(const Eigen::Vector3d &p) const {
|
||||||
|
return {static_cast<std::int64_t>(std::floor(p.x()/resolution_)),
|
||||||
|
static_cast<std::int64_t>(std::floor(p.y()/resolution_)),
|
||||||
|
static_cast<std::int64_t>(std::floor(p.z()/resolution_))};
|
||||||
|
}
|
||||||
|
void VoxelMap::insert(const Eigen::Vector3d &p) {
|
||||||
|
// Bound before integer conversion, including malicious finite file input.
|
||||||
|
if (!p.allFinite() || p.cwiseAbs().maxCoeff()/resolution_>1e12) return;
|
||||||
|
points_.try_emplace(key(p),p); planes_.clear();
|
||||||
|
}
|
||||||
|
void VoxelMap::insert(const PointCloud &cloud,const Pose3D &pose) {
|
||||||
|
for (const auto &p:cloud.points) if (p.position.allFinite()) insert(pose.rotation*p.position.cast<double>()+pose.translation);
|
||||||
|
}
|
||||||
|
void VoxelMap::clear() { points_.clear(); planes_.clear(); }
|
||||||
|
std::vector<Eigen::Vector3d> VoxelMap::points() const {
|
||||||
|
std::vector<Eigen::Vector3d> result; result.reserve(points_.size());
|
||||||
|
for (const auto &[k,p]:points_) { (void)k; result.push_back(p); }
|
||||||
|
std::sort(result.begin(),result.end(),[](const auto &a,const auto &b) {
|
||||||
|
return std::tuple{a.x(),a.y(),a.z()}<std::tuple{b.x(),b.y(),b.z()}; });
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Plane VoxelMap::plane(const Eigen::Vector3d &p,double radius) const {
|
||||||
|
if (!p.allFinite() || p.cwiseAbs().maxCoeff()/resolution_>1e12 || !std::isfinite(radius) || radius<=0)
|
||||||
|
return {};
|
||||||
|
if (radius!=cached_radius_) { planes_.clear(); cached_radius_=radius; }
|
||||||
|
const auto center=key(p);
|
||||||
|
if (const auto it=planes_.find(center);it!=planes_.end()) return it->second;
|
||||||
|
// Cache planes per query voxel, using voxel center for a deterministic neighborhood.
|
||||||
|
const Eigen::Vector3d query=resolution_*Eigen::Vector3d{center.x+0.5,center.y+0.5,center.z+0.5};
|
||||||
|
std::vector<std::pair<double,Eigen::Vector3d>> neighbors;
|
||||||
|
const int extent=static_cast<int>(std::min(20.0,std::ceil(radius/resolution_)));
|
||||||
|
for (int x=-extent;x<=extent;++x) for (int y=-extent;y<=extent;++y) for (int z=-extent;z<=extent;++z) {
|
||||||
|
const auto it=points_.find({center.x+x,center.y+y,center.z+z});
|
||||||
|
if (it==points_.end()) continue;
|
||||||
|
const double distance=(it->second-query).squaredNorm();
|
||||||
|
if (distance<=radius*radius) neighbors.emplace_back(distance,it->second);
|
||||||
|
}
|
||||||
|
Plane result;
|
||||||
|
if (neighbors.size()>=5) {
|
||||||
|
const auto count=std::min<std::size_t>(20,neighbors.size());
|
||||||
|
std::partial_sort(neighbors.begin(),neighbors.begin()+static_cast<std::ptrdiff_t>(count),neighbors.end(),
|
||||||
|
[](const auto &a,const auto &b) { return a.first<b.first; });
|
||||||
|
for (std::size_t i=0;i<count;++i) result.center+=neighbors[i].second;
|
||||||
|
result.center/=static_cast<double>(count);
|
||||||
|
Eigen::Matrix3d covariance=Eigen::Matrix3d::Zero();
|
||||||
|
for (std::size_t i=0;i<count;++i) {
|
||||||
|
const Eigen::Vector3d d=neighbors[i].second-result.center; covariance+=d*d.transpose();
|
||||||
|
}
|
||||||
|
const Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> eig(covariance);
|
||||||
|
if (eig.info()==Eigen::Success && eig.eigenvalues()[1]>1e-6 &&
|
||||||
|
eig.eigenvalues()[0]/eig.eigenvalues()[1]<0.03) {
|
||||||
|
result.normal=eig.eigenvectors().col(0); result.valid=true;
|
||||||
|
for(std::size_t i=0;i<count;++i) {
|
||||||
|
const Eigen::Vector3d d=neighbors[i].second-result.center;
|
||||||
|
result.support_radius=std::max(result.support_radius,
|
||||||
|
(d-result.normal*d.dot(result.normal)).norm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
planes_.emplace(center,result); return result;
|
||||||
|
}
|
||||||
|
PointCloud voxel_downsample(const PointCloud &cloud,double resolution) {
|
||||||
|
if (!std::isfinite(resolution) || resolution<=0) throw std::invalid_argument("invalid scan voxel");
|
||||||
|
PointCloud out{cloud.timestamp_sec,cloud.frame_id,{}};
|
||||||
|
std::unordered_map<VoxelKey,bool,VoxelHash> seen;
|
||||||
|
for (const auto &p:cloud.points) {
|
||||||
|
if (!p.position.allFinite() || !std::isfinite(p.intensity) || !std::isfinite(p.timestamp_sec) ||
|
||||||
|
p.position.cwiseAbs().maxCoeff()/resolution>1e12) continue;
|
||||||
|
const VoxelKey k{static_cast<std::int64_t>(std::floor(p.position.x()/resolution)),
|
||||||
|
static_cast<std::int64_t>(std::floor(p.position.y()/resolution)),
|
||||||
|
static_cast<std::int64_t>(std::floor(p.position.z()/resolution))};
|
||||||
|
if (seen.try_emplace(k,true).second) out.points.push_back(p);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
Degeneracy detect_degeneracy(const Matrix6 &h,const RegistrationOptions &o) {
|
||||||
|
Degeneracy result;
|
||||||
|
if (!h.allFinite()) return result;
|
||||||
|
const Eigen::JacobiSVD<Matrix6> svd(h,Eigen::ComputeFullV);
|
||||||
|
if (svd.info()!=Eigen::Success) return result;
|
||||||
|
result.singular_values=svd.singularValues();
|
||||||
|
result.dimensions=0;
|
||||||
|
const double threshold=std::max(o.degeneracy_absolute,o.degeneracy_relative*result.singular_values[0]);
|
||||||
|
for (int i=0;i<6;++i) {
|
||||||
|
const auto v=svd.matrixV().col(i);
|
||||||
|
if (result.singular_values[i]<=threshold) result.null_basis.col(result.dimensions++)=v;
|
||||||
|
else result.projector+=v*v.transpose();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
namespace {
|
||||||
|
struct Linearization {
|
||||||
|
Matrix6 h{Matrix6::Zero()}; Vector6 gradient{Vector6::Zero()};
|
||||||
|
double squared_error{0}; AssociationCounts counts;
|
||||||
|
};
|
||||||
|
Linearization linearize(const PointCloud &cloud,const Pose3D &extrinsic,const VoxelMap &map,
|
||||||
|
const MotionState &state,const RegistrationOptions &o) {
|
||||||
|
Linearization out;
|
||||||
|
out.counts.sampled=cloud.points.size();
|
||||||
|
for (const auto &point:cloud.points) {
|
||||||
|
const Eigen::Vector3d body=extrinsic.rotation*point.position.cast<double>()+extrinsic.translation;
|
||||||
|
const Eigen::Vector3d world=state.pose.rotation*body+state.pose.translation;
|
||||||
|
const auto plane=map.plane(world,o.neighborhood_radius);
|
||||||
|
if (!plane.valid) continue;
|
||||||
|
++out.counts.candidate_planes;
|
||||||
|
const Eigen::Vector3d offset=world-plane.center;
|
||||||
|
const double residual=plane.normal.dot(offset);
|
||||||
|
if ((offset-plane.normal*residual).norm()>plane.support_radius+map.resolution()) {
|
||||||
|
++out.counts.outside_support;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (std::abs(residual)>o.max_plane_distance) {
|
||||||
|
++out.counts.plane_distance_rejected;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Vector6 j; j.head<3>()=plane.normal;
|
||||||
|
j.tail<3>()=(-state.pose.rotation.toRotationMatrix()*skew(body)).transpose()*plane.normal;
|
||||||
|
const double weight=std::min(1.0,o.huber_threshold/std::max(1e-12,std::abs(residual)))/
|
||||||
|
(o.measurement_sigma*o.measurement_sigma);
|
||||||
|
out.h.noalias()+=weight*j*j.transpose(); out.gradient.noalias()+=weight*j*residual;
|
||||||
|
out.squared_error+=residual*residual; ++out.counts.inliers;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AssociationCounts inspect_scan_support(const PointCloud &cloud,const Pose3D &extrinsic,
|
||||||
|
const VoxelMap &map,const Pose3D &map_from_imu,const RegistrationOptions &options) {
|
||||||
|
MotionState state; state.pose=map_from_imu;
|
||||||
|
return linearize(voxel_downsample(cloud,options.scan_voxel),extrinsic,map,state,options).counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *registration_stage_name(RegistrationStage stage) {
|
||||||
|
switch (stage) {
|
||||||
|
case RegistrationStage::NOT_RUN:return "NOT_RUN";
|
||||||
|
case RegistrationStage::INITIAL_MATCH:return "INITIAL_MATCH";
|
||||||
|
case RegistrationStage::ITERATION:return "ITERATION";
|
||||||
|
case RegistrationStage::FINAL_FUSION:return "FINAL_FUSION";
|
||||||
|
case RegistrationStage::COMPLETE:return "COMPLETE";
|
||||||
|
}
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
const char *registration_failure_name(RegistrationFailure failure) {
|
||||||
|
switch (failure) {
|
||||||
|
case RegistrationFailure::NONE:return "NONE";
|
||||||
|
case RegistrationFailure::NO_CORRESPONDENCES:return "NO_CORRESPONDENCES";
|
||||||
|
case RegistrationFailure::DEGENERATE:return "DEGENERATE";
|
||||||
|
case RegistrationFailure::INNOVATION:return "INNOVATION";
|
||||||
|
case RegistrationFailure::QUALITY:return "QUALITY";
|
||||||
|
}
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
|
||||||
|
RegistrationResult scan_to_map(const PointCloud &cloud,const Pose3D &extrinsic,const VoxelMap &map,
|
||||||
|
const FilterSnapshot &prediction,const NoiseOptions &noise,const RegistrationOptions &o) {
|
||||||
|
RegistrationResult result; result.estimate=prediction;
|
||||||
|
const auto scan=voxel_downsample(cloud,o.scan_voxel);
|
||||||
|
result.stage=RegistrationStage::INITIAL_MATCH;
|
||||||
|
result.initial_associations.sampled=scan.points.size();
|
||||||
|
result.last_associations=result.initial_associations;
|
||||||
|
if (scan.points.empty() || map.size()<5) return result;
|
||||||
|
ErrorStateFilter filter(noise); filter.restore(prediction);
|
||||||
|
auto record=[&](const Linearization &l) {
|
||||||
|
result.last_associations=l.counts;
|
||||||
|
result.inliers=l.counts.inliers; result.inlier_ratio=static_cast<double>(l.counts.inliers)/scan.points.size();
|
||||||
|
result.residual_available=l.counts.inliers>0;
|
||||||
|
result.rmse=l.counts.inliers ? std::sqrt(l.squared_error/l.counts.inliers) : 0;
|
||||||
|
result.information=l.h; result.gradient=l.gradient;
|
||||||
|
result.degeneracy=detect_degeneracy(l.h/std::max(1.0,static_cast<double>(l.counts.inliers)),o);
|
||||||
|
result.estimate=filter.snapshot();
|
||||||
|
};
|
||||||
|
Matrix6 model_covariance=Matrix6::Zero();
|
||||||
|
model_covariance.topLeftCorner<3,3>().diagonal().setConstant(o.map_translation_sigma*o.map_translation_sigma);
|
||||||
|
model_covariance.bottomRightCorner<3,3>().diagonal().setConstant(o.map_rotation_sigma*o.map_rotation_sigma);
|
||||||
|
for (int iteration=0;iteration<o.maximum_iterations;++iteration) {
|
||||||
|
const auto before=filter.snapshot().state;
|
||||||
|
const auto l=linearize(scan,extrinsic,map,before,o);
|
||||||
|
record(l);
|
||||||
|
if (iteration==0) result.initial_associations=l.counts;
|
||||||
|
if (l.counts.inliers<o.minimum_inliers) return result;
|
||||||
|
const auto °=result.degeneracy;
|
||||||
|
if (deg.dimensions==6) { result.failure=RegistrationFailure::DEGENERATE; return result; }
|
||||||
|
// Trial iterates update correspondence geometry in this private filter.
|
||||||
|
// The innovation gate is evaluated against the original prior once those
|
||||||
|
// correspondences have settled, before the result can reach LocalizationCore.
|
||||||
|
result.stage=RegistrationStage::ITERATION;
|
||||||
|
const bool updated=filter.correct_information(prediction,before,l.h,l.gradient,
|
||||||
|
deg.projector,model_covariance,InnovationCheck::TRIAL);
|
||||||
|
result.nis=filter.last_nis(); result.measurement_rank=filter.measurement_rank();
|
||||||
|
if (!updated) { result.failure=RegistrationFailure::INNOVATION; return result; }
|
||||||
|
const auto trial=ErrorStateFilter::difference(prediction.state,filter.snapshot().state);
|
||||||
|
if (trial.head<3>().norm()>=0.5 || trial.segment<3>(6).norm()>=0.35) {
|
||||||
|
result.failure=RegistrationFailure::QUALITY; return result;
|
||||||
|
}
|
||||||
|
const auto step=ErrorStateFilter::difference(before,filter.snapshot().state);
|
||||||
|
if (step.segment<3>(0).norm()<1e-4 && step.segment<3>(6).norm()<1e-4) break;
|
||||||
|
}
|
||||||
|
result.stage=RegistrationStage::FINAL_FUSION;
|
||||||
|
const auto final=linearize(scan,extrinsic,map,filter.snapshot().state,o);
|
||||||
|
record(final);
|
||||||
|
if (result.inliers<o.minimum_inliers) return result;
|
||||||
|
if (result.degeneracy.dimensions==6) { result.failure=RegistrationFailure::DEGENERATE; return result; }
|
||||||
|
const bool fused=filter.correct_information(prediction,filter.snapshot().state,
|
||||||
|
final.h,final.gradient,result.degeneracy.projector,model_covariance);
|
||||||
|
result.nis=filter.last_nis(); result.measurement_rank=filter.measurement_rank();
|
||||||
|
if (!fused) { result.failure=RegistrationFailure::INNOVATION; return result; }
|
||||||
|
record(linearize(scan,extrinsic,map,filter.snapshot().state,o));
|
||||||
|
const auto change=ErrorStateFilter::difference(prediction.state,filter.snapshot().state);
|
||||||
|
result.success=result.inliers>=o.minimum_inliers && result.inlier_ratio>=o.minimum_inlier_ratio &&
|
||||||
|
result.rmse<=o.max_rmse && result.degeneracy.dimensions<6 &&
|
||||||
|
change.segment<3>(0).norm()<0.5 && change.segment<3>(6).norm()<0.35;
|
||||||
|
result.failure=result.success ? RegistrationFailure::NONE : RegistrationFailure::QUALITY;
|
||||||
|
if (result.success) result.stage=RegistrationStage::COMPLETE;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace field_localization::core
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
# field_localization/src/ros/ (ROS 适配)
|
||||||
|
|
||||||
|
把 `core/` 接到 ROS 上的三个文件。**这里只写胶水**:读参数、订阅、查 TF、排队、发布。
|
||||||
|
|
||||||
|
```
|
||||||
|
ros/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── main.cpp 可执行文件入口
|
||||||
|
├── localization_node.cpp LocalizationNode:定位节点
|
||||||
|
└── conversion.cpp PointCloud2 / Transform ⇄ core 类型
|
||||||
|
```
|
||||||
|
|
||||||
|
| 文件 | 编进 |
|
||||||
|
|---|---|
|
||||||
|
| `main.cpp` | `field_localization_node`(可执行文件) |
|
||||||
|
| `localization_node.cpp`、`conversion.cpp` | `field_localization_ros`(动态库,节点和录制工具共用) |
|
||||||
|
|
||||||
|
## `main.cpp`
|
||||||
|
|
||||||
|
`rclcpp::init` → 创建 `LocalizationNode` → `spin`。
|
||||||
|
构造失败(地图读不了、参数非法)会打印异常并返回 1。
|
||||||
|
|
||||||
|
## `conversion.cpp`
|
||||||
|
|
||||||
|
三个纯函数:`convert_cloud()`、`from_transform()`、`to_transform()`。
|
||||||
|
只依赖消息类型,不起节点。格式要求见
|
||||||
|
[`conversion.hpp` 的说明](../../include/field_localization/ros/README.md)。
|
||||||
|
|
||||||
|
## `localization_node.cpp` —— 定位节点
|
||||||
|
|
||||||
|
节点名 `field_localization`,下面写作 `~/`。
|
||||||
|
|
||||||
|
### 订阅和发布
|
||||||
|
|
||||||
|
| 方向 | 名称 | 类型 | 说明 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 订阅 | `point_cloud_topic`(默认 `/scan/points`) | `sensor_msgs/PointCloud2` | 点云。帧可以是 `lidar_frame` / `base_frame` / `imu_frame`,节点会转到雷达系 |
|
||||||
|
| 订阅 | `imu_topic`(默认 `/imu`) | `sensor_msgs/Imu` | IMU 消息的坐标系原点必须是配置的 IMU 原点 |
|
||||||
|
| 订阅 | TF | — | 读固定外参:`base_frame ← imu_frame`、`imu_frame ← lidar_frame`、点云的帧到 `lidar_frame` |
|
||||||
|
| 发布 | `~/odometry` | `nav_msgs/Odometry` | map 系的 `base_link` 位姿(6×6 协方差)+ `base_link` 系的刚体速度 `twist`(已扣除零偏与 IMU 杆臂效应,含 6×6 协方差) |
|
||||||
|
| 发布 | `~/navigation_valid` | `std_msgs/Bool` | 定位能否用于导航。状态一变立即发,另有 10 Hz 心跳 |
|
||||||
|
| 发布 | `~/status` | `std_msgs/String` | 每 5 秒一次,内容是 `模式,原因,退化维数` |
|
||||||
|
| 发布 | TF `map_frame → odom_frame` | — | 唯一的 `map → odom` 来源,不能和 AMCL 同时开 |
|
||||||
|
| 服务 | `~/save_map` | `std_srvs/Trigger` | 把当前地图存到 `export_map_path` |
|
||||||
|
| 服务 | `~/reset` | `std_srvs/Trigger` | 回到配置的已知初始位姿,不做全局搜索 |
|
||||||
|
|
||||||
|
启动入口(`sentry_up.sh` 和 launch)把 `point_cloud_topic` 设成 `/scan/points_lio`、
|
||||||
|
`reliable_clouds` 设成 `true`,也就是吃 `sentry_nav/self_filter` 出的、保留地面回波的那份点云。
|
||||||
|
|
||||||
|
### 参数
|
||||||
|
|
||||||
|
| 参数 | 默认 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `mode` | `localization` | `mapping` 或 `localization`。定位模式必须给 `map_path` |
|
||||||
|
| `map_path` | 空 | 定位模式只读加载的地图(FLMAP) |
|
||||||
|
| `export_map_path` | 空 | 建图模式的保存 / 导出路径。节点正常退出时会做一次最终导出 |
|
||||||
|
| `publish_map_to_odom` | `true` | 是否广播 TF |
|
||||||
|
| `map_frame` / `odom_frame` / `base_frame` | `map` / `odom` / `base_link` | 坐标系名 |
|
||||||
|
| `imu_frame` / `lidar_frame` | `imu_link` / `lidar_link` | 坐标系名 |
|
||||||
|
| `point_cloud_topic` / `imu_topic` | `/scan/points` / `/imu` | 输入话题 |
|
||||||
|
| `reliable_clouds` | `false` | 点云用 RELIABLE 还是 SensorData QoS。要和发布方一致 |
|
||||||
|
| `initial_x` / `initial_y` / `initial_z` | `-5` / `3` / `0` | 已知的初始位姿,**必须和出生点一致** |
|
||||||
|
| `initial_yaw` / `initial_pitch` / `initial_roll` | 0 | 同上,弧度 |
|
||||||
|
| `map_voxel_size` / `scan_voxel_size` | 0.1 / 0.1 | 地图、扫描体素边长(m) |
|
||||||
|
| `scan_timing` | `instantaneous` | `instantaneous` 或 `azimuth` |
|
||||||
|
| `scan_period_sec` / `scan_start_angle_rad` / `scan_counterclockwise` / `scan_stamp_at_end` | 0.1 / −π / true / true | 只在 `azimuth` 下有意义 |
|
||||||
|
| `gyro_noise_density` / `accel_noise_density` | 0.003 / 0.03 | IMU 噪声密度 |
|
||||||
|
| `gyro_bias_walk` / `accel_bias_walk` | 1e-5 / 1e-4 | 零偏随机游走 |
|
||||||
|
| `integration_error_scale` | 1.4 | 积分误差尺度 |
|
||||||
|
| `map_translation_sigma` / `map_rotation_sigma` | 0.03 / 0.002 | 地图和关联的不确定度(m / rad) |
|
||||||
|
| `navigation_correction_timeout` | 0.3 | 多久没配准成功就判导航无效(s) |
|
||||||
|
| `navigation_position_three_sigma` | 0.5 | 水平位置 3σ 上限(m) |
|
||||||
|
| `navigation_yaw_three_sigma_deg` | 15 | 航向 3σ 上限(度) |
|
||||||
|
| `diagnostics_path` | 空 | 非空时每帧写三行调优 CSV(预测 / 候选 / 后验),会增加磁盘写入 |
|
||||||
|
|
||||||
|
节点支持 `use_sim_time`,**只有消息和 ROS 仿真时间参与状态计算**。
|
||||||
|
|
||||||
|
### 节点内部几条要紧的逻辑
|
||||||
|
|
||||||
|
- **外参从 TF 读,读不到就等**。`LocalizationCore` 在两组固定外参齐全后才创建,不假设任何变换是恒等的
|
||||||
|
- **点云排队等 IMU**。点云到了要等 IMU 历史覆盖整帧扫描才处理,队列最多 5 帧(满了丢最旧的)。
|
||||||
|
仿真时间比扫描结束时刻晚 0.2 s 还没等到 IMU,就丢弃这帧
|
||||||
|
- **TF 是补发的**。先缓存最多 30 个位姿快照,等 `odom ← base_link` 在同一时刻的 TF 可查了,
|
||||||
|
再按 `map → odom = (map → base_link) ∘ (odom → base_link)⁻¹` 广播。
|
||||||
|
状态超过 0.1 s 没更新时,里程计和 TF 都不发
|
||||||
|
- **定位无效时不发 TF**。`navigation_valid` 为 false 期间清空待发队列;
|
||||||
|
里程计和心跳照常发,方便排查
|
||||||
|
- **仿真时钟回跳就停**。检测到 `/clock` 倒退后不再输出任何结果,必须调 `~/reset` 或重启。
|
||||||
|
联锁用的是单调墙上时钟,暂停或回拨仿真时间绕不过去
|
||||||
|
|
||||||
|
### 谁在用它的输出
|
||||||
|
|
||||||
|
| 输出 | 使用方 |
|
||||||
|
|---|---|
|
||||||
|
| TF `map → odom` | Nav2(规划、代价地图) |
|
||||||
|
| `~/navigation_valid` | [`sentry_nav/cmd_vel_relay`](../../../sentry_nav/src/cmd_vel_relay.cpp):失效就发零速度并取消目标。`nav_client`:失效就不发目标 |
|
||||||
|
|
||||||
|
## 加新东西
|
||||||
|
|
||||||
|
| 要加的 | 怎么做 |
|
||||||
|
|---|---|
|
||||||
|
| 新的参数 | 构造函数里 `declare_parameter`,写进 `core_options_` 或 `health_options`,并更新上面的表 |
|
||||||
|
| 新的话题 / 服务 | 头文件里声明,`localization_node.cpp` 里创建 |
|
||||||
|
| 新的 ROS 消息类型 ⇄ core 转换 | 写在 `conversion.cpp`,别写进节点 |
|
||||||
|
|
||||||
|
本目录的 `.cpp` 在 `xmake.lua` 里是逐个列出的,**加新的实现文件要去 `field_localization_ros` 补一行**。
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 类的声明和转换函数的要求:[`../../include/field_localization/ros/README.md`](../../include/field_localization/ros/README.md)
|
||||||
|
- 被调用的算法:[`../core/README.md`](../core/README.md)
|
||||||
|
- 录制工具复用了这里的转换函数:[`../tools/README.md`](../tools/README.md)
|
||||||
|
- 怎么把节点拉起来:[`sentry_up.sh`](../../../../src/sentry_sim/scripts/sentry_up.sh)、
|
||||||
|
[`sentry_arena.launch.py`](../../../../src/sentry_sim/launch/sentry_arena.launch.py)
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#include "field_localization/ros/conversion.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <bit>
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
namespace field_localization::ros {
|
||||||
|
core::PointCloud convert_cloud(const sensor_msgs::msg::PointCloud2 &msg) {
|
||||||
|
const auto field=[&](const char *name,bool required)->const sensor_msgs::msg::PointField* {
|
||||||
|
const auto it=std::find_if(msg.fields.begin(),msg.fields.end(),[&](const auto &f) { return f.name==name; });
|
||||||
|
if (it==msg.fields.end()) { if (required) throw std::runtime_error("missing XYZ field"); return nullptr; }
|
||||||
|
if (it->datatype!=sensor_msgs::msg::PointField::FLOAT32 || it->count<1 ||
|
||||||
|
std::uint64_t(it->offset)+4>msg.point_step) {
|
||||||
|
if (required) throw std::runtime_error("XYZ must be bounded FLOAT32 fields");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return &*it;
|
||||||
|
};
|
||||||
|
const auto *x=field("x",true),*y=field("y",true),*z=field("z",true),*intensity=field("intensity",false);
|
||||||
|
if (msg.point_step==0 || std::uint64_t(msg.width)*msg.height>1000000 ||
|
||||||
|
std::uint64_t(msg.width)*msg.point_step>msg.row_step ||
|
||||||
|
std::uint64_t(msg.row_step)*msg.height>msg.data.size()) throw std::runtime_error("invalid PointCloud2 layout");
|
||||||
|
const auto value=[&](std::size_t offset) {
|
||||||
|
std::array<std::uint8_t,4> bytes{}; std::copy_n(msg.data.data()+offset,4,bytes.data());
|
||||||
|
if (msg.is_bigendian!=(std::endian::native==std::endian::big)) std::reverse(bytes.begin(),bytes.end());
|
||||||
|
return std::bit_cast<float>(bytes);
|
||||||
|
};
|
||||||
|
core::PointCloud cloud;
|
||||||
|
cloud.timestamp_sec=msg.header.stamp.sec+1e-9*msg.header.stamp.nanosec; cloud.frame_id=msg.header.frame_id;
|
||||||
|
cloud.points.reserve(std::size_t(msg.width)*msg.height);
|
||||||
|
for (std::uint32_t row=0;row<msg.height;++row) for (std::uint32_t column=0;column<msg.width;++column) {
|
||||||
|
const std::size_t offset=std::size_t(row)*msg.row_step+std::size_t(column)*msg.point_step;
|
||||||
|
core::PointXYZI p; p.timestamp_sec=cloud.timestamp_sec;
|
||||||
|
p.position={value(offset+x->offset),value(offset+y->offset),value(offset+z->offset)};
|
||||||
|
p.intensity=intensity ? value(offset+intensity->offset) : 0;
|
||||||
|
if (p.position.allFinite() && std::isfinite(p.intensity)) cloud.points.push_back(p);
|
||||||
|
}
|
||||||
|
return cloud;
|
||||||
|
}
|
||||||
|
core::Pose3D from_transform(const geometry_msgs::msg::Transform &t) {
|
||||||
|
core::Pose3D p{Eigen::Quaterniond{t.rotation.w,t.rotation.x,t.rotation.y,t.rotation.z},
|
||||||
|
Eigen::Vector3d{t.translation.x,t.translation.y,t.translation.z}};
|
||||||
|
if (!p.translation.allFinite() || !p.rotation.coeffs().allFinite() || p.rotation.norm()<1e-12)
|
||||||
|
throw std::runtime_error("invalid TF transform");
|
||||||
|
p.rotation.normalize(); return p;
|
||||||
|
}
|
||||||
|
core::PointCloud convert_cloud_in_frame(const sensor_msgs::msg::PointCloud2 &msg,
|
||||||
|
const std::string &frame,const tf2_ros::Buffer &buffer) {
|
||||||
|
auto cloud=convert_cloud(msg);
|
||||||
|
if (cloud.frame_id==frame) return cloud;
|
||||||
|
const auto transform=from_transform(buffer.lookupTransform(
|
||||||
|
frame,cloud.frame_id,rclcpp::Time(msg.header.stamp),rclcpp::Duration::from_seconds(0.1)).transform);
|
||||||
|
for (auto &point:cloud.points)
|
||||||
|
point.position=(transform.rotation*point.position.cast<double>()+transform.translation).cast<float>();
|
||||||
|
cloud.frame_id=frame;
|
||||||
|
return cloud;
|
||||||
|
}
|
||||||
|
std::optional<core::MapBounds> declare_map_bounds(rclcpp::Node &node) {
|
||||||
|
const auto low=node.declare_parameter("map_crop_min",std::vector<double>{});
|
||||||
|
const auto high=node.declare_parameter("map_crop_max",std::vector<double>{});
|
||||||
|
if (low.empty() && high.empty()) return std::nullopt;
|
||||||
|
if (low.size()!=3 || high.size()!=3) throw std::invalid_argument("map crop requires two XYZ triples");
|
||||||
|
const core::MapBounds bounds{{low[0],low[1],low[2]},{high[0],high[1],high[2]}};
|
||||||
|
if (!bounds.valid()) throw std::invalid_argument("map crop bounds must be finite and ordered");
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
geometry_msgs::msg::Transform to_transform(const core::Pose3D &p) {
|
||||||
|
geometry_msgs::msg::Transform t; t.translation.x=p.translation.x(); t.translation.y=p.translation.y(); t.translation.z=p.translation.z();
|
||||||
|
t.rotation.w=p.rotation.w(); t.rotation.x=p.rotation.x(); t.rotation.y=p.rotation.y(); t.rotation.z=p.rotation.z(); return t;
|
||||||
|
}
|
||||||
|
geometry_msgs::msg::Twist to_twist(const core::Twist3D &v) {
|
||||||
|
geometry_msgs::msg::Twist t;
|
||||||
|
t.linear.x=v.linear.x(); t.linear.y=v.linear.y(); t.linear.z=v.linear.z();
|
||||||
|
t.angular.x=v.angular.x(); t.angular.y=v.angular.y(); t.angular.z=v.angular.z();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
} // namespace field_localization::ros
|
||||||
@@ -1,234 +1,244 @@
|
|||||||
#include "field_localization/ros/localization_node.hpp"
|
#include "field_localization/ros/localization_node.hpp"
|
||||||
|
|
||||||
#include <sensor_msgs/point_cloud2_iterator.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <numbers>
|
||||||
#include <functional>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const sensor_msgs::msg::PointField *
|
|
||||||
find_field(const sensor_msgs::msg::PointCloud2 &cloud,
|
|
||||||
const std::string &name) {
|
|
||||||
const auto it =
|
|
||||||
std::find_if(cloud.fields.begin(), cloud.fields.end(),
|
|
||||||
[&name](const auto &field) { return field.name == name; });
|
|
||||||
|
|
||||||
return it != cloud.fields.end() ? &(*it) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_float32_field(const sensor_msgs::msg::PointField *field,
|
|
||||||
std::uint32_t point_step) {
|
|
||||||
if (field == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return field->datatype == sensor_msgs::msg::PointField::FLOAT32 &&
|
|
||||||
field->count >= 1 &&
|
|
||||||
static_cast<std::size_t>(field->offset) + sizeof(float) <= point_step;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace field_localization::ros {
|
namespace field_localization::ros {
|
||||||
LocalizationNode::LocalizationNode(const rclcpp::NodeOptions &options)
|
LocalizationNode::LocalizationNode(const rclcpp::NodeOptions &options):Node("field_localization",options) {
|
||||||
: Node("field_localization", options) {
|
map_frame_=declare_parameter<std::string>("map_frame","map"); odom_frame_=declare_parameter<std::string>("odom_frame","odom");
|
||||||
point_cloud_topic_ =
|
base_frame_=declare_parameter<std::string>("base_frame","base_link"); imu_frame_=declare_parameter<std::string>("imu_frame","imu_link");
|
||||||
declare_parameter<std::string>("point_cloud_topic", "/livox/lidar");
|
lidar_frame_=declare_parameter<std::string>("lidar_frame","lidar_link");
|
||||||
|
const auto mode=declare_parameter<std::string>("mode","localization");
|
||||||
imu_topic_ = declare_parameter<std::string>("imu_topic", "/livox/imu");
|
if (mode!="mapping" && mode!="localization") throw std::invalid_argument("mode must be mapping or localization");
|
||||||
|
core_options_.map_mode=mode=="mapping" ? core::MapMode::MAPPING : core::MapMode::LOCALIZATION;
|
||||||
// Subscribe to LiDAR point clouds.
|
core_options_.map_bounds=declare_map_bounds(*this);
|
||||||
point_cloud_sub_ = create_subscription<sensor_msgs::msg::PointCloud2>(
|
map_path_=declare_parameter<std::string>("map_path",""); export_path_=declare_parameter<std::string>("export_map_path","");
|
||||||
point_cloud_topic_, rclcpp::SensorDataQoS(),
|
if (mode=="localization" && map_path_.empty()) throw std::invalid_argument("localization requires map_path; run explicit mapping first");
|
||||||
std::bind(&LocalizationNode::on_point_cloud, this,
|
if (mode=="localization") {
|
||||||
std::placeholders::_1));
|
std::string error;
|
||||||
|
if (!core::read_map(map_path_,error,core_options_.map_bounds)) throw std::runtime_error(error);
|
||||||
// Subscribe to IMU measurements.
|
}
|
||||||
imu_sub_ = create_subscription<sensor_msgs::msg::Imu>(
|
publish_map_to_odom_=declare_parameter<bool>("publish_map_to_odom",true);
|
||||||
imu_topic_, rclcpp::SensorDataQoS(),
|
auto &pose=core_options_.initial_pose;
|
||||||
std::bind(&LocalizationNode::on_imu, this, std::placeholders::_1));
|
pose.translation={declare_parameter<double>("initial_x",-5),declare_parameter<double>("initial_y",3),declare_parameter<double>("initial_z",0)};
|
||||||
|
const double roll=declare_parameter<double>("initial_roll",0),pitch=declare_parameter<double>("initial_pitch",0),yaw=declare_parameter<double>("initial_yaw",0);
|
||||||
RCLCPP_INFO(get_logger(), "Field localization node started.");
|
pose.rotation=core::exp_so3({0,0,yaw})*core::exp_so3({0,pitch,0})*core::exp_so3({roll,0,0});
|
||||||
|
core_options_.noise.gyro=declare_parameter<double>("gyro_noise_density",0.003);
|
||||||
RCLCPP_INFO(get_logger(), "Point cloud topic: %s",
|
core_options_.noise.accel=declare_parameter<double>("accel_noise_density",0.03);
|
||||||
point_cloud_topic_.c_str());
|
core_options_.noise.gyro_bias_walk=declare_parameter<double>("gyro_bias_walk",1e-5);
|
||||||
|
core_options_.noise.integration_error_scale=declare_parameter<double>("integration_error_scale",core_options_.noise.integration_error_scale);
|
||||||
RCLCPP_INFO(get_logger(), "IMU topic: %s", imu_topic_.c_str());
|
core_options_.noise.accel_bias_walk=declare_parameter<double>("accel_bias_walk",1e-4);
|
||||||
|
core_options_.map_resolution=declare_parameter<double>("map_voxel_size",0.1);
|
||||||
status_timer_ = create_wall_timer(
|
core_options_.registration.map_translation_sigma=declare_parameter<double>("map_translation_sigma",core_options_.registration.map_translation_sigma);
|
||||||
std::chrono::seconds(5),
|
core_options_.registration.map_rotation_sigma=declare_parameter<double>("map_rotation_sigma",0.002);
|
||||||
std::bind(&LocalizationNode::print_localization_status, this));
|
if(!std::isfinite(core_options_.registration.map_translation_sigma) || core_options_.registration.map_translation_sigma<0 ||
|
||||||
|
!std::isfinite(core_options_.registration.map_rotation_sigma) || core_options_.registration.map_rotation_sigma<0)
|
||||||
|
throw std::invalid_argument("invalid map model uncertainty");
|
||||||
|
core_options_.registration.scan_voxel=declare_parameter<double>("scan_voxel_size",0.1);
|
||||||
|
const auto timing=declare_parameter<std::string>("scan_timing","instantaneous");
|
||||||
|
if (timing!="instantaneous" && timing!="azimuth") throw std::invalid_argument("scan_timing must be instantaneous or azimuth");
|
||||||
|
core_options_.deskew.timing=timing=="azimuth" ? core::ScanTiming::AZIMUTH : core::ScanTiming::INSTANTANEOUS;
|
||||||
|
core_options_.deskew.period_sec=declare_parameter<double>("scan_period_sec",0.1);
|
||||||
|
core_options_.deskew.start_angle_rad=declare_parameter<double>("scan_start_angle_rad",-std::numbers::pi);
|
||||||
|
core_options_.deskew.counterclockwise=declare_parameter<bool>("scan_counterclockwise",true);
|
||||||
|
core_options_.deskew.stamp_at_end=declare_parameter<bool>("scan_stamp_at_end",true);
|
||||||
|
if (!pose.translation.allFinite() || !pose.rotation.coeffs().allFinite()) throw std::invalid_argument("invalid initial pose");
|
||||||
|
// Validate process-noise options before the first sensor callback.
|
||||||
|
const core::ErrorStateFilter validate_noise(core_options_.noise); (void)validate_noise;
|
||||||
|
tf_buffer_=std::make_unique<tf2_ros::Buffer>(get_clock());
|
||||||
|
tf_listener_=std::make_unique<tf2_ros::TransformListener>(*tf_buffer_);
|
||||||
|
broadcaster_=std::make_unique<tf2_ros::TransformBroadcaster>(this);
|
||||||
|
odometry_pub_=create_publisher<nav_msgs::msg::Odometry>("~/odometry",10);
|
||||||
|
core::HealthOptions health_options;
|
||||||
|
health_options.correction_timeout=declare_parameter<double>("navigation_correction_timeout",0.3);
|
||||||
|
health_options.position_three_sigma=declare_parameter<double>("navigation_position_three_sigma",0.5);
|
||||||
|
health_options.yaw_three_sigma=declare_parameter<double>("navigation_yaw_three_sigma_deg",15)*std::numbers::pi/180;
|
||||||
|
if(!std::isfinite(health_options.correction_timeout) || health_options.correction_timeout<=0 ||
|
||||||
|
!std::isfinite(health_options.position_three_sigma) || health_options.position_three_sigma<=0 ||
|
||||||
|
!std::isfinite(health_options.yaw_three_sigma) || health_options.yaw_three_sigma<=0)
|
||||||
|
throw std::invalid_argument("invalid navigation health limits");
|
||||||
|
health_=core::TrackingHealth(health_options);
|
||||||
|
navigation_valid_pub_=create_publisher<std_msgs::msg::Bool>("~/navigation_valid",rclcpp::QoS(1));
|
||||||
|
const auto trace_path=declare_parameter<std::string>("diagnostics_path","");
|
||||||
|
if(!trace_path.empty()) {
|
||||||
|
trace_.open(trace_path); trace_.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
core::write_filter_trace_header(trace_);
|
||||||
|
}
|
||||||
|
health_timer_=create_wall_timer(std::chrono::milliseconds(100),[this] { publish_health(true); });
|
||||||
|
status_pub_=create_publisher<std_msgs::msg::String>("~/status",10);
|
||||||
|
const auto cloud_topic=declare_parameter<std::string>("point_cloud_topic","/scan/points");
|
||||||
|
const auto imu_topic=declare_parameter<std::string>("imu_topic","/imu");
|
||||||
|
const bool reliable_clouds=declare_parameter<bool>("reliable_clouds",false);
|
||||||
|
const rclcpp::QoS cloud_qos=reliable_clouds ? rclcpp::QoS(5).reliable() : rclcpp::SensorDataQoS().keep_last(5);
|
||||||
|
point_cloud_sub_=create_subscription<sensor_msgs::msg::PointCloud2>(cloud_topic,cloud_qos,
|
||||||
|
[this](sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) { on_point_cloud(std::move(msg)); });
|
||||||
|
imu_sub_=create_subscription<sensor_msgs::msg::Imu>(imu_topic,rclcpp::SensorDataQoS().keep_last(400),
|
||||||
|
[this](sensor_msgs::msg::Imu::ConstSharedPtr msg) { on_imu(std::move(msg)); });
|
||||||
|
save_service_=create_service<std_srvs::srv::Trigger>("~/save_map",[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
if (!core_ || export_path_.empty()) { response->message="core not initialized or export_map_path empty"; return; }
|
||||||
|
response->success=core_->export_map(export_path_,response->message);
|
||||||
|
if (response->success) response->message=export_path_;
|
||||||
|
});
|
||||||
|
reset_service_=create_service<std_srvs::srv::Trigger>("~/reset",[this](const std::shared_ptr<std_srvs::srv::Trigger::Request>,
|
||||||
|
std::shared_ptr<std_srvs::srv::Trigger::Response> response) {
|
||||||
|
core_.reset(); health_.reset(); scans_.clear(); pending_tf_.clear(); clock_rewound_=false; last_clock_=-1; last_published_=-1;
|
||||||
|
response->success=true; response->message="reset to configured known initial pose; no global search";
|
||||||
|
});
|
||||||
|
status_timer_=create_wall_timer(std::chrono::seconds(5),[this] { print_localization_status(); });
|
||||||
|
RCLCPP_INFO(get_logger(),"mode=%s cloud=%s imu=%s TF=%s->%s enabled=%d; initial pose must be known",
|
||||||
|
mode.c_str(),cloud_topic.c_str(),imu_topic.c_str(),map_frame_.c_str(),odom_frame_.c_str(),publish_map_to_odom_);
|
||||||
}
|
}
|
||||||
|
LocalizationNode::~LocalizationNode() {
|
||||||
void LocalizationNode::on_point_cloud(
|
if (core_ && core_options_.map_mode==core::MapMode::MAPPING && !export_path_.empty()) {
|
||||||
sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) {
|
std::string error;
|
||||||
core::PointCloud cloud;
|
if (!core_->export_map(export_path_,error)) RCLCPP_ERROR(get_logger(),"map export failed: %s",error.c_str());
|
||||||
|
|
||||||
cloud.timestamp_sec = rclcpp::Time(msg->header.stamp).seconds();
|
|
||||||
|
|
||||||
cloud.frame_id = msg->header.frame_id;
|
|
||||||
|
|
||||||
// 查找点云字段
|
|
||||||
const auto *field_x = find_field(*msg, "x");
|
|
||||||
const auto *field_y = find_field(*msg, "y");
|
|
||||||
const auto *field_z = find_field(*msg, "z");
|
|
||||||
const auto *field_intensity = find_field(*msg, "intensity");
|
|
||||||
|
|
||||||
// 检查 XYZ 字段
|
|
||||||
if (!is_float32_field(field_x, msg->point_step) ||
|
|
||||||
!is_float32_field(field_y, msg->point_step) ||
|
|
||||||
!is_float32_field(field_z, msg->point_step)) {
|
|
||||||
RCLCPP_ERROR(get_logger(), "PointCloud2 requires FLOAT32 x/y/z fields.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 检查 intensity 字段
|
bool LocalizationNode::check_clock() {
|
||||||
if (field_intensity != nullptr &&
|
const double time=now().seconds();
|
||||||
!is_float32_field(field_intensity, msg->point_step)) {
|
if (last_clock_>=0 && time<last_clock_-1e-6) {
|
||||||
RCLCPP_WARN(get_logger(),
|
clock_rewound_=true; scans_.clear(); pending_tf_.clear();
|
||||||
"Unsupported intensity datatype. Intensity will be ignored.");
|
RCLCPP_ERROR(get_logger(),"simulation time rewound; output halted, explicit ~/reset or restart required");
|
||||||
field_intensity = nullptr;
|
|
||||||
}
|
}
|
||||||
|
last_clock_=time; return !clock_rewound_;
|
||||||
// 检查点云内存布局
|
}
|
||||||
const std::size_t minimum_row_size =
|
bool LocalizationNode::ensure_core() {
|
||||||
static_cast<std::size_t>(msg->width) * msg->point_step;
|
if (core_) return true;
|
||||||
|
|
||||||
const std::size_t required_data_size =
|
|
||||||
static_cast<std::size_t>(msg->row_step) * msg->height;
|
|
||||||
|
|
||||||
if (msg->point_step == 0 || msg->row_step < minimum_row_size ||
|
|
||||||
msg->data.size() < required_data_size) {
|
|
||||||
RCLCPP_ERROR(get_logger(), "Invalid PointCloud2 memory layout.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool has_intensity = field_intensity != nullptr;
|
|
||||||
|
|
||||||
cloud.points.reserve(static_cast<std::size_t>(msg->width) * msg->height);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_x(*msg, "x");
|
core_options_.base_from_imu=from_transform(tf_buffer_->lookupTransform(base_frame_,imu_frame_,tf2::TimePointZero).transform);
|
||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_y(*msg, "y");
|
if (core_options_.deskew.timing==core::ScanTiming::AZIMUTH) {
|
||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_z(*msg, "z");
|
const auto fixed=tf_buffer_->lookupTransform(imu_frame_,lidar_frame_,tf2::TimePointZero);
|
||||||
|
if (rclcpp::Time(fixed.header.stamp).nanoseconds()!=0)
|
||||||
if (has_intensity) {
|
throw std::runtime_error("azimuth deskew requires a fixed IMU-to-LiDAR transform");
|
||||||
sensor_msgs::PointCloud2ConstIterator<float> iter_intensity(*msg,
|
core_options_.deskew.imu_from_sensor=from_transform(fixed.transform);
|
||||||
"intensity");
|
|
||||||
|
|
||||||
for (; iter_x != iter_x.end();
|
|
||||||
++iter_x, ++iter_y, ++iter_z, ++iter_intensity) {
|
|
||||||
core::PointXYZI point;
|
|
||||||
|
|
||||||
point.position.x() = *iter_x;
|
|
||||||
point.position.y() = *iter_y;
|
|
||||||
point.position.z() = *iter_z;
|
|
||||||
point.intensity = *iter_intensity;
|
|
||||||
|
|
||||||
point.timestamp_sec = cloud.timestamp_sec;
|
|
||||||
|
|
||||||
if (!point.position.allFinite() || !std::isfinite(point.intensity)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cloud.points.push_back(std::move(point));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z) {
|
core_options_.deskew.imu_from_sensor=core::Pose3D{};
|
||||||
core::PointXYZI point;
|
|
||||||
|
|
||||||
point.position.x() = *iter_x;
|
|
||||||
point.position.y() = *iter_y;
|
|
||||||
point.position.z() = *iter_z;
|
|
||||||
|
|
||||||
point.timestamp_sec = cloud.timestamp_sec;
|
|
||||||
|
|
||||||
if (!point.position.allFinite() || !std::isfinite(point.intensity)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cloud.points.push_back(std::move(point));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (const std::runtime_error &error) {
|
core_=std::make_unique<core::LocalizationCore>(core_options_);
|
||||||
RCLCPP_ERROR(get_logger(), "Failed to convert PointCloud2: %s",
|
if (core_options_.map_mode==core::MapMode::LOCALIZATION) {
|
||||||
error.what());
|
std::string error; if (!core_->load_map(map_path_,error)) { core_.reset(); throw std::runtime_error(error); }
|
||||||
return;
|
}
|
||||||
|
return true;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"waiting for fixed extrinsics/map: %s",e.what()); return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloud.points.empty()) {
|
|
||||||
RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 5000,
|
|
||||||
"Received an empty or invalid point cloud.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
++point_cloud_count_;
|
|
||||||
|
|
||||||
if (!core_.process_point_cloud(cloud)) {
|
|
||||||
RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 5000,
|
|
||||||
"Rejected point cloud");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RCLCPP_INFO_THROTTLE(
|
|
||||||
get_logger(), *get_clock(), 5000,
|
|
||||||
"Received %zu point clouds, latest cloud contains %zu points.",
|
|
||||||
point_cloud_count_, cloud.points.size());
|
|
||||||
}
|
}
|
||||||
|
void LocalizationNode::on_point_cloud(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) {
|
||||||
|
if (!check_clock() || !ensure_core()) return;
|
||||||
|
try {
|
||||||
|
const auto &frame=msg->header.frame_id;
|
||||||
|
if (frame!=lidar_frame_ && frame!=base_frame_ && frame!=imu_frame_)
|
||||||
|
throw std::runtime_error("unexpected cloud frame; configure lidar_frame explicitly");
|
||||||
|
const auto &target=core_options_.deskew.timing==core::ScanTiming::AZIMUTH ? lidar_frame_ : imu_frame_;
|
||||||
|
auto cloud=convert_cloud_in_frame(*msg,target,*tf_buffer_);
|
||||||
|
if (scans_.size()>=5) { scans_.pop_front(); RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"scan queue overflow"); }
|
||||||
|
scans_.push_back(std::move(cloud)); drain_scans(); publish_estimate();
|
||||||
|
} catch (const std::exception &e) { RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"cloud rejected: %s",e.what()); }
|
||||||
|
}
|
||||||
void LocalizationNode::on_imu(sensor_msgs::msg::Imu::ConstSharedPtr msg) {
|
void LocalizationNode::on_imu(sensor_msgs::msg::Imu::ConstSharedPtr msg) {
|
||||||
core::ImuData imu;
|
if (!check_clock() || !ensure_core()) return;
|
||||||
|
try {
|
||||||
imu.timestamp_sec = rclcpp::Time(msg->header.stamp).seconds();
|
const auto extrinsic=from_transform(tf_buffer_->lookupTransform(imu_frame_,msg->header.frame_id,tf2::TimePointZero).transform);
|
||||||
|
if (extrinsic.translation.norm()>1e-6) throw std::runtime_error("IMU frame must refer to configured IMU origin");
|
||||||
imu.frame_id = msg->header.frame_id;
|
core::ImuData imu; imu.timestamp_sec=msg->header.stamp.sec+1e-9*msg->header.stamp.nanosec; imu.frame_id=imu_frame_;
|
||||||
|
imu.angular_velocity=extrinsic.rotation*Eigen::Vector3d{msg->angular_velocity.x,msg->angular_velocity.y,msg->angular_velocity.z};
|
||||||
imu.angular_velocity =
|
imu.linear_acceleration=extrinsic.rotation*Eigen::Vector3d{msg->linear_acceleration.x,msg->linear_acceleration.y,msg->linear_acceleration.z};
|
||||||
Eigen::Vector3d{msg->angular_velocity.x, msg->angular_velocity.y,
|
if (!core_->process_imu(imu)) RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"IMU rejected: %s",core::reason_name(core_->get_status().reason));
|
||||||
msg->angular_velocity.z};
|
drain_scans(); publish_estimate();
|
||||||
|
} catch (const std::exception &e) { RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"IMU conversion rejected: %s",e.what()); }
|
||||||
imu.linear_acceleration =
|
}
|
||||||
Eigen::Vector3d{msg->linear_acceleration.x, msg->linear_acceleration.y,
|
void LocalizationNode::drain_scans() {
|
||||||
msg->linear_acceleration.z};
|
while (!scans_.empty()) {
|
||||||
|
const auto s=core_->get_status(); const double end=core::scan_window(scans_.front(),core_options_.deskew).second;
|
||||||
++imu_count_;
|
if (!s.has_imu || s.last_imu_timestamp<end) {
|
||||||
|
if (now().seconds()-end>0.2) { scans_.pop_front(); RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"scan expired waiting for IMU"); continue; }
|
||||||
if (!core_.process_imu(imu)) {
|
break;
|
||||||
RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 5000,
|
}
|
||||||
"Rejected IMU message");
|
core_->process_point_cloud(scans_.front());
|
||||||
return;
|
if(trace_.is_open()) {
|
||||||
|
const auto snapshot=core_->get_snapshot();
|
||||||
|
core::write_filter_trace(trace_,end,"prediction",snapshot.status.registration_prediction,snapshot.status);
|
||||||
|
core::write_filter_trace(trace_,end,"candidate",snapshot.status.registration.estimate,snapshot.status);
|
||||||
|
core::write_filter_trace(trace_,end,"posterior",snapshot.filter,snapshot.status); trace_.flush();
|
||||||
|
}
|
||||||
|
scans_.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
RCLCPP_INFO_THROTTLE(get_logger(), *get_clock(), 5000,
|
|
||||||
"Received %zu IMU messages. "
|
|
||||||
"Gyro: [%.3f, %.3f, %.3f] rad/s",
|
|
||||||
imu_count_, imu.angular_velocity.x(),
|
|
||||||
imu.angular_velocity.y(), imu.angular_velocity.z());
|
|
||||||
}
|
}
|
||||||
|
void LocalizationNode::publish_estimate() {
|
||||||
|
if (!core_) return;
|
||||||
|
const auto snapshot=core_->get_snapshot();
|
||||||
|
if (!snapshot.status.has_imu || now().seconds()-snapshot.status.state_timestamp>0.1) { pending_tf_.clear(); return; }
|
||||||
|
if (snapshot.status.state_timestamp>last_published_) {
|
||||||
|
const auto stamp=rclcpp::Time(static_cast<std::int64_t>(std::llround(snapshot.status.state_timestamp*1e9)),RCL_ROS_TIME);
|
||||||
|
nav_msgs::msg::Odometry odom; odom.header.stamp=stamp; odom.header.frame_id=map_frame_; odom.child_frame_id=base_frame_;
|
||||||
|
const auto transform=to_transform(snapshot.pose);
|
||||||
|
odom.pose.pose.position.x=transform.translation.x; odom.pose.pose.position.y=transform.translation.y; odom.pose.pose.position.z=transform.translation.z;
|
||||||
|
odom.pose.pose.orientation=transform.rotation;
|
||||||
|
const core::Matrix6 covariance=core::base_pose_covariance(snapshot,core_options_.base_from_imu);
|
||||||
|
for (int i=0;i<6;++i) for (int j=0;j<6;++j) odom.pose.covariance[6*i+j]=covariance(i,j);
|
||||||
|
odom.twist.twist=to_twist(snapshot.twist);
|
||||||
|
const core::Matrix6 twist_covariance=core::base_twist_covariance(
|
||||||
|
snapshot,core_options_.base_from_imu,core_options_.noise.gyro);
|
||||||
|
for (int i=0;i<6;++i) for (int j=0;j<6;++j) odom.twist.covariance[6*i+j]=twist_covariance(i,j);
|
||||||
|
odometry_pub_->publish(odom); last_published_=snapshot.status.state_timestamp;
|
||||||
|
pending_tf_.push_back(snapshot); if (pending_tf_.size()>30) pending_tf_.pop_front();
|
||||||
|
}
|
||||||
|
publish_health();
|
||||||
|
if (!navigation_valid()) { pending_tf_.clear(); return; }
|
||||||
|
if (!publish_map_to_odom_) { pending_tf_.clear(); return; }
|
||||||
|
while (!pending_tf_.empty()) {
|
||||||
|
const auto &s=pending_tf_.front();
|
||||||
|
if (now().seconds()-s.status.state_timestamp>0.1) { pending_tf_.pop_front(); continue; }
|
||||||
|
const auto stamp=rclcpp::Time(static_cast<std::int64_t>(std::llround(s.status.state_timestamp*1e9)),RCL_ROS_TIME);
|
||||||
|
try {
|
||||||
|
const auto odom_from_base=from_transform(tf_buffer_->lookupTransform(odom_frame_,base_frame_,stamp).transform);
|
||||||
|
geometry_msgs::msg::TransformStamped tf; tf.header.stamp=stamp; tf.header.frame_id=map_frame_; tf.child_frame_id=odom_frame_;
|
||||||
|
tf.transform=to_transform(core::compose(s.pose,core::inverse(odom_from_base))); broadcaster_->sendTransform(tf); pending_tf_.pop_front();
|
||||||
|
} catch (const tf2::TransformException &) { break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool LocalizationNode::navigation_valid() {
|
||||||
|
if(!core_ || clock_rewound_) return false;
|
||||||
|
return health_.update(core_->get_snapshot(),core_options_.base_from_imu,now().seconds());
|
||||||
|
}
|
||||||
|
void LocalizationNode::publish_health(bool heartbeat) {
|
||||||
|
const bool valid=check_clock() && navigation_valid();
|
||||||
|
if(heartbeat || valid!=last_health_) {
|
||||||
|
std_msgs::msg::Bool message; message.data=valid; navigation_valid_pub_->publish(message);
|
||||||
|
}
|
||||||
|
if(last_health_ && !valid && core_) {
|
||||||
|
const auto s=core_->get_status();
|
||||||
|
RCLCPP_ERROR(get_logger(),"localization no longer valid for navigation; TF halted: state_age=%.6f correction_age=%.6f position_3sigma=%.6f yaw_3sigma_deg=%.6f reason=%s",
|
||||||
|
now().seconds()-s.state_timestamp,now().seconds()-s.last_correction_timestamp,
|
||||||
|
health_.position_three_sigma(),health_.yaw_three_sigma()*180/std::numbers::pi,core::reason_name(s.reason));
|
||||||
|
if (s.reason==core::FailureReason::REGISTRATION_FAILED) {
|
||||||
|
const auto ®=s.registration;
|
||||||
|
const auto &initial=reg.initial_associations;
|
||||||
|
const auto &last=reg.last_associations;
|
||||||
|
RCLCPP_ERROR(get_logger(),"registration stage=%s failure=%s scan=%.9f initial(inliers=%zu planes=%zu outside_support=%zu distance_rejected=%zu) last(inliers=%zu planes=%zu outside_support=%zu distance_rejected=%zu)",
|
||||||
|
core::registration_stage_name(reg.stage),core::registration_failure_name(reg.failure),
|
||||||
|
s.last_point_cloud_timestamp,initial.inliers,initial.candidate_planes,initial.outside_support,
|
||||||
|
initial.plane_distance_rejected,last.inliers,last.candidate_planes,last.outside_support,
|
||||||
|
last.plane_distance_rejected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last_health_=valid;
|
||||||
|
}
|
||||||
void LocalizationNode::print_localization_status() {
|
void LocalizationNode::print_localization_status() {
|
||||||
const auto status = core_.get_status();
|
if (!core_) { RCLCPP_INFO(get_logger(),"localization waiting for fixed sensor TF"); return; }
|
||||||
|
const auto s=core_->get_status(); std::ostringstream directions;
|
||||||
RCLCPP_INFO(get_logger(), "========== Localization Status ==========");
|
for (int i=0;i<s.degenerate_dimensions;++i) directions<<'['<<s.degenerate_basis.col(i).transpose()<<"] ";
|
||||||
|
RCLCPP_INFO(get_logger(),"mode=%s reason=%s%s IMU=%zu rejected=%zu clouds=%zu rejected=%zu valid=%zu rmse=%s inliers=%zu (%.1f%%) degenerate=%d keyframes=%zu map=%zu",
|
||||||
RCLCPP_INFO(
|
core::mode_name(s.mode),core::reason_name(s.reason),clock_rewound_ ? " CLOCK_REWOUND" : "",s.imu_count,s.rejected_imu_count,
|
||||||
get_logger(), "IMU: received=%zu, rejected=%zu, last_timestamp=%.6f",
|
s.point_cloud_count,s.rejected_point_cloud_count,s.last_point_count,(s.registration_residual_available ? std::to_string(s.registration_rmse)+"m" : "unavailable").c_str(),s.inlier_count,100*s.inlier_ratio,
|
||||||
status.imu_count, status.rejected_imu_count, status.last_imu_timestamp);
|
s.degenerate_dimensions,s.keyframe_count,s.map_point_count);
|
||||||
|
if(!s.registration_residual_available) RCLCPP_INFO(get_logger(),"registration residual unavailable (not zero error)");
|
||||||
RCLCPP_INFO(get_logger(),
|
RCLCPP_INFO(get_logger(),"navigation_valid=%d correction_age=%.3fs NIS=%.3f rank=%d",navigation_valid(),
|
||||||
"PointCloud: received=%zu, rejected=%zu, last_timestamp=%.6f",
|
s.last_correction_timestamp<0 ? -1 : now().seconds()-s.last_correction_timestamp,s.registration.nis,s.registration.measurement_rank);
|
||||||
status.point_cloud_count, status.rejected_point_cloud_count,
|
RCLCPP_INFO(get_logger(),"null directions [map dx dy dz, IMU droll dpitch dyaw]: %s",directions.str().c_str());
|
||||||
status.last_point_cloud_timestamp);
|
std_msgs::msg::String message; message.data=std::string(core::mode_name(s.mode))+","+core::reason_name(s.reason)+","+std::to_string(s.degenerate_dimensions);
|
||||||
|
status_pub_->publish(message);
|
||||||
RCLCPP_INFO(get_logger(), "Latest valid point count: %zu",
|
|
||||||
status.last_point_count);
|
|
||||||
|
|
||||||
RCLCPP_INFO(get_logger(), "==========================================");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace field_localization::ros
|
} // namespace field_localization::ros
|
||||||
@@ -8,7 +8,8 @@ int main(int argc, char **argv) {
|
|||||||
rclcpp::init(argc, argv);
|
rclcpp::init(argc, argv);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto node = std::make_shared<field_localization::ros::LocalizationNode>();
|
rclcpp::NodeOptions options;
|
||||||
|
auto node = std::make_shared<field_localization::ros::LocalizationNode>(options);
|
||||||
|
|
||||||
rclcpp::spin(node);
|
rclcpp::spin(node);
|
||||||
} catch (const std::exception &error) {
|
} catch (const std::exception &error) {
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
# field_localization/src/tools/ (离线工具)
|
||||||
|
|
||||||
|
两个独立的可执行文件,都是录制 / 命令行工具,不在导航链路上跑。
|
||||||
|
|
||||||
|
```
|
||||||
|
tools/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── record.cpp field_localization_record 录数据集(ROS 节点)
|
||||||
|
└── replay.cpp field_localization_replay 离线回放打分(不依赖 ROS)
|
||||||
|
```
|
||||||
|
|
||||||
|
| target | 依赖 ROS | 作用 |
|
||||||
|
|---|---|---|
|
||||||
|
| `field_localization_record` | 是 | 把仿真里的点云、IMU、真值按时间录成一个数据集目录 |
|
||||||
|
| `field_localization_replay` | 否 | 不开 Gazebo,把录好的数据集喂给同一套 `core/`,输出轨迹和精度指标 |
|
||||||
|
|
||||||
|
两个工具和在线节点链接的是同一个静态库 `field_localization_core`,
|
||||||
|
回放走的就是在线那套滤波和配准代码,结果才和在线行为可比。
|
||||||
|
|
||||||
|
## `record.cpp` —— 录数据集
|
||||||
|
|
||||||
|
节点名 `field_localization_record`。通常不用手敲,由
|
||||||
|
[`tools/capture_lio.py`](../../../../tools/capture_lio.py) 在隔离的 Gazebo 里拉起来。
|
||||||
|
|
||||||
|
| 参数 | 默认 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `output_directory` | 空(必填) | 输出目录,**必须是新的**(里面已有 `imu.csv` 就拒绝启动) |
|
||||||
|
| `duration_sec` | 120 | 录多长(仿真时间) |
|
||||||
|
| `point_cloud_topic` | `/scan/points_lio` | 点云输入,RELIABLE QoS |
|
||||||
|
| `initial_x` / `initial_y` / `initial_z` / `initial_yaw` | `-5` / `3` / `0` / `0` | 写进 `config.txt` 的已知初始位姿 |
|
||||||
|
|
||||||
|
订阅点云、`/imu`(坐标系必须是 `imu_link`)和 `/evaluation/ground_truth`
|
||||||
|
(Gazebo 的 PosePublisher 发的独立真值)。
|
||||||
|
收到第一条 IMU 且固定外参可查时开始录,IMU 和真值都越过结束时刻后写 `complete.txt` 并退出。
|
||||||
|
|
||||||
|
输出的布局(每种文件的格式见 [`../../tests/data/README.md`](../../tests/data/README.md)):
|
||||||
|
|
||||||
|
```
|
||||||
|
<output_directory>/
|
||||||
|
├── config.txt 已知初始位姿、固定外参、扫描时间模型
|
||||||
|
├── imu.csv IMU 系原始测量
|
||||||
|
├── scans.csv 每帧点云的时间戳和文件名
|
||||||
|
├── clouds/N.flpc 点云,已转到 lidar_link 系
|
||||||
|
├── truth.tum 世界系真值
|
||||||
|
└── complete.txt 录完的标志,里面有样本计数
|
||||||
|
```
|
||||||
|
|
||||||
|
- 真值只写进 `truth.tum`,不进定位器,也不发到 TF
|
||||||
|
- 点云只收时间戳落在录制窗口内的,而且必须严格递增
|
||||||
|
- IMU 和真值缺一样都不会结束,节点会一直等
|
||||||
|
|
||||||
|
## `replay.cpp` —— 离线回放
|
||||||
|
|
||||||
|
不依赖 ROS,直接跑:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev
|
||||||
|
build/bin/field_localization_replay \
|
||||||
|
--dataset generated/lio_evaluation \
|
||||||
|
--mode localization \
|
||||||
|
--map src/sentry_sim/maps/field_full.flmap \
|
||||||
|
--output generated/lio_metrics
|
||||||
|
```
|
||||||
|
|
||||||
|
| 参数 | 必填 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `--dataset DIR` | 是 | 数据集目录 |
|
||||||
|
| `--mode mapping` 或 `--mode localization` | 是 | 回放模式。`mapping` 结束时把地图写到 `--map` |
|
||||||
|
| `--map FILE` | 是 | 定位模式要加载的地图,或建图模式要输出的地图 |
|
||||||
|
| `--output DIR` | 是 | 结果目录,不存在会创建 |
|
||||||
|
| `--inspect-scan 秒` | 否 | 打印某一帧在预测位姿和真值位姿下各有多少关联。要求定位模式、`instantaneous` 扫描和 `truth.tum` |
|
||||||
|
| `--map-translation-sigma 值` | 否 | 覆盖地图平移不确定度 |
|
||||||
|
| `--integration-error-scale 值` | 否 | 覆盖积分误差尺度 |
|
||||||
|
|
||||||
|
参数一律写成 `--键 值` 成对出现,**每个选项后面都必须跟一个值**。
|
||||||
|
要查的时间戳从数据集的 `scans.csv` 里挑。
|
||||||
|
|
||||||
|
`--output` 里生成四个文件:
|
||||||
|
|
||||||
|
| 文件 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| `trajectory.tum` | 估计轨迹(未对齐真值) |
|
||||||
|
| `status.csv` | 每帧的模式、原因、RMSE、内点、退化维数、零偏、新息、单帧耗时 |
|
||||||
|
| `filter_trace.csv` | 每帧三行(预测 / 候选 / 后验)的完整滤波状态、协方差、信息矩阵 |
|
||||||
|
| `metrics.txt` | 帧数、`FULL` 比例、单帧耗时 p95;有真值时还有 ATE 和 1 秒 RPE,没有就写 `ground_truth=UNVERIFIED` |
|
||||||
|
|
||||||
|
回放不读轮速里程计,位姿全部来自 IMU + 点云。出错时向 stderr 打印原因并返回 1。
|
||||||
|
|
||||||
|
> `tests/data/` 里的三个回归片段不能直接用这个工具回放:回放从 `config.txt` 的初始位姿起步,
|
||||||
|
> 不读 `checkpoint.txt`,而那三个片段的起点状态只存在 `checkpoint.txt` 里。
|
||||||
|
|
||||||
|
## 加新工具
|
||||||
|
|
||||||
|
1. 在本目录加 `xxx.cpp`(自带 `int main()`)
|
||||||
|
2. 到 [`../../xmake.lua`](../../xmake.lua) 照抄一个 target:
|
||||||
|
不依赖 ROS 就只 `add_deps("field_localization_core")`;
|
||||||
|
需要 ROS 消息再 `add_deps("field_localization_ros")` 并加上 `ros_common()`
|
||||||
|
3. 记得 `set_targetdir("$(builddir)/bin")`
|
||||||
|
4. 仓库根 `xmake`
|
||||||
|
|
||||||
|
工具里只写参数解析和文件输出,算法调用 `core/`。
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 录制脚本和验收脚本的用法:[`tools/README.md`](../../../../tools/README.md)
|
||||||
|
- 数据集格式:[`../../tests/data/README.md`](../../tests/data/README.md)
|
||||||
|
- 被调用的算法:[`../core/README.md`](../core/README.md)
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#include "field_localization/ros/conversion.hpp"
|
||||||
|
#include <rclcpp/rclcpp.hpp>
|
||||||
|
#include <sensor_msgs/msg/imu.hpp>
|
||||||
|
#include <geometry_msgs/msg/pose_stamped.hpp>
|
||||||
|
#include <tf2_ros/buffer.hpp>
|
||||||
|
#include <tf2_ros/transform_listener.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <thread>
|
||||||
|
using namespace field_localization;
|
||||||
|
class Recorder:public rclcpp::Node {
|
||||||
|
public:
|
||||||
|
explicit Recorder(const rclcpp::NodeOptions &options):Node("field_localization_record",options) {
|
||||||
|
directory_=declare_parameter<std::string>("output_directory","");
|
||||||
|
if (directory_.empty() || std::filesystem::exists(directory_/"imu.csv")) throw std::runtime_error("output_directory must be new");
|
||||||
|
duration_=declare_parameter<double>("duration_sec",120);
|
||||||
|
if (!std::isfinite(duration_) || duration_<=0) throw std::runtime_error("invalid duration");
|
||||||
|
config_.initial_pose.translation={declare_parameter<double>("initial_x",-5),declare_parameter<double>("initial_y",3),declare_parameter<double>("initial_z",0)};
|
||||||
|
config_.initial_pose.rotation=core::exp_so3({0,0,declare_parameter<double>("initial_yaw",0)});
|
||||||
|
config_.map_bounds=ros::declare_map_bounds(*this);
|
||||||
|
config_.deskew.imu_from_sensor=core::Pose3D{};
|
||||||
|
std::filesystem::create_directories(directory_/"clouds");
|
||||||
|
imu_.open(directory_/"imu.csv"); scans_.open(directory_/"scans.csv"); truth_.open(directory_/"truth.tum");
|
||||||
|
imu_.exceptions(std::ios::badbit|std::ios::failbit); scans_.exceptions(std::ios::badbit|std::ios::failbit); truth_.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
imu_<<std::setprecision(17)<<"timestamp,gx,gy,gz,ax,ay,az\n"; scans_<<std::setprecision(17)<<"timestamp,file\n";
|
||||||
|
buffer_=std::make_unique<tf2_ros::Buffer>(get_clock()); listener_=std::make_unique<tf2_ros::TransformListener>(*buffer_);
|
||||||
|
cloud_sub_=create_subscription<sensor_msgs::msg::PointCloud2>(declare_parameter<std::string>("point_cloud_topic","/scan/points_lio"),
|
||||||
|
rclcpp::QoS(20).reliable(),[this](sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) {
|
||||||
|
if (!ready_ || done_) return;
|
||||||
|
const auto stamp=rclcpp::Time(msg->header.stamp).seconds();
|
||||||
|
if (stamp<start_ || stamp<=last_scan_ || stamp>start_+duration_) return;
|
||||||
|
core::PointCloud cloud;
|
||||||
|
try {
|
||||||
|
cloud=ros::convert_cloud_in_frame(*msg,"imu_link",*buffer_);
|
||||||
|
} catch (const tf2::TransformException &e) {
|
||||||
|
RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),2000,"scan not recorded: %s",e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto file="clouds/"+std::to_string(scan_count_++)+".flpc"; core::write_cloud(cloud,directory_/file);
|
||||||
|
scans_<<cloud.timestamp_sec<<','<<file<<'\n'; scans_.flush(); last_scan_=cloud.timestamp_sec;
|
||||||
|
});
|
||||||
|
imu_sub_=create_subscription<sensor_msgs::msg::Imu>("/imu",rclcpp::SensorDataQoS().keep_last(1000),
|
||||||
|
[this](sensor_msgs::msg::Imu::ConstSharedPtr msg) {
|
||||||
|
if (done_) return;
|
||||||
|
const double t=msg->header.stamp.sec+1e-9*msg->header.stamp.nanosec;
|
||||||
|
if (t<=last_imu_) return;
|
||||||
|
if (!ready_) {
|
||||||
|
try {
|
||||||
|
config_.base_from_imu=ros::from_transform(buffer_->lookupTransform("base_link","imu_link",tf2::TimePointZero).transform);
|
||||||
|
} catch (const tf2::TransformException &) { return; }
|
||||||
|
core::write_dataset_config(config_,directory_/"config.txt","imu_link"); start_=t; ready_=true;
|
||||||
|
RCLCPP_INFO(get_logger(),"recording started at sim %.3f for %.1f sec",start_,duration_);
|
||||||
|
}
|
||||||
|
if (t>start_+duration_+0.1) { imu_complete_=true; return; }
|
||||||
|
if (msg->header.frame_id!="imu_link") throw std::runtime_error("recorder expects imu_link input");
|
||||||
|
const auto &w=msg->angular_velocity; const auto &a=msg->linear_acceleration;
|
||||||
|
imu_<<t<<','<<w.x<<','<<w.y<<','<<w.z<<','<<a.x<<','<<a.y<<','<<a.z<<'\n';
|
||||||
|
last_imu_=t; if (++imu_count_%100==0) imu_.flush();
|
||||||
|
});
|
||||||
|
truth_sub_=create_subscription<geometry_msgs::msg::PoseStamped>("/evaluation/ground_truth",1000,
|
||||||
|
[this](geometry_msgs::msg::PoseStamped::ConstSharedPtr msg) {
|
||||||
|
if (done_) return;
|
||||||
|
const double t=msg->header.stamp.sec+1e-9*msg->header.stamp.nanosec;
|
||||||
|
if (t<=last_truth_) return;
|
||||||
|
if (ready_ && t>start_+duration_+0.1) { truth_complete_=true; return; }
|
||||||
|
const auto &p=msg->pose; core::Pose3D pose{Eigen::Quaterniond{p.orientation.w,p.orientation.x,p.orientation.y,p.orientation.z},
|
||||||
|
Eigen::Vector3d{p.position.x,p.position.y,p.position.z}};
|
||||||
|
if (!pose.translation.allFinite() || !pose.rotation.coeffs().allFinite() || pose.rotation.norm()<1e-12) throw std::runtime_error("invalid independent truth");
|
||||||
|
pose.rotation.normalize(); core::write_trajectory_sample(truth_,{t,pose}); last_truth_=t;
|
||||||
|
});
|
||||||
|
timer_=create_wall_timer(std::chrono::milliseconds(200),[this] {
|
||||||
|
if (imu_complete_ && truth_complete_) {
|
||||||
|
imu_.flush(); scans_.flush(); truth_.flush(); done_=true;
|
||||||
|
std::ofstream(directory_/"complete.txt")<<"imu="<<imu_count_<<" scans="<<scan_count_<<"\nIMU sensor noise: zero (Gazebo configuration)\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
bool done() const { return done_; }
|
||||||
|
private:
|
||||||
|
std::filesystem::path directory_;
|
||||||
|
core::CoreOptions config_;
|
||||||
|
double duration_{120},start_{0},last_imu_{-1},last_scan_{-1},last_truth_{-1};
|
||||||
|
std::size_t imu_count_{0},scan_count_{0};
|
||||||
|
bool ready_{false},done_{false},imu_complete_{false},truth_complete_{false};
|
||||||
|
std::ofstream imu_,scans_,truth_;
|
||||||
|
std::unique_ptr<tf2_ros::Buffer> buffer_;
|
||||||
|
std::unique_ptr<tf2_ros::TransformListener> listener_;
|
||||||
|
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr cloud_sub_;
|
||||||
|
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr imu_sub_;
|
||||||
|
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr truth_sub_;
|
||||||
|
rclcpp::TimerBase::SharedPtr timer_;
|
||||||
|
};
|
||||||
|
int main(int argc,char **argv) {
|
||||||
|
rclcpp::init(argc,argv); int result=0;
|
||||||
|
try {
|
||||||
|
rclcpp::NodeOptions options;
|
||||||
|
auto node=std::make_shared<Recorder>(options);
|
||||||
|
rclcpp::executors::SingleThreadedExecutor executor; executor.add_node(node);
|
||||||
|
while (rclcpp::ok() && !node->done()) { executor.spin_some(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); }
|
||||||
|
} catch (const std::exception &e) { std::fprintf(stderr,"recording failed: %s\n",e.what()); result=1; }
|
||||||
|
rclcpp::shutdown(); return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
#include "field_localization/core/dataset.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <chrono>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
#include <numbers>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <unordered_map>
|
||||||
|
using namespace field_localization::core;
|
||||||
|
namespace {
|
||||||
|
void print_support(const char *label,const AssociationCounts &counts) {
|
||||||
|
std::cout<<label<<" sampled="<<counts.sampled<<" planes="<<counts.candidate_planes
|
||||||
|
<<" outside_support="<<counts.outside_support
|
||||||
|
<<" distance_rejected="<<counts.plane_distance_rejected<<" inliers="<<counts.inliers<<'\n';
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
int main(int argc,char **argv) {
|
||||||
|
try {
|
||||||
|
std::unordered_map<std::string,std::string> args;
|
||||||
|
for (int i=1;i<argc;i+=2) {
|
||||||
|
if (i+1>=argc) throw std::runtime_error("arguments require values");
|
||||||
|
args[argv[i]]=argv[i+1];
|
||||||
|
}
|
||||||
|
if (!args.contains("--dataset") || !args.contains("--mode") || !args.contains("--map") || !args.contains("--output"))
|
||||||
|
throw std::runtime_error("usage: field_localization_replay --dataset DIR --mode mapping|localization --map FILE --output DIR [--inspect-scan SIM_SECONDS]");
|
||||||
|
const std::filesystem::path dataset=args.at("--dataset"),output=args.at("--output");
|
||||||
|
std::string cloud_frame;
|
||||||
|
auto options=read_dataset_config(dataset/"config.txt",&cloud_frame);
|
||||||
|
if (args.at("--mode")!="mapping" && args.at("--mode")!="localization") throw std::runtime_error("invalid mode");
|
||||||
|
options.map_mode=args.at("--mode")=="mapping" ? MapMode::MAPPING : MapMode::LOCALIZATION;
|
||||||
|
if(args.contains("--map-translation-sigma")) options.registration.map_translation_sigma=std::stod(args.at("--map-translation-sigma"));
|
||||||
|
if(args.contains("--integration-error-scale")) options.noise.integration_error_scale=std::stod(args.at("--integration-error-scale"));
|
||||||
|
LocalizationCore core(options); std::string error;
|
||||||
|
if (options.map_mode==MapMode::LOCALIZATION && !core.load_map(args.at("--map"),error)) throw std::runtime_error(error);
|
||||||
|
const auto truth_path=dataset/"truth.tum";
|
||||||
|
const bool have_truth=std::filesystem::exists(truth_path);
|
||||||
|
const auto truth=have_truth ? read_trajectory(truth_path) : std::vector<TrajectorySample>{};
|
||||||
|
std::optional<double> inspect_time;
|
||||||
|
std::optional<VoxelMap> inspect_map;
|
||||||
|
if (args.contains("--inspect-scan")) {
|
||||||
|
if (options.map_mode!=MapMode::LOCALIZATION || options.deskew.timing!=ScanTiming::INSTANTANEOUS || !have_truth)
|
||||||
|
throw std::runtime_error("--inspect-scan requires localization with instantaneous scans and truth.tum");
|
||||||
|
inspect_time=std::stod(args.at("--inspect-scan"));
|
||||||
|
if (!std::isfinite(*inspect_time)) throw std::runtime_error("invalid scan timestamp");
|
||||||
|
inspect_map=read_map(args.at("--map"),error,options.map_bounds);
|
||||||
|
if (!inspect_map) throw std::runtime_error(error);
|
||||||
|
}
|
||||||
|
bool inspected=false;
|
||||||
|
std::ifstream input(dataset/"imu.csv"); if (!input) throw std::runtime_error("missing imu.csv");
|
||||||
|
std::vector<ImuData> imu; std::string line; std::getline(input,line);
|
||||||
|
while (std::getline(input,line)) {
|
||||||
|
std::replace(line.begin(),line.end(),',',' '); std::istringstream row(line); ImuData sample;
|
||||||
|
row>>sample.timestamp_sec>>sample.angular_velocity.x()>>sample.angular_velocity.y()>>sample.angular_velocity.z()
|
||||||
|
>>sample.linear_acceleration.x()>>sample.linear_acceleration.y()>>sample.linear_acceleration.z();
|
||||||
|
if (!row || !valid_imu(sample) || (!imu.empty() && sample.timestamp_sec<=imu.back().timestamp_sec)) throw std::runtime_error("invalid IMU sequence");
|
||||||
|
imu.push_back(sample);
|
||||||
|
}
|
||||||
|
std::filesystem::create_directories(output);
|
||||||
|
std::ofstream trajectory(output/"trajectory.tum"),status(output/"status.csv"),trace(output/"filter_trace.csv");
|
||||||
|
write_filter_trace_header(trace);
|
||||||
|
trajectory.exceptions(std::ios::badbit|std::ios::failbit); status.exceptions(std::ios::badbit|std::ios::failbit);
|
||||||
|
status<<"scan_time,state_time,mode,reason,rmse,inliers,inlier_ratio,degenerate,bgx,bgy,bgz,bax,bay,baz,residual_available,nis,measurement_rank,registration_failure,elapsed_ms\n";
|
||||||
|
std::ifstream scans(dataset/"scans.csv"); if (!scans) throw std::runtime_error("missing scans.csv"); std::getline(scans,line);
|
||||||
|
std::size_t index=0,total=0,full=0; std::vector<TrajectorySample> estimated; std::vector<double> latency;
|
||||||
|
while (std::getline(scans,line)) {
|
||||||
|
const auto comma=line.find(','); if (comma==std::string::npos) throw std::runtime_error("invalid scan index");
|
||||||
|
const auto relative=std::filesystem::path(line.substr(comma+1));
|
||||||
|
if (relative.is_absolute() || relative.string().find("..")!=std::string::npos) throw std::runtime_error("unsafe scan path");
|
||||||
|
auto cloud=read_cloud(dataset/relative,cloud_frame); const double end=scan_window(cloud,options.deskew).second;
|
||||||
|
while (index<imu.size() && (!core.get_status().has_imu || core.get_status().last_imu_timestamp<end)) {
|
||||||
|
if (!core.process_imu(imu[index++])) throw std::runtime_error("IMU rejected during replay");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto begin=std::chrono::steady_clock::now(); core.process_point_cloud(cloud);
|
||||||
|
const auto diagnostic=core.get_snapshot();
|
||||||
|
if (inspect_time && std::abs(cloud.timestamp_sec-*inspect_time)<1e-8) {
|
||||||
|
const auto truth_base=trajectory_pose(truth,end);
|
||||||
|
const auto ®=diagnostic.status.registration;
|
||||||
|
if (!truth_base || reg.stage==RegistrationStage::NOT_RUN)
|
||||||
|
throw std::runtime_error("scan has no aligned truth or registration prediction");
|
||||||
|
const auto map_from_imu=compose(*truth_base,options.base_from_imu);
|
||||||
|
const auto &prediction=diagnostic.status.registration_prediction.state;
|
||||||
|
const auto corrected=deskew(cloud,std::array{prediction},options.deskew);
|
||||||
|
if (!corrected) throw std::runtime_error("failed to prepare instantaneous scan");
|
||||||
|
const auto inspected_scan=options.map_bounds ? crop_to_map(*corrected,
|
||||||
|
compose(map_from_imu,options.deskew.imu_from_sensor),*options.map_bounds,map_association_margin) : *corrected;
|
||||||
|
const auto truth_support=inspect_scan_support(inspected_scan,options.deskew.imu_from_sensor,*inspect_map,
|
||||||
|
map_from_imu,options.registration);
|
||||||
|
const auto error_xyz=prediction.pose.translation-map_from_imu.translation;
|
||||||
|
std::cout<<std::setprecision(12)<<"scan="<<cloud.timestamp_sec
|
||||||
|
<<" stage="<<registration_stage_name(reg.stage)
|
||||||
|
<<" failure="<<registration_failure_name(reg.failure)
|
||||||
|
<<" prediction_minus_truth_xyz_m="<<error_xyz.transpose()
|
||||||
|
<<" rotation_error_deg="
|
||||||
|
<<log_so3(map_from_imu.rotation.conjugate()*prediction.pose.rotation).norm()*180/std::numbers::pi
|
||||||
|
<<'\n';
|
||||||
|
print_support("prediction",reg.initial_associations);
|
||||||
|
print_support("last",reg.last_associations);
|
||||||
|
print_support("truth",truth_support);
|
||||||
|
inspected=true;
|
||||||
|
}
|
||||||
|
write_filter_trace(trace,cloud.timestamp_sec,"prediction",diagnostic.status.registration_prediction,diagnostic.status);
|
||||||
|
write_filter_trace(trace,cloud.timestamp_sec,"candidate",diagnostic.status.registration.estimate,diagnostic.status);
|
||||||
|
write_filter_trace(trace,cloud.timestamp_sec,"posterior",diagnostic.filter,diagnostic.status);
|
||||||
|
const double ms=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-begin).count(); latency.push_back(ms);
|
||||||
|
const auto s=core.get_snapshot(); const auto &state=s.filter.state;
|
||||||
|
if (s.status.mode==TrackingMode::FULL) ++full;
|
||||||
|
++total;
|
||||||
|
if (estimated.empty() || s.status.state_timestamp>estimated.back().time) {
|
||||||
|
estimated.push_back({s.status.state_timestamp,s.pose}); write_trajectory_sample(trajectory,estimated.back());
|
||||||
|
}
|
||||||
|
status<<std::setprecision(12)<<cloud.timestamp_sec<<','<<s.status.state_timestamp<<','<<mode_name(s.status.mode)<<','<<reason_name(s.status.reason)
|
||||||
|
<<','<<s.status.registration_rmse<<','<<s.status.inlier_count<<','<<s.status.inlier_ratio<<','<<s.status.degenerate_dimensions<<','
|
||||||
|
<<state.gyro_bias.x()<<','<<state.gyro_bias.y()<<','<<state.gyro_bias.z()<<','<<state.accel_bias.x()<<','<<state.accel_bias.y()<<','<<state.accel_bias.z()<<','<<s.status.registration_residual_available<<','<<s.status.registration.nis<<','<<s.status.registration.measurement_rank<<','<<static_cast<int>(s.status.registration.failure)<<','<<ms<<'\n';
|
||||||
|
}
|
||||||
|
if (inspect_time && !inspected) throw std::runtime_error("requested scan not in dataset");
|
||||||
|
if (options.map_mode==MapMode::MAPPING && !core.export_map(args.at("--map"),error)) throw std::runtime_error(error);
|
||||||
|
if (total==0) throw std::runtime_error("empty replay");
|
||||||
|
std::sort(latency.begin(),latency.end());
|
||||||
|
std::ostringstream report; report<<std::setprecision(9)<<"scans="<<total<<" FULL="<<full<<" FULL_ratio="<<double(full)/total
|
||||||
|
<<" scan_p95_ms="<<latency[static_cast<std::size_t>(0.95*(latency.size()-1))]<<'\n';
|
||||||
|
if (have_truth) {
|
||||||
|
const auto metric=evaluate(estimated,truth);
|
||||||
|
if (metric.matched==0 || metric.relative_pairs==0) throw std::runtime_error("insufficient matching ground truth");
|
||||||
|
report<<"matched="<<metric.matched<<'/'<<metric.total<<" coverage="<<double(metric.matched)/metric.total<<" RPE_pairs="<<metric.relative_pairs<<'\n'
|
||||||
|
<<"ATE_translation_RMSE_m="<<metric.ate_translation<<" ATE_rotation_RMSE_deg="<<metric.ate_rotation_rad*180/std::numbers::pi<<'\n'
|
||||||
|
<<"RPE_1s_translation_RMSE_m="<<metric.rpe_translation<<" RPE_1s_rotation_RMSE_deg="<<metric.rpe_rotation_rad*180/std::numbers::pi<<'\n';
|
||||||
|
} else report<<"ground_truth=UNVERIFIED\n";
|
||||||
|
std::cout<<report.str(); std::ofstream(output/"metrics.txt")<<report.str(); return 0;
|
||||||
|
} catch (const std::exception &e) { std::cerr<<e.what()<<'\n'; return 1; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
# field_localization/tests/ (单元测试与回归数据)
|
||||||
|
|
||||||
|
**12 个测试程序,`xmake test` 统一跑。其中 11 个不需要 ROS,全部不需要 Gazebo。**
|
||||||
|
|
||||||
|
```
|
||||||
|
tests/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── test_util.hpp 断言宏(转调 sentry_nav 的计数框架)
|
||||||
|
├── test_localization_core.cpp 定位主流程
|
||||||
|
├── test_imu_integration.cpp IMU 积分、去畸变
|
||||||
|
├── test_eskf.cpp 滤波器零偏收敛
|
||||||
|
├── test_registration.cpp 配准、退化、新息门限
|
||||||
|
├── test_lio_synthetic.cpp 合成数据的端到端
|
||||||
|
├── test_map_management.cpp 建图 / 只读定位 / 地图文件
|
||||||
|
├── test_dataset.cpp 点云文件、数据集配置、ATE/RPE
|
||||||
|
├── test_ros_conversion.cpp ROS 消息转换(唯一需要 ROS 的)
|
||||||
|
├── test_tracking_safety.cpp 定位有效性、运动联锁
|
||||||
|
├── test_field_tracking.cpp 2.5D 合成场地的跟踪
|
||||||
|
├── test_filter_consistency.cpp 滤波器一致性
|
||||||
|
├── test_recorded_update.cpp 录制数据的回归(读 data/)
|
||||||
|
├── data/ ★ 回归用的录制片段(3 个数据集)
|
||||||
|
│ └── README.md
|
||||||
|
└── validation/ 历次验收的文字记录(没有任何代码读)
|
||||||
|
└── README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## 怎么跑
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev # 仓库根;先 source ROS 环境
|
||||||
|
xmake # 编译
|
||||||
|
xmake test # 全部 15 个:sentry_nav 3 个 + 本包 12 个
|
||||||
|
xmake test test_eskf/default # 只跑一个(必须带 /default)
|
||||||
|
xmake test -v # 带输出,能看到每个套件打印的数字
|
||||||
|
```
|
||||||
|
|
||||||
|
`xmake test` 在 release 下也执行,没有「只在 debug 跑」的开关。
|
||||||
|
|
||||||
|
11 个不依赖 ROS 的测试也可以直接执行二进制,不用 source ROS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
build/bin/test_registration
|
||||||
|
```
|
||||||
|
|
||||||
|
只有两个会往磁盘写东西,且都是临时位置:
|
||||||
|
|
||||||
|
| 测试 | 写什么 |
|
||||||
|
|---|---|
|
||||||
|
| `test_eskf` | `/tmp/field_lio_bias_filter.csv`(5 个种子的零偏收敛曲线) |
|
||||||
|
| `test_lio_synthetic` | `/tmp/field_lio_bias_end_to_end.csv`(同上,端到端版) |
|
||||||
|
|
||||||
|
这两个的第一个位置参数可以改 CSV 路径:`build/bin/test_eskf /tmp/mine.csv`。
|
||||||
|
|
||||||
|
## 断言框架
|
||||||
|
|
||||||
|
本目录的 `test_util.hpp` 只有 4 行:include 兄弟包的 `../../sentry_nav/tests/test_util.hpp`,
|
||||||
|
再把 `EXPECT_TRUE` / `EXPECT_NEAR` 包成 `CHECK` / `CHECK_NEAR`。
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
CHECK(condition); // 断言为真
|
||||||
|
CHECK_NEAR(actual, expected, tolerance); // 浮点近似相等,浮点只准用这个
|
||||||
|
return sentry_nav_test::Summary("套件名"); // 返回失败数:0 = 通过
|
||||||
|
```
|
||||||
|
|
||||||
|
## 每个测试测什么
|
||||||
|
|
||||||
|
| 测试(套件名) | 测什么 | 通过条件(摘要) |
|
||||||
|
|---|---|---|
|
||||||
|
| `test_localization_core`(`LocalizationCore`) | 主流程的输入输出:默认位姿、`set_pose`、乱序输入被拒、静止不漂移、匀加速 1 s 走 0.5 m、空点云报 `NO_VALID_POINTS`、`reset` 清零 | 逐项断言 |
|
||||||
|
| `test_imu_integration`(`ImuIntegration`) | 恒定角速度下预积分的旋转和闭式解一致;时间区间非法、时间戳重复时返回空;逐点时间戳去畸变后一面墙的点落回同一个平面,非有限的点被丢掉;`instantaneous` 模式不改点的坐标;`azimuth` 模式对一帧旋转扫描去畸变 | 旋转误差 < 1e-6 rad;平面残差 < 1 mm |
|
||||||
|
| `test_eskf`(`ESKF`) | 合成一条带真实零偏的轨迹(陀螺 (0.02, −0.015, 0.01) rad/s、加计 (0.15, −0.10, 0.08) m/s²)。IMU 加高斯噪声,100 Hz 传播,每 10 个样本给一次带噪位姿,5 个随机种子。另测 IMU 间隔过大被拒,以及只观测 z、横滚、俯仰时 x、y 位置和它们的协方差**一个数都不变** | 最后 100 次修正的零偏 RMSE:陀螺 < 0.003 rad/s、加计 < 0.03 m/s²;协方差保持半正定 |
|
||||||
|
| `test_registration`(`Registration`) | 三面正交墙的地图,带初始误差配准能收敛;关联计数自洽;初始位姿偏 20 m 时报 `NO_CORRESPONDENCES`;只有一个平面时退化 3 维,x、y 不被更新;整体偏 0.09 m 的平面配上过度自信的先验,内点很多但被最终新息门限拒绝(`INNOVATION`,阶段 `FINAL_FUSION`);信息矩阵整体旋转后零空间跟着转;`set_pose` 后要等新的 IMU 时刻才更新;全是 `inf` 的点云被拒 | 收敛时位置、旋转误差均 < 1e-3 |
|
||||||
|
| `test_lio_synthetic`(`LioSynthetic`) | 端到端:合成地图 + 带零偏和噪声的 IMU + 带噪声的扫描,60 秒、600 帧,5 个种子 | 每个种子 `FULL` ≥ 570/600 帧;零偏 RMSE 陀螺 < 0.003 rad/s、加计 < 0.03 m/s² |
|
||||||
|
| `test_map_management`(`MapManagement`) | 关键帧门槛(0.5 m 和 10° 都是严格大于);建图模式首帧播种 1 个关键帧、不动不加,平移 0.6 m 后才有第 2 个;地图导出再读回;定位模式不往地图写,导出的文件和原地图逐字节相同;坏地图、缺失地图被拒且不清空已加载的地图;`reset` 只在建图模式清地图 | 逐项断言 |
|
||||||
|
| `test_dataset`(`DatasetAndMetrics`) | 点云写读往返(含一个 `inf` 点);数据集配置往返;整体偏 0.1 m 的轨迹算出 ATE = 0.1 m、RPE ≈ 0;真值间隔过大时拒绝插值;截断的点云文件被拒 | 逐项断言 |
|
||||||
|
| `test_ros_conversion`(`RosConversion`) | 大端、带行填充的 `PointCloud2` 正确转成 core 点云;数据被截断时抛异常;`from_transform` / `to_transform` 往返后和 `odom → base_link` 复合,能还原 `map → base_link` | 逐项断言 |
|
||||||
|
| `test_tracking_safety`(`TrackingSafety`) | 恢复有效要数满 5 **帧**成功配准,同一帧重复更新 20 次不计数;`IMU_ONLY` 0.2 s 内仍有效、0.31 s 失效;协方差变大立即失效,恢复要重新数 5 帧。另测 `sentry_nav` 的 `MotionInterlock`:指令和心跳各自超时 0.3 s 就不放行、时间往回走不放行、手动模式不要求心跳 | 逐项断言 |
|
||||||
|
| `test_field_tracking`(`FieldTracking`) | 2.5D 合成场地(地面、四面墙、一块 0.42 m 高的平台),按 MID-360 的视场和量程生成扫描;第 4–14 秒出现一个地图里没有的圆柱,第 8.0–8.8 秒点云全空。分无噪声和带零偏噪声两版 | 每版 `FULL` ≥ 180/200 帧;最大位置误差 < 0.15 m;断流期间 `navigation_valid` 变 false,之后恢复 |
|
||||||
|
| `test_filter_consistency`(`FilterConsistency`) | 不可观的 x 量测不改变任何状态(含相关的速度、零偏);秩一量测的 4σ 新息被一自由度门限拒绝,状态和协方差原样不动;有限大的平面不匹配支撑范围之外的点;零噪声 IMU 里单个 50 m/s² 的加速度尖峰不被当成加计零偏 | 逐项断言 |
|
||||||
|
| `test_recorded_update`(`RecordedUpdate`) | 用 `data/` 里三段真实录制做回归,见下 | 见下 |
|
||||||
|
|
||||||
|
## `test_recorded_update` 和 `data/`
|
||||||
|
|
||||||
|
`xmake.lua` 在 `on_load` 里给这个测试塞了三个固定参数,按顺序是
|
||||||
|
`data/turn_contact`、`data/return_contact`、`data/return_cylinder`。
|
||||||
|
每个片段从自己的 `checkpoint.txt`(出事前一瞬间的滤波器状态)出发,重放里面的点云和 IMU。
|
||||||
|
|
||||||
|
| 片段 | 用哪份地图 | 断言 |
|
||||||
|
|---|---|---|
|
||||||
|
| `turn_contact` | 自带的 `map.flmap`,当前默认参数 | 5 帧全部成功;最大位置误差 < 0.10 m;最大旋转误差 < 0.02 rad |
|
||||||
|
| `return_contact` | 自带的 `map.flmap` | 当前参数和旧参数(积分误差尺度 2.0、地图平移 σ 0.02 m)都 5/5 成功;当前参数的最大位置误差 < 0.10 m;先验水平位置 3σ 的最大值:当前参数 < 0.5 m,旧参数 > 0.5 m |
|
||||||
|
| `return_cylinder` | `return_contact/map.flmap` | 7 帧;当前参数成功的帧数多于旧参数(地图平移 σ 0.02 m);最大配准间隔当前参数 < 0.3 s、旧参数 ≥ 0.3 s;最大位置误差 < 0.10 m;旧参数至少 1 次新息拒绝 |
|
||||||
|
|
||||||
|
手动跑必须**正好带这三个目录**,顺序也要对,少一个多一个都直接返回 1:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/Gazebo_projects/sentry_nav_dev
|
||||||
|
build/bin/test_recorded_update \
|
||||||
|
src/field_localization/tests/data/turn_contact \
|
||||||
|
src/field_localization/tests/data/return_contact \
|
||||||
|
src/field_localization/tests/data/return_cylinder
|
||||||
|
```
|
||||||
|
|
||||||
|
每个片段的来源和它复现的问题见 [`data/README.md`](data/README.md)。
|
||||||
|
|
||||||
|
## 跨包依赖
|
||||||
|
|
||||||
|
本包的测试有两处依赖兄弟包 `sentry_nav` 的文件,删改那边时要留意:
|
||||||
|
|
||||||
|
| 依赖的文件 | 谁用 |
|
||||||
|
|---|---|
|
||||||
|
| `../../sentry_nav/tests/test_util.hpp` | 本目录的 `test_util.hpp`,也就是全部 12 个测试 |
|
||||||
|
| `../../sentry_nav/include/sentry_nav/core/motion_interlock.hpp` | `test_tracking_safety.cpp`(`xmake.lua` 里给它加了 `add_includedirs("../sentry_nav/include")`) |
|
||||||
|
|
||||||
|
## 加新测试
|
||||||
|
|
||||||
|
1. 在本目录建 `test_xxx.cpp`
|
||||||
|
2. `#include "test_util.hpp"` + `#include "field_localization/core/xxx.hpp"`
|
||||||
|
3. `main()` 里跑断言,最后 `return sentry_nav_test::Summary("xxx");`
|
||||||
|
4. 到 [`../xmake.lua`](../xmake.lua) 照抄一段:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
target("test_xxx")
|
||||||
|
set_targetdir("$(builddir)/bin")
|
||||||
|
set_kind("binary")
|
||||||
|
set_languages("c++23")
|
||||||
|
add_files("tests/test_xxx.cpp")
|
||||||
|
add_deps("field_localization_core")
|
||||||
|
add_tests("default", {group = "unit"})
|
||||||
|
```
|
||||||
|
|
||||||
|
5. `xmake test`
|
||||||
|
|
||||||
|
> 加**测试**要改 `xmake.lua`(每个测试是独立 target);
|
||||||
|
> 加**被测实现**(`src/core/*.cpp`)不用改,那是通配。
|
||||||
|
|
||||||
|
## 规矩
|
||||||
|
|
||||||
|
- **浮点比较永远用 `CHECK_NEAR`**,别用 `CHECK(a == b)`(`0.1 + 0.2 != 0.3`)
|
||||||
|
- 每个测试文件 `main()` 只干一件事:把所有断言跑一遍、返回 `Summary()`
|
||||||
|
- 断言旁边写一句**为什么**这个值是期望值,否则半年后看不懂
|
||||||
|
- 除了 `test_ros_conversion`,测试里不许出现 ROS 头文件
|
||||||
|
- 合成的精确地图要显式把 `map_translation_sigma` / `map_rotation_sigma` 设成 0,
|
||||||
|
参考 `test_registration.cpp` 里的 `exact_map`
|
||||||
|
- 修复过的线上(或录制里)失败要留一段数据做回归,放进 `data/`,并在 `provenance.txt` 里写清来源和现象
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 回归数据:[`data/README.md`](data/README.md)
|
||||||
|
- 历次验收记录:[`validation/README.md`](validation/README.md)
|
||||||
|
- 被测实现:[`../src/core/README.md`](../src/core/README.md)
|
||||||
|
- 接口:[`../include/field_localization/core/README.md`](../include/field_localization/core/README.md)
|
||||||
|
- 断言框架的本体:[`../../sentry_nav/tests/README.md`](../../sentry_nav/tests/README.md)
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
# field_localization/tests/data/ (回归用的录制数据)
|
||||||
|
|
||||||
|
三段从 Gazebo 仿真里录下来的真实数据,**只有 `test_recorded_update.cpp` 用**,
|
||||||
|
用来复现三个修复过的配准失败。总共约 1.2 MB,都在 git 里。
|
||||||
|
|
||||||
|
```
|
||||||
|
data/
|
||||||
|
├── README.md 本文件
|
||||||
|
├── turn_contact/ 转弯时接触冲击:地图模型过度自信 → 新息拒绝级联
|
||||||
|
├── return_contact/ 回程接触冲击:积分误差尺度太大 → 位置 3σ 越界、联锁停车
|
||||||
|
└── return_cylinder/ 绕圆柱回程:配准在 FINAL_FUSION 被拒 → 停车
|
||||||
|
```
|
||||||
|
|
||||||
|
它们不是完整的数据集,是从长录制里剪出来的几帧(5–7 帧点云、半秒多的 IMU),
|
||||||
|
再加上一个**起始时刻的滤波器状态**,所以能从出事前一瞬间开始重放。
|
||||||
|
|
||||||
|
## 每个目录里有什么
|
||||||
|
|
||||||
|
| 文件 | 内容 | 读写方 |
|
||||||
|
|---|---|---|
|
||||||
|
| `config.txt` | 数据集头:已知初始位姿、两组固定外参、扫描时间模型 | `read_dataset_config()` / `write_dataset_config()` |
|
||||||
|
| `imu.csv` | 表头 `timestamp,gx,gy,gz,ax,ay,az`。IMU 系的原始角速度(rad/s)和比力(m/s²),单位秒 | 录制工具写;回放工具和 `test_recorded_update` 读 |
|
||||||
|
| `scans.csv` | 表头 `timestamp,file`。每帧点云的时间戳和相对本目录的路径 | 同上 |
|
||||||
|
| `N.flpc` | FLPC v1 二进制点云,`lidar_link` 系 | `write_cloud()` / `read_cloud()` |
|
||||||
|
| `truth.tum` | TUM 文本轨迹 `tx ty tz qx qy qz qw`,世界系(= map 系)真值 | `write_trajectory_sample()` / `read_trajectory()` |
|
||||||
|
| `checkpoint.txt` | 起始时刻的滤波器状态,344 个空白分隔的数 | **只有 `test_recorded_update` 读** |
|
||||||
|
| `provenance.txt` | 给人看的来源说明 | 没有代码读 |
|
||||||
|
| `map.flmap` | FLMAP v1 地图,只有前两个目录有 | `read_map()` |
|
||||||
|
|
||||||
|
格式的定义在 [`dataset.hpp`](../../include/field_localization/core/dataset.hpp)
|
||||||
|
和 [`map_io.hpp`](../../include/field_localization/core/map_io.hpp)。
|
||||||
|
|
||||||
|
`checkpoint.txt` 的排列顺序和 `FilterSnapshot` 一致:
|
||||||
|
|
||||||
|
```
|
||||||
|
时间戳(1) 平移 xyz(3) 速度 xyz(3) 四元数 x y z w(4)
|
||||||
|
陀螺零偏(3) 加计零偏(3) 重力(3) 协方差 18×18(324,按行)
|
||||||
|
```
|
||||||
|
|
||||||
|
三份片段的 `config.txt` 内容相同:初始位姿 (−5, 3, 0) 朝向 0、IMU 在 base_link 上方 0.15 m、
|
||||||
|
雷达相对 IMU 在 (−0.0935, −0.1512, 0.2552)、`instantaneous` 扫描。
|
||||||
|
|
||||||
|
`.flpc` 的编号不是从 0 开始的,因为是从长录制里剪出来的,保留的是原录制里的序号。
|
||||||
|
|
||||||
|
## 怎么用
|
||||||
|
|
||||||
|
平时不用管,`xmake test` 会连同 `test_recorded_update` 一起跑。手动跑的方式见
|
||||||
|
[`../README.md`](../README.md)。
|
||||||
|
|
||||||
|
**这几个片段不能用 `field_localization_replay` 回放**:回放工具从 `config.txt` 的初始位姿起步、
|
||||||
|
不读 `checkpoint.txt`,而片段的起点状态只存在 `checkpoint.txt` 里。
|
||||||
|
|
||||||
|
## 几条注意
|
||||||
|
|
||||||
|
- **IMU 传感器本身没有噪声**(Gazebo 的 IMU 配置如此),但有限采样率下的动力学不为零,
|
||||||
|
接触冲击时单个样本的加速度变化能到 70 m/s² 以上
|
||||||
|
- **真值只用来打分**,从不喂给滤波器
|
||||||
|
- **三份片段用的是同一张地图**:`turn_contact/map.flmap` 和 `return_contact/map.flmap`
|
||||||
|
是同一个文件,`return_cylinder` 直接用后者
|
||||||
|
|
||||||
|
## 加新的回归片段
|
||||||
|
|
||||||
|
1. 用 [`tools/capture_lio.py`](../../../../tools/capture_lio.py) 录一段完整的数据
|
||||||
|
2. 新建目录,把出事前后的几帧剪出来:
|
||||||
|
- `imu.csv` 要从起始时刻**或之前**开始,一直覆盖到最后一帧点云
|
||||||
|
- `truth.tum` 覆盖同样的区间
|
||||||
|
- `scans.csv` 里的路径是相对本目录的,`.flpc` 的文件名随意
|
||||||
|
- `config.txt` 照抄录制出来的那份
|
||||||
|
3. 写 `checkpoint.txt`。仓库里**没有**生成它的代码,现有三份是修复过程中手工导出的
|
||||||
|
4. 写 `provenance.txt`:怎么录的、当时看到了什么现象
|
||||||
|
5. 注册进测试:
|
||||||
|
- [`../../xmake.lua`](../../xmake.lua) 里 `test_recorded_update` 的 `runargs` 加一项
|
||||||
|
- [`../test_recorded_update.cpp`](../test_recorded_update.cpp) 里 `CHECK(argc==4)`
|
||||||
|
和参数解析要一起改,并补上断言
|
||||||
|
|
||||||
|
## 相关
|
||||||
|
|
||||||
|
- 各片段的说明:[`turn_contact/`](turn_contact/README.md)、
|
||||||
|
[`return_contact/`](return_contact/README.md)、[`return_cylinder/`](return_cylinder/README.md)
|
||||||
|
- 用它们的测试:[`../README.md`](../README.md)
|
||||||
|
- 完整数据集是怎么录出来的:[`../../src/tools/README.md`](../../src/tools/README.md)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,47 @@
|
|||||||
|
# tests/data/return_contact/ (回归片段:回程接触冲击 → 位置 3σ 越界、联锁停车)
|
||||||
|
|
||||||
|
5 帧点云 + 对应 IMU,仿真时间 108.5–108.9 s,外加 108.5 s 时刻的滤波器预测。
|
||||||
|
`test_recorded_update` 的第 2 个参数就是本目录。
|
||||||
|
|
||||||
|
## 来源
|
||||||
|
|
||||||
|
- 隔离的 Gazebo 仿真,**Shell 启动入口**(`sentry_up.sh`)拉起,空场景
|
||||||
|
- 第二段路程:从 (0, 0) 回 (−5, 3)
|
||||||
|
- 加速度在 108.59 s 变化了 72.23 m/s²,108.60 s 又变化了 71.77 m/s²(接触冲击)
|
||||||
|
- IMU 传感器无噪声
|
||||||
|
|
||||||
|
来源说明的原文在 [`provenance.txt`](provenance.txt)。
|
||||||
|
|
||||||
|
## 它复现的问题
|
||||||
|
|
||||||
|
旧的积分误差尺度(2.0)下,冲击之后水平位置的 3σ 在 108.7 s 越过 0.5 m 的阈值,
|
||||||
|
运动联锁据此停掉了导航目标。**地图匹配其实一直在正常进行**,停车是因为不确定度被估得太大。
|
||||||
|
|
||||||
|
现在的默认积分误差尺度是 1.4,同样的数据 3σ 保持在阈值以内。
|
||||||
|
|
||||||
|
## 文件
|
||||||
|
|
||||||
|
| 文件 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| `1070.flpc` – `1074.flpc` | 5 帧点云,108.5 – 108.9 s |
|
||||||
|
| `imu.csv` | 45 个 IMU 样本,108.48 – 108.92 s,100 Hz |
|
||||||
|
| `truth.tum` | 44 行真值,108.48 – 108.92 s |
|
||||||
|
| `map.flmap` | 本片段和 [`return_cylinder`](../return_cylinder/README.md) 用的地图。和 `turn_contact/map.flmap` 内容相同 |
|
||||||
|
| `checkpoint.txt` | 108.5 s 的原始滤波器预测 |
|
||||||
|
| `config.txt` | 初始位姿、外参、扫描时间模型 |
|
||||||
|
| `provenance.txt` | 来源说明 |
|
||||||
|
|
||||||
|
通用的文件格式见 [`../README.md`](../README.md)。
|
||||||
|
|
||||||
|
## 测试里断言了什么
|
||||||
|
|
||||||
|
同一份数据跑两遍,比较**每帧扫描之前**的先验(见
|
||||||
|
[`test_recorded_update.cpp`](../../test_recorded_update.cpp)):
|
||||||
|
|
||||||
|
| | 当前默认参数 | 旧参数 |
|
||||||
|
|---|---|---|
|
||||||
|
| 积分误差尺度 | 1.4 | 2.0 |
|
||||||
|
| 地图平移 σ | 0.03 m | 0.02 m |
|
||||||
|
| 配准成功 | 5/5 | 5/5 |
|
||||||
|
| 最大位置误差 | < 0.10 m | 不断言 |
|
||||||
|
| 先验水平位置 3σ 的最大值 | < 0.5 m | > 0.5 m |
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
108.5 -4.9021935418437943 2.9320217193133793 0.1557928922336535 0.11953694764680566 0.19908177120751999 0.045965043312493209 -0.00086052905380611946 3.8835947097606263e-05 -0.55033851439645454 -0.83494118209214019 3.8119482349976081e-05 -4.76556171027656e-05 -1.0893553551394554e-05 -0.0076579611075292681 -0.001573404450170669 0.062223414195409221 -0.020740954303261897 0.047091173245459049 -9.7476220442384385 0.00032180030162672231 -3.3109679715980393e-06 -1.4134561776379964e-07 0.00128395026095998 -1.6746730317314658e-05 -8.4886017517825797e-07 4.1240730271156636e-07 2.1418971002544343e-07 -2.8876581180948139e-07 -4.3422373923642243e-09 -5.1748223345340147e-10 9.9958077796484632e-10 3.3266378490022887e-07 1.0028474513103997e-06 1.0691009716774382e-06 1.1444559866337746e-06 3.7771093654250646e-07 1.0691201494343238e-06 -3.3109679715980393e-06 0.00030135439567193314 -1.7703924751834215e-07 -1.6662850139947176e-05 0.0011985416218993159 3.8619545898588747e-07 -2.6147583384228565e-07 5.5485281955242264e-07 -3.657478893010278e-07 4.2797428049573721e-10 -5.5219694040548798e-09 1.2780944746782657e-09 -1.6542624247824321e-06 8.9990442499691803e-08 -3.7854466338783015e-06 -8.0172810695956697e-07 1.1298994983796557e-06 -3.7801386121655004e-06 -1.4134561776379964e-07 -1.7703924751834215e-07 0.00023484235692365681 7.7976930255511676e-07 -1.5315893762949035e-06 0.00072374316475533275 8.0054833699954886e-07 -3.7983349382611144e-07 4.7014732995790377e-08 -6.6169668059266572e-09 5.1662907401548531e-09 -2.0922013649704161e-10 -2.7197868772262445e-09 4.3794454248856465e-10 -7.2241387348460554e-07 -3.4340629368096118e-09 4.8637981713538916e-09 2.0170234401260474e-08 0.00128395026095998 -1.6662850139947176e-05 7.7976930255511676e-07 0.016671016339951206 0.00028959121918970378 -3.798955913976945e-06 4.2882917579726604e-06 1.8958563347564645e-06 -8.2652501644825307e-08 -4.4522500494586826e-08 -8.0812241942467223e-09 3.0057389155497851e-10 1.8752153113102324e-06 6.3682456726758585e-06 6.5733340033091501e-06 7.1989659236711069e-06 2.4250924065566434e-06 6.5747187554529147e-06 -1.6746730317314658e-05 0.0011985416218993159 -1.5315893762949035e-06 0.00028959121918970378 0.017016380591946909 4.1421284919585015e-06 -2.2637764100331944e-06 5.1619542058896502e-06 -4.0037244977777193e-07 8.6781637833258431e-09 -5.2328110182931958e-08 1.58419438820848e-09 -9.7135882093019719e-06 2.9077145220395079e-07 -2.1870543798192066e-05 -4.6791391025785722e-06 6.6544502227089111e-06 -2.1840445337136608e-05 -8.4886017517825797e-07 3.8619545898588747e-07 0.00072374316475533275 -3.798955913976945e-06 4.1421284919585015e-06 0.012275672165360777 8.4060340358083866e-07 -3.7510481928876981e-07 6.8149456965885298e-08 -6.8844559369381303e-09 4.0437621421826469e-09 -3.4178005968171159e-10 -1.5153987088700559e-08 2.4507827427223861e-09 -4.2341934360751864e-06 -1.889941795210489e-08 2.6848198981890525e-08 1.244230272814858e-07 4.1240730271156636e-07 -2.6147583384228565e-07 8.0054833699954886e-07 4.2882917579726604e-06 -2.2637764100331944e-06 8.4060340358083866e-07 2.8207167738484057e-06 -9.6336778435724137e-08 1.3781317221426031e-08 -2.6440380244751873e-08 4.0522447969181831e-09 -5.8201390497764061e-11 -8.0099878941585013e-10 -7.872340442403864e-10 -3.4323625809851157e-09 -1.0303682108364948e-09 4.8412100509677764e-12 -2.0828522750049064e-09 2.1418971002544343e-07 5.5485281955242264e-07 -3.7983349382611144e-07 1.8958563347564645e-06 5.1619542058896502e-06 -3.7510481928876981e-07 -9.6336778435724137e-08 3.0510260124192839e-06 -8.5184113912824024e-09 -2.5010269657606956e-09 -2.8533187359619162e-08 1.6596970762816415e-11 1.0235809829900821e-09 -4.1617052782586423e-10 3.4166161706316234e-09 2.8897888828753661e-10 -9.6927714973496483e-10 2.9900252507395201e-09 -2.8876581180948139e-07 -3.657478893010278e-07 4.7014732995790377e-08 -8.2652501644825307e-08 -4.0037244977777193e-07 6.8149456965885298e-08 1.3781317221426031e-08 -8.5184113912824024e-09 4.9531797132419396e-06 -1.0899538712701036e-10 1.012607157604397e-10 -2.1846203888502755e-08 6.4585465639471621e-10 -3.8025781452778024e-10 1.3770155571674219e-09 1.3125030002545032e-11 -6.4473039908968704e-10 1.4534369723133827e-09 -4.3422373923642243e-09 4.2797428049573721e-10 -6.6169668059266572e-09 -4.4522500494586826e-08 8.6781637833258431e-09 -6.8844559369381303e-09 -2.6440380244751873e-08 -2.5010269657606956e-09 -1.0899538712701036e-10 9.5243509910712323e-08 -1.2449932005997435e-10 -5.3657067385421009e-12 -1.1880921854779703e-10 2.755054987508737e-10 5.021226678365264e-10 -4.1880538357733795e-10 1.4253390980595335e-10 3.58472159966974e-10 -5.1748223345340147e-10 -5.5219694040548798e-09 5.1662907401548531e-09 -8.0812241942467223e-09 -5.2328110182931958e-08 4.0437621421826469e-09 4.0522447969181831e-09 -2.8533187359619162e-08 1.012607157604397e-10 -1.2449932005997435e-10 9.6602785462132596e-08 7.2250758694789384e-12 2.5951113791785858e-10 -1.9493442618219454e-10 -1.044466662172168e-09 -1.771308527273993e-10 -1.558599068747Line truncated
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
FIELD_LIO_DATASET 1
|
||||||
|
initial_pose -5 3 0 0 0 0 1
|
||||||
|
base_from_imu 0 0 0.14999999999999999 0 0 0 1
|
||||||
|
imu_from_lidar -0.0935 -0.1512 0.25519999999999998 0 0 0 1
|
||||||
|
scan_timing 0 0.10000000000000001 -3.1415926535897931 1 1
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
timestamp,gx,gy,gz,ax,ay,az
|
||||||
|
108.48,-0.00027579711156923295,-9.6228164683447422e-05,-0.56779033555889469,-1.0530966798405577,-2.6010947767770594,9.8095553816565157
|
||||||
|
108.48999999999999,-0.00025615782747161729,-0.00010587090718420355,-0.55785202563478387,-1.7876666177385214,-1.0631781169629055,9.8094280629193058
|
||||||
|
108.5,-0.00023825784714968831,-0.00011711104903238535,-0.58693848212030686,-1.9043254046636544,-1.139065472424273,9.8094578216037966
|
||||||
|
108.51000000000001,-0.0038630553244536035,-0.0038254066591876645,-0.68517701957796229,1.1061646030349155,-2.5481938512545188,9.7882127819939981
|
||||||
|
108.52,-0.012606909063535997,0.016247733271579818,-0.78297260155929282,-2.4583754036013685,-1.7038647361881609,11.839716492099672
|
||||||
|
108.53,-0.061277268073585023,0.079820328714736447,-0.95872965467934201,-4.2708544673441109,-0.84812091026555592,9.9852964166452605
|
||||||
|
108.54000000000001,-0.076112960000572827,0.10118717039092451,-1.0492460237459966,-0.95334847078538454,0.71509630025199966,9.7244760393909324
|
||||||
|
108.55,-0.067641209642736802,0.092385150361106574,-1.0531247188783339,-0.96299303923260471,0.70118110999445338,9.7257429713406207
|
||||||
|
108.56,0.0033595937551803329,0.0020697239466177832,-1.0235049120000919,-8.3456600758072401,-2.6104502542668877,9.1893792949826683
|
||||||
|
108.56999999999999,0.02633565443321674,-0.027770362691463782,-1.0327068282495309,-0.86663841190981339,0.59485616933232788,9.7503275368400892
|
||||||
|
108.58,0.044817131676968228,-0.052668601183060743,-1.0250939063161346,-0.87108193784216637,0.59289071702653651,9.7503813880634009
|
||||||
|
108.59,0.027626257433854592,-0.031687748948603475,-0.97521425042473509,12.881843216107459,71.50407345556205,10.073106197385915
|
||||||
|
108.59999999999999,-0.036474759445082425,0.051364487006142587,-0.96049966667821285,-4.4324684565237389,1.8562481433950828,9.8677515940224332
|
||||||
|
108.61,-0.04134819767885773,0.05920975956051068,-1.030264108649404,-0.99297521928374843,0.65187845641134368,9.7303549205617799
|
||||||
|
108.62,0.01295842388313628,-0.0039726626729746648,-1.0139150953741738,0.19457236107968115,-0.55040386338858716,9.7250152706423183
|
||||||
|
108.63,0.034377204593879558,-0.033473846614123254,-0.99454322329474421,0.2959840955286403,-0.63552909536554569,9.7783991319795742
|
||||||
|
108.64,0.050820131406794901,-0.055549240334301773,-0.97760185137247102,-1.9641378332748467,2.153826777994603,14.191482820845833
|
||||||
|
108.65000000000001,0.061042066837415115,-0.04419677239597361,-0.96473456396457447,-0.18272266438283608,-0.26120167792698396,9.294572520726657
|
||||||
|
108.66,0.089517043233146909,-0.060374879806683657,-0.9403871801458199,-0.15826475289053657,-0.24363012237265588,9.3217861415882517
|
||||||
|
108.67,0.00075568636684762713,0.083573010739332126,-0.91678558238484609,4.0341898535273764,-4.6884496196539844,7.7014957643994784
|
||||||
|
108.68000000000001,0.0021557033600065473,0.12707896757705958,-1.0486907811541184,4.0785371406202495,-4.6392205782611713,7.7203149932024022
|
||||||
|
108.69,0.0020433518921272572,0.0020166876327267751,-0.9054452167476853,2.5840014331377761,-3.0474611788932653,9.7424379876060367
|
||||||
|
108.7,0.0018146512053483586,0.033385534243483068,-0.75254006007709262,2.9177303958871978,-0.9347762921025552,9.2265301165200722
|
||||||
|
108.70999999999999,-0.0071175103038246743,2.2653503118359557e-06,-0.79580071923165763,1.5862332837852466,1.7892895525491757,8.5117099060340156
|
||||||
|
108.72,0.0018226364070514966,-0.00047441621740520361,-0.64959146474622242,-2.5218861545502262,-4.5195339577395215,9.8019501144738008
|
||||||
|
108.73,0.00061213745480492821,0.00064759022433580143,-0.23765205614659146,-2.1891152862620129,-4.6163027052355474,9.7575703912375431
|
||||||
|
108.73999999999999,-8.5173882333780833e-05,-0.00040036893615584556,0.0001979938570819452,-0.029016022025761215,-0.0004040832591799702,9.8094296040077413
|
||||||
|
108.75,-8.2351569187941569e-05,-0.0003822955018146262,0.00018844413837782267,-0.029031520889687464,-0.00034444352750586152,9.8094544409425399
|
||||||
|
108.76000000000001,-7.8845306342528189e-05,-0.00036413257485318955,0.0001793636084983912,-0.028968714585963447,-0.000346458398696414,9.8094811772970907
|
||||||
|
108.77,-7.4880532471881042e-05,-0.00034611221051486372,0.00017072867345419888,-0.028935081983888621,-0.00032672658632929149,9.809505062753086
|
||||||
|
108.78,-7.1115196251946727e-05,-0.00032899306246744709,0.00016251599600637965,-0.02890308134415694,-0.00030795031942689192,9.8095277389049578
|
||||||
|
108.79000000000001,-6.7539261185498663e-05,-0.00031272916713399293,0.00015470497749903061,-0.028872634220905094,-0.00029008367401124532,9.8095492684904784
|
||||||
|
108.8,-6.4222286693821823e-05,-0.00029725638885302771,0.00014727580938687338,-0.02884335197079773,-0.00027185352010715869,9.809571495474632
|
||||||
|
108.81,-6.1074528905443468e-05,-0.00028255450086174305,0.00014021005859313153,-0.02881582584481648,-0.00025581286497402487,9.8095907279037284
|
||||||
|
108.81999999999999,-5.8081104455341283e-05,-0.00026858606364358782,0.00013348999987412524,-0.028789638923466501,-0.00024055457626561674,9.8096089957348145
|
||||||
|
108.83,-5.5234443560975581e-05,-0.00025531389037077289,0.00012709875209389966,-0.028764726530231797,-0.00022604070858204839,9.8096263483606254
|
||||||
|
108.84,-5.2527348000840473e-05,-0.00024270273620216737,0.00012102025508831105,-0.028741027063309946,-0.00021223512807402926,9.8096428325524521
|
||||||
|
108.84999999999999,-4.9952972850119343e-05,-0.00023071919154618757,0.00011523923010331233,-0.028718481854024532,-0.00019910343697915361,9.8096584926023418
|
||||||
|
108.86,-4.7504809118585898e-05,-0.00021933158168783681,0.00010974114210159096,-0.028697035031996648,-0.00018661288834960618,9.8096733704656565
|
||||||
|
108.87,-4.5176667237112169e-05,-0.00020850987238039211,0.00010451216386677535,-0.028676633395378699,-0.00017473231118386127,9.8096875058901745
|
||||||
|
108.88,-4.2962661368461969e-05,-0.00019822558091676793,9.9539141778251435e-05,-0.02865722628771946,-0.00016343203616670909,9.8097009365388317
|
||||||
|
108.89,-4.0857194480294721e-05,-0.00018845169243943518,9.4809563240037353e-05,-0.028638765478787489,-0.00015268382383709634,9.8097136981062469
|
||||||
|
108.90000000000001,-3.8854944159717922e-05,-0.00017916258107389583,9.0311525646290502e-05,-0.028621205051879525,-0.00014246079525618113,9.8097258244280425
|
||||||
|
108.91,-3.6950849126026176e-05,-0.00017033393556493636,8.6033706814335204e-05,-0.028604501294363802,-0.00013273737693193267,9.8097373475763607
|
||||||
|
108.92,-3.5140096402690625e-05,-0.00016194268924257522,8.1965336865759034e-05,-0.028588612596438932,-0.0001234892242220093,9.8097482979663546
|
||||||
|
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
Isolated Gazebo Shell launch, clear scene, second leg from (0,0) back to (-5,3).
|
||||||
|
The checkpoint is the original filter prediction at simulated time 108.5 s.
|
||||||
|
Scans at 108.5--108.9 s, IMU samples and independent truth are from the same run.
|
||||||
|
Acceleration changed by 72.23 m/s^2 at 108.59 s, then by 71.77 m/s^2 at 108.60 s.
|
||||||
|
The old integration scale 2.0 crossed the horizontal position 3-sigma threshold
|
||||||
|
(0.5 m) at 108.7 s and the drive interlock stopped the goal. Map matching continued.
|
||||||
|
The test compares the prior before each scan at both scales and checks corrections
|
||||||
|
and truth error. Truth only scores the output. This is separate from the
|
||||||
|
unrecorded failure that had no correspondences.
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
timestamp,file
|
||||||
|
108.5,1070.flpc
|
||||||
|
108.59999999999999,1071.flpc
|
||||||
|
108.7,1072.flpc
|
||||||
|
108.8,1073.flpc
|
||||||
|
108.90000000000001,1074.flpc
|
||||||
|
@@ -0,0 +1,45 @@
|
|||||||
|
108.48 -4.9071026036118548 2.9233913230750783 0.0029858126403290871 7.2250798166288425e-06 2.8442624406782508e-05 0.55507890540450322 0.83179769650664104
|
||||||
|
108.48999999999999 -4.9062642203379969 2.9255680970807725 0.0029865468907930271 6.3291191353360092e-06 2.7307813742419122e-05 0.55276430081705308 0.83333764282939971
|
||||||
|
108.5 -4.9053972077996111 2.9275282001593639 0.0029872286798281614 5.5399981504607552e-06 2.6178129603476733e-05 0.55036534252022395 0.83492394206694698
|
||||||
|
108.51000000000001 -4.9046646886830549 2.9292729227331513 0.0029936313785604166 -4.736127786470753e-06 3.3049173620555536e-05 0.54761911569906785 0.83672773529164923
|
||||||
|
108.52 -4.9038096193174239 2.9308242408481151 0.0029844753027834731 -4.9230391904278006e-05 2.243576255743785e-05 0.54461563620190612 0.83868576110328608
|
||||||
|
108.53 -4.9029951128170328 2.9319089098101028 0.0030006080810971733 -0.00037185933427108623 0.00013601574900552754 0.5408852167529149 0.84109632356734498
|
||||||
|
108.54000000000001 -4.9022632148810406 2.9325382215656548 0.0030306202514057898 -0.00098584198609175241 0.00035761968065051636 0.53652427507351241 0.84388423523643596
|
||||||
|
108.55 -4.9016446671925502 2.9330504405569773 0.0030581468303319923 -0.001544564748203659 0.00056650094536240755 0.53207935443970145 0.8466928923614796
|
||||||
|
108.56 -4.9012232035425685 2.9335773095391842 0.0030746075327204988 -0.0018251026007992592 0.00068374173436587299 0.52766200432833754 0.84945218269537615
|
||||||
|
108.56999999999999 -4.9010350946153922 2.9340649288436951 0.0030712408664604692 -0.0017346514287665561 0.0006601243266040756 0.5232426619061783 0.85218171300587708
|
||||||
|
108.58 -4.9009513477400262 2.9345809755178025 0.0030603042691265932 -0.0014667422006025576 0.00056709949674644926 0.5188551578902586 0.8548607209342074
|
||||||
|
108.59 -4.9011856833308274 2.9351716379965223 0.0030486176107153568 -0.0011813940203852925 0.00046400831990277692 0.51448633770426766 0.85749763691808378
|
||||||
|
108.59999999999999 -4.9025325962781743 2.9358826277467109 0.0030583004600324795 -0.0013722337617795045 0.00054506094092712603 0.51048467726222702 0.85988558201865073
|
||||||
|
108.61 -4.9042171088724684 2.9362391277319615 0.0030755562493143384 -0.0017189437160433187 0.0006910657880021667 0.50611596493250299 0.86246344716806356
|
||||||
|
108.62 -4.9059845880932338 2.9365916184328378 0.0030726120932165349 -0.0017579433845956738 0.00072700441405718129 0.50162314016042819 0.86508416142895017
|
||||||
|
108.63 -4.9077037294256938 2.9369549108499187 0.0030549526657664824 -0.0015906492030189677 0.00068766861934978067 0.49727550118258251 0.86759095942188935
|
||||||
|
108.64 -4.9093583297663042 2.9373585080073492 0.0030191847395952794 -0.0012747314821810044 0.00060554175097587125 0.49300634869296989 0.87002456777223369
|
||||||
|
108.65000000000001 -4.9110518183553697 2.9377027711543717 0.0029664317860478985 -0.0009074190385914881 0.00052551606818008632 0.48878714497942805 0.87240244573614656
|
||||||
|
108.66 -4.9127338187093921 2.9380444130606538 0.0028672150785611118 -0.00042283910851417572 0.00046832055697665017 0.48466240927990606 0.87470106374346035
|
||||||
|
108.67 -4.9141628840969114 2.9381489038979098 0.0027565590016154378 -0.00027719379602898368 0.00060403682294858359 0.48064260716109708 0.87691632581706414
|
||||||
|
108.68000000000001 -4.9152086923244882 2.9381074413261659 0.0025694281599019544 -0.00055042288347394999 0.0011055583485082147 0.47628672908702829 0.87928915975972732
|
||||||
|
108.69 -4.9161351835595939 2.93864659832927 0.0025383300594161349 -0.00059853666229444497 0.0012018901858600714 0.47201549865874842 0.88158922761101055
|
||||||
|
108.7 -4.9167952516904698 2.9394702423291088 0.0025057824865530377 -0.00064228777597694423 0.0012922911428858172 0.46842127708854053 0.88350406033065609
|
||||||
|
108.70999999999999 -4.9173018922715146 2.940362071952022 0.0024918813891934215 -0.00068859771738163955 0.0013387330363737859 0.46495892627369939 0.88533097229536117
|
||||||
|
108.72 -4.9177556213521374 2.9411980850974202 0.0025009992843522595 -0.0006718193217249693 0.0013178923164732753 0.46155766211772059 0.8871089765970499
|
||||||
|
108.73 -4.9180187668671556 2.9416340556595397 0.0025015281783265855 -0.00066939373545388465 0.00131865235183839 0.45977143268899689 0.8880360593754677
|
||||||
|
108.73999999999999 -4.9180544473336081 2.941683628128029 0.002501154514657559 -0.00067050560271407912 0.0013205948330638885 0.45956901953254004 0.88814082370839342
|
||||||
|
108.75 -4.9180547737815665 2.9416842658140818 0.0025017594416658884 -0.00067018684139458023 0.001319432124916569 0.45956953788076993 0.88814055745727605
|
||||||
|
108.76000000000001 -4.9180553984216857 2.9416854842061171 0.0025029151068616351 -0.00066957979335071434 0.0013171997000242573 0.45957052959788774 0.8881400480627859
|
||||||
|
108.77 -4.9180559872349887 2.9416866303269003 0.0025040022766528716 -0.00066900887500588179 0.0013150964352657767 0.45957146426949047 0.88813956796085125
|
||||||
|
108.78 -4.918056268866053 2.941687177613542 0.0025045214778418212 -0.00066873603972176642 0.0013140919444938187 0.45957191126200286 0.88813933835488923
|
||||||
|
108.79000000000001 -4.9180566316896259 2.9416878817389449 0.002505189559091462 -0.00066838478328363647 0.0013127993806705148 0.45957248705398718 0.88813904258431309
|
||||||
|
108.8 -4.9180573159650995 2.941689206524909 0.0025064470135053628 -0.0006677233142186968 0.001310366532802802 0.45957357276097899 0.88813848486867997
|
||||||
|
108.81 -4.9180576384942549 2.9416898293585856 0.0025070385860793605 -0.00066741227345367327 0.0013092221421721927 0.45957408439159536 0.88813822204309312
|
||||||
|
108.81999999999999 -4.918057948634182 2.9416904271975306 0.00250760671196067 -0.00066711367701798203 0.0013081232115439393 0.45957457629499837 0.88813796934726208
|
||||||
|
108.83 -4.9180582468721754 2.9416910010247697 0.0025081523257144845 -0.00066682701988258033 0.0013070679209143726 0.45957504924727111 0.8881377263828758
|
||||||
|
108.84 -4.9180585336763993 2.9416915517847468 0.0025086763242520749 -0.00066655181805750784 0.0013060545242227191 0.45957550399401981 0.88813749276724963
|
||||||
|
108.84999999999999 -4.9180588767864721 2.9416922091752897 0.0025093022340924032 -0.00066622321997631935 0.0013048441461448572 0.45957604791451118 0.88813721333567286
|
||||||
|
108.86 -4.9180592035726489 2.9416928336327022 0.0025098973182049495 -0.00066591093349993114 0.0013036934913511122 0.45957656584359741 0.88813694725155701
|
||||||
|
108.87 -4.9180595148337707 2.9416934267685386 0.0025104631019277146 -0.00066561413916471884 0.0013025995936241192 0.45957705905345159 0.88813669386187222
|
||||||
|
108.88 -4.9180598113296483 2.9416939901156209 0.0025110010344434287 -0.00066533205959182315 0.0013015596358814619 0.4595775287540666 0.88813645254548013
|
||||||
|
108.89 -4.9180601486496087 2.9416946288586678 0.0025116117236652956 -0.00066501195181030263 0.0013003791296257951 0.4595780629790025 0.88813617807276113
|
||||||
|
108.90000000000001 -4.9180604669283969 2.9416952291860867 0.002512186535750748 -0.00066471077005743004 0.0012992680814553675 0.45957856688710369 0.88813591917005619
|
||||||
|
108.91 -4.9180607672789973 2.9416957933432286 0.0025127275864666853 -0.00066442738445443193 0.0012982223830156918 0.45957904225069685 0.88813567492744439
|
||||||
|
108.92 -4.9180607672789973 2.9416957933432286 0.0025127275864666853 -0.00066442738445443193 0.0012982223830156918 0.45957904225069685 0.88813567492744439
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,50 @@
|
|||||||
|
# tests/data/return_cylinder/ (回归片段:绕圆柱回程 → 配准被拒后停车)
|
||||||
|
|
||||||
|
7 帧点云 + 对应 IMU,仿真时间 73.0–73.6 s,外加 73.0 s 时刻的实时预测。
|
||||||
|
`test_recorded_update` 的第 3 个参数就是本目录。
|
||||||
|
|
||||||
|
## 来源
|
||||||
|
|
||||||
|
- 隔离的 Gazebo 仿真,**Python 启动入口**(`ros2 launch`)拉起
|
||||||
|
- 场地里放了一个圆柱:中心 (−4, −1.5) m,半径 0.22 m
|
||||||
|
- 路线:从 (0, 0) 回 (−5, 3)
|
||||||
|
- IMU 传感器无噪声
|
||||||
|
|
||||||
|
来源说明的原文在 [`provenance.txt`](provenance.txt)。
|
||||||
|
|
||||||
|
## 它复现的问题
|
||||||
|
|
||||||
|
这段路在 73.3 s 和 73.4 s 连续两帧被拒后停下。被拒的帧配准阶段停在 `FINAL_FUSION`,
|
||||||
|
新息超过六自由度门限。73.3 s 时估计比真值低了 0.075 m;
|
||||||
|
在预测位姿和真实位姿下分别能找到 513 和 545 个内点。
|
||||||
|
|
||||||
|
> `provenance.txt` 写明:最初那次「找不到任何对应」的失败是另一个症状,
|
||||||
|
> 没有同步录制,不在本片段里。
|
||||||
|
|
||||||
|
## 文件
|
||||||
|
|
||||||
|
| 文件 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| `716.flpc` – `722.flpc` | 7 帧点云,73.0 – 73.6 s |
|
||||||
|
| `imu.csv` | 65 个 IMU 样本,72.98 – 73.62 s,100 Hz |
|
||||||
|
| `truth.tum` | 63 行真值,72.986 – 73.616 s |
|
||||||
|
| `checkpoint.txt` | 73.0 s 的实时预测 |
|
||||||
|
| `config.txt` | 初始位姿、外参、扫描时间模型 |
|
||||||
|
| `provenance.txt` | 来源说明 |
|
||||||
|
|
||||||
|
**本目录没有 `map.flmap`**,测试用的是 [`../return_contact/map.flmap`](../return_contact/map.flmap)。
|
||||||
|
|
||||||
|
通用的文件格式见 [`../README.md`](../README.md)。
|
||||||
|
|
||||||
|
## 测试里断言了什么
|
||||||
|
|
||||||
|
用 `return_contact/map.flmap`,同样跑两遍比较(见
|
||||||
|
[`test_recorded_update.cpp`](../../test_recorded_update.cpp)):
|
||||||
|
|
||||||
|
| | 当前默认参数 | 旧参数 |
|
||||||
|
|---|---|---|
|
||||||
|
| 地图平移 σ | 0.03 m | 0.02 m |
|
||||||
|
| 配准成功的帧数 | **多于**旧参数(不写死具体数) | 较少 |
|
||||||
|
| 最大配准间隔 | < 0.3 s | ≥ 0.3 s |
|
||||||
|
| 最大位置误差 | < 0.10 m | 不断言 |
|
||||||
|
| 新息拒绝次数 | 不断言 | ≥ 1 |
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
73 -1.1860204800839835 -1.5637071989344469 0.091575138745469603 -0.42970067883716345 -0.32356653324631857 -0.21993780179039443 0.0051528723832590748 0.01813053226079377 -0.96370380891118801 0.2663075297399809 -4.2996599124332597e-05 -0.00013302682205245796 -3.3626316872579628e-05 -0.093146036471238869 -0.033023000640963425 0.043485336943729629 -0.088175115845336036 0.0099135394819331538 -9.7661660023761758 0.00060780813598797028 4.4833770274984383e-05 4.068913437385071e-06 0.0024170781771618599 0.00032731725695303603 2.1443137968033931e-05 -2.3597143001486444e-07 -2.9741917115125317e-07 9.7966640722376522e-08 2.1208513955816369e-09 2.5997265115716957e-09 -5.113828143965986e-10 2.1029545238081228e-05 6.2372126519518097e-06 5.6578640848176513e-06 1.9615872912915468e-05 8.7608927362914083e-06 5.6572697499445987e-06 4.4833770274984383e-05 0.00058045375687999019 3.5739298696195479e-06 0.00032917108381059015 0.0022005736005506395 1.7655757929154496e-05 3.1281479923900358e-07 -1.5012792304465173e-07 -2.8812862283482996e-07 -2.5530828508678023e-09 2.1325162410567553e-09 1.6011305635602758e-09 2.7572024541284657e-05 3.161555051603116e-05 1.2174875434780663e-05 2.2894475561072589e-05 3.5215830711721919e-05 1.2296275724162208e-05 4.068913437385071e-06 3.5739298696195479e-06 0.00036996744205358592 2.1762306440312313e-05 1.8755039425128898e-05 0.001267729477946909 4.5968173799619698e-07 -4.7184537272925347e-07 -4.5523729647643344e-08 -1.2926610506547117e-09 7.6217213133024349e-09 2.0332494642726058e-10 -2.9738024273382044e-07 -8.9656572513236403e-08 -2.3517667470055742e-06 -3.0426650126010034e-07 -1.4059474625069041e-07 9.7645343680620327e-08 0.0024170781771618599 0.00032917108381059015 2.1762306440312313e-05 0.013004981872738922 0.0029538966226704873 0.00015059828618843344 -2.6950965138518528e-06 -3.2909985277179347e-06 1.0445772255283359e-07 1.1634575468226878e-08 3.6590981458874928e-08 4.5667612011030474e-10 0.00015391619821639938 7.0450603260494027e-05 2.6355904239605509e-05 0.00014045666395491198 8.9179988054358458e-05 2.668278274914003e-05 0.00032731725695303603 0.0022005736005506395 1.8755039425128898e-05 0.0029538966226704873 0.010820450467951836 0.00011822554732653555 4.4540326413927473e-06 -2.0273734031960157e-06 -8.1556642792206085e-07 -1.7782839561356206e-08 3.0154785129451994e-08 3.667696296450078e-09 0.00017401610397799848 0.00018705211874168816 0.00010033429121629731 0.00014621392729136367 0.00020948544565366656 0.00010114826278730152 2.1443137968033931e-05 1.7655757929154496e-05 0.001267729477946909 0.00015059828618843344 0.00011822554732653555 0.0055765334401990984 1.1013160576330035e-06 -1.0088574257788578e-06 -1.0961393002398403e-07 1.8637431860427857e-09 1.5312453369595839e-08 3.2583612666746484e-10 3.6917601363854277e-06 4.0897525574045234e-06 -2.4921569959613943e-06 3.0462239662268385e-06 4.4678089343898683e-06 2.1691496353306824e-06 -2.3597143001486444e-07 3.1281479923900358e-07 4.5968173799619698e-07 -2.6950965138518528e-06 4.4540326413927473e-06 1.1013160576330035e-06 3.4247221086581215e-06 -6.5891096198150198e-08 -1.187155203932947e-08 -2.1047558332211635e-08 4.5418772101169739e-09 4.9683278470875706e-11 -1.8711916522636576e-08 -2.2622656198800191e-08 -9.4311040824366266e-09 -1.5400373926889885e-08 -2.5140465461497681e-08 -4.6779374320385916e-09 -2.9741917115125317e-07 -1.5012792304465173e-07 -4.7184537272925347e-07 -3.2909985277179347e-06 -2.0273734031960157e-06 -1.0088574257788578e-06 -6.5891096198150198e-08 2.7149352451710811e-06 7.8258829819440609e-09 -7.5838761822832311e-10 -4.0630668458863094e-08 2.182671615426844e-10 4.9921698727328337e-08 3.448164264717186e-08 1.9429585390713286e-08 4.4425236541581794e-08 4.1186405868944011e-08 1.4371428402872669e-08 9.7966640722376522e-08 -2.8812862283482996e-07 -4.5523729647643344e-08 1.0445772255283359e-07 -8.1556642792206085e-07 -1.0961393002398403e-07 -1.187155203932947e-08 7.8258829819440609e-09 3.014322181734162e-06 -1.2908373390480706e-12 -3.1928208071312328e-10 -2.9578396566249657e-08 -8.0321909476482999e-09 -1.5523546607456403e-08 -6.3644223888952986e-10 -5.8602056426427837e-09 -1.6653232158043849e-08 -1.1790315830824377e-09 2.1208513955816369e-09 -2.5530828508678023e-09 -1.2926610506547117e-09 1.1634575468226878e-08 -1.7782839561356206e-08 1.8637431860427857e-09 -2.1047558332211635e-08 -7.5838761822832311e-10 -1.2908373390480706e-12 1.4050409667273109e-07 2.3134995379579986e-10 -1.0183564798966984e-11 5.6081121799700914e-10 3.6452506447547404e-09 -2.031496723107663e-11 -1.8652785264268853e-10 3.6442353976070112e-09 3.998341940603152e-10 2.5997265115716957e-09 2.1325162410567553e-09 7.6217213133024349e-09 3.6590981458874928e-08 3.0154785129451994e-08 1.5312453369595839e-08 4.5418772101169739e-09 -4.0630668458863094e-08 -3.1928208071312328e-10 2.3134995379579986e-10 1.4357264987777869e-07 2.0860137790629101e-12 -1.9743536842213233e-08 -4.5985801264556568e-09 -8.2796884336933679e-10 -1.9262466674324068e-08 -8.3772533955529158e-09 -2.83116437057Line truncated
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
FIELD_LIO_DATASET 1
|
||||||
|
initial_pose -5 3 0 0 0 0 1
|
||||||
|
base_from_imu 0 0 0.14999999999999999 0 0 0 1
|
||||||
|
imu_from_lidar -0.0935 -0.1512 0.25519999999999998 0 0 0 1
|
||||||
|
scan_timing 0 0.10000000000000001 -3.1415926535897931 1 1
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
timestamp,gx,gy,gz,ax,ay,az
|
||||||
|
72.980000000000004,-7.8354344495958116e-05,0.0095295871084581964,-0.40739038834408964,-0.041949331379137061,-0.40863398003707235,9.8029440637868142
|
||||||
|
72.989999999999995,-7.3445220699919602e-05,0.0095113057692195364,-0.40655347375757722,-0.039464776810238023,-0.40787204291537943,9.802970698353878
|
||||||
|
73,-6.8033195655882233e-05,0.0098425386307416651,-0.42062532687378923,-1.3161440472412049,0.16967734403580129,9.8164590321196279
|
||||||
|
73.010000000000005,-6.3597823361189864e-05,0.0098286904958939207,-0.4199872868871603,-0.034141829697482876,-0.40945695897781187,9.8029496912850789
|
||||||
|
73.019999999999996,-5.9341521983073166e-05,0.0098168195913204692,-0.41943156805504295,-0.031546239725835791,-0.40873087065589297,9.8029742104844022
|
||||||
|
73.030000000000001,-5.5283234408234081e-05,0.0098068675357802157,-0.41896020205728984,-0.02894551323978679,-0.40801612392929887,9.8029980776249648
|
||||||
|
73.040000000000006,-5.1615350498180257e-05,0.0097014442445658815,-0.41442021007447988,0.35012569403667682,-0.57895913734330717,9.7990144597578244
|
||||||
|
73.049999999999997,0.010749540989019113,0.023703760187714196,-0.42430441883196418,-0.11473139056687723,-1.2961638708162919,9.7374199952169338
|
||||||
|
73.060000000000002,0.024303927187207697,0.040879816859937128,-0.42559991237085804,-0.11327635071346677,-1.2928375708421962,9.7374869126916384
|
||||||
|
73.069999999999993,0.011412485762278794,0.024264627647123997,-0.42690041610405216,0.07181388081345752,-0.29356281998120104,9.8063506255141295
|
||||||
|
73.079999999999998,0.011295930155629234,0.024014880793753864,-0.42820673267455744,0.070551367013256525,-0.29155143514622267,9.8064053609436499
|
||||||
|
73.090000000000003,0.011183363015874911,0.023771824625249252,-0.4295188125035202,0.069293193095837022,-0.28955419304502961,9.806459106887063
|
||||||
|
73.099999999999994,0.011349343630145552,0.023428029971142277,-0.40965036640913116,0.8281804914627362,-0.74377350931533792,9.7919120325237081
|
||||||
|
73.109999999999999,0.011239564517979195,0.023191634279775646,-0.41084419631700425,0.062884985538621901,-0.28317107779209555,9.8066250865740248
|
||||||
|
73.120000000000005,0.011133353776816027,0.022961275854002344,-0.41204619386088653,0.061633262867204719,-0.2812335932141441,9.8066751868936297
|
||||||
|
73.129999999999995,0.011030729056048787,0.022736898797387675,-0.41325344136489545,0.060385529321138373,-0.27930995565973848,9.8067243829796755
|
||||||
|
73.140000000000001,0.011009118823154775,0.022477589753996052,-0.40764763612085608,0.73902402991684912,-0.68217803029561108,9.7972592354529766
|
||||||
|
73.150000000000006,0.010911927208145267,0.022262952080531619,-0.40882478462142591,0.056855632474657011,-0.27486972319131597,9.8068356450403389
|
||||||
|
73.159999999999997,0.0011274837720274869,0.0096627950295530875,-0.41000923225785857,-0.59716098488484803,0.99474275639518506,9.9966213998068234
|
||||||
|
73.170000000000002,0.014424957123130768,0.026625172415456429,-0.41119682285533699,-0.096278728185410153,-1.2796255714939075,9.7393101514228846
|
||||||
|
73.180000000000007,0.027789354319285468,0.043528158300441842,-0.41239166812700828,-0.09541531211295326,-1.2760540185785516,9.7393508281239285
|
||||||
|
73.189999999999998,0.041241544356000713,0.060397187554580921,-0.41359304209948777,-0.095928208106676072,-1.2715840444755129,9.7393222843429612
|
||||||
|
73.200000000000003,0.056096268276119438,0.079154014092196731,-0.42882841160407531,-0.37496325908254702,-1.1245738899271704,9.7200666981755059
|
||||||
|
73.209999999999994,0.069771135804016574,0.095975899158274591,-0.43012831949445679,-0.099376497938928374,-1.260096442126009,9.7391313347710557
|
||||||
|
73.219999999999999,0.083602924510002563,0.11284191224767212,-0.43143312218211588,-0.10404648846002076,-1.2527028069300319,9.7388717949879915
|
||||||
|
73.230000000000004,0.097576154389577702,0.1297292978229892,-0.43265617490999292,-0.10193310607482825,-1.2463394403026862,9.7392105327075242
|
||||||
|
73.239999999999995,0.10284555420217026,0.13547804755532483,-0.45082200125836597,1.7493305204857117,-2.2058649128626109,9.8926098286351003
|
||||||
|
73.25,0.11718256848883389,0.15255198489044203,-0.45242543218879611,-0.11573071861390831,-1.2283726625084974,9.7396514667232577
|
||||||
|
73.260000000000005,0.13172216874918213,0.16971541915165328,-0.45387565352792597,-0.13100471438432626,-1.2148573787767349,9.7380098279116929
|
||||||
|
73.269999999999996,0.14651888968594512,0.18702855363576426,-0.45533576667306319,-0.14153514855913343,-1.2027668920853274,9.7373371381992744
|
||||||
|
73.280000000000001,0.16159635833286834,0.20451668446936047,-0.45680629260130595,-0.15347071295778156,-1.1895657968484012,9.7365366560660682
|
||||||
|
73.290000000000006,0.17697857439565889,0.22220474901567216,-0.45828815603846612,-0.16681668041367642,-1.1752044487194755,9.7356001897313185
|
||||||
|
73.299999999999997,0.19317938387111885,0.24096209442295696,-0.44330059132484445,-0.32601790288839161,-1.0814763533931744,9.7179752444769445
|
||||||
|
73.310000000000002,0.20924681156617111,0.2591997520549254,-0.44470322812392088,-0.20005417423733532,-1.1427413633144983,9.7330382921714751
|
||||||
|
73.319999999999993,0.21799100295136525,0.27313151403498587,-0.43980839089244594,-0.21007216449068022,-1.0025491156634148,9.7454605177780973
|
||||||
|
73.329999999999998,0.23288777627506119,0.28981750868208533,-0.44127550976639796,-0.22918030374248341,-0.98393951018281656,9.7439637648319231
|
||||||
|
73.340000000000003,0.24458329896663189,0.30301441633392945,-0.41276865111697753,2.5259868908446221,1.5417214323607373,9.8767183112935903
|
||||||
|
73.349999999999994,0.04670193778725152,0.089972856964108353,-0.33938019711657563,-1.8581802015841355,4.2524418790403562,5.0166236830827415
|
||||||
|
73.359999999999999,-0.023033935035377841,-0.044325621378972835,-0.25668604600173428,-2.4445259469386813,5.6563400047690697,6.5398699530043114
|
||||||
|
73.370000000000005,-0.11548343221942599,-0.16354870515891556,-0.39319706972899976,-4.0700637614422241,-16.712599868001288,31.415677482000284
|
||||||
|
73.379999999999995,-0.10816181034319979,-0.1538397404140206,-0.42195887516994757,-0.24592455318405387,-1.1445999717616107,9.7401309387465353
|
||||||
|
73.390000000000001,-0.093391386527653858,-0.13368654534171145,-0.42320449357488288,-0.23155778985928718,-1.1493817872544265,9.7413798757177315
|
||||||
|
73.400000000000006,-0.084723749092420919,-0.12032911328889175,-0.38509361277589499,0.93222191855265923,-1.6405616540193313,9.8661844224595807
|
||||||
|
73.409999999999997,-0.07001750024545815,-0.10062080805496776,-0.38612060666621112,-0.21128500605782019,-1.154742724074667,9.7426710011034974
|
||||||
|
73.420000000000002,-0.055373222601836629,-0.08114331114713795,-0.3871575638424587,-0.20141361068485586,-1.1570598987616196,9.7434584692680009
|
||||||
|
73.430000000000007,-0.040768607507474686,-0.061867670724642519,-0.38819835455162177,-0.19308418516556647,-1.158355767869238,9.7441003166961409
|
||||||
|
73.439999999999998,-0.029559138861381382,-0.04635890691270271,-0.35746102627438814,0.45053145277940698,-1.4115767250331073,9.807803517919286
|
||||||
|
73.450000000000003,-0.014895278490932962,-0.027306014586986567,-0.35834076391564817,-0.18416775203970459,-1.1572689145193358,9.7445953836794494
|
||||||
|
73.459999999999994,-0.00020511751773792794,-0.0083598975532057015,-0.35922913558038883,-0.1780823996002367,-1.1512554001287785,9.7448560762734751
|
||||||
|
73.469999999999999,0.017576967131798776,0.014387198741614459,-0.36012131810905157,0.12000139884387431,-0.53074901562916732,9.7439790888988966
|
||||||
|
73.480000000000004,0.035455749590555974,0.037087097815893144,-0.36101644273562561,0.11596641417312487,-0.53172432874625919,9.7436965220290936
|
||||||
|
73.489999999999995,0.051139603805240991,0.056629455590295141,-0.36428063944003952,0.081754199690666607,-0.51300593922714532,9.7533136220894736
|
||||||
|
73.5,0.062949892556653259,0.07255574335997958,-0.30458072326919639,5.3607773514998627,4.8651334266379376,9.9672454470668104
|
||||||
|
73.510000000000005,0.080093947171883478,0.093774571062345477,-0.3052256501626589,0.074807149362320746,-0.47877550007980313,9.751305284643589
|
||||||
|
73.519999999999996,0.097420639914153062,0.11507873598934916,-0.3058964247111195,0.064973701725612065,-0.47475406283817656,9.7502222255262012
|
||||||
|
73.530000000000001,0.11495685821268421,0.13649546381171412,-0.3065837564438485,0.053370590896538506,-0.46965324624279176,9.7489145355568247
|
||||||
|
73.540000000000006,0.29723332159126603,0.37461955584236989,-0.22351489315656864,-12.788428419911225,-5.9459184533471117,8.911534997472458
|
||||||
|
73.549999999999997,-0.0066481793987961044,0.20825765418887801,-0.2226766795842833,-3.7620317988710532,1.7741290509259613,5.4903190207580019
|
||||||
|
73.560000000000002,0.0062837318174231993,0.12637890870908894,-0.16769073775878729,-6.6064098596231249,0.41758271667715674,8.3696263076125792
|
||||||
|
73.569999999999993,0.0040442971016930226,0.056573159912984013,-0.10212823950165814,-6.7379210190338803,0.15044657152919713,8.4427996491416533
|
||||||
|
73.579999999999998,0.0016495690894367616,-0.013163794294091001,-0.036572344137316609,-6.7375967545183801,0.15443064835544271,8.4423661799084453
|
||||||
|
73.590000000000003,0.00022069049724417894,-0.08737929976847815,1.7012733126897927e-05,-6.2479265595145961,1.5459013180568317,8.2960183842218616
|
||||||
|
73.599999999999994,4.9683713493571535e-05,-0.16736300845426663,1.5905618074494828e-05,-6.2355129994503384,1.546419311232109,8.3003729570604605
|
||||||
|
73.609999999999999,-0.00012075011793151458,-0.2476389531478862,1.4609841830961557e-05,-6.2108012231131546,1.5441335599584702,8.3018758052246326
|
||||||
|
73.620000000000005,-0.09678470505438122,-0.12357589020282497,-2.1495070713531232e-07,0.10627007267836641,-0.31333170698237695,9.7335273902384483
|
||||||
|
@@ -0,0 +1,7 @@
|
|||||||
|
Isolated Gazebo Python launch, cylinder centered at (-4,-1.5), radius 0.22 m.
|
||||||
|
The leg from (0,0) back to (-5,3) stopped after rejections at 73.3 and 73.4 s
|
||||||
|
with registration stage FINAL_FUSION and innovation above the rank-six gate.
|
||||||
|
The checkpoint is the live prediction at sim 73.0 s. The estimate was low by
|
||||||
|
0.075 m at 73.3 s. Predicted and true sensor poses had 513 and 545 inliers.
|
||||||
|
Uses return_contact/map.flmap. Ground truth only scores the result.
|
||||||
|
The original unrecorded zero-correspondence failure is a separate symptom.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
timestamp,file
|
||||||
|
73,716.flpc
|
||||||
|
73.099999999999994,717.flpc
|
||||||
|
73.200000000000003,718.flpc
|
||||||
|
73.299999999999997,719.flpc
|
||||||
|
73.400000000000006,720.flpc
|
||||||
|
73.5,721.flpc
|
||||||
|
73.599999999999994,722.flpc
|
||||||
|
@@ -0,0 +1,64 @@
|
|||||||
|
72.986000000000004 -1.1827268115237362 -1.5545798885105371 0.0058503683128641685 0.0031301075244346047 -0.011291668895969408 0.96303472306647764 -0.26912231941758785
|
||||||
|
72.995999999999995 -1.1871888648243818 -1.5576408724309503 0.0058506913738757497 0.0031073608787444322 -0.011298428291316116 0.96357973301227318 -0.2671643463385629
|
||||||
|
73.006 -1.1916342342322537 -1.5606819444765541 0.0058509988583626453 0.0030839596115858335 -0.011305291957612885 0.96413552600730001 -0.26515159259844956
|
||||||
|
73.016000000000005 -1.1960801508860572 -1.5637051949047489 0.0058512915210192735 0.0030604007959725938 -0.011312122327296068 0.96469019752111762 -0.26312638150152751
|
||||||
|
73.025999999999996 -1.2005324013228871 -1.5667114803470656 0.0058515701113706535 0.0030368478865988595 -0.01131887567226837 0.96523991156191746 -0.26110261150814101
|
||||||
|
73.036000000000001 -1.2049911000891447 -1.569700966017002 0.0058518353561440436 0.0030132968344191305 -0.011325554296524652 0.9657847915226504 -0.25907988792188191
|
||||||
|
73.046000000000006 -1.2094761555512541 -1.5726563636090436 0.0058514931440729551 0.0029775415743041557 -0.011327041109622219 0.96632793569678654 -0.25704698612872584
|
||||||
|
73.055999999999997 -1.2139813859319666 -1.5755217306559217 0.0058467866734837094 0.0028531614658296417 -0.011290521870982027 0.9668725771097133 -0.25499373172443324
|
||||||
|
73.066000000000003 -1.2184970583372341 -1.5783420770566474 0.0058411485173472224 0.0027101286142647055 -0.011245432738640568 0.9674146672986218 -0.25293290996015494
|
||||||
|
73.075999999999993 -1.2230230999073919 -1.581174339566185 0.0058372459161947837 0.0026026102969416822 -0.011215152911073112 0.96795363620886388 -0.25086491367838176
|
||||||
|
73.085999999999999 -1.2275594802434509 -1.584004724373161 0.0058334010181124874 0.0024965007395751663 -0.011185053184934762 0.96848978920550355 -0.24878944968383798
|
||||||
|
73.096000000000004 -1.2321061458005205 -1.586833273349284 0.0058296125281075833 0.0023917628099110935 -0.011155125972395104 0.96902309106103679 -0.24670648881963916
|
||||||
|
73.105999999999995 -1.2366770672797653 -1.5896597593421413 0.0058257933189042521 0.0022875676175172907 -0.011124399978516344 0.96953274426748903 -0.24469832968916033
|
||||||
|
73.116 -1.2412612759579238 -1.5924844438350985 0.0058220077784071631 0.0021845019836098339 -0.011093611178925624 0.97003453494922343 -0.24270385400305933
|
||||||
|
73.126000000000005 -1.2458551695513467 -1.5953074384597066 0.005818276249389181 0.0020827332471716501 -0.011062995599026178 0.9705336511324667 -0.24070252256692404
|
||||||
|
73.135999999999996 -1.2504586966141451 -1.5981287852739068 0.0058145975239704299 0.0019822282630259577 -0.011032546067196629 0.97103006156964311 -0.23869430916224993
|
||||||
|
73.146000000000001 -1.255084419744052 -1.6009479136873122 0.0058109448845094034 0.001882740217275448 -0.011001970759730145 0.97151727032669921 -0.23670573585284282
|
||||||
|
73.156000000000006 -1.2597227209909205 -1.6037653292807263 0.0058073367000094668 0.0017844065781903173 -0.010971482741895466 0.97200017467302524 -0.23471706988460922
|
||||||
|
73.165999999999997 -1.2643703716012211 -1.6065692004929799 0.0058054351471337629 0.0017207138821939841 -0.010956429657944052 0.97248007250003377 -0.23272194650100214
|
||||||
|
73.176000000000002 -1.2690273659231286 -1.6092870412226157 0.0057995853584831784 0.0015774642266509142 -0.010904630443552707 0.9729579453695304 -0.23071939056742757
|
||||||
|
73.186000000000007 -1.2736936294264443 -1.6119132852962943 0.0057888903842487011 0.0013366454841123518 -0.010807168976942191 0.9734338788669914 -0.22870920827880409
|
||||||
|
73.195999999999998 -1.2783690768235658 -1.6144484411759916 0.0057733570847300335 0.00099838714014245981 -0.010663363271679079 0.97390776174996807 -0.22669134855574477
|
||||||
|
73.206000000000003 -1.2830459816176745 -1.6168935041479873 0.0057526303709198659 0.00055478348460317756 -0.010469086626791425 0.97439213585460505 -0.22461089916828808
|
||||||
|
73.215999999999994 -1.2877302190973396 -1.6192486817193614 0.0057269994531547698 1.1858640024756509e-05 -0.010226038876597652 0.97487711803995747 -0.22250850031037867
|
||||||
|
73.225999999999999 -1.2924236269314422 -1.6215143558841598 0.0056965603103861003 -0.00062870174059144587 -0.0099341254176952484 0.97535929519869891 -0.2203977385451229
|
||||||
|
73.236000000000004 -1.2971263107162498 -1.6236910792608883 0.0056613326323830615 -0.0013670999905177658 -0.0095924540980015325 0.97583833270215847 -0.21827886817341038
|
||||||
|
73.245999999999995 -1.3018883834526711 -1.6257740491873514 0.0056239117144352598 -0.0021517079689924931 -0.0092250211793455002 0.97632841537557724 -0.2160858497617815
|
||||||
|
73.256 -1.3066724522289066 -1.6277675579927218 0.005582366458046736 -0.0030220127470465268 -0.0088121498758130402 0.97681841066491237 -0.21386679508422426
|
||||||
|
73.266000000000005 -1.3114658236480086 -1.6296735204577222 0.005536059271095733 -0.0039917655401962571 -0.0083463838234752209 0.97730427806235165 -0.2116382568581803
|
||||||
|
73.275999999999996 -1.3162683485699671 -1.6314924744494148 0.0054849957814838224 -0.0050619140072993641 -0.007826374711552871 0.97778560591429009 -0.2094001761037505
|
||||||
|
73.286000000000001 -1.3210799159925637 -1.6332249663976133 0.0054291888087800583 -0.0062335075109966193 -0.0072506941703858385 0.97826195609988331 -0.20715239816566938
|
||||||
|
73.296000000000006 -1.3259004157127494 -1.6348715556793953 0.0053686555042825965 -0.0075077337713179019 -0.0066178173011011698 0.9787328436423689 -0.20489475152748682
|
||||||
|
73.305999999999997 -1.3307258730288571 -1.6364331023120495 0.0053031983619743518 -0.0088901447072203075 -0.0059243973886139627 0.97918432592740234 -0.20269169371428425
|
||||||
|
73.316000000000003 -1.3355688420359801 -1.6379338642402002 0.0052066599772398357 -0.010349309723247574 -0.0051351687533685254 0.97962303805373774 -0.20051240646027871
|
||||||
|
73.325999999999993 -1.3404288287396919 -1.6393094520762683 0.0051431728984243112 -0.01191358322865199 -0.0043528051038197648 0.98005172552508568 -0.19833742692110404
|
||||||
|
73.335999999999999 -1.3452969908923822 -1.6406113168530503 0.0050762464459957867 -0.013574640558649069 -0.003513638653623339 0.9804731942281727 -0.19615223393354278
|
||||||
|
73.346000000000004 -1.3501895167318128 -1.6419798548380817 0.005108738976746104 -0.015112268455780108 -0.002745964899443495 0.98085529585059306 -0.19413131540464329
|
||||||
|
73.355999999999995 -1.3549640787730097 -1.643812391091483 0.0052728105183241208 -0.015456375536794619 -0.0026939842015352993 0.98116484973653617 -0.19253410229325085
|
||||||
|
73.366 -1.3595536153661432 -1.6459691252064099 0.0050727415228652038 -0.015103014156831235 -0.0028926586344415043 0.98142075506854209 -0.19125070721462972
|
||||||
|
73.376000000000005 -1.3644408608921856 -1.6481096591831021 0.0050303164843351379 -0.014129238367996394 -0.0031990403064940261 0.98181768324296859 -0.18927273347122053
|
||||||
|
73.385999999999996 -1.3693679054219983 -1.6500463243136565 0.0050716421136637185 -0.013287502301379286 -0.0036035105415935555 0.98222354639289056 -0.18720940656318727
|
||||||
|
73.396000000000001 -1.3743027258731864 -1.6518878352927291 0.0051078334634670477 -0.012558165495312168 -0.0039544144955527879 0.9826243984334011 -0.18513764254949971
|
||||||
|
73.406000000000006 -1.3792750390455779 -1.653630489318143 0.0051402522403393063 -0.011910411700310231 -0.0042684389015000919 0.98299183291174042 -0.18321293336249561
|
||||||
|
73.415999999999997 -1.3842618856175508 -1.6552783728159306 0.0051678629559868527 -0.011365311066434713 -0.0045325318919417308 0.98334805810745662 -0.18131983475424274
|
||||||
|
73.426000000000002 -1.3892557057606063 -1.6568332167167177 0.0051903275164664614 -0.010928970993995174 -0.0047423280642563716 0.98370049479445809 -0.1794196323111874
|
||||||
|
73.436000000000007 -1.394256443797167 -1.6582956225633008 0.0052076506453389328 -0.010600293412376642 -0.0048976108430821763 0.98404929433243071 -0.17751234749010111
|
||||||
|
73.445999999999998 -1.3992803525324311 -1.6596636580785431 0.0052205679673638641 -0.010362552415903985 -0.0050074287281092989 0.9843722748967384 -0.17572355442450174
|
||||||
|
73.456000000000003 -1.4043146774059381 -1.6609397975496776 0.0052285160752110005 -0.010227302423756654 -0.0050641691906889597 0.98468660432798594 -0.17395990265737007
|
||||||
|
73.465999999999994 -1.4093552246548775 -1.6621424203794255 0.0052310615029692153 -0.010203195071777764 -0.0050622497105420518 0.98499790146017485 -0.17219001875035322
|
||||||
|
73.475999999999999 -1.4144019162987285 -1.6633231241499224 0.0052274511189123575 -0.01030546793865101 -0.0049927276760517187 0.98530606351375705 -0.17041370603311956
|
||||||
|
73.486000000000004 -1.4194603931236236 -1.6644842632343171 0.0052180160450279768 -0.010528061320118303 -0.0048578627442221181 0.98561223941979692 -0.16862406293376736
|
||||||
|
73.495999999999995 -1.4245287535741527 -1.6656258096952028 0.0052034305511925519 -0.01086466396589038 -0.0046597265761129372 0.98591593499195707 -0.16682330518869151
|
||||||
|
73.506 -1.4296621409454648 -1.6668540088835526 0.0051845470553112281 -0.011296878445963545 -0.0044096432938098198 0.98617617643336519 -0.16525581568788048
|
||||||
|
73.516000000000005 -1.4348154349037505 -1.6680920915855586 0.0051606356239071475 -0.011842531349017563 -0.0040958759277063429 0.98642343956985878 -0.16374301853453616
|
||||||
|
73.525999999999996 -1.4399737281517972 -1.6693138150216535 0.0051314803138102659 -0.012507535848080481 -0.0037139381697808187 0.98666753687285635 -0.1622249669179523
|
||||||
|
73.536000000000001 -1.4448108571510392 -1.6703872549451679 0.0050748358390243983 -0.013654117135374278 -0.0030522962961160565 0.98687800113934654 -0.16086037249671561
|
||||||
|
73.546000000000006 -1.448396490965824 -1.6708636848531406 0.005251067238020434 -0.015408964009291733 -0.002318675811017387 0.98703020248953166 -0.15977661576124966
|
||||||
|
73.555999999999997 -1.4515248319730381 -1.6713613042405748 0.0055058843437679012 -0.016317612017665597 -0.0026360788593341013 0.98719442384803147 -0.15866302704045965
|
||||||
|
73.566000000000003 -1.4541058422468496 -1.6717288667858907 0.0056966781063328351 -0.016875331532463796 -0.0027096104034522975 0.98730797652805991 -0.15789503057790946
|
||||||
|
73.575999999999993 -1.4561705707068855 -1.6719405539160637 0.005769558057817115 -0.017087362353195943 -0.002733171804277935 0.98737458440055792 -0.15745469792776765
|
||||||
|
73.585999999999999 -1.4577188766658054 -1.6719969350138024 0.0057247128990593867 -0.016953677612950045 -0.0027079798480792918 0.98739581231247131 -0.15733642136623532
|
||||||
|
73.596000000000004 -1.4587606276285694 -1.6719950828801873 0.0055514879861516108 -0.016443476617033503 -0.0026257375244013747 0.98740443243506093 -0.15733786698310492
|
||||||
|
73.605999999999995 -1.4593019073162419 -1.6719919533146337 0.0052435932373300249 -0.015538053557393336 -0.002481383320436847 0.98741908353097274 -0.1573402844389151
|
||||||
|
73.616 -1.4593872573948983 -1.6719896736122408 0.0050093300597352768 -0.014500939174517082 -0.0025331301065374453 0.98743382718860817 -0.1573459339753602
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,44 @@
|
|||||||
|
# tests/data/turn_contact/ (回归片段:转弯接触 → 新息拒绝级联)
|
||||||
|
|
||||||
|
5 帧点云 + 对应 IMU,仿真时间 21.6–22.0 s,外加 21.5 s 时刻的滤波器状态。
|
||||||
|
`test_recorded_update` 的第 1 个参数就是本目录。
|
||||||
|
|
||||||
|
## 来源
|
||||||
|
|
||||||
|
- 隔离的 Gazebo 仿真,**Python 启动入口**(`ros2 launch`)拉起
|
||||||
|
- 场地里放了一个圆柱:中心 (−4, −1.5) m,半径 0.22 m,高 0.8 m
|
||||||
|
- IMU 传感器无噪声,但有限采样率下的动力学不为零
|
||||||
|
|
||||||
|
来源说明的原文在 [`provenance.txt`](provenance.txt)。
|
||||||
|
|
||||||
|
## 它复现的问题
|
||||||
|
|
||||||
|
[`checkpoint.txt`](checkpoint.txt) 是 21.5 s 时刻、**修复前的模型**已经接受的估计。
|
||||||
|
从它出发处理这 5 帧,在「地图模型过度自信」的旧参数下会触发新息拒绝级联
|
||||||
|
(NIS 先是 31.6,随后 35.1……):对应找得到,却因为新息过大被整帧拒绝。
|
||||||
|
|
||||||
|
> `provenance.txt` 里写明:这是**修复过程中发现的**失败的录制回归,
|
||||||
|
> 不声称精确复现了最初那次没有录下来的发散。
|
||||||
|
|
||||||
|
## 文件
|
||||||
|
|
||||||
|
| 文件 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| `152.flpc` – `156.flpc` | 5 帧点云(`lidar_link` 系),时间 21.6 / 21.7 / 21.8 / 21.9 / 22.0 s |
|
||||||
|
| `imu.csv` | 61 个 IMU 样本,21.5 – 22.1 s,100 Hz |
|
||||||
|
| `truth.tum` | 5 行真值,21.6 – 22.0 s |
|
||||||
|
| `map.flmap` | 本片段用的地图。和 [`return_contact/map.flmap`](../return_contact/map.flmap) 内容相同 |
|
||||||
|
| `checkpoint.txt` | 21.5 s 的滤波器状态 |
|
||||||
|
| `config.txt` | 初始位姿 (−5, 3, 0)、外参、`instantaneous` 扫描 |
|
||||||
|
| `provenance.txt` | 来源说明 |
|
||||||
|
|
||||||
|
通用的文件格式见 [`../README.md`](../README.md)。
|
||||||
|
|
||||||
|
## 测试里断言了什么
|
||||||
|
|
||||||
|
用本目录的 `map.flmap` 和**当前默认参数**(见
|
||||||
|
[`test_recorded_update.cpp`](../../test_recorded_update.cpp)):
|
||||||
|
|
||||||
|
- 5 帧全部配准成功(`FULL = 5/5`)
|
||||||
|
- 最大位置误差 < 0.10 m
|
||||||
|
- 最大旋转误差 < 0.02 rad
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
21.5 -4.9584264520627084 2.8312555285145069 0.066642701693339218 0.28925532856581104 -0.18381915008460603 -0.088000693255994411 -0.00067113795667528883 0.0020454012507826885 -0.59983425677615865 0.8001213847319415 0.00013545462743937917 -0.00011407959527293953 7.7473698313815906e-05 0.094527591711915243 -0.018654076254896023 0.0059506817166394832 0.09629720315366537 -0.0095379732857951496 -9.8076595698943176 5.4211970910770516e-05 -1.6913810010464369e-06 7.7093436287022919e-08 0.00019387688324965145 -3.9371910845080579e-05 -3.076733516773156e-09 -6.5879156639180102e-08 3.3594270298662e-08 -6.9256690960194507e-08 2.7813913824052845e-09 -3.9388948155551208e-09 2.7030692132274592e-09 6.7300085074034144e-05 -0.00014701238697221737 -3.6740275206857811e-07 6.7649803199897789e-05 -0.00014627685630574802 -4.5186245904610204e-07 -1.6913810010464369e-06 5.72793708146413e-05 2.8440372274030672e-07 -3.2377452257135454e-05 0.00025496896000278674 7.2995229948893227e-07 5.0336174808415647e-08 8.6199059252662469e-08 -5.8734582018920561e-09 -3.5968463297817861e-09 -4.8402498733582902e-09 1.616767127151391e-10 0.00012940623942249684 7.7784760250283177e-05 -6.2149350554646791e-08 0.00012864861059710134 7.8059097522582328e-05 6.5809483616306078e-08 7.7093436287022919e-08 2.8440372274030672e-07 4.4887792501138219e-05 1.6481005494312824e-07 3.3036051466097291e-07 9.4396205964828535e-05 1.0746546275263083e-07 7.1978980696136641e-08 -4.56926219074464e-09 -9.2063759574381534e-09 -2.9925456873137583e-09 1.0356849209793115e-10 4.1101855612585824e-08 8.5015802052718161e-08 -5.6829671521961278e-06 4.3297632733567627e-08 8.3966956861444471e-08 2.2914719948329354e-07 0.00019387688324965145 -3.2377452257135454e-05 1.6481005494312824e-07 0.0014059864076449847 -0.00060156667631372442 -1.4477134773688117e-06 -2.1823656182909228e-06 5.9188720608873556e-07 -1.4649709427784945e-07 1.3273493659769134e-07 -6.9244332841764212e-08 6.2740980664033955e-09 0.00089514847072110935 -0.0013394792725598911 -8.5265579403348356e-06 0.00089525610558024722 -0.0013328928842766964 -9.1617952588180192e-06 -3.9371910845080579e-05 0.00025496896000278674 3.3036051466097291e-07 -0.00060156667631372442 0.002463472591958255 3.5836619389065894e-06 -4.4575707601887398e-07 -1.1768510327073258e-06 9.9552288663074785e-08 4.6256335948957022e-08 7.1161172428782834e-08 -4.2102789712100902e-09 0.0011477879323172333 0.00065501652442554468 -1.9605052538671123e-06 0.0011427053782942492 0.00065527039106214242 -1.0098242081899217e-06 -3.076733516773156e-09 7.2995229948893227e-07 9.4396205964828535e-05 -1.4477134773688117e-06 3.5836619389065894e-06 0.00043323801298578271 4.7889351727371411e-07 -3.7836925694658505e-08 -6.0909800875255969e-09 -7.3782931566863936e-09 2.1482886014884101e-08 -8.1860284535393516e-11 2.4471929872239124e-06 1.5975125965650238e-06 -2.6141701453767846e-05 2.5003766573461859e-06 1.5647774043328547e-06 1.0714728784118976e-06 -6.5879156639180102e-08 5.0336174808415647e-08 1.0746546275263083e-07 -2.1823656182909228e-06 -4.4575707601887398e-07 4.7889351727371411e-07 1.8634814206817319e-06 -6.5406181501742526e-08 -5.9879319969574165e-09 -1.1308758845294002e-07 3.2875194268899705e-08 3.6605395830826769e-10 9.5395073951606776e-07 -1.2086054116854707e-06 -1.7791229708523751e-08 9.5805103233717334e-07 -1.1994805300485477e-06 4.4726135709942555e-10 3.3594270298662e-08 8.6199059252662469e-08 7.1978980696136641e-08 5.9188720608873556e-07 -1.1768510327073258e-06 -3.7836925694658505e-08 -6.5406181501742526e-08 1.6306204086006391e-06 -3.7659580115382053e-09 -1.9568111489965129e-08 -1.0266195435166226e-07 1.6962366071786955e-10 9.9466921733896439e-07 1.0447122421018458e-06 -3.3863971471289592e-09 9.8565734537631504e-07 1.0470045147292737e-06 1.4724984962219323e-09 -6.9256690960194507e-08 -5.8734582018920561e-09 -4.56926219074464e-09 -1.4649709427784945e-07 9.9552288663074785e-08 -6.0909800875255969e-09 -5.9879319969574165e-09 -3.7659580115382053e-09 1.738679824274879e-06 3.0547132036890773e-10 4.9222657173568789e-11 -7.974542467371376e-08 -9.6533208413801504e-08 1.1328959003903214e-07 3.6098490506195615e-10 -9.6748486948590507e-08 1.1239758479133494e-07 6.7324089562498283e-11 2.7813913824052845e-09 -3.5968463297817861e-09 -9.2063759574381534e-09 1.3273493659769134e-07 4.6256335948957022e-08 -7.3782931566863936e-09 -1.1308758845294002e-07 -1.9568111489965129e-08 3.0547132036890773e-10 6.0976535317072009e-07 -5.3356788860148487e-10 -1.3567694186530896e-10 -1.0852134915108957e-07 -8.0855594335962174e-08 -3.6660465634396378e-10 -1.0355841555197264e-07 -7.5482084479384465e-08 3.5358876726330169e-11 -3.9388948155551208e-09 -4.8402498733582902e-09 -2.9925456873137583e-09 -6.9244332841764212e-08 7.1161172428782834e-08 2.1482886014884101e-08 3.2875194268899705e-08 -1.0266195435166226e-07 4.9222657173568789e-11 -5.3356788860148487e-10 6.101867536363909e-07 3.7511965469393576e-11 7.998411272557813e-08 -1.39999752509837e-07 -1.7172385625784348e-09 7.6460470194792003e-08 -1.36667696931179Line truncated
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
FIELD_LIO_DATASET 1
|
||||||
|
initial_pose -5 3 0 0 0 0 1
|
||||||
|
base_from_imu 0 0 0.14999999999999999 0 0 0 1
|
||||||
|
imu_from_lidar -0.0935 -0.1512 0.25519999999999998 0 0 0 1
|
||||||
|
scan_timing 0 0.10000000000000001 -3.1415926535897931 1 1
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
timestamp,gx,gy,gz,ax,ay,az
|
||||||
|
21.5,0.027876815948866075,0.030751855940937323,-1.1842935700125712,-0.023111402382871217,-0.1395854844850429,9.8048196820867783
|
||||||
|
21.510000000000002,-0.017607971943273938,-0.019452753963797663,-1.0602135046058219,-1.8701885300232559,-4.8705061252712838,9.8492370134248119
|
||||||
|
21.52,-0.018846260953600025,-0.022937105492543533,-1.0885774106073516,1.7897503972716406,-0.52672997202580918,10.044685765383601
|
||||||
|
21.530000000000001,-0.016026186362089922,-0.020400366678482509,-1.0917241522243037,-0.62935551826196445,-0.1902268052569194,9.8327730329417005
|
||||||
|
21.539999999999999,-0.0039680052956488614,-0.0048802501128351631,-1.0654810805867481,-0.44032183352333709,-0.87969651611324595,9.7995619192456243
|
||||||
|
21.550000000000001,0.003925853378591285,0.0043237549583911806,-1.050994136270337,-0.44419549879966652,-0.97063770692490714,9.7865771166979361
|
||||||
|
21.559999999999999,0.015521072951268861,0.018556156846335888,-1.0353119198407827,-0.44966512255833768,-1.1168820870323035,9.7662886848858701
|
||||||
|
21.57,-0.010713980836765676,-0.013782805389494718,-0.94648142161182514,1.0499207329160547,-1.5307281829738353,9.8558645017074973
|
||||||
|
21.579999999999998,0.0031908795850543073,0.0035817993979718257,-0.92877659759056419,-0.4049306552659751,-1.4212029132690633,9.753489507374999
|
||||||
|
21.59,-0.021896214870731016,-0.027220937407084374,-1.046273171064463,-0.019080772620131286,-0.6706677557942925,9.8494812269271783
|
||||||
|
21.600000000000001,-0.0066984038660593166,-0.011113690260045382,-1.0149032364140909,-0.57963659076810203,-0.72547828545723159,9.7982242770199388
|
||||||
|
21.609999999999999,-0.039158333081591237,-0.052117197217750884,-0.89957843673794069,3.139885509588999,-1.5781583695599466,9.9983700160178195
|
||||||
|
21.620000000000001,-0.027351924574812329,-0.031862753564538271,-0.88420699018074034,0.69448039315213117,-1.6305374543474735,9.2340980561444557
|
||||||
|
21.629999999999999,-0.015742222043143166,-0.016493939663926746,-0.88981339413502702,0.13150673202177771,-1.1306170708571193,9.7647431139790921
|
||||||
|
21.640000000000001,-0.004022699885873662,-0.001259569669767647,-0.89551123337432403,0.13599635495643095,-1.1261639413381019,9.7647800516600576
|
||||||
|
21.649999999999999,0.0053353662239785616,0.010725575725301893,-0.90942875157974634,0.15789610004821517,-1.0530705154987865,9.7628617078795266
|
||||||
|
21.66,0.016491250498544736,0.024609379686451945,-0.91558626730855419,0.13365907581890527,-1.0429172980073094,9.7708766453126117
|
||||||
|
21.670000000000002,-0.021584399663932677,-0.024912300322534046,-0.76095815345993478,6.334705400986917,-1.9226497375982048,10.16362673678579
|
||||||
|
21.68,-0.024613197565842172,-0.028395976761316468,-0.72376627351450273,0.16010078508940159,-1.1232093770948182,9.7658992604965018
|
||||||
|
21.690000000000001,-0.01332931734631751,-0.01358980859023368,-0.72760711502275677,0.16465795448040937,-1.120516879442744,9.7659457879414191
|
||||||
|
21.699999999999999,-0.0019575192421991657,0.0011106136969861063,-0.73150418485493418,0.16801879382850354,-1.1169314917879238,9.7659654174605368
|
||||||
|
21.710000000000001,-0.044054573922724313,-0.053285716147205384,-0.61035702732550567,6.0602938776630646,-1.7233623359755605,10.128535591728884
|
||||||
|
21.719999999999999,-0.033182538192041783,-0.038747817964841308,-0.61310117399133168,0.18427679543960218,-1.1232537058471808,9.7662459312502019
|
||||||
|
21.73,0.0065937579963648487,0.01220371761027326,-0.61819333204270599,0.42320660850550007,-1.1077954778840988,9.7787270047329358
|
||||||
|
21.739999999999998,0.017743748619107744,0.026227702779281103,-0.62109178345466298,0.17964983435637935,-1.07910404731498,9.7687556248026848
|
||||||
|
21.75,0.032070966256201157,0.044123934778049302,-0.6215635501503658,0.84781519798736116,-1.1424853289040711,9.8052938196326451
|
||||||
|
21.760000000000002,0.04323159084711134,0.05774811074414956,-0.62595909325220001,0.17881946371284294,-1.0776411109044441,9.7676732379160764
|
||||||
|
21.77,0.014565654737886168,0.020141041915345721,-0.51962271077133859,3.5985100821990623,-1.301336010579152,9.9755222340616978
|
||||||
|
21.780000000000001,0.025801767523406849,0.034196267656947055,-0.52176828690226362,0.18271536293139218,-1.0746575281330528,9.768878610689395
|
||||||
|
21.789999999999999,0.037193714362879646,0.048275107001682457,-0.52410013243946096,0.1837758742603682,-1.0694389692875366,9.7691355126248602
|
||||||
|
21.800000000000001,0.01223316024587217,0.019170210150084323,-0.45087651659991557,-0.0016956389731149143,-0.025951705650085775,9.8096683309132633
|
||||||
|
21.809999999999999,-0.00014021699382744945,0.087350461521265688,-0.35560102149335326,-12.017207426083699,12.525109252441553,17.022397415679425
|
||||||
|
21.82,-0.00018166526363231261,-0.0010756693194457732,-0.22095831438709318,-6.0427967228584052,0.88698691055288525,8.3850437959484463
|
||||||
|
21.829999999999998,-0.00040895771439254658,-0.086090056130199294,-0.21465058401431397,-6.0590794225276614,0.020058605902515955,8.397829504956416
|
||||||
|
21.84,-0.00026355398198325039,9.7904213798260322e-05,-4.2769962500452402e-07,-9.8707398799650079,-1.5965914924433029,9.8098653716609068
|
||||||
|
21.850000000000001,-0.00025050049702286293,9.3204854111866273e-05,-1.4542927798134628e-08,-9.8061290208515803,0.2527329127215982,9.8097768235231264
|
||||||
|
21.859999999999999,-0.00023879590816752226,8.7332624985708365e-05,-1.1593175628075952e-08,-0.001764775913125201,0.00036811344182996567,9.8095835903475646
|
||||||
|
21.870000000000001,-0.00022709254981645351,8.3052230814051822e-05,-1.0502390166897367e-08,9.9535930503896199e-05,0.00026561050962938242,9.8096475330243074
|
||||||
|
21.879999999999999,-0.00021596264222375556,7.8981892437700638e-05,-9.4969272472534689e-09,9.4713541093136591e-05,0.00025242575083570602,9.8096648083568869
|
||||||
|
21.890000000000001,-0.00020537820496690276,7.5111043850616314e-05,-8.5876661972860452e-09,9.0127483839020159e-05,0.000239887096402082,9.8096812369447548
|
||||||
|
21.899999999999999,-0.00019531250426390155,7.1429908199846623e-05,-7.7654053039581541e-09,8.5766177110097508e-05,0.00022796288931141036,9.8096968602951602
|
||||||
|
21.91,-0.00018574011653788892,6.7929187801640416e-05,-7.0218228570528799e-09,8.1618606354085882e-05,0.00021662302360277895,9.8097117178802993
|
||||||
|
21.920000000000002,-0.00017663686420234747,6.4600040662224806e-05,-6.3493930202361042e-09,7.7674297127672986e-05,0.00020583886784211096,9.8097258472369333
|
||||||
|
21.93,-0.00016797975459500661,6.1434058138850052e-05,-5.7413096683436485e-09,7.3923288085381996e-05,0.00019558319324319956,9.8097392840616973
|
||||||
|
21.940000000000001,-0.00015974692190305937,5.8423243706815917e-05,-5.1914176625325811e-09,7.035610602655997e-05,0.00018583010503157816,9.8097520623012606
|
||||||
|
21.949999999999999,-0.00015191757193588139,5.5559992759625349e-05,-4.6941504767884928e-09,6.6963741937274546e-05,0.00017655497694641463,9.8097642142377186
|
||||||
|
21.960000000000001,-0.00014447192960282323,5.2837073402874852e-05,-4.244473988010895e-09,6.3737628363540714e-05,0.0001677343891905942,9.8097757705710382
|
||||||
|
21.969999999999999,-0.00013739118896762418,5.0247608185847667e-05,-3.8378355327169014e-09,6.0669617530851912e-05,0.00015934606945459698,9.8097867604958644
|
||||||
|
21.98,-0.00013065746574668732,4.7785056735067413e-05,-3.470117895178189e-09,5.775196114331094e-05,0.00015136883648773686,9.8097972117756687
|
||||||
|
21.989999999999998,-0.00012425375213870804,4.5443199230114358e-05,-3.1375976145222629e-09,5.4977290465550821e-05,0.00014378254678249264,9.8098071508129543
|
||||||
|
22,-0.00011816387386841682,4.3216120697468507e-05,-2.8369073533752963e-09,5.2338597750746862e-05,0.00013656804408554844,9.809816602716035
|
||||||
|
22.010000000000002,-0.0001123724493311345,4.1098196068081264e-05,-2.5650018791755717e-09,4.9829218857646998e-05,0.00012970711036944108,9.8098255913621486
|
||||||
|
22.02,-0.00010686485074289968,3.9084075973122962e-05,-2.3191271625440211e-09,4.7442816148963473e-05,0.00012318242028306969,9.8098341394582906
|
||||||
|
22.030000000000001,-0.00010162716719666886,3.7168673228841246e-05,-2.0967926695168354e-09,4.5173362454866423e-05,0.00011697749758873088,9.8098422685983877
|
||||||
|
22.039999999999999,-9.6646169523062264e-05,3.534714999127065e-05,-1.895746026129816e-09,4.3015126098136043e-05,0.00011107667321795587,9.8098499993176098
|
||||||
|
22.050000000000001,-9.1909276878162586e-05,3.3614905535276057e-05,-1.7139503102811479e-09,4.0962656144982116e-05,0.0001054650458994324,9.8098573511448244
|
||||||
|
22.059999999999999,-8.7404524966776096e-05,3.1967564634825251e-05,-1.5495634754864029e-09,3.9010768977033052e-05,0.00010012844451797148,9.8098643426515846
|
||||||
|
22.07,-8.3120535823239054e-05,3.040096651154403e-05,-1.4009196137885638e-09,3.715453465619199e-05,9.5053392424021405e-05,9.80987099149886
|
||||||
|
22.079999999999998,-7.90464890723387e-05,2.8911154327071686e-05,-1.2665122120811435e-09,3.538926515309853e-05,9.0227073343135129e-05,9.809877314482172
|
||||||
|
22.09,-7.5172094600004836e-05,2.7494365189110178e-05,-1.1449788632454963e-09,3.3710502056849816e-05,8.5637298907652895e-05,9.8098833275738873
|
||||||
|
22.100000000000001,-7.1487566562624332e-05,2.6147020645983372e-05,-1.0350874626715972e-09,3.211400534500572e-05,8.1272478241284333e-05,9.8098890459632262
|
||||||
|
Binary file not shown.
Loaded 100 of 214 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user