Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4502296915 | ||
|
|
0602144ac5 | ||
|
|
28ac7c488e | ||
|
|
b772174c1c | ||
|
|
b833e6f658 | ||
|
|
55e9456e4a | ||
|
|
9b72f580c3 | ||
|
|
3c3a34c1ed | ||
|
|
ff39d32123 | ||
|
|
3c58a08dad |
No files matched your search
@@ -9,6 +9,12 @@
|
||||
|
||||
---
|
||||
|
||||
## 当前定位入口
|
||||
|
||||
默认定位已切换到连续跟踪的 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。
|
||||
|
||||
## 0. 开发环境
|
||||
|
||||
### 0.1 操作系统
|
||||
@@ -27,15 +33,15 @@
|
||||
| Gazebo(ROS vendor) | **10.5.0** | `/opt/ros/lyrical/opt/gz_*_vendor/` |
|
||||
| ros_gz / ros_gz_sim | 3.0.10 | `/opt/ros/lyrical` |
|
||||
| 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 | |
|
||||
| CMake | 4.2.3 | 系统自带。**本工程不用**(构建全走 xmake) |
|
||||
| GCC / G++ | 15.2.0 | |
|
||||
| GNU Make | 4.4.1 | |
|
||||
| Python | 3.14.4 | `/usr/bin/python3`(系统版) |
|
||||
| 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 |
|
||||
| **xmake** | **3.1.1** | `~/.local/bin/xmake`。**全工程唯一的构建系统**,在仓库根跑 `xmake`(核心库 + 两个节点 + 223 项单测,增量 0.5 秒)。`sentry_sim` 是纯数据包,不需要编译 |
|
||||
| **C++ 标准** | **C++23** | 仓库根 `xmake.lua` 的 `set_languages("c++23")`<br>**固定要求 C++23**,不能降为 C++17/20 |
|
||||
| **xmake** | **3.1.1** | `~/.local/bin/xmake`。**全工程唯一的构建系统**,在仓库根跑 `xmake`(导航与定位核心库、节点、离线工具及单元测试)。`sentry_sim` 是纯数据包,不需要编译 |
|
||||
|
||||
## 1. 目录结构
|
||||
|
||||
@@ -54,7 +60,7 @@ sentry_nav_dev/ 仓库根(xmake 工程根)
|
||||
│ │
|
||||
│ ├── sentry_nav/ 导航/决策节点(C++,唯一的可编译包)
|
||||
│ └── sentry_sim/ 仿真环境(147 MB,其中网格 146 MB)
|
||||
├── tools/ 模型转换与调试工具(独立脚本,不参与构建)
|
||||
├── tools/ 日常工具、验收和启动/构建辅助脚本
|
||||
├── generated/ 运行时产物(可随时删)
|
||||
├── .vscode/ IDE 配置(不影响仿真)
|
||||
└── build/ xmake 构建产物(不入 git)
|
||||
@@ -68,7 +74,7 @@ sentry_nav_dev/ 仓库根(xmake 工程根)
|
||||
| `src/sentry_nav/` | 算法代码 | 在这块实现算法 |
|
||||
| `src/sentry_sim/` | 仿真基础设施(模型/参数/启动) | 改模型和调参时动 |
|
||||
| `field/` | 官方场地包副本(地图 + 3D 场地) | 官方更新时整包替换 |
|
||||
| `tools/` | 辅助工具脚本 | 按需加新工具 |
|
||||
| `tools/` | [工具索引](tools/README.md) | 日常命令在顶层,内部脚本与验收分别归档 |
|
||||
| `docs/` | 技术文档 | 有新发现就补 |
|
||||
| `generated/` | 运行时产物 | 可删 |
|
||||
| `build/` | xmake 产物 | 不入 git |
|
||||
@@ -124,9 +130,9 @@ ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true rviz:=fa
|
||||
|
||||
```bash
|
||||
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 # 体检(只读)
|
||||
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}}" # 手动前进
|
||||
```
|
||||
|
||||
@@ -223,14 +229,10 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
||||
| `tools/build_vehicle.py` | 整车装配体 → base/wheel 网格 + 布局 json |
|
||||
| `tools/decimate.py` | 顶点聚类减面(纯 numpy,不依赖 MeshLab) |
|
||||
| `tools/gen_sdf.sh` | URDF(xacro) → Gazebo 用的 model.sdf |
|
||||
| `tools/demo.py` | 驱动演示(前进/转向/打印雷达+里程计) |
|
||||
| `build/linux/x86_64/release/nav_client` | 发 Nav2 目标(C++ 版,源码 `src/sentry_nav/src/nav_client.cpp`;原 `tools/nav_client.py` 已删除),**发前先查地图预检**(障碍/未知/净空不足直接拦),再打位置/重试/结果与导航耗时 |
|
||||
| `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 + 真值对照 |
|
||||
| `nav_client`(xmake 产物) | 发 Nav2 目标(C++ 版,源码 `src/sentry_nav/src/nav_client.cpp`),**发前先查地图预检**(障碍/未知/净空不足直接拦),再打位置/重试/结果与导航耗时。实际路径随平台变,查法 `python3 tools/project_env.py` |
|
||||
| `tools/check_stack.py` | 只读体检:10 个 lifecycle 节点 + 节点总览 + 话题 + TF + 真值对照 |
|
||||
| `tools/check_dds.sh` | Fast DDS 体检:`/dev/shm` 残留段、残留进程。`--clean` 清残留 |
|
||||
| `tools/project_env.py` | 路径/版本探测(ROS 发行版、产物目录、场地包、地图、gz 版本),排查"路径不对"先跑它;被 `launch/` import,是依赖库 |
|
||||
|
||||
---
|
||||
|
||||
@@ -262,7 +264,7 @@ python3 tools/decimate.py src/sentry_sim/meshes/full/wheel.stl src/sentry_sim/me
|
||||
> (`failed to plan from <一个奇怪的位置>`),极容易查错方向。
|
||||
>
|
||||
> 根因与修法:`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),**垂直视场为真机规格**:
|
||||
|
||||
|
||||
+15
-3
@@ -124,11 +124,23 @@ gz 的 `/scan` 取**中间那层**射线,而中间角 = (−7 + 52) / 2 = **+2
|
||||
自检命令:
|
||||
|
||||
```bash
|
||||
python3 tools/cloud_probe.py # 点数、测距范围、高度范围、距离直方图
|
||||
python3 tools/scan_probe.py /scan # 3D 雷达中间层(+22.5°,基本失效,仅参考)
|
||||
python3 tools/scan_probe.py # 0° 单线雷达 /scan2d(给 AMCL 用)
|
||||
# 点云规模 / 有效率
|
||||
ros2 topic hz /scan/points
|
||||
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. 怎么看
|
||||
|
||||
+23
-3
@@ -1,5 +1,7 @@
|
||||
# 定位接入(AMCL)
|
||||
|
||||
> 本文适用于显式选择 `LOCALIZATION=amcl` 的旧定位分支。当前默认 LIO,使用说明见 [field_localization](../src/field_localization/README.md)。不要同时启动两个 map→odom 发布者。
|
||||
|
||||
> **状态**:🟢 **已修复(2026-11-19)** —— `scan2d` 改为由 `self_filter` 从 3D 点云投影生成
|
||||
> (取 `z ∈ [0.05, 0.50] m` 车体碰撞带、360 方位取最小距离),消除了「雷达看不见 0.42 m
|
||||
> 悬空平板、地图却有」的高度失配跑飞。原问题复盘见 §4.1 的更正与
|
||||
@@ -266,7 +268,25 @@ ros2 action list | grep -E "^/wait$"
|
||||
|
||||
```bash
|
||||
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 的话,代价地图会把它绕开,就制造不出「轮子转了但车没动」的漂移场景
|
||||
- 而那个场景(打滑)正是 AMCL 唯一能体现价值的地方
|
||||
|
||||
要验证 Nav2 自己的避障,得用 `build/linux/x86_64/release/nav_client x y` 发导航目标。
|
||||
要验证 Nav2 自己的避障,得用 `build/bin/nav_client x y` 发导航目标。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+14
-6
@@ -34,7 +34,7 @@ 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 |
|
||||
| 点云里全是近距离点 | 传感器被车身碰撞盒包住 | 检查碰撞体是否把雷达罩进去(已拆成 `chassis_collision` + `gimbal_collision`) |
|
||||
| 代价地图把车自己标成障碍 | 没跑自滤,或包围盒太小 | 确认 `self_filter` 在跑:`ros2 topic hz /scan/points_filtered` |
|
||||
@@ -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 步专门起它 |
|
||||
| 目标成功但位置偏差大 | 控制器有到达容差,正常 0.1~0.3 m | 调 `goal_checker` 的 `xy_goal_tolerance` |
|
||||
| 打滑 / 被撞后位置永远不对 | **定位是「作弊」的**:静态 `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` 已内置预检会先拦一道 |
|
||||
| 导航目标 `ABORTED`,日志是 `failed to plan from (<一个奇怪的位置>)` | **定位瞬移**:AMCL 跑飞后,起点落到障碍格里。报错落在规划器上,真凶在 AMCL | `python3 tools/tf_watch.py --time 60` 一个窗口盯着,另一个窗口发目标;再用 `gz model -m sentry --pose` 对真值 |
|
||||
| `failed to create plan with tolerance of: 0.500000` | 这条报错**不区分**「目标点在障碍里 / 起点在障碍里 / 中间真没路」,只能靠人排查 | `nav_client` 已内置预检会先拦一道;再不行就在 RViz 里看 `/global_costmap/costmap` |
|
||||
| 导航目标 `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 |
|
||||
| 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 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` |
|
||||
| `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]`**(浮点) |
|
||||
|
||||
## F. 编辑器
|
||||
@@ -98,11 +98,19 @@ TF 链(`map→odom` / `odom→base_link` / `map→base_link`),结尾直接
|
||||
|
||||
## G. 还不行:先把日志拿到手
|
||||
|
||||
**`sentry_up.sh` 现在默认就把日志落盘到 `generated/up.log`**,不用再手动 `| tee`。
|
||||
每次启动会在日志里加一条分隔线(`===== sentry_up 启动 … =====`),历次会话分得清。
|
||||
|
||||
```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` |
|
||||
| 不起 RViz(省内存) | `RVIZ=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 …`(两个都要改) |
|
||||
| **用 `ros2 launch` 起**(等价入口) | `ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true rviz:=false` |
|
||||
|
||||
**单独跑某个节点**(本工程没有 ament 注册,**没有 `ros2 run`**):
|
||||
|
||||
```bash
|
||||
build/linux/x86_64/release/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/linux/x86_64/release/odom_tf --ros-args -p use_sim_time:=true
|
||||
build/bin/self_filter --ros-args -p use_sim_time:=true
|
||||
build/bin/patrol --ros-args -p use_sim_time:=true -p loop:=false
|
||||
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 原生工具代替):
|
||||
|
||||
| 脚本 | 做什么 |
|
||||
|---|---|
|
||||
| `python3 tools/demo.py` | 前进 → 转向 → 再前进,同时打印雷达和里程计真实数据 |
|
||||
| `python3 tools/drive_demo.py 1.0` | 走 1 m 边长正方形,输出轨迹数据和 SVG(`generated/drive_trajectory.svg`) |
|
||||
```bash
|
||||
# 直线前进 0.5 m/s
|
||||
ros2 topic pub -r 10 /cmd_vel geometry_msgs/msg/Twist \
|
||||
"{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. 发导航目标
|
||||
|
||||
```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)都直接拦下:
|
||||
|
||||
```
|
||||
目标 (3.00, 4.00) -> 栅格 (136, 176) 占据值 100 (障碍) 净空 0.00 m
|
||||
目标 (-2.50, 1.00) -> 栅格 (156, 216) 占据值 100 (障碍) 净空 0.00 m
|
||||
❌ 这个点不适合当目标(净空需 >= 0.50 m):
|
||||
点落在障碍格里 —— 规划器必然报 "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)
|
||||
目标 (3.11, 1.61) -> 栅格 (140, 80) 占据值 0 (空闲) 净空 1.38 m
|
||||
地图 512x352 @ 0.025 m/px origin=(-6.40, -4.40)
|
||||
目标 ( 0.11, 1.61) -> 栅格 (260, 240) 占据值 0 (空闲) 净空 1.60 m
|
||||
等待 navigate_to_pose 动作服务器...
|
||||
✅ 动作服务器可用
|
||||
✅ 目标已接受,等待结果...
|
||||
位置 ( 0.90, 4.00) 重试 0 ← 当前位姿 + 恢复行为重试次数
|
||||
位置 ( 1.21, 3.76) 重试 0
|
||||
位置 (-5.00, 3.00) 重试 0 ← 当前位姿 + 恢复行为重试次数
|
||||
位置 (-4.62, 2.71) 重试 0
|
||||
结果: ✅ 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)。
|
||||
`map→field` 现在是恒等变换(两者都以场地中心为原点),所以两个坐标数值相同。
|
||||
|
||||
> ⚠️ **别指望「剩余距离」这类进度数字**。早期版本打印 `feedback.distance_remaining`,
|
||||
> 而 Nav2 1.5 根本不填这个字段,永远是 `0.00`,看起来像「车原地不动」。
|
||||
> 现在改用**当前位姿 + 重试次数**跟踪进度。
|
||||
|
||||
不知道有哪些点可去?先跑(**不需要起 ROS**):
|
||||
|
||||
```bash
|
||||
python3 tools/free_goals.py
|
||||
```
|
||||
|
||||
会打印「从起点连通的安全区」面积、可去目标点(含净空和距离)、以及一张安全通行走廊图。
|
||||
不知道有哪些点可去?**在 RViz 里看 `/global_costmap/costmap`** —— 膨胀层会把不可通行的走廊标成高代价值,
|
||||
一眼就能看出哪片是空地。
|
||||
|
||||
- **RViz**:工具栏的 **Nav2 Goal** 点一下选目标
|
||||
- ❌ **不要用** `tools/send_goal.py` —— 它往 `/goal_pose` 话题发 PoseStamped,
|
||||
而 Nav2 **没有任何节点订阅这个话题**(`bt_navigator` 二进制里连这个字符串都没有),发了等于空炮
|
||||
- ⚠️ 只有 `nav_client` 和 RViz 的 **Nav2 Goal** 这两条路能发目标。
|
||||
往 `/goal_pose` **话题**发是没有用的 —— Nav2 没有任何节点订阅它
|
||||
(`bt_navigator` 二进制里连这个字符串都没有),发了等于空炮
|
||||
|
||||
**目标莫名 `ABORTED`、或最后一行 TF 突然跳好几米**(定位跑飞,不是避障问题):
|
||||
另开一个窗口盯着,再发目标:
|
||||
把三个位姿摆在一起看,差异一眼就出来:
|
||||
|
||||
```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 真值,
|
||||
任一单帧跳变超过 0.25 m 就标 ⚠️,还会统计 `/scan2d` 的有效返回率。
|
||||
|
||||
@@ -162,7 +176,7 @@ python3 tools/tf_watch.py --time 60
|
||||
## 4. 航点巡逻(跑自己编的节点)
|
||||
|
||||
```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]"
|
||||
```
|
||||
|
||||
@@ -192,8 +206,8 @@ ros2 topic hz /scan # 2D 雷达
|
||||
ros2 topic hz /scan/points # MID-360 点云(约 10 Hz)
|
||||
ros2 topic hz /scan/points_filtered # 自滤后
|
||||
ros2 run tf2_ros tf2_echo map base_link # 定位位姿
|
||||
python3 tools/scan_probe.py # 雷达质量(默认 /scan2d;可传话题名)
|
||||
python3 tools/probe_all.py # 一次性检查多个话题有没有数据
|
||||
ros2 topic echo /scan2d --once | grep -E 'count|range_' # 雷达束数与量程
|
||||
python3 tools/check_stack.py # 一次性检查节点/话题/TF/真值
|
||||
```
|
||||
|
||||
**RViz 里已配好的显示项**(`src/sentry_sim/config/sentry.rviz`):
|
||||
@@ -213,6 +227,13 @@ python3 tools/probe_all.py # 一次性检查多个话题有没有
|
||||
|
||||
## 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`) |
|
||||
@@ -220,11 +241,33 @@ python3 tools/probe_all.py # 一次性检查多个话题有没有
|
||||
| `RVIZ` | `1` | `0` = 不起 RViz |
|
||||
| `ROS_DOMAIN_ID` | `0` | 两个终端必须一致才能互相看到话题 |
|
||||
| `GZ_PARTITION` | `sentry` | Gazebo 分区,多套仿真隔离用 |
|
||||
| `SENTRY_FIELD_ROOT` | 仓库内 `field/RMUL2027_map_transfer_20261016_STEP_R1` | 场地模型/地图目录(找不到才退回 `~/Gazebo_projects/` 下的旧路径) |
|
||||
| `SENTRY_MAP_YAML` | 上面路径下的 `maps/rmul_2027/rmul_2027.yaml` | 想换地图时直接指这个 |
|
||||
| `NAV_BIN_DIR` | `<仓库根>/build/linux/x86_64/release` | xmake 产物目录,想用别处的二进制时覆盖 |
|
||||
| `BRIDGE_WAIT_TIMEOUT` | `120` | 等待 Gazebo 发布 `/clock` 的秒数。单次查询至多 2 秒,等不到时启动失败 |
|
||||
| `SENTRY_DRY_RUN` | `0` | `1` = 只打印探测结果然后退出,不启动任何进程 |
|
||||
| `SENTRY_LOG` | `1` | 启动日志自动写 `generated/up.log`(每次加分隔线)。`0` = 关闭,`<路径>` = 换位置 |
|
||||
| `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. 场地坐标速查
|
||||
@@ -258,22 +301,16 @@ ros2 run tf2_ros tf2_echo map field
|
||||
# 现在 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
|
||||
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` 这条变换是对的。
|
||||
黄框应该正好套在 RViz 地图里场地围挡的内沿上。
|
||||
|
||||
@@ -299,7 +336,7 @@ ros2 run ros_gz_sim create -world rmul_arena -name center_check \
|
||||
**用 field 系发目标**:
|
||||
|
||||
```bash
|
||||
build/linux/x86_64/release/patrol --ros-args \
|
||||
build/bin/patrol --ros-args \
|
||||
-p frame_id:=field -p loop:=false \
|
||||
-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_sim odom_tf.py` | `build/linux/x86_64/release/odom_tf` |
|
||||
| `ros2 run sentry_nav self_filter` | 直接跑 `build/bin/self_filter` |
|
||||
| `ros2 run sentry_sim odom_tf.py` | `build/bin/odom_tf` |
|
||||
| `ros2 pkg prefix sentry_sim` | `SENTRY_SIM_SHARE` 环境变量(默认 `<仓库>/src/sentry_sim`) |
|
||||
| `xacro` 的 `$(find sentry_sim)` | 改成 `$(env SENTRY_SIM_SHARE)`;不设变量会明确报错 |
|
||||
| `ros2 launch sentry_sim …`(备用入口) | 只保留 `scripts/sentry_up.sh`(本来就是主入口) |
|
||||
@@ -187,7 +187,24 @@ src/sentry_nav/
|
||||
| `cannot find -lxxx` | 那个包是 header-only | 用 `os.isfile()` 过滤,别直接 `add_links` |
|
||||
| `xmake test` 报 `invalid task: run_tests` | 老写法 | 用 **`xmake test`** |
|
||||
| `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 |
|
||||
|
||||
### 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。
|
||||
+17
-3
@@ -131,7 +131,7 @@ velocity_smoother collision_monitor docking_server following_server
|
||||
排查 Nav2 起不来时,我在隔离沙箱里看到过**三种不同**的失败
|
||||
(keepout 的 `/get_state` 等不到、`is_path_valid` 60 秒拿不到、controller bond 4 秒超时)——
|
||||
每次失败点都不一样,而同一张图里另开探针却能看到**全部 227 个服务**。
|
||||
最后在真机跑 `check_stack.py`,**七个节点全 ACTIVE**。
|
||||
最后在真机跑 `check_stack.py`,**全部节点 ACTIVE**(当时探针还只查 7 个,现在是 10 个)。
|
||||
|
||||
**教训**:容器/沙箱/CI 里的网络与共享内存行为可能和真机完全不同。
|
||||
这种环境里的结论,要么标明「在 X 环境下观察到」,要么先在真机验一遍。
|
||||
@@ -194,6 +194,13 @@ gazebo 只报 `Unable to find uri[model://xxx]`,不会告诉你路径写错了
|
||||
|
||||
> 这一节全是 2026-11-19 一天内踩出来的。**起因**:导航目标 `ABORTED`,
|
||||
> 而报错信息一直指向规划器,真正崩掉的却是 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. 「地图画错了」——先怀疑自己的对拍程序
|
||||
|
||||
@@ -298,6 +305,13 @@ scan2d 光平面 z = 0.4052 m → 从 0.42 m 平板底下钻过去,零回
|
||||
> 顺带一个对照数据:现有 `scan2d` 和「在 0.4052 m 切的图」是 **100% 吻合(273/273)**,
|
||||
> 和官方图只有 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
|
||||
|
||||
写导航客户端时打印了这个字段,刷了 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),不合格直接拦下并说明原因。
|
||||
找安全点用 `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/` 下):
|
||||
|
||||
```
|
||||
build/linux/x86_64/release/
|
||||
build/bin/
|
||||
├── self_filter 点云自滤节点
|
||||
├── patrol 航点巡逻节点
|
||||
├── libsentry_nav_core.a 纯算法静态库
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
# 场地 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°。初始化种子帧是唯一例外。配准失败不写图。
|
||||
|
||||
### 单独生成全场 Gazebo 地图
|
||||
|
||||
```bash
|
||||
python3 tools/capture_lio.py --profile mapping --full-field \
|
||||
--output generated/full_survey --map generated/field_full.flmap
|
||||
python3 tools/validation/validate_lio_navigation.py --full-field --launcher shell \
|
||||
--map generated/field_full.flmap --lio-cloud-topic /scan/points_lio --output generated/full_shell
|
||||
```
|
||||
|
||||
该模式在隔离的 Gazebo 空场沿重叠测站采集实际雷达扫描。测站坐标由命令指定,Gazebo 真值只核对到位误差。全场图包含南走廊的地面回波,为 LIO 提供垂直方向约束。避障用的 `/scan/points_filtered` 和 `/scan2d` 继续沿用原有的地面滤除规则。全场图对应当前仿真模型和雷达外参,改场地或更换外参后应重新采集和验收。
|
||||
|
||||
## 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`;适配器使用固定 TF 统一到 LiDAR 系。方位角时间估计也在 LiDAR 系完成,不重复施加安装外参。
|
||||
- 默认固定帧:`map/odom/base_link/imu_link/lidar_link`,均可通过同名 frame 参数配置。外参从现有固定 TF 读取;缺失时等待,禁止假设为恒等变换。
|
||||
- 内部状态原点为 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 系车体位姿及变换后的位姿协方差;twist 未填充,不能用于速度反馈(速度状态可通过 core 快照读取)。不额外广播 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` 保存版本、已知初始位姿、固定外参及扫描时间模型;`imu.csv` 保存 IMU 系原始测量;`scans.csv` 索引 `clouds/*.flpc`;`truth.tum` 保存世界系真值。FLPC v1 使用固定小端标量:8 字节 magic、uint32 版本、double header 时间、uint32 点数;每点为 double 绝对时间及四个 float32。地图 FLMAP v1 为 8 字节 magic、uint32 版本、double 体素边长、uint64 点数,随后为 map 系 xyz double。均不序列化 Eigen 内存。
|
||||
|
||||
回放工具不依赖 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,24 @@
|
||||
#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);
|
||||
void write_dataset_config(const CoreOptions &options,const std::filesystem::path &path);
|
||||
CoreOptions read_dataset_config(const std::filesystem::path &path);
|
||||
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,52 @@
|
||||
#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};
|
||||
};
|
||||
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
|
||||
|
||||
#include "field_localization/core/types.hpp"
|
||||
#include "field_localization/core/map_io.hpp"
|
||||
#include <optional>
|
||||
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
|
||||
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 {
|
||||
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_point_cloud{false};
|
||||
|
||||
@@ -23,9 +43,29 @@ struct LocalizationStatus {
|
||||
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;
|
||||
};
|
||||
struct LocalizationSnapshot {
|
||||
Pose3D pose;
|
||||
FilterSnapshot filter;
|
||||
LocalizationStatus status;
|
||||
};
|
||||
class LocalizationCore {
|
||||
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 数据
|
||||
bool process_imu(const ImuData &imu);
|
||||
@@ -48,6 +88,14 @@ public:
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
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_{};
|
||||
LocalizationStatus status_{};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "field_localization/core/registration.hpp"
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
namespace field_localization::core {
|
||||
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);
|
||||
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,64 @@
|
||||
#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();
|
||||
}
|
||||
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
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "field_localization/core/dataset.hpp"
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <geometry_msgs/msg/transform.hpp>
|
||||
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);
|
||||
} // namespace field_localization::ros
|
||||
@@ -1,42 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
#include "field_localization/core/types.hpp"
|
||||
|
||||
#include "field_localization/ros/conversion.hpp"
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <sensor_msgs/msg/imu.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <std_msgs/msg/string.hpp>
|
||||
#include <std_srvs/srv/trigger.hpp>
|
||||
#include <tf2_ros/buffer.hpp>
|
||||
#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 {
|
||||
|
||||
class LocalizationNode : public rclcpp::Node {
|
||||
class LocalizationNode:public rclcpp::Node {
|
||||
public:
|
||||
explicit LocalizationNode(
|
||||
const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
|
||||
|
||||
explicit LocalizationNode(const rclcpp::NodeOptions &options=rclcpp::NodeOptions());
|
||||
~LocalizationNode() override;
|
||||
private:
|
||||
bool ensure_core();
|
||||
void on_point_cloud(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
|
||||
|
||||
void on_imu(sensor_msgs::msg::Imu::ConstSharedPtr msg);
|
||||
|
||||
void drain_scans();
|
||||
void publish_estimate();
|
||||
void print_localization_status();
|
||||
|
||||
rclcpp::TimerBase::SharedPtr status_timer_;
|
||||
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr
|
||||
point_cloud_sub_;
|
||||
|
||||
bool check_clock();
|
||||
bool navigation_valid();
|
||||
void publish_health(bool heartbeat=false);
|
||||
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_;
|
||||
|
||||
std::string point_cloud_topic_;
|
||||
std::string imu_topic_;
|
||||
core::LocalizationCore core_;
|
||||
|
||||
std::size_t point_cloud_count_{0};
|
||||
std::size_t imu_count_{0};
|
||||
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odometry_pub_;
|
||||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr status_pub_;
|
||||
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr save_service_,reset_service_;
|
||||
rclcpp::TimerBase::SharedPtr status_timer_,health_timer_;
|
||||
rclcpp::Publisher<std_msgs::msg::Bool>::SharedPtr navigation_valid_pub_;
|
||||
core::TrackingHealth health_;
|
||||
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
|
||||
@@ -0,0 +1,169 @@
|
||||
#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) {
|
||||
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="lidar_link"; 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) {
|
||||
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';
|
||||
}
|
||||
CoreOptions read_dataset_config(const std::filesystem::path &path) {
|
||||
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); 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,154 @@
|
||||
#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)};
|
||||
}
|
||||
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
|
||||
@@ -4,6 +4,33 @@
|
||||
#include <cmath>
|
||||
|
||||
namespace field_localization::core {
|
||||
LocalizationCore::LocalizationCore():LocalizationCore(CoreOptions{}) {}
|
||||
LocalizationCore::LocalizationCore(const CoreOptions &options):options_(options),map_(options.map_resolution),filter_(options.noise) {
|
||||
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);
|
||||
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) 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_};
|
||||
}
|
||||
|
||||
|
||||
bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -11,6 +38,7 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||
// 时间戳必须有效
|
||||
if (!std::isfinite(imu.timestamp_sec) || imu.timestamp_sec < 0.0) {
|
||||
++status_.rejected_imu_count;
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::INVALID_INPUT;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,15 +46,38 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||
if (!imu.angular_velocity.allFinite() ||
|
||||
!imu.linear_acceleration.allFinite()) {
|
||||
++status_.rejected_imu_count;
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::INVALID_INPUT;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 拒绝乱序或重复数据
|
||||
if (status_.has_imu && imu.timestamp_sec <= status_.last_imu_timestamp) {
|
||||
++status_.rejected_imu_count;
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (previous_imu_) {
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
auto snapshot=filter_.snapshot(); snapshot.state.timestamp_sec=imu.timestamp_sec;
|
||||
filter_.restore(snapshot);
|
||||
}
|
||||
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());
|
||||
}
|
||||
pose_=compose(filter_.snapshot().state.pose,inverse(options_.base_from_imu));
|
||||
status_.state_timestamp=imu.timestamp_sec;
|
||||
status_.has_imu = true;
|
||||
status_.last_imu_timestamp = imu.timestamp_sec;
|
||||
++status_.imu_count;
|
||||
@@ -39,6 +90,7 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
||||
|
||||
if (!std::isfinite(cloud.timestamp_sec) || cloud.timestamp_sec < 0.0) {
|
||||
++status_.rejected_point_cloud_count;
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -46,9 +98,15 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
||||
if (status_.has_point_cloud &&
|
||||
cloud.timestamp_sec <= status_.last_point_cloud_timestamp) {
|
||||
++status_.rejected_point_cloud_count;
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::TIME_ORDER;
|
||||
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(
|
||||
cloud.points.begin(), cloud.points.end(), [](const PointXYZI &point) {
|
||||
@@ -57,6 +115,7 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
||||
});
|
||||
|
||||
if (valid_point_count == 0) {
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::NO_VALID_POINTS;
|
||||
++status_.rejected_point_cloud_count;
|
||||
return false;
|
||||
}
|
||||
@@ -66,7 +125,79 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
||||
status_.last_point_count = static_cast<std::size_t>(valid_point_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;
|
||||
}
|
||||
if (map_.size()<5) {
|
||||
if (options_.map_mode==MapMode::MAPPING && corrected->points.size()>=options_.registration.minimum_inliers) {
|
||||
map_.insert(voxel_downsample(*corrected,options_.map_resolution),
|
||||
compose(at_scan.snapshot().state.pose,options_.deskew.imu_from_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();
|
||||
const auto registration=scan_to_map(*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))) {
|
||||
map_.insert(voxel_downsample(*corrected,options_.map_resolution),
|
||||
compose(registration.estimate.state.pose,options_.deskew.imu_from_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;
|
||||
pose_=compose(filter_.snapshot().state.pose,inverse(options_.base_from_imu));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,6 +216,11 @@ void LocalizationCore::set_pose(const Pose3D &pose) {
|
||||
|
||||
pose_ = pose;
|
||||
pose_.rotation.normalize();
|
||||
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 {
|
||||
@@ -95,8 +231,12 @@ LocalizationStatus LocalizationCore::get_status() const {
|
||||
void LocalizationCore::reset() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
pose_ = Pose3D{};
|
||||
status_ = LocalizationStatus{};
|
||||
pose_ = options_.initial_pose;
|
||||
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
|
||||
@@ -0,0 +1,62 @@
|
||||
#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 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) {
|
||||
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");
|
||||
map.insert(p);
|
||||
}
|
||||
if (map.size()==0) throw std::runtime_error("empty voxel map");
|
||||
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,49 @@
|
||||
#include "field_localization/ros/conversion.hpp"
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
} // namespace field_localization::ros
|
||||
@@ -1,234 +1,233 @@
|
||||
#include "field_localization/ros/localization_node.hpp"
|
||||
|
||||
#include <sensor_msgs/point_cloud2_iterator.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <numbers>
|
||||
#include <sstream>
|
||||
#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 {
|
||||
LocalizationNode::LocalizationNode(const rclcpp::NodeOptions &options)
|
||||
: Node("field_localization", options) {
|
||||
point_cloud_topic_ =
|
||||
declare_parameter<std::string>("point_cloud_topic", "/livox/lidar");
|
||||
|
||||
imu_topic_ = declare_parameter<std::string>("imu_topic", "/livox/imu");
|
||||
|
||||
// Subscribe to LiDAR point clouds.
|
||||
point_cloud_sub_ = create_subscription<sensor_msgs::msg::PointCloud2>(
|
||||
point_cloud_topic_, rclcpp::SensorDataQoS(),
|
||||
std::bind(&LocalizationNode::on_point_cloud, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
// Subscribe to IMU measurements.
|
||||
imu_sub_ = create_subscription<sensor_msgs::msg::Imu>(
|
||||
imu_topic_, rclcpp::SensorDataQoS(),
|
||||
std::bind(&LocalizationNode::on_imu, this, std::placeholders::_1));
|
||||
|
||||
RCLCPP_INFO(get_logger(), "Field localization node started.");
|
||||
|
||||
RCLCPP_INFO(get_logger(), "Point cloud topic: %s",
|
||||
point_cloud_topic_.c_str());
|
||||
|
||||
RCLCPP_INFO(get_logger(), "IMU topic: %s", imu_topic_.c_str());
|
||||
|
||||
status_timer_ = create_wall_timer(
|
||||
std::chrono::seconds(5),
|
||||
std::bind(&LocalizationNode::print_localization_status, this));
|
||||
LocalizationNode::LocalizationNode(const rclcpp::NodeOptions &options):Node("field_localization",options) {
|
||||
map_frame_=declare_parameter<std::string>("map_frame","map"); odom_frame_=declare_parameter<std::string>("odom_frame","odom");
|
||||
base_frame_=declare_parameter<std::string>("base_frame","base_link"); imu_frame_=declare_parameter<std::string>("imu_frame","imu_link");
|
||||
lidar_frame_=declare_parameter<std::string>("lidar_frame","lidar_link");
|
||||
const auto mode=declare_parameter<std::string>("mode","localization");
|
||||
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;
|
||||
map_path_=declare_parameter<std::string>("map_path",""); export_path_=declare_parameter<std::string>("export_map_path","");
|
||||
if (mode=="localization" && map_path_.empty()) throw std::invalid_argument("localization requires map_path; run explicit mapping first");
|
||||
if (mode=="localization") {
|
||||
std::string error;
|
||||
if (!core::read_map(map_path_,error)) throw std::runtime_error(error);
|
||||
}
|
||||
publish_map_to_odom_=declare_parameter<bool>("publish_map_to_odom",true);
|
||||
auto &pose=core_options_.initial_pose;
|
||||
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);
|
||||
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);
|
||||
core_options_.noise.accel=declare_parameter<double>("accel_noise_density",0.03);
|
||||
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);
|
||||
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);
|
||||
core_options_.registration.map_translation_sigma=declare_parameter<double>("map_translation_sigma",core_options_.registration.map_translation_sigma);
|
||||
core_options_.registration.map_rotation_sigma=declare_parameter<double>("map_rotation_sigma",0.002);
|
||||
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_);
|
||||
}
|
||||
|
||||
void LocalizationNode::on_point_cloud(
|
||||
sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) {
|
||||
core::PointCloud cloud;
|
||||
|
||||
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;
|
||||
LocalizationNode::~LocalizationNode() {
|
||||
if (core_ && core_options_.map_mode==core::MapMode::MAPPING && !export_path_.empty()) {
|
||||
std::string error;
|
||||
if (!core_->export_map(export_path_,error)) RCLCPP_ERROR(get_logger(),"map export failed: %s",error.c_str());
|
||||
}
|
||||
|
||||
// 检查 intensity 字段
|
||||
if (field_intensity != nullptr &&
|
||||
!is_float32_field(field_intensity, msg->point_step)) {
|
||||
RCLCPP_WARN(get_logger(),
|
||||
"Unsupported intensity datatype. Intensity will be ignored.");
|
||||
field_intensity = nullptr;
|
||||
}
|
||||
bool LocalizationNode::check_clock() {
|
||||
const double time=now().seconds();
|
||||
if (last_clock_>=0 && time<last_clock_-1e-6) {
|
||||
clock_rewound_=true; scans_.clear(); pending_tf_.clear();
|
||||
RCLCPP_ERROR(get_logger(),"simulation time rewound; output halted, explicit ~/reset or restart required");
|
||||
}
|
||||
|
||||
// 检查点云内存布局
|
||||
const std::size_t minimum_row_size =
|
||||
static_cast<std::size_t>(msg->width) * msg->point_step;
|
||||
|
||||
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);
|
||||
|
||||
last_clock_=time; return !clock_rewound_;
|
||||
}
|
||||
bool LocalizationNode::ensure_core() {
|
||||
if (core_) return true;
|
||||
try {
|
||||
sensor_msgs::PointCloud2ConstIterator<float> iter_x(*msg, "x");
|
||||
sensor_msgs::PointCloud2ConstIterator<float> iter_y(*msg, "y");
|
||||
sensor_msgs::PointCloud2ConstIterator<float> iter_z(*msg, "z");
|
||||
|
||||
if (has_intensity) {
|
||||
sensor_msgs::PointCloud2ConstIterator<float> iter_intensity(*msg,
|
||||
"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 {
|
||||
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z) {
|
||||
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));
|
||||
}
|
||||
core_options_.base_from_imu=from_transform(tf_buffer_->lookupTransform(base_frame_,imu_frame_,tf2::TimePointZero).transform);
|
||||
core_options_.deskew.imu_from_sensor=from_transform(tf_buffer_->lookupTransform(imu_frame_,lidar_frame_,tf2::TimePointZero).transform);
|
||||
core_=std::make_unique<core::LocalizationCore>(core_options_);
|
||||
if (core_options_.map_mode==core::MapMode::LOCALIZATION) {
|
||||
std::string error; if (!core_->load_map(map_path_,error)) { core_.reset(); throw std::runtime_error(error); }
|
||||
}
|
||||
} catch (const std::runtime_error &error) {
|
||||
RCLCPP_ERROR(get_logger(), "Failed to convert PointCloud2: %s",
|
||||
error.what());
|
||||
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 {
|
||||
auto cloud=convert_cloud(*msg);
|
||||
if (cloud.frame_id!=lidar_frame_ && cloud.frame_id!=base_frame_ && cloud.frame_id!=imu_frame_)
|
||||
throw std::runtime_error("unexpected cloud frame; configure lidar_frame explicitly");
|
||||
const auto extrinsic=from_transform(tf_buffer_->lookupTransform(lidar_frame_,cloud.frame_id,tf2::TimePointZero).transform);
|
||||
for (auto &p:cloud.points) p.position=(extrinsic.rotation*p.position.cast<double>()+extrinsic.translation).cast<float>();
|
||||
cloud.frame_id=lidar_frame_;
|
||||
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) {
|
||||
core::ImuData imu;
|
||||
|
||||
imu.timestamp_sec = rclcpp::Time(msg->header.stamp).seconds();
|
||||
|
||||
imu.frame_id = msg->header.frame_id;
|
||||
|
||||
imu.angular_velocity =
|
||||
Eigen::Vector3d{msg->angular_velocity.x, msg->angular_velocity.y,
|
||||
msg->angular_velocity.z};
|
||||
|
||||
imu.linear_acceleration =
|
||||
Eigen::Vector3d{msg->linear_acceleration.x, msg->linear_acceleration.y,
|
||||
msg->linear_acceleration.z};
|
||||
|
||||
++imu_count_;
|
||||
|
||||
if (!core_.process_imu(imu)) {
|
||||
RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 5000,
|
||||
"Rejected IMU message");
|
||||
return;
|
||||
if (!check_clock() || !ensure_core()) return;
|
||||
try {
|
||||
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");
|
||||
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.linear_acceleration=extrinsic.rotation*Eigen::Vector3d{msg->linear_acceleration.x,msg->linear_acceleration.y,msg->linear_acceleration.z};
|
||||
if (!core_->process_imu(imu)) RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"IMU rejected: %s",core::reason_name(core_->get_status().reason));
|
||||
drain_scans(); publish_estimate();
|
||||
} catch (const std::exception &e) { RCLCPP_WARN_THROTTLE(get_logger(),*get_clock(),5000,"IMU conversion rejected: %s",e.what()); }
|
||||
}
|
||||
void LocalizationNode::drain_scans() {
|
||||
while (!scans_.empty()) {
|
||||
const auto s=core_->get_status(); const double end=core::scan_window(scans_.front(),core_options_.deskew).second;
|
||||
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; }
|
||||
break;
|
||||
}
|
||||
core_->process_point_cloud(scans_.front());
|
||||
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);
|
||||
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() {
|
||||
const auto status = core_.get_status();
|
||||
|
||||
RCLCPP_INFO(get_logger(), "========== Localization Status ==========");
|
||||
|
||||
RCLCPP_INFO(
|
||||
get_logger(), "IMU: received=%zu, rejected=%zu, last_timestamp=%.6f",
|
||||
status.imu_count, status.rejected_imu_count, status.last_imu_timestamp);
|
||||
|
||||
RCLCPP_INFO(get_logger(),
|
||||
"PointCloud: received=%zu, rejected=%zu, last_timestamp=%.6f",
|
||||
status.point_cloud_count, status.rejected_point_cloud_count,
|
||||
status.last_point_cloud_timestamp);
|
||||
|
||||
RCLCPP_INFO(get_logger(), "Latest valid point count: %zu",
|
||||
status.last_point_count);
|
||||
|
||||
RCLCPP_INFO(get_logger(), "==========================================");
|
||||
if (!core_) { RCLCPP_INFO(get_logger(),"localization waiting for fixed sensor TF"); return; }
|
||||
const auto s=core_->get_status(); std::ostringstream directions;
|
||||
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",
|
||||
core::mode_name(s.mode),core::reason_name(s.reason),clock_rewound_ ? " CLOCK_REWOUND" : "",s.imu_count,s.rejected_imu_count,
|
||||
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,
|
||||
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(),"navigation_valid=%d correction_age=%.3fs NIS=%.3f rank=%d",navigation_valid(),
|
||||
s.last_correction_timestamp<0 ? -1 : now().seconds()-s.last_correction_timestamp,s.registration.nis,s.registration.measurement_rank);
|
||||
RCLCPP_INFO(get_logger(),"null directions [map dx dy dz, IMU droll dpitch dyaw]: %s",directions.str().c_str());
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace field_localization::ros
|
||||
@@ -8,7 +8,8 @@ int main(int argc, char **argv) {
|
||||
rclcpp::init(argc, argv);
|
||||
|
||||
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);
|
||||
} catch (const std::exception &error) {
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#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)});
|
||||
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;
|
||||
auto cloud=ros::convert_cloud(*msg);
|
||||
if (cloud.timestamp_sec<start_ || cloud.timestamp_sec<=last_scan_ || cloud.timestamp_sec>start_+duration_) return;
|
||||
const auto tf=ros::from_transform(buffer_->lookupTransform("lidar_link",cloud.frame_id,tf2::TimePointZero).transform);
|
||||
for (auto &p:cloud.points) p.position=(tf.rotation*p.position.cast<double>()+tf.translation).cast<float>();
|
||||
cloud.frame_id="lidar_link";
|
||||
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);
|
||||
config_.deskew.imu_from_sensor=ros::from_transform(buffer_->lookupTransform("imu_link","lidar_link",tf2::TimePointZero).transform);
|
||||
} catch (const tf2::TransformException &) { return; }
|
||||
core::write_dataset_config(config_,directory_/"config.txt"); 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,130 @@
|
||||
#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");
|
||||
auto options=read_dataset_config(dataset/"config.txt");
|
||||
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);
|
||||
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); 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 truth_support=inspect_scan_support(*corrected,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; }
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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 @@
|
||||
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 @@
|
||||
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.
@@ -0,0 +1,8 @@
|
||||
Gazebo isolated Python launch, cylinder at (-4,-1.5), radius .22 m, height .8 m.
|
||||
Input acceleration/gyro are sensor-noise-free; finite-rate dynamics are not zero.
|
||||
Checkpoint is the prior accepted estimate at sim 21.5 s from the pre-final-model run.
|
||||
Five real scans 21.6--22.0 s and corresponding IMU samples reproduce the innovation
|
||||
rejection cascade (NIS 31.6 then 35.1...) with an overconfident map model.
|
||||
This is a recorded regression for a discovered failure during repair, not a claim
|
||||
that the user's unrecorded original divergence has been reproduced exactly.
|
||||
Ground truth is evaluation-only and never supplied to the filter.
|
||||
@@ -0,0 +1,6 @@
|
||||
timestamp,file
|
||||
21.600000000000001,152.flpc
|
||||
21.699999999999999,153.flpc
|
||||
21.800000000000001,154.flpc
|
||||
21.899999999999999,155.flpc
|
||||
22,156.flpc
|
||||
|
@@ -0,0 +1,5 @@
|
||||
21.6 -4.938314134624523 2.796687470553623 0.0030149441445529064 -0.0007754419507424783 -0.00012456097725818525 -0.6408927062560147 0.7676300686152059
|
||||
21.7 -4.925609698330944 2.7637372767944877 0.0030671789615293672 -0.0015214828458520557 -0.000254778602981217 -0.6729537584402829 0.7396829450372034
|
||||
21.8 -4.923934087982928 2.7224593206086922 0.002981906031251714 -0.000194014824747835 -7.274393365116528e-05 -0.6945213952429082 0.719472020732156
|
||||
21.9 -4.923427531970908 2.7076583973333985 0.002987579905231361 9.171974543353667e-06 -1.9365968979289335e-05 -0.6979490977997831 0.7161473706027992
|
||||
22.0 -4.923427531952121 2.7076583973504693 0.0029924332530261426 5.532422580515229e-06 -1.1786157218031994e-05 -0.6979490980902097 0.7161473705219769
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "field_localization/core/dataset.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
using namespace field_localization::core;
|
||||
int main() {
|
||||
const auto dir=std::filesystem::temp_directory_path()/"field_lio_dataset_tests";
|
||||
std::filesystem::create_directories(dir);
|
||||
PointCloud cloud; cloud.timestamp_sec=1;
|
||||
PointXYZI p; p.timestamp_sec=0.99; p.position={0.01F,-2,3}; p.intensity=4; cloud.points.push_back(p);
|
||||
p.position.x()=std::numeric_limits<float>::infinity(); cloud.points.push_back(p);
|
||||
write_cloud(cloud,dir/"scan.flpc"); const auto read=read_cloud(dir/"scan.flpc");
|
||||
CHECK(read.points.size()==2); CHECK_NEAR(read.timestamp_sec,1,1e-12);
|
||||
CHECK_NEAR(read.points[0].timestamp_sec,0.99,1e-12); CHECK(read.points[0].position==cloud.points[0].position);
|
||||
CHECK(!read.points[1].position.allFinite());
|
||||
CoreOptions options; options.initial_pose.translation={-5,3,0}; options.deskew.imu_from_sensor.translation={-0.0935,-0.1512,0.2552};
|
||||
write_dataset_config(options,dir/"config.txt"); const auto config=read_dataset_config(dir/"config.txt");
|
||||
CHECK(config.initial_pose.translation==options.initial_pose.translation);
|
||||
CHECK(config.deskew.imu_from_sensor.translation==options.deskew.imu_from_sensor.translation);
|
||||
std::vector<TrajectorySample> truth,estimate;
|
||||
for (int i=0;i<=200;++i) {
|
||||
const double t=0.01*i; Pose3D pose{exp_so3({0.01*t,-0.03*t,0.1*t}),Eigen::Vector3d{t,0.2*t,0.1*t*t}};
|
||||
truth.push_back({t,pose}); pose.translation.x()+=0.1; estimate.push_back({t,pose});
|
||||
}
|
||||
const auto metric=evaluate(estimate,truth);
|
||||
CHECK(metric.matched==estimate.size()); CHECK(metric.relative_pairs>0);
|
||||
CHECK_NEAR(metric.ate_translation,0.1,1e-12); CHECK_NEAR(metric.ate_rotation_rad,0,1e-12);
|
||||
CHECK(metric.rpe_translation<1e-12); CHECK(metric.rpe_rotation_rad<1e-12);
|
||||
const std::vector<TrajectorySample> sparse{{0,{}},{1,{}}}; CHECK(!trajectory_pose(sparse,0.5));
|
||||
{ std::ofstream out(dir/"broken"); out<<"FLPC0001"; }
|
||||
bool rejected=false; try { (void)read_cloud(dir/"broken"); } catch (const std::exception &) { rejected=true; }
|
||||
CHECK(rejected); std::filesystem::remove_all(dir);
|
||||
return sentry_nav_test::Summary("DatasetAndMetrics");
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "field_localization/core/eskf.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <Eigen/Eigenvalues>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
using namespace field_localization::core;
|
||||
namespace {
|
||||
Pose3D truth(double t) {
|
||||
return {exp_so3({0.5*std::sin(0.7*t),0,0})*exp_so3({0,0.4*std::sin(0.9*t),0})*
|
||||
exp_so3({0,0,0.8*std::sin(0.5*t)}),
|
||||
Eigen::Vector3d{std::sin(0.6*t),0.8*std::sin(0.8*t),0.5*std::sin(1.1*t)}};
|
||||
}
|
||||
ImuData measurement(double t,const Eigen::Vector3d &bg,const Eigen::Vector3d &ba) {
|
||||
const double h=1e-4;
|
||||
ImuData s; s.timestamp_sec=t;
|
||||
const auto p=truth(t);
|
||||
s.angular_velocity=log_so3(truth(t-h/2).rotation.conjugate()*truth(t+h/2).rotation)/h+bg;
|
||||
const Eigen::Vector3d acc{-0.36*std::sin(0.6*t),-0.512*std::sin(0.8*t),-0.605*std::sin(1.1*t)};
|
||||
s.linear_acceleration=p.rotation.conjugate()*(acc+Eigen::Vector3d{0,0,9.81})+ba;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
int main(int argc,char **argv) {
|
||||
std::ofstream curve(argc>1 ? argv[1] : "/tmp/field_lio_bias_filter.csv");
|
||||
curve << "seed,time,bgx,bgy,bgz,bax,bay,baz,gyro_error,accel_error\n";
|
||||
const Eigen::Vector3d bg{0.02,-0.015,0.01}, ba{0.15,-0.10,0.08};
|
||||
for (unsigned seed=1;seed<=5;++seed) {
|
||||
std::mt19937 random(seed); std::normal_distribution<double> normal;
|
||||
ErrorStateFilter filter;
|
||||
MotionState initial; initial.pose=truth(0); initial.velocity={0.6,0.64,0.55};
|
||||
filter.initialize(initial);
|
||||
auto sample=[&](double t) {
|
||||
auto s=measurement(t,bg,ba);
|
||||
for (int j=0;j<3;++j) { s.angular_velocity[j]+=0.003*normal(random); s.linear_acceleration[j]+=0.03*normal(random); }
|
||||
return s;
|
||||
};
|
||||
ImuData previous=sample(0);
|
||||
Eigen::Vector3d gyro_sq=Eigen::Vector3d::Zero(),accel_sq=Eigen::Vector3d::Zero();
|
||||
for (int i=1;i<=6000;++i) {
|
||||
ImuData next=sample(0.01*i);
|
||||
CHECK(filter.propagate(previous,next)); previous=next;
|
||||
if (i%10) continue;
|
||||
auto pose=truth(next.timestamp_sec);
|
||||
Eigen::Vector3d angle_noise;
|
||||
for (int j=0;j<3;++j) { pose.translation[j]+=0.005*normal(random); angle_noise[j]=0.001*normal(random); }
|
||||
pose.rotation*=exp_so3(angle_noise);
|
||||
Matrix6 r=Matrix6::Identity(); r.topLeftCorner<3,3>()*=0.005*0.005; r.bottomRightCorner<3,3>()*=1e-6;
|
||||
CHECK(filter.correct_pose(pose,r));
|
||||
const auto &state=filter.snapshot().state;
|
||||
const Eigen::Vector3d ge=state.gyro_bias-bg,ae=state.accel_bias-ba;
|
||||
curve<<seed<<','<<next.timestamp_sec<<','<<state.gyro_bias.x()<<','<<state.gyro_bias.y()<<','<<state.gyro_bias.z()
|
||||
<<','<<state.accel_bias.x()<<','<<state.accel_bias.y()<<','<<state.accel_bias.z()<<','<<ge.norm()<<','<<ae.norm()<<'\n';
|
||||
if (i>5000) { gyro_sq+=ge.cwiseAbs2(); accel_sq+=ae.cwiseAbs2(); }
|
||||
}
|
||||
const Eigen::Vector3d gyro_rmse=(gyro_sq/100).cwiseSqrt(),accel_rmse=(accel_sq/100).cwiseSqrt();
|
||||
std::printf("seed %u final100 bias RMSE gyro=(%.6g %.6g %.6g) rad/s accel=(%.6g %.6g %.6g) m/s2\n",
|
||||
seed,gyro_rmse.x(),gyro_rmse.y(),gyro_rmse.z(),accel_rmse.x(),accel_rmse.y(),accel_rmse.z());
|
||||
CHECK(gyro_rmse.maxCoeff()<0.003); CHECK(accel_rmse.maxCoeff()<0.03);
|
||||
const Eigen::SelfAdjointEigenSolver<Matrix18> eig(filter.snapshot().covariance);
|
||||
CHECK(eig.info()==Eigen::Success); CHECK(eig.eigenvalues().minCoeff()>-1e-10);
|
||||
auto bad=previous; bad.timestamp_sec+=1;
|
||||
CHECK(!filter.propagate(previous,bad));
|
||||
}
|
||||
ErrorStateFilter planar;
|
||||
const auto before=planar.snapshot();
|
||||
Matrix6 projector=Matrix6::Zero(); projector(2,2)=1; projector(3,3)=1; projector(4,4)=1;
|
||||
Pose3D observation; observation.translation={10,20,0.1}; observation.rotation=exp_so3({0,0,0.5});
|
||||
CHECK(planar.correct_pose(observation,0.001*Matrix6::Identity(),projector));
|
||||
CHECK_NEAR(planar.snapshot().state.pose.translation.x(),before.state.pose.translation.x(),1e-12);
|
||||
CHECK_NEAR(planar.snapshot().state.pose.translation.y(),before.state.pose.translation.y(),1e-12);
|
||||
CHECK_NEAR(planar.snapshot().covariance(0,0),before.covariance(0,0),1e-12);
|
||||
return sentry_nav_test::Summary("ESKF");
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "field_localization/core/tracking_health.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <random>
|
||||
#include <cstdio>
|
||||
using namespace field_localization::core;
|
||||
namespace {
|
||||
Pose3D truth(double t) {
|
||||
return {exp_so3({0,0,0.15*std::sin(0.3*t)}),{-2+0.3*std::sin(0.4*t),-1+0.2*std::sin(0.5*t),0}};
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
std::vector<Eigen::Vector3d> map;
|
||||
for(int x=-30;x<=30;++x) for(int y=-20;y<=20;++y) map.emplace_back(0.2*x,0.2*y,0);
|
||||
for(int i=-60;i<=60;++i) for(int z=0;z<=4;++z) {
|
||||
map.emplace_back(0.1*i,-4,0.1*z);map.emplace_back(0.1*i,4,0.1*z);
|
||||
if(std::abs(i)<=40) { map.emplace_back(-6,0.1*i,0.1*z);map.emplace_back(6,0.1*i,0.1*z); }
|
||||
}
|
||||
for(int x=0;x<=10;++x) for(int y=-5;y<=5;++y) map.emplace_back(0.1*x,0.1*y,0.42);
|
||||
for(bool noisy:{false,true}) {
|
||||
CoreOptions options;options.initial_pose=truth(0);
|
||||
options.deskew.imu_from_sensor.translation={-0.0935,-0.1512,0.2552};
|
||||
LocalizationCore core(options);core.set_map_points(map);TrackingHealth health;
|
||||
std::mt19937 random(42);std::normal_distribution<double> normal;
|
||||
double maximum_error=0;int full=0;bool stopped=false,recovered=false;
|
||||
for(int i=0;i<=2000;++i) {
|
||||
const double t=0.01*i;const auto pose=truth(t);
|
||||
ImuData imu;imu.timestamp_sec=t;imu.angular_velocity={0,0,0.045*std::cos(0.3*t)};
|
||||
const Eigen::Vector3d acceleration{-0.048*std::sin(0.4*t),-0.05*std::sin(0.5*t),9.81};
|
||||
imu.linear_acceleration=pose.rotation.conjugate()*acceleration;
|
||||
if(noisy) for(int j=0;j<3;++j) { imu.angular_velocity[j]+=0.003*normal(random)+0.002;imu.linear_acceleration[j]+=0.03*normal(random)+0.02; }
|
||||
CHECK(core.process_imu(imu));
|
||||
if(i==0 || i%10) continue;
|
||||
PointCloud scan;scan.timestamp_sec=t;
|
||||
const auto lidar=compose(compose(pose,options.base_from_imu),options.deskew.imu_from_sensor);
|
||||
auto add=[&](const Eigen::Vector3d &world) {
|
||||
Eigen::Vector3d p=lidar.rotation.conjugate()*(world-lidar.translation);
|
||||
const double range=p.norm(),elevation=std::atan2(p.z(),p.head<2>().norm());
|
||||
if(range>12 || elevation < -7*std::numbers::pi/180 || elevation>52*std::numbers::pi/180) return;
|
||||
if(noisy) for(int j=0;j<3;++j) p[j]+=0.005*normal(random);
|
||||
PointXYZI point;point.timestamp_sec=t;point.position=p.cast<float>();scan.points.push_back(point);
|
||||
};
|
||||
for(const auto &p:map) add(p);
|
||||
// Previously unmapped object, taller than the static 0.42 m field.
|
||||
if(t>=4 && t<=14) for(int angle=0;angle<48;++angle) for(int z=1;z<=8;++z)
|
||||
add({-1.3+0.22*std::cos(angle*2*std::numbers::pi/48),-1+0.22*std::sin(angle*2*std::numbers::pi/48),0.1*z});
|
||||
if(t>=8 && t<8.8) scan.points.clear(); // complete observation failure
|
||||
PointXYZI invalid;invalid.timestamp_sec=t;invalid.position.setConstant(std::numeric_limits<float>::infinity());
|
||||
scan.points.push_back(invalid);
|
||||
const bool accepted=core.process_point_cloud(scan);
|
||||
CHECK(accepted==(t<8 || t>=8.8));
|
||||
const auto snapshot=core.get_snapshot();const bool valid=health.update(snapshot,options.base_from_imu,t);
|
||||
if(t>=8.4 && t<8.8) { CHECK(!valid);stopped=true; }
|
||||
if(t>10 && valid) recovered=true;
|
||||
if(snapshot.status.mode==TrackingMode::FULL) ++full;
|
||||
maximum_error=std::max(maximum_error,(snapshot.pose.translation-pose.translation).norm());
|
||||
CHECK(snapshot.pose.translation.allFinite());CHECK(snapshot.filter.covariance.allFinite());
|
||||
}
|
||||
std::printf("2.5D noisy=%d FULL=%d/200 maximum_position_error=%.9gm stopped=%d recovered=%d\n",noisy,full,maximum_error,stopped,recovered);
|
||||
CHECK(full>=180);CHECK(maximum_error<0.15);CHECK(stopped);CHECK(recovered);
|
||||
}
|
||||
return sentry_nav_test::Summary("FieldTracking");
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <Eigen/Eigenvalues>
|
||||
using namespace field_localization::core;
|
||||
int main() {
|
||||
// Correlated motion states: an unavailable x measurement must not change ANY state.
|
||||
ErrorStateFilter filter;
|
||||
auto prior=filter.snapshot();
|
||||
Vector18 cross=Vector18::Zero(); cross[0]=0.1;cross[3]=0.2;cross[9]=0.01;cross[12]=0.05;cross[15]=0.02;
|
||||
prior.covariance+=cross*cross.transpose(); filter.restore(prior);
|
||||
ImuData a,b; a.linear_acceleration={0,0,9.81};
|
||||
for(int i=1;i<=20;++i) { b=a;b.timestamp_sec=0.01*i;CHECK(filter.propagate(a,b));a=b; }
|
||||
prior=filter.snapshot();
|
||||
Matrix6 plane=Matrix6::Zero(); plane(2,2)=plane(3,3)=plane(4,4)=1;
|
||||
Pose3D observation=prior.state.pose;observation.translation.x()+=0.05;
|
||||
CHECK(filter.correct_pose(observation,0.001*Matrix6::Identity(),plane));
|
||||
CHECK(ErrorStateFilter::difference(prior.state,filter.snapshot().state).norm()<1e-12);
|
||||
CHECK_NEAR(prior.covariance(0,0),filter.snapshot().covariance(0,0),1e-12);
|
||||
// Rank-one 4-sigma innovation: below the six-DOF gate, above the one-DOF gate.
|
||||
filter.initialize({});prior=filter.snapshot();
|
||||
Matrix6 one=Matrix6::Zero();one(0,0)=1;
|
||||
observation={};observation.translation.x()=4*std::sqrt(0.011);
|
||||
CHECK(!filter.correct_pose(observation,0.001*Matrix6::Identity(),one));
|
||||
CHECK(filter.measurement_rank()==1);CHECK_NEAR(filter.last_nis(),16,1e-10);
|
||||
CHECK(ErrorStateFilter::difference(prior.state,filter.snapshot().state).norm()==0);
|
||||
CHECK((prior.covariance-filter.snapshot().covariance).norm()==0);
|
||||
// A finite plane is not an infinite wall: points beyond its support cannot match it.
|
||||
VoxelMap patch(0.02);
|
||||
for(int x=-4;x<=4;++x) for(int y=-4;y<=4;++y) patch.insert({0.025*x,0.025*y,0});
|
||||
PointCloud outside;outside.timestamp_sec=1;
|
||||
for(int x=0;x<5;++x) for(int y=-4;y<=4;++y) {
|
||||
PointXYZI p;p.timestamp_sec=1;p.position={0.35F+0.01F*x,0.025F*y,0};outside.points.push_back(p);
|
||||
}
|
||||
RegistrationOptions ro;ro.scan_voxel=0.01;ro.minimum_inliers=3;
|
||||
const auto no_match=scan_to_map(outside,{},patch,prior,{},ro);
|
||||
CHECK(!no_match.success);CHECK(!no_match.residual_available);CHECK(no_match.inliers==0);
|
||||
CHECK((no_match.degeneracy.null_basis.transpose()*no_match.degeneracy.null_basis-Matrix6::Identity()).norm()<1e-10);
|
||||
// Finite-rate acceleration aliasing is model error even with zero sensor noise.
|
||||
ErrorStateFilter contact;
|
||||
a={};a.linear_acceleration={0,0,9.81};
|
||||
int corrections=0;
|
||||
for(int i=1;i<=100;++i) {
|
||||
b=a;b.timestamp_sec=0.01*i;b.linear_acceleration={0,0,9.81};
|
||||
if(i==10) b.linear_acceleration.z()+=50;
|
||||
CHECK(contact.propagate(a,b));a=b;
|
||||
if(i%10==0) { if(contact.correct_pose({},1e-6*Matrix6::Identity())) ++corrections; }
|
||||
}
|
||||
CHECK(corrections==10);CHECK(contact.snapshot().state.velocity.norm()<0.01);
|
||||
CHECK(contact.snapshot().state.accel_bias.norm()<0.02);
|
||||
return sentry_nav_test::Summary("FilterConsistency");
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "field_localization/core/imu_integration.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
using namespace field_localization::core;
|
||||
int main() {
|
||||
std::vector<ImuData> imu;
|
||||
const Eigen::Vector3d omega{0.1,-0.2,0.7};
|
||||
for (int i=0;i<=100;++i) {
|
||||
ImuData s; s.timestamp_sec=0.01*i; s.angular_velocity=omega;
|
||||
imu.push_back(s);
|
||||
}
|
||||
const auto p=preintegrate(imu,0.003,0.997);
|
||||
CHECK(p.has_value());
|
||||
if (p) {
|
||||
const double error=log_so3(p->dR.conjugate()*exp_so3(0.994*omega)).norm();
|
||||
CHECK(error<1e-6); CHECK_NEAR(p->dt,0.994,1e-12);
|
||||
std::printf("preintegration rotation error = %.12g rad\n",error);
|
||||
}
|
||||
CHECK(!preintegrate(imu,-0.01,0.9)); CHECK(!preintegrate(imu,0.8,0.7));
|
||||
auto bad=imu; bad[2].timestamp_sec=bad[1].timestamp_sec;
|
||||
CHECK(!preintegrate(bad,0,1));
|
||||
MotionState initial; initial.gravity.setZero(); initial.velocity={0.8,-0.4,0.1};
|
||||
initial.pose.rotation=exp_so3({0.1,0.2,0.3});
|
||||
const auto trajectory=integrate_trajectory(imu,initial,1);
|
||||
CHECK(trajectory.has_value());
|
||||
if (trajectory) {
|
||||
DeskewOptions o; o.timing=ScanTiming::POINT_TIMESTAMPS;
|
||||
o.imu_from_sensor.translation={-0.0935,-0.1512,0.2552};
|
||||
PointCloud cloud; cloud.timestamp_sec=1;
|
||||
for (int i=0;i<100;++i) {
|
||||
const double time=0.01*i;
|
||||
const auto motion=interpolate_motion(*trajectory,time);
|
||||
CHECK(motion.has_value()); if (!motion) continue;
|
||||
const Pose3D sensor=compose(motion->pose,o.imu_from_sensor);
|
||||
const Eigen::Vector3d world{2.0,0.05*i-2.5,0.01*i}; // wall x=2
|
||||
PointXYZI point; point.timestamp_sec=time;
|
||||
point.position=(sensor.rotation.conjugate()*(world-sensor.translation)).cast<float>();
|
||||
cloud.points.push_back(point);
|
||||
}
|
||||
PointXYZI invalid; invalid.position.x()=std::numeric_limits<float>::infinity();
|
||||
cloud.points.push_back(invalid);
|
||||
const auto corrected=deskew(cloud,*trajectory,o);
|
||||
CHECK(corrected.has_value());
|
||||
double max_error=0;
|
||||
if (corrected) {
|
||||
CHECK(corrected->points.size()==100);
|
||||
const Pose3D end_sensor=compose(trajectory->back().pose,o.imu_from_sensor);
|
||||
for (const auto &point:corrected->points) {
|
||||
const Eigen::Vector3d world=end_sensor.rotation*point.position.cast<double>()+end_sensor.translation;
|
||||
max_error=std::max(max_error,std::abs(world.x()-2));
|
||||
}
|
||||
CHECK(max_error<1e-3);
|
||||
std::printf("deskew maximum plane residual = %.12g m\n",max_error);
|
||||
}
|
||||
o.timing=ScanTiming::INSTANTANEOUS;
|
||||
const auto same=deskew(cloud,*trajectory,o);
|
||||
CHECK(same && same->points.front().position.isApprox(cloud.points.front().position,1e-6F));
|
||||
o.timing=ScanTiming::AZIMUTH;
|
||||
const auto az=deskew(cloud,*trajectory,o);
|
||||
CHECK(az && az->points.size()==100);
|
||||
o.period_sec=1.0;
|
||||
PointCloud rolling; rolling.timestamp_sec=1.0;
|
||||
for (int i=0;i<360;++i) {
|
||||
const double angle=-std::numbers::pi+2*std::numbers::pi*(i+0.5)/360;
|
||||
const double time=(i+0.5)/360;
|
||||
const auto motion=interpolate_motion(*trajectory,time);
|
||||
const auto sensor=compose(motion->pose,o.imu_from_sensor);
|
||||
const Eigen::Vector3d ray{std::cos(angle),std::sin(angle),-1.5};
|
||||
const Eigen::Vector3d direction=sensor.rotation*ray;
|
||||
const double distance=(-2-sensor.translation.z())/direction.z();
|
||||
CHECK(distance>0);
|
||||
PointXYZI point; point.timestamp_sec=1;
|
||||
point.position=(distance*ray).cast<float>();
|
||||
rolling.points.push_back(point);
|
||||
}
|
||||
const auto corrected_az=deskew(rolling,*trajectory,o);
|
||||
CHECK(corrected_az.has_value());
|
||||
if (corrected_az) {
|
||||
double residual=0;
|
||||
const auto sensor=compose(trajectory->back().pose,o.imu_from_sensor);
|
||||
for (const auto &point:corrected_az->points) {
|
||||
const Eigen::Vector3d world=sensor.rotation*point.position.cast<double>()+sensor.translation;
|
||||
residual=std::max(residual,std::abs(world.z()+2));
|
||||
}
|
||||
std::printf("azimuth deskew maximum residual = %.12g m\n",residual);
|
||||
CHECK(residual<1e-3);
|
||||
}
|
||||
}
|
||||
return sentry_nav_test::Summary("ImuIntegration");
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
using namespace field_localization::core;
|
||||
namespace {
|
||||
Pose3D truth(double t) {
|
||||
return {exp_so3({0.5*std::sin(0.7*t),0,0})*exp_so3({0,0.4*std::sin(0.9*t),0})*exp_so3({0,0,0.8*std::sin(0.5*t)}),
|
||||
Eigen::Vector3d{std::cos(0.6*t)-1,0.8*(std::cos(0.8*t)-1),0.5*(std::cos(1.1*t)-1)}};
|
||||
}
|
||||
}
|
||||
int main(int argc,char **argv) {
|
||||
std::ofstream curve(argc>1 ? argv[1] : "/tmp/field_lio_bias_end_to_end.csv");
|
||||
curve<<"seed,time,bgx,bgy,bgz,bax,bay,baz,gyro_error,accel_error,position_error,rotation_error,mode\n";
|
||||
std::vector<Eigen::Vector3d> map;
|
||||
for (int i=-12;i<=12;++i) for (int j=-12;j<=12;++j) {
|
||||
map.emplace_back(0.2*i,0.2*j,-3); map.emplace_back(3,0.2*i,0.2*j); map.emplace_back(0.2*i,3,0.2*j);
|
||||
}
|
||||
const Eigen::Vector3d bg{0.02,-0.015,0.01},ba{0.15,-0.1,0.08};
|
||||
for (unsigned seed=1;seed<=5;++seed) {
|
||||
CoreOptions options; options.base_from_imu={};
|
||||
LocalizationCore core(options); core.set_map_points(map);
|
||||
std::mt19937 rng(seed); std::normal_distribution<double> normal;
|
||||
Eigen::Vector3d gs=Eigen::Vector3d::Zero(),as=Eigen::Vector3d::Zero();
|
||||
int full=0;
|
||||
for (int i=0;i<=6000;++i) {
|
||||
const double t=0.01*i,h=1e-4;
|
||||
const auto pose=truth(t);
|
||||
ImuData imu; imu.timestamp_sec=t;
|
||||
imu.angular_velocity=log_so3(truth(t-h/2).rotation.conjugate()*truth(t+h/2).rotation)/h+bg;
|
||||
const Eigen::Vector3d acc{-0.36*std::cos(0.6*t),-0.512*std::cos(0.8*t),-0.605*std::cos(1.1*t)};
|
||||
imu.linear_acceleration=pose.rotation.conjugate()*(acc+Eigen::Vector3d{0,0,9.81})+ba;
|
||||
for (int axis=0;axis<3;++axis) { imu.angular_velocity[axis]+=0.003*normal(rng); imu.linear_acceleration[axis]+=0.03*normal(rng); }
|
||||
CHECK(core.process_imu(imu));
|
||||
if (i==0 || i%10) continue;
|
||||
PointCloud scan; scan.timestamp_sec=t;
|
||||
for (const auto &world:map) {
|
||||
Eigen::Vector3d p=pose.rotation.conjugate()*(world-pose.translation);
|
||||
for (int axis=0;axis<3;++axis) p[axis]+=0.01*normal(rng);
|
||||
PointXYZI point; point.timestamp_sec=t; point.position=p.cast<float>(); scan.points.push_back(point);
|
||||
}
|
||||
CHECK(core.process_point_cloud(scan));
|
||||
const auto snapshot=core.get_snapshot(); const auto &s=snapshot.filter.state;
|
||||
if (snapshot.status.mode==TrackingMode::FULL) ++full;
|
||||
const Eigen::Vector3d ge=s.gyro_bias-bg,ae=s.accel_bias-ba;
|
||||
curve<<seed<<','<<t<<','<<s.gyro_bias.x()<<','<<s.gyro_bias.y()<<','<<s.gyro_bias.z()<<','<<s.accel_bias.x()<<','<<s.accel_bias.y()<<','<<s.accel_bias.z()
|
||||
<<','<<ge.norm()<<','<<ae.norm()<<','<<(s.pose.translation-pose.translation).norm()<<','
|
||||
<<log_so3(pose.rotation.conjugate()*s.pose.rotation).norm()<<','<<static_cast<int>(snapshot.status.mode)<<'\n';
|
||||
if (i>5000) { gs+=ge.cwiseAbs2(); as+=ae.cwiseAbs2(); }
|
||||
}
|
||||
const Eigen::Vector3d g=(gs/100).cwiseSqrt(),a=(as/100).cwiseSqrt();
|
||||
std::printf("end-to-end seed %u FULL=%d/600 gyro bias RMSE max=%.9g rad/s accel=%.9g m/s2\n",seed,full,g.maxCoeff(),a.maxCoeff());
|
||||
CHECK(full>=570); CHECK(g.maxCoeff()<0.003); CHECK(a.maxCoeff()<0.03);
|
||||
}
|
||||
return sentry_nav_test::Summary("LioSynthetic");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include "test_util.hpp"
|
||||
#include <cmath>
|
||||
|
||||
using namespace field_localization::core;
|
||||
@@ -11,8 +11,8 @@ int main() {
|
||||
// 1. 检查默认位姿
|
||||
Pose3D pose = core.get_pose();
|
||||
|
||||
assert(pose.translation.isZero());
|
||||
assert(pose.rotation.isApprox(
|
||||
CHECK(pose.translation.isZero());
|
||||
CHECK(pose.rotation.isApprox(
|
||||
Eigen::Quaterniond::Identity()
|
||||
));
|
||||
|
||||
@@ -30,8 +30,8 @@ int main() {
|
||||
|
||||
pose = core.get_pose();
|
||||
|
||||
assert(pose.translation.isApprox(new_pose.translation));
|
||||
assert(pose.rotation.isApprox(new_pose.rotation));
|
||||
CHECK(pose.translation.isApprox(new_pose.translation));
|
||||
CHECK(pose.rotation.isApprox(new_pose.rotation));
|
||||
|
||||
// 3. 输入 IMU 数据
|
||||
ImuData imu;
|
||||
@@ -39,7 +39,7 @@ int main() {
|
||||
imu.angular_velocity = Eigen::Vector3d{0.1, 0.2, 0.3};
|
||||
imu.linear_acceleration = Eigen::Vector3d{0.0, 0.0, 9.81};
|
||||
|
||||
assert(core.process_imu(imu));
|
||||
CHECK(core.process_imu(imu));
|
||||
|
||||
// 4. 输入点云数据
|
||||
PointCloud cloud;
|
||||
@@ -52,31 +52,62 @@ int main() {
|
||||
|
||||
cloud.points.push_back(point);
|
||||
|
||||
assert(core.process_point_cloud(cloud));
|
||||
CHECK(core.process_point_cloud(cloud));
|
||||
|
||||
// 5. 检查状态
|
||||
const LocalizationStatus status = core.get_status();
|
||||
|
||||
assert(status.has_imu);
|
||||
assert(status.has_point_cloud);
|
||||
assert(status.imu_count == 1);
|
||||
assert(status.point_cloud_count == 1);
|
||||
assert(status.last_point_count == 1);
|
||||
CHECK(status.has_imu);
|
||||
CHECK(status.has_point_cloud);
|
||||
CHECK(status.imu_count == 1);
|
||||
CHECK(status.point_cloud_count == 1);
|
||||
CHECK(status.last_point_count == 1);
|
||||
|
||||
// 6. 检查乱序 IMU 是否被拒绝
|
||||
assert(!core.process_imu(imu));
|
||||
CHECK(!core.process_imu(imu));
|
||||
|
||||
CHECK(core.get_status().mode == TrackingMode::IMU_ONLY);
|
||||
CHECK(core.get_snapshot().filter.covariance.allFinite());
|
||||
LocalizationCore stationary;
|
||||
ImuData still;
|
||||
still.linear_acceleration={0,0,9.81};
|
||||
for (int i=0;i<=100;++i) {
|
||||
still.timestamp_sec=0.01*i;
|
||||
CHECK(stationary.process_imu(still));
|
||||
}
|
||||
CHECK(stationary.get_pose().translation.norm()<1e-12);
|
||||
PointCloud empty; empty.timestamp_sec=1;
|
||||
CHECK(!stationary.process_point_cloud(empty));
|
||||
CHECK(stationary.get_status().reason==FailureReason::NO_VALID_POINTS);
|
||||
CHECK(stationary.get_pose().translation.allFinite());
|
||||
LocalizationCore moving;
|
||||
ImuData accelerated; accelerated.linear_acceleration={1,0,9.81};
|
||||
for (int i=0;i<=100;++i) {
|
||||
accelerated.timestamp_sec=0.01*i;
|
||||
CHECK(moving.process_imu(accelerated));
|
||||
}
|
||||
CHECK_NEAR(moving.get_pose().translation.x(),0.5,1e-9);
|
||||
CHECK_NEAR(moving.get_snapshot().filter.state.velocity.x(),1,1e-9);
|
||||
CHECK(moving.get_status().mode==TrackingMode::IMU_ONLY);
|
||||
accelerated.timestamp_sec=0.5;
|
||||
CHECK(!moving.process_imu(accelerated));
|
||||
CHECK(moving.get_status().reason==FailureReason::TIME_ORDER);
|
||||
PointCloud backwards=cloud; backwards.timestamp_sec=0.5;
|
||||
CHECK(!core.process_point_cloud(backwards));
|
||||
CHECK(core.get_status().mode==TrackingMode::IMU_ONLY);
|
||||
CHECK(core.get_status().reason==FailureReason::TIME_ORDER);
|
||||
CHECK(core.get_pose().translation.allFinite());
|
||||
// 7. 检查重置
|
||||
core.reset();
|
||||
|
||||
const auto reset_status = core.get_status();
|
||||
assert(!reset_status.has_imu);
|
||||
assert(!reset_status.has_point_cloud);
|
||||
assert(reset_status.imu_count == 0);
|
||||
assert(reset_status.point_cloud_count == 0);
|
||||
CHECK(!reset_status.has_imu);
|
||||
CHECK(!reset_status.has_point_cloud);
|
||||
CHECK(reset_status.imu_count == 0);
|
||||
CHECK(reset_status.point_cloud_count == 0);
|
||||
|
||||
pose = core.get_pose();
|
||||
assert(pose.translation.isZero());
|
||||
CHECK(pose.translation.isZero());
|
||||
|
||||
return 0;
|
||||
return sentry_nav_test::Summary("LocalizationCore");
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <numbers>
|
||||
using namespace field_localization::core;
|
||||
namespace {
|
||||
std::string bytes(const std::filesystem::path &p) {
|
||||
std::ifstream in(p,std::ios::binary); return {std::istreambuf_iterator<char>(in),{}};
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
const auto folder=std::filesystem::temp_directory_path()/"field_lio_map_tests";
|
||||
std::filesystem::create_directories(folder);
|
||||
Pose3D previous,current;
|
||||
current.translation.x()=0.5; CHECK(!new_keyframe(previous,current));
|
||||
current.translation.x()=0.50001; CHECK(new_keyframe(previous,current));
|
||||
current={}; current.rotation=exp_so3({0,0,9.99*std::numbers::pi/180}); CHECK(!new_keyframe(previous,current));
|
||||
current.rotation=exp_so3({0,0,10.01*std::numbers::pi/180}); CHECK(new_keyframe(previous,current));
|
||||
CoreOptions options; options.map_mode=MapMode::MAPPING; options.base_from_imu={};
|
||||
LocalizationCore mapping(options);
|
||||
ImuData imu; imu.linear_acceleration={0,0,9.81};
|
||||
PointCloud scan;
|
||||
for (int i=-15;i<=15;++i) for (int j=-15;j<=15;++j) {
|
||||
for (const Eigen::Vector3f &p:{Eigen::Vector3f{0.12F*i,0.12F*j,0},Eigen::Vector3f{3,0.12F*i,0.12F*j},Eigen::Vector3f{0.12F*i,3,0.12F*j}}) {
|
||||
PointXYZI point; point.position=p; scan.points.push_back(point);
|
||||
}
|
||||
}
|
||||
for (int i=0;i<=30;++i) { imu.timestamp_sec=0.01*i; CHECK(mapping.process_imu(imu)); }
|
||||
scan.timestamp_sec=0.1; CHECK(mapping.process_point_cloud(scan)); CHECK(mapping.get_status().keyframe_count==1);
|
||||
scan.timestamp_sec=0.2; CHECK(mapping.process_point_cloud(scan)); CHECK(mapping.get_status().mode==TrackingMode::FULL);
|
||||
CHECK(mapping.get_status().keyframe_count==1);
|
||||
Pose3D shifted; shifted.translation.x()=0.6; mapping.set_pose(shifted);
|
||||
for (int i=40;i<=70;++i) { imu.timestamp_sec=0.01*i; CHECK(mapping.process_imu(imu)); }
|
||||
scan.timestamp_sec=0.6;
|
||||
for (auto &p:scan.points) p.position.x()-=0.6F;
|
||||
CHECK(mapping.process_point_cloud(scan)); CHECK(mapping.get_status().keyframe_count==2);
|
||||
std::string error;
|
||||
CHECK(mapping.export_map(folder/"map.flmap",error)); CHECK(error.empty());
|
||||
const auto map=read_map(folder/"map.flmap",error); CHECK(map.has_value());
|
||||
LocalizationCore localization;
|
||||
CHECK(localization.load_map(folder/"map.flmap",error));
|
||||
const auto count=localization.get_status().map_point_count;
|
||||
for (int i=0;i<=30;++i) { imu.timestamp_sec=0.01*i; CHECK(localization.process_imu(imu)); }
|
||||
// Map must remain byte-identical even if localization measurements are rejected.
|
||||
scan.timestamp_sec=0.2; CHECK(localization.process_point_cloud(scan));
|
||||
CHECK(localization.get_status().map_point_count==count);
|
||||
CHECK(localization.export_map(folder/"readonly.flmap",error));
|
||||
CHECK(bytes(folder/"map.flmap")==bytes(folder/"readonly.flmap"));
|
||||
{ std::ofstream out(folder/"broken.flmap",std::ios::binary); out<<"FLMAP001"; }
|
||||
CHECK(!localization.load_map(folder/"broken.flmap",error)); CHECK(!error.empty());
|
||||
CHECK(localization.get_status().map_point_count==count);
|
||||
CHECK(!localization.load_map(folder/"missing.flmap",error));
|
||||
mapping.reset(); CHECK(mapping.get_status().map_point_count==0);
|
||||
localization.reset(); CHECK(localization.get_status().map_point_count==count);
|
||||
std::filesystem::remove_all(folder);
|
||||
return sentry_nav_test::Summary("MapManagement");
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
#include "field_localization/core/dataset.hpp"
|
||||
#include "field_localization/core/tracking_health.hpp"
|
||||
#include "test_util.hpp"
|
||||
|
||||
#include <Eigen/Eigenvalues>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace field_localization::core;
|
||||
|
||||
namespace {
|
||||
struct Report {
|
||||
int scans{0};
|
||||
int full{0};
|
||||
int innovation_rejections{0};
|
||||
double maximum_rotation_error{0};
|
||||
double maximum_correction_gap{0};
|
||||
double maximum_position_error{0};
|
||||
double maximum_position_three_sigma{0};
|
||||
};
|
||||
|
||||
Report evaluate_recording(const std::filesystem::path &directory,const NoiseOptions &noise,
|
||||
const std::filesystem::path &map_path,const RegistrationOptions ®istration={}) {
|
||||
const auto options=read_dataset_config(directory/"config.txt");
|
||||
FilterSnapshot checkpoint;
|
||||
auto &state=checkpoint.state;
|
||||
std::ifstream input(directory/"checkpoint.txt");
|
||||
input>>state.timestamp_sec;
|
||||
for (auto *v:{&state.pose.translation,&state.velocity})
|
||||
for (int i=0;i<3;++i) input>>(*v)[i];
|
||||
for (int i=0;i<4;++i) input>>state.pose.rotation.coeffs()[i];
|
||||
for (auto *v:{&state.gyro_bias,&state.accel_bias,&state.gravity})
|
||||
for (int i=0;i<3;++i) input>>(*v)[i];
|
||||
for (int i=0;i<18;++i)
|
||||
for (int j=0;j<18;++j) input>>checkpoint.covariance(i,j);
|
||||
CHECK(static_cast<bool>(input));
|
||||
|
||||
std::string error;
|
||||
const auto map=read_map(map_path,error);
|
||||
CHECK(map.has_value());
|
||||
if (!map) return {};
|
||||
|
||||
std::vector<ImuData> samples;
|
||||
std::ifstream imu(directory/"imu.csv");
|
||||
std::string line;
|
||||
std::getline(imu,line);
|
||||
while (std::getline(imu,line)) {
|
||||
std::replace(line.begin(),line.end(),',',' ');
|
||||
std::istringstream row(line);
|
||||
ImuData value;
|
||||
row>>value.timestamp_sec>>value.angular_velocity.x()>>value.angular_velocity.y()>>value.angular_velocity.z()
|
||||
>>value.linear_acceleration.x()>>value.linear_acceleration.y()>>value.linear_acceleration.z();
|
||||
CHECK(static_cast<bool>(row));
|
||||
samples.push_back(value);
|
||||
}
|
||||
const auto truth=read_trajectory(directory/"truth.tum");
|
||||
std::ifstream scans(directory/"scans.csv");
|
||||
std::getline(scans,line);
|
||||
ErrorStateFilter filter(noise);
|
||||
filter.restore(checkpoint);
|
||||
Report report;
|
||||
TrackingHealth health;
|
||||
const auto imu_from_base=inverse(options.base_from_imu);
|
||||
double last_correction=-1;
|
||||
auto observe_prior=[&] {
|
||||
const auto &prior=filter.snapshot();
|
||||
LocalizationSnapshot snapshot{compose(prior.state.pose,imu_from_base),prior,{}};
|
||||
health.update(snapshot,options.base_from_imu,prior.state.timestamp_sec);
|
||||
report.maximum_position_three_sigma=std::max(report.maximum_position_three_sigma,
|
||||
health.position_three_sigma());
|
||||
};
|
||||
while (std::getline(scans,line)) {
|
||||
const auto cloud=read_cloud(directory/line.substr(line.find(',')+1));
|
||||
auto a=interpolate_imu(samples,filter.snapshot().state.timestamp_sec);
|
||||
CHECK(a.has_value());
|
||||
if (!a) return report;
|
||||
for (const auto &b:samples) {
|
||||
if (b.timestamp_sec<=a->timestamp_sec || b.timestamp_sec>=cloud.timestamp_sec) continue;
|
||||
CHECK(filter.propagate(*a,b));
|
||||
observe_prior();
|
||||
a=b;
|
||||
}
|
||||
const auto finish=interpolate_imu(samples,cloud.timestamp_sec);
|
||||
CHECK(finish.has_value());
|
||||
if (!finish) return report;
|
||||
if (finish->timestamp_sec>a->timestamp_sec) CHECK(filter.propagate(*a,*finish));
|
||||
observe_prior();
|
||||
const auto result=scan_to_map(cloud,options.deskew.imu_from_sensor,*map,filter.snapshot(),
|
||||
noise,registration);
|
||||
++report.scans;
|
||||
if (result.failure==RegistrationFailure::INNOVATION) ++report.innovation_rejections;
|
||||
if (last_correction>=0)
|
||||
report.maximum_correction_gap=std::max(report.maximum_correction_gap,
|
||||
cloud.timestamp_sec-last_correction);
|
||||
if (result.success) {
|
||||
last_correction=cloud.timestamp_sec;
|
||||
filter.restore(result.estimate);
|
||||
++report.full;
|
||||
}
|
||||
const auto base=compose(filter.snapshot().state.pose,imu_from_base);
|
||||
const auto gt=trajectory_pose(truth,cloud.timestamp_sec);
|
||||
CHECK(gt.has_value());
|
||||
if (!gt) return report;
|
||||
report.maximum_position_error=std::max(report.maximum_position_error,
|
||||
(base.translation-gt->translation).norm());
|
||||
report.maximum_rotation_error=std::max(report.maximum_rotation_error,
|
||||
log_so3(gt->rotation.conjugate()*base.rotation).norm());
|
||||
const Eigen::SelfAdjointEigenSolver<Matrix18> eigen(filter.snapshot().covariance);
|
||||
CHECK(eigen.info()==Eigen::Success);
|
||||
CHECK(eigen.eigenvalues().minCoeff()>-1e-10);
|
||||
}
|
||||
std::printf("%s scale=%.2f map_sigma=%.3f FULL=%d/%d innovation_rejections=%d max_position_error=%.6f m max_prior_horizontal_3sigma=%.6f m max_rotation_error=%.6f rad max_correction_gap=%.6f s\n",
|
||||
directory.filename().string().c_str(),noise.integration_error_scale,registration.map_translation_sigma,
|
||||
report.full,report.scans,report.innovation_rejections,report.maximum_position_error,
|
||||
report.maximum_position_three_sigma,report.maximum_rotation_error,report.maximum_correction_gap);
|
||||
return report;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc,char **argv) {
|
||||
CHECK(argc==4);
|
||||
if (argc!=4) return 1;
|
||||
const std::filesystem::path turn=argv[1],clear_return=argv[2],cylinder_return=argv[3];
|
||||
const auto turn_report=evaluate_recording(turn,{},turn/"map.flmap");
|
||||
CHECK(turn_report.scans==5 && turn_report.full==5);
|
||||
CHECK(turn_report.maximum_position_error<0.10);
|
||||
CHECK(turn_report.maximum_rotation_error<0.02);
|
||||
|
||||
const auto return_map=clear_return/"map.flmap";
|
||||
const auto updated=evaluate_recording(clear_return,{},return_map);
|
||||
NoiseOptions previous_noise;
|
||||
previous_noise.integration_error_scale=2.0;
|
||||
RegistrationOptions previous_map;
|
||||
previous_map.map_translation_sigma=0.02;
|
||||
const auto baseline=evaluate_recording(clear_return,previous_noise,return_map,previous_map);
|
||||
CHECK(updated.scans==5 && updated.full==5);
|
||||
CHECK(baseline.scans==5 && baseline.full==5);
|
||||
CHECK(updated.maximum_position_error<0.10);
|
||||
CHECK(baseline.maximum_position_three_sigma>HealthOptions{}.position_three_sigma);
|
||||
CHECK(updated.maximum_position_three_sigma<HealthOptions{}.position_three_sigma);
|
||||
|
||||
const auto cylinder=evaluate_recording(cylinder_return,{},return_map);
|
||||
const auto previous_cylinder=evaluate_recording(cylinder_return,{},return_map,previous_map);
|
||||
CHECK(cylinder.scans==7 && cylinder.full>previous_cylinder.full);
|
||||
CHECK(cylinder.maximum_correction_gap<HealthOptions{}.correction_timeout);
|
||||
CHECK(previous_cylinder.maximum_correction_gap>=HealthOptions{}.correction_timeout-1e-9);
|
||||
CHECK(cylinder.maximum_position_error<0.10);
|
||||
CHECK(previous_cylinder.innovation_rejections>=1);
|
||||
return sentry_nav_test::Summary("RecordedUpdate");
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "field_localization/core/localization_core.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
using namespace field_localization::core;
|
||||
int main() {
|
||||
VoxelMap map;
|
||||
for (int i=-20;i<=20;++i) for (int j=-20;j<=20;++j) {
|
||||
map.insert({0.1*i,0.1*j,0}); map.insert({3,0.1*i,0.1*j}); map.insert({0.1*i,3,0.1*j});
|
||||
}
|
||||
const auto points=map.points();
|
||||
Pose3D truth{exp_so3({0.02,-0.03,0.08}),Eigen::Vector3d{0.1,0.2,0.15}};
|
||||
PointCloud scan; scan.timestamp_sec=1;
|
||||
for (const auto &p:points) {
|
||||
PointXYZI s; s.timestamp_sec=1; s.position=(truth.rotation.conjugate()*(p-truth.translation)).cast<float>(); scan.points.push_back(s);
|
||||
}
|
||||
ErrorStateFilter filter; MotionState initial; initial.pose=truth;
|
||||
initial.pose.translation+=Eigen::Vector3d{0.03,-0.02,0.025}; initial.pose.rotation*=exp_so3({0.005,-0.008,0.012});
|
||||
filter.initialize(initial);
|
||||
RegistrationOptions exact_map; exact_map.map_translation_sigma=0; exact_map.map_rotation_sigma=0;
|
||||
const auto result=scan_to_map(scan,{},map,filter.snapshot(),{},exact_map);
|
||||
CHECK(result.success); CHECK(result.degeneracy.dimensions==0);
|
||||
CHECK(result.stage==RegistrationStage::COMPLETE);
|
||||
const auto support=inspect_scan_support(scan,{},map,initial.pose,exact_map);
|
||||
CHECK(support.candidate_planes<=support.sampled);
|
||||
CHECK(support.candidate_planes==support.outside_support+support.plane_distance_rejected+support.inliers);
|
||||
CHECK(result.initial_associations.inliers==support.inliers);
|
||||
CHECK(result.last_associations.inliers==result.inliers);
|
||||
auto far=initial;
|
||||
far.pose.translation.x()+=20;
|
||||
filter.initialize(far);
|
||||
const auto unsupported=scan_to_map(scan,{},map,filter.snapshot(),{},exact_map);
|
||||
CHECK(!unsupported.success);
|
||||
CHECK(unsupported.stage==RegistrationStage::INITIAL_MATCH);
|
||||
CHECK(unsupported.failure==RegistrationFailure::NO_CORRESPONDENCES);
|
||||
CHECK(unsupported.initial_associations.sampled>0 && unsupported.initial_associations.candidate_planes==0);
|
||||
const double position_error=(result.estimate.state.pose.translation-truth.translation).norm();
|
||||
const double rotation_error=log_so3(truth.rotation.conjugate()*result.estimate.state.pose.rotation).norm();
|
||||
std::printf("3-plane registration: translation %.9g m, rotation %.9g rad, rmse %.9g, inliers %zu\n",
|
||||
position_error,rotation_error,result.rmse,result.inliers);
|
||||
CHECK(position_error<1e-3); CHECK(rotation_error<1e-3);
|
||||
VoxelMap floor;
|
||||
PointCloud planar; planar.timestamp_sec=1;
|
||||
for (int i=-20;i<=20;++i) for (int j=-20;j<=20;++j) {
|
||||
Eigen::Vector3d p{0.1*i,0.1*j,0}; floor.insert(p);
|
||||
PointXYZI s; s.timestamp_sec=1; s.position=p.cast<float>(); planar.points.push_back(s);
|
||||
}
|
||||
initial={}; initial.pose.translation={0.05,-0.03,0.04}; filter.initialize(initial);
|
||||
const auto plane=scan_to_map(planar,{},floor,filter.snapshot());
|
||||
CHECK(plane.success); CHECK(plane.degeneracy.dimensions==3);
|
||||
CHECK_NEAR(plane.estimate.state.pose.translation.x(),0.05,1e-12);
|
||||
CHECK_NEAR(plane.estimate.state.pose.translation.y(),-0.03,1e-12);
|
||||
CHECK(plane.degeneracy.projector.col(0).norm()<1e-8);
|
||||
CHECK(plane.degeneracy.projector.col(1).norm()<1e-8);
|
||||
CHECK(plane.degeneracy.projector.col(5).norm()<1e-8);
|
||||
CHECK_NEAR(plane.estimate.covariance(0,0),filter.snapshot().covariance(0,0),1e-12);
|
||||
// An offset plane yields plenty of inliers but disagrees with a confident
|
||||
// prediction. Trial re-association still has to pass the final innovation gate.
|
||||
PointCloud shifted=planar;
|
||||
for (auto &point:shifted.points) point.position.z()+=0.09F;
|
||||
FilterSnapshot confident;
|
||||
confident.covariance=1e-6*Matrix18::Identity();
|
||||
RegistrationOptions strict;
|
||||
strict.map_translation_sigma=0.01;
|
||||
const auto rejected=scan_to_map(shifted,{},floor,confident,{},strict);
|
||||
CHECK(!rejected.success);
|
||||
CHECK(rejected.failure==RegistrationFailure::INNOVATION);
|
||||
CHECK(rejected.stage==RegistrationStage::FINAL_FUSION);
|
||||
CHECK(rejected.inliers>100);
|
||||
CHECK(rejected.measurement_rank==3);
|
||||
// Rotate the whole plane; verify its null space rather than an axis label.
|
||||
Matrix6 transform=Matrix6::Identity();
|
||||
const Eigen::Matrix3d rotation=exp_so3({0.4,-0.3,0.1}).toRotationMatrix();
|
||||
transform.topLeftCorner<3,3>()=rotation; transform.bottomRightCorner<3,3>()=rotation;
|
||||
Matrix6 h=Matrix6::Zero(); h(2,2)=2; h(3,3)=3; h(4,4)=4;
|
||||
const auto tilted=detect_degeneracy(transform*h*transform.transpose());
|
||||
CHECK(tilted.dimensions==3);
|
||||
CHECK((tilted.projector*transform.col(0)).norm()<1e-10);
|
||||
CHECK((tilted.projector*transform.col(5)).norm()<1e-10);
|
||||
LocalizationCore core; core.set_map_points(points);
|
||||
ImuData imu; imu.linear_acceleration={0,0,9.81};
|
||||
for (int i=0;i<=110;++i) { imu.timestamp_sec=0.01*i; CHECK(core.process_imu(imu)); }
|
||||
core.set_pose({}); // explicit reset requires a new IMU epoch
|
||||
for (int i=0;i<=110;++i) { imu.timestamp_sec=0.01*i; CHECK(core.process_imu(imu)); }
|
||||
PointCloud at_origin;
|
||||
at_origin.timestamp_sec=1.005;
|
||||
for (const auto &p:points) { PointXYZI s; s.timestamp_sec=at_origin.timestamp_sec; s.position=(p-Eigen::Vector3d{0,0,0.15}).cast<float>(); at_origin.points.push_back(s); }
|
||||
CHECK(core.process_point_cloud(at_origin)); CHECK(core.get_status().mode==TrackingMode::FULL);
|
||||
CHECK_NEAR(core.get_snapshot().filter.state.timestamp_sec,1.1,1e-12);
|
||||
imu.timestamp_sec=1.11; CHECK(core.process_imu(imu));
|
||||
CHECK(core.get_pose().translation.norm()<1e-3);
|
||||
PointCloud invalid; invalid.timestamp_sec=1.12;
|
||||
PointXYZI inf; inf.position.setConstant(std::numeric_limits<float>::infinity()); invalid.points.push_back(inf);
|
||||
CHECK(!core.process_point_cloud(invalid)); CHECK(core.get_status().mode==TrackingMode::IMU_ONLY);
|
||||
CHECK(core.get_pose().translation.allFinite());
|
||||
return sentry_nav_test::Summary("Registration");
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "field_localization/ros/conversion.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <array>
|
||||
#include <bit>
|
||||
using namespace field_localization;
|
||||
int main() {
|
||||
sensor_msgs::msg::PointCloud2 msg; msg.width=2; msg.height=2; msg.point_step=16; msg.row_step=40;
|
||||
msg.is_bigendian=true; msg.data.resize(80); msg.header.stamp.sec=3;
|
||||
for (const auto &[name,offset]:{std::pair{"x",0U},std::pair{"y",4U},std::pair{"z",8U},std::pair{"intensity",12U}}) {
|
||||
sensor_msgs::msg::PointField f; f.name=name; f.offset=offset; f.datatype=sensor_msgs::msg::PointField::FLOAT32; f.count=1; msg.fields.push_back(f);
|
||||
}
|
||||
for (std::size_t row=0;row<2;++row) for (std::size_t col=0;col<2;++col) for (std::size_t k=0;k<4;++k) {
|
||||
auto bytes=std::bit_cast<std::array<std::uint8_t,4>>(static_cast<float>(row*10+col+k));
|
||||
if constexpr(std::endian::native==std::endian::little) std::reverse(bytes.begin(),bytes.end());
|
||||
std::copy(bytes.begin(),bytes.end(),msg.data.begin()+static_cast<std::ptrdiff_t>(row*40+col*16+k*4));
|
||||
}
|
||||
const auto cloud=ros::convert_cloud(msg); CHECK(cloud.points.size()==4);
|
||||
CHECK_NEAR(cloud.points[2].position.x(),10,1e-6); CHECK_NEAR(cloud.points[3].intensity,14,1e-6);
|
||||
msg.data.resize(10); bool rejected=false;
|
||||
try { (void)ros::convert_cloud(msg); } catch (const std::exception &) { rejected=true; } CHECK(rejected);
|
||||
const core::Pose3D map_from_base{core::exp_so3({0,0,0.3}),Eigen::Vector3d{1,2,0}};
|
||||
const core::Pose3D odom_from_base{core::exp_so3({0,0,0.2}),Eigen::Vector3d{0.5,1,0}};
|
||||
const auto map_from_odom=core::compose(map_from_base,core::inverse(odom_from_base));
|
||||
const auto recovered=core::compose(ros::from_transform(ros::to_transform(map_from_odom)),odom_from_base);
|
||||
CHECK((recovered.translation-map_from_base.translation).norm()<1e-12);
|
||||
CHECK(core::log_so3(recovered.rotation.conjugate()*map_from_base.rotation).norm()<1e-12);
|
||||
return sentry_nav_test::Summary("RosConversion");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "field_localization/core/tracking_health.hpp"
|
||||
#include "sentry_nav/core/motion_interlock.hpp"
|
||||
#include "test_util.hpp"
|
||||
#include <Eigen/Eigenvalues>
|
||||
using namespace field_localization::core;
|
||||
int main() {
|
||||
// Health recovery counts distinct scans, not 100 Hz IMU callbacks.
|
||||
TrackingHealth health;LocalizationSnapshot s;
|
||||
s.status.has_imu=true;s.status.mode=TrackingMode::FULL;
|
||||
s.filter.covariance=1e-6*Matrix18::Identity();
|
||||
for(int i=1;i<=5;++i) {
|
||||
s.status.accepted_corrections=i;s.status.last_correction_timestamp=s.status.state_timestamp=0.1*i;
|
||||
CHECK(health.update(s,{},0.1*i)==(i==5));
|
||||
for(int j=0;j<20;++j) CHECK(health.update(s,{},0.1*i)==(i==5));
|
||||
}
|
||||
CHECK(health.update(s,{},s.status.state_timestamp-0.022)); // measured /clock delivery skew
|
||||
s.status.mode=TrackingMode::IMU_ONLY;s.status.state_timestamp=0.7;
|
||||
CHECK(health.update(s,{},0.7)); // bounded short IMU-only grace period
|
||||
s.status.state_timestamp=0.81;CHECK(!health.update(s,{},0.81));
|
||||
for(int i=6;i<=10;++i) {
|
||||
s.status.mode=TrackingMode::FULL;s.status.accepted_corrections=i;
|
||||
s.status.last_correction_timestamp=s.status.state_timestamp=0.1*i+0.5;
|
||||
CHECK(health.update(s,{},s.status.state_timestamp)==(i==10));
|
||||
}
|
||||
s.filter.covariance(0,0)=0.04;CHECK(!health.update(s,{},s.status.state_timestamp));
|
||||
s.filter.covariance=1e-6*Matrix18::Identity();CHECK(!health.update(s,{},s.status.state_timestamp));
|
||||
sentry_nav::core::MotionInterlock gate;
|
||||
gate.command(1);CHECK(!gate.allowed(1));gate.health(true,1);CHECK(gate.allowed(1.29));
|
||||
CHECK(!gate.allowed(1.31));gate.command(1.31);CHECK(!gate.allowed(1.31));
|
||||
gate.health(true,1.31);CHECK(gate.allowed(1.31));gate.health(false,1.32);CHECK(!gate.allowed(1.32));
|
||||
CHECK(!gate.allowed(0.9));
|
||||
sentry_nav::core::MotionInterlock manual(false);manual.command(2);CHECK(manual.allowed(2.1));CHECK(!manual.allowed(2.31));
|
||||
return sentry_nav_test::Summary("TrackingSafety");
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "../../sentry_nav/tests/test_util.hpp"
|
||||
#define CHECK(condition) EXPECT_TRUE(condition)
|
||||
#define CHECK_NEAR(actual, expected, tolerance) EXPECT_NEAR(actual, expected, tolerance)
|
||||
@@ -0,0 +1,27 @@
|
||||
Arena validation, 2026-11-22
|
||||
GCC 15.2 / C++23, xmake release, zero compiler warnings; 15/15 test suites.
|
||||
Five-frame contact fixture: all scan corrections accepted; maximum 3D error
|
||||
below 0.10 m. A separate shifted-plane case was rejected by the final NIS
|
||||
gate despite plenty of inliers.
|
||||
|
||||
Isolated Shell and Python launchers used the same map, start (-5,3) and
|
||||
goal (0,0). The added cylinder was centered at (-4,-1.5), radius 0.22 m
|
||||
and height 0.8 m. Acceptance requires Nav2 success, truth goal error <=0.30 m,
|
||||
3D ATE <0.10 m, maximum 3D position error <0.25 m, and nonnegative clearance.
|
||||
The final parameter file has SHA-256
|
||||
ba353622d65e94628689842cbc55052420e529d9cba46cb9aee5742b28a16e9d.
|
||||
|
||||
Cylinder acceptance: Shell 2/3; Python 0/3 (2/3 reached the goal).
|
||||
The two passing runs had cylinder clearances 0.1441 and 0.1215 m and
|
||||
maximum position errors 0.0855 and 0.0798 m. Other runs either exhausted
|
||||
recovery near the cylinder or exceeded the 3D position error criterion.
|
||||
The vertical error reached 0.652 m in a weakly observed direction in one
|
||||
run. The horizontal/yaw interlock does not guarantee vertical accuracy.
|
||||
|
||||
Replay of the passing Shell cylinder: 369/369 corrections, 100% matched
|
||||
truth samples; translation/rotation ATE 0.01992 m / 0.3233 degrees,
|
||||
translation/rotation 1 s RPE 0.01746 m / 0.1919 degrees. No trajectory alignment.
|
||||
Lidar loss in the final Python configuration: first measured zero output
|
||||
310 ms after injection, active goal canceled. No competing AMCL or map-to-odom
|
||||
publisher was present. The original user failure lacks a synchronized recording,
|
||||
and full navigation acceptance remains open.
|
||||
@@ -0,0 +1,25 @@
|
||||
Filter stage validation (2026-11-22, GCC 15.2, C++23, xmake release)
|
||||
|
||||
Confirmed defects: unavailable pose innovations could update correlated velocity/bias states;
|
||||
iterated right-attitude Jacobian did not transport the fixed-prior tangent; failure metrics
|
||||
were lost on early exits; successful-correction age was mislabeled as lidar arrival timeout.
|
||||
|
||||
Tests: existing noisy/bias convergence suites plus FilterConsistency (135 checks) passed.
|
||||
The working tree test run passed 14/14 suites. Build emitted zero compiler warnings.
|
||||
1078-frame Gazebo replay: FULL 1078/1078, ATE translation 0.00985860048 m,
|
||||
ATE rotation 0.193377704 deg, 1s RPE translation 0.00807591639 m,
|
||||
1s RPE rotation 0.0808637461 deg. No alignment; independent PosePublisher truth.
|
||||
159-frame contact/turn segment: FULL 159/159; ATE translation 0.0160423958 m,
|
||||
ATE rotation 0.0967433312 deg; 1s RPE translation 0.0136078463 m,
|
||||
rotation 0.0755077506 deg.
|
||||
|
||||
The recorder's noiseless IMU contains contact acceleration samples up to about 59 m/s^2.
|
||||
Finite-rate integration uncertainty is modeled separately from random sensor noise.
|
||||
A frame-level map/association covariance prevents treating hundreds of correlated point
|
||||
residuals as hundreds of independent absolute pose observations. Defaults: 0.02 m,
|
||||
0.002 rad. Pure exact-map unit fixtures explicitly select zero map uncertainty.
|
||||
|
||||
The user's original unrecorded failure has not been reproduced exactly. This stage fixes
|
||||
confirmed consistency defects and covers recorded integration failures; it does not prove
|
||||
that one defect alone caused the original divergence. Online motion protection and route
|
||||
validation are delivered separately.
|
||||
@@ -0,0 +1,11 @@
|
||||
Protection and transport validation, 2026-11-22
|
||||
GCC 15.2 / C++23 release build emitted zero compiler warnings.
|
||||
The complete working tree passed xmake test (15/15), 15 Nav2 readiness checks,
|
||||
5 supervisor checks and 9 live ROS relay checks. The relay check measured a
|
||||
302 ms zero-output response after final-input publication stopped.
|
||||
|
||||
In an isolated Shell-launched Gazebo run the LiDAR filter process was stopped
|
||||
while driving a Nav2 goal. The first zero actuator command arrived 233 ms after
|
||||
fault injection. Nav2 canceled the active goal and the localization node halted
|
||||
map-to-odom publication. Exactly one map-to-odom publisher and no AMCL were
|
||||
observed. The bridge and filtered point cloud endpoints negotiated RELIABLE QoS.
|
||||
@@ -1,3 +1,8 @@
|
||||
add_requires("pkgconfig::eigen3", {system = true})
|
||||
add_cxxflags("-Wall", "-Wextra")
|
||||
if is_mode("release") then
|
||||
set_optimize("faster")
|
||||
end
|
||||
-- ============================================================================
|
||||
-- Field Localization
|
||||
-- ============================================================================
|
||||
@@ -8,6 +13,8 @@
|
||||
|
||||
local ros_direct_packages = {
|
||||
"rclcpp",
|
||||
"std_srvs",
|
||||
"tf2",
|
||||
"sensor_msgs",
|
||||
"nav_msgs",
|
||||
"geometry_msgs",
|
||||
@@ -15,6 +22,12 @@ local ros_direct_packages = {
|
||||
}
|
||||
|
||||
local message_packages = {
|
||||
"statistics_msgs",
|
||||
"rosgraph_msgs",
|
||||
"rcl_interfaces",
|
||||
"service_msgs",
|
||||
"type_description_interfaces",
|
||||
"std_srvs",
|
||||
"sensor_msgs",
|
||||
"nav_msgs",
|
||||
"geometry_msgs",
|
||||
@@ -64,10 +77,22 @@ local function ros_common()
|
||||
end
|
||||
end
|
||||
|
||||
if not ROS then
|
||||
local distro = os.getenv("ROS_DISTRO")
|
||||
if distro and distro ~= "" then
|
||||
local candidate = "/opt/ros/" .. distro
|
||||
if os.isdir(candidate .. "/include")
|
||||
and os.isdir(candidate .. "/lib") then
|
||||
|
||||
ROS = candidate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not ROS then
|
||||
raise(
|
||||
"ROS installation not found. "
|
||||
.. "Source ROS setup or set ROS_PREFIX."
|
||||
.. "Source ROS setup or set ROS_PREFIX / ROS_DISTRO."
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -75,7 +100,7 @@ local function ros_common()
|
||||
-- Resolve ROS include directories.
|
||||
local script = path.join(
|
||||
target:scriptdir(),
|
||||
"../../tools/resolve_ros_includes.py"
|
||||
"../../tools/_internal/resolve_ros_includes.py"
|
||||
)
|
||||
|
||||
if not os.isfile(script) then
|
||||
@@ -208,7 +233,11 @@ local function ros_common()
|
||||
|
||||
local config = get_ros_config()
|
||||
|
||||
target:add("includedirs", config.includes)
|
||||
local project_include = path.join(target:scriptdir(), "include")
|
||||
for _, dir in ipairs(config.includes) do
|
||||
if dir ~= project_include then target:add("sysincludedirs", dir) end
|
||||
end
|
||||
target:add("includedirs", project_include)
|
||||
|
||||
target:add(
|
||||
"defines",
|
||||
@@ -217,6 +246,7 @@ local function ros_common()
|
||||
|
||||
target:add("linkdirs", config.prefix .. "/lib")
|
||||
target:add("rpathdirs", config.prefix .. "/lib")
|
||||
target:add("runenvs", "LD_LIBRARY_PATH", config.prefix .. "/lib")
|
||||
|
||||
target:add(
|
||||
"linkgroups",
|
||||
@@ -233,13 +263,15 @@ end
|
||||
-- ============================================================================
|
||||
|
||||
target("field_localization_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})
|
||||
add_sysincludedirs("/usr/include/eigen3", {public = true})
|
||||
add_packages("pkgconfig::eigen3", {public = true})
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
@@ -247,6 +279,7 @@ target("field_localization_core")
|
||||
-- ============================================================================
|
||||
|
||||
target("test_localization_core")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
|
||||
@@ -261,10 +294,11 @@ target("test_localization_core")
|
||||
-- ============================================================================
|
||||
|
||||
target("field_localization_ros")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("shared")
|
||||
set_languages("c++23")
|
||||
|
||||
add_files("src/ros/localization_node.cpp")
|
||||
add_files("src/ros/localization_node.cpp", "src/ros/conversion.cpp")
|
||||
|
||||
add_deps("field_localization_core")
|
||||
|
||||
@@ -276,6 +310,7 @@ target("field_localization_ros")
|
||||
-- ============================================================================
|
||||
|
||||
target("field_localization_node")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
|
||||
@@ -283,3 +318,121 @@ target("field_localization_node")
|
||||
|
||||
add_deps("field_localization_ros")
|
||||
ros_common()
|
||||
|
||||
|
||||
target("test_imu_integration")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_imu_integration.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
|
||||
target("test_eskf")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_eskf.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
|
||||
target("test_registration")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_registration.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_lio_synthetic")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_lio_synthetic.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
|
||||
target("test_map_management")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_map_management.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
|
||||
target("field_localization_replay")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("src/tools/replay.cpp")
|
||||
add_deps("field_localization_core")
|
||||
|
||||
target("field_localization_record")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("src/tools/record.cpp")
|
||||
add_deps("field_localization_ros")
|
||||
ros_common()
|
||||
|
||||
target("test_dataset")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_dataset.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_ros_conversion")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_ros_conversion.cpp")
|
||||
add_deps("field_localization_ros")
|
||||
ros_common()
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_tracking_safety")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_tracking_safety.cpp")
|
||||
add_includedirs("../sentry_nav/include")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_field_tracking")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_field_tracking.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_filter_consistency")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_filter_consistency.cpp")
|
||||
add_deps("field_localization_core")
|
||||
add_tests("default", {group = "unit"})
|
||||
|
||||
target("test_recorded_update")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
set_languages("c++23")
|
||||
add_files("tests/test_recorded_update.cpp")
|
||||
add_deps("field_localization_core")
|
||||
on_load(function(target)
|
||||
local fixtures = path.join(os.projectdir(), "src/field_localization/tests/data")
|
||||
target:set("runargs", {
|
||||
path.join(fixtures, "turn_contact"),
|
||||
path.join(fixtures, "return_contact"),
|
||||
path.join(fixtures, "return_cylinder"),
|
||||
})
|
||||
end)
|
||||
add_tests("default", {group = "unit"})
|
||||
@@ -20,7 +20,7 @@ xmake # 约 9 秒(首次),增量 0.5 秒
|
||||
xmake test # 3 个套件 223 项,约 5 ms
|
||||
```
|
||||
|
||||
产物在**仓库根**的 `build/linux/x86_64/release/{self_filter,patrol}`。
|
||||
产物在**仓库根**的 `build/bin/{self_filter,patrol}`。
|
||||
|
||||
| | 现在(纯 xmake) | 以前(colcon 侧) |
|
||||
|---|---|---|
|
||||
@@ -64,7 +64,7 @@ HEADLESS=0 scripts/sentry_up.sh # 节点自动从 build/ 取,不需要
|
||||
|
||||
| 能力 | 现在 | 备注 |
|
||||
|---|---|---|
|
||||
| `ros2 run sentry_nav xxx` | ❌ | 直接跑 `build/linux/x86_64/release/xxx` |
|
||||
| `ros2 run sentry_nav xxx` | ❌ | 直接跑 `build/bin/xxx` |
|
||||
| `ros2 launch sentry_nav/sentry_sim …` | ❌ | 主入口一直是 `scripts/sentry_up.sh` |
|
||||
| `ros2 pkg prefix` / `ament_index` | ❌ | `PKG_SHARE` 直接指 `src/sentry_sim` |
|
||||
| **自定义 `.msg` / `.srv` 代码生成** | ❌ | **以后要加消息类型就必须重新引入 colcon**(xmake 生成不了 ROS 消息的 C++/Python 绑定) |
|
||||
@@ -153,10 +153,10 @@ cd ~/Gazebo_projects/sentry_nav_dev
|
||||
source /opt/ros/lyrical/setup.bash
|
||||
|
||||
# 点云自滤(已由 scripts/sentry_up.sh 自动启动,单独跑用于调试)
|
||||
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 \
|
||||
build/bin/patrol --ros-args -p use_sim_time:=true \
|
||||
-p loop:=false -p waypoints:="[2.0, 2.0, 4.0, 3.0, 3.0, 5.0]"
|
||||
```
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
```bash
|
||||
cd ~/Gazebo_projects/sentry_nav_dev
|
||||
build/linux/x86_64/release/patrol --ros-args -p loop:=false -p waypoints:="[2.0, 2.0, 4.0, 3.0]"
|
||||
build/bin/patrol --ros-args -p loop:=false -p waypoints:="[2.0, 2.0, 4.0, 3.0]"
|
||||
```
|
||||
|
||||
> 本工程不使用 ament/colcon,**没有 `ros2 run`**,直接跑二进制。
|
||||
@@ -21,7 +21,7 @@ build/linux/x86_64/release/patrol --ros-args -p loop:=false -p waypoints:="[2.0,
|
||||
|
||||
```bash
|
||||
cd ~/Gazebo_projects/sentry_nav_dev
|
||||
build/linux/x86_64/release/patrol --ros-args \
|
||||
build/bin/patrol --ros-args \
|
||||
--params-file src/sentry_nav/config/xxx.yaml
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
namespace sentry_nav::core {
|
||||
// All times are monotonic wall seconds: a paused or rewound /clock cannot defeat a stop.
|
||||
class MotionInterlock {
|
||||
public:
|
||||
explicit MotionInterlock(bool navigation=true,double timeout=0.3):navigation_(navigation),timeout_(timeout) {}
|
||||
void health(bool valid,double time) { healthy_=valid; health_time_=time; }
|
||||
void command(double time) { command_time_=time; }
|
||||
bool allowed(double time) const {
|
||||
auto fresh=[&](double stamp) { return stamp>=0 && time>=stamp && time-stamp<=timeout_; };
|
||||
return std::isfinite(time) && fresh(command_time_) && localization_valid(time);
|
||||
}
|
||||
bool localization_valid(double time) const {
|
||||
return !navigation_ || (healthy_ && health_time_>=0 && time>=health_time_ && time-health_time_<=timeout_);
|
||||
}
|
||||
private:
|
||||
bool navigation_,healthy_{false};
|
||||
double timeout_,health_time_{-1},command_time_{-1};
|
||||
};
|
||||
} // namespace sentry_nav::core
|
||||
@@ -21,15 +21,16 @@ namespace sentry_nav {
|
||||
|
||||
// 自滤参数。单位统一为米,坐标系为 base_link。
|
||||
struct FilterParams {
|
||||
// 车身包围盒。车身真实尺寸约 x±0.288 / y±0.26,这里留了 ~10 cm 余量:
|
||||
// 雷达偏后挂在车里,车身对角距传感器约 0.56 m,盒子太小会漏掉自己的点,
|
||||
// 代价地图就会把车标成障碍、导致规划失败。
|
||||
float box_min_x = -0.40f;
|
||||
float box_max_x = 0.40f;
|
||||
float box_min_y = -0.38f;
|
||||
float box_max_y = 0.38f;
|
||||
// Keep the lateral limits close to the chassis (y +/-0.2605 m). Gazebo
|
||||
// lidar range noise puts gimbal returns beyond its physical x=0.32 m and
|
||||
// z=0.50 m limits. The recorded stationary envelope reaches x=0.357 m
|
||||
// and z=0.530 m, so retain margin at the front and above the gimbal.
|
||||
float box_min_x = -0.294f;
|
||||
float box_max_x = 0.365f;
|
||||
float box_min_y = -0.2655f;
|
||||
float box_max_y = 0.2655f;
|
||||
float box_min_z = -0.05f;
|
||||
float box_max_z = 0.60f;
|
||||
float box_max_z = 0.545f;
|
||||
|
||||
float keep_min_z = 0.02f; // 低于此高度视为地面/噪声
|
||||
float max_range = 12.0f; // 水平距离上限
|
||||
|
||||
@@ -14,7 +14,7 @@ src/
|
||||
```
|
||||
|
||||
两个 `.cpp` 各自 `main()`,编出来就是两个独立可执行文件
|
||||
(`build/linux/x86_64/release/self_filter` 和 `patrol`)。
|
||||
(`build/bin/self_filter` 和 `patrol`)。
|
||||
|
||||
## 这两个文件只准写"胶水"
|
||||
|
||||
@@ -58,7 +58,7 @@ src/
|
||||
|
||||
```bash
|
||||
cd ~/Gazebo_projects/sentry_nav_dev
|
||||
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]"
|
||||
```
|
||||
|
||||
@@ -92,7 +92,7 @@ target("xxx")
|
||||
cd ~/Gazebo_projects/sentry_nav_dev
|
||||
xmake # 编译
|
||||
python3 tools/check_stack.py # 体检当前跑着的栈
|
||||
build/linux/x86_64/release/patrol ... # 单独跑某个节点
|
||||
build/bin/patrol ... # 单独跑某个节点
|
||||
```
|
||||
|
||||
详见 [`../README.md`](../README.md) 与 [`../../docs/构建体系与代码分层.md`](../../../docs/构建体系与代码分层.md)。
|
||||
@@ -1,95 +1,102 @@
|
||||
// Copyright 2026 sentry_nav_dev
|
||||
//
|
||||
// cmd_vel_relay:把 Nav2 的 /cmd_vel_smoothed(及兼容的 /cmd_vel、/cmd_vel_nav)
|
||||
// 转发到 ros_gz 桥用的 /model/sentry/cmd_vel。
|
||||
// (C++ 版,2026-11-17 从 scripts/cmd_vel_relay.py 移植;用户要求能 C++ 就 C++。)
|
||||
//
|
||||
// 为什么需要:Gazebo 的 MecanumDrive 插件订阅的是「模型名/cmd_vel」(即
|
||||
// /model/sentry/cmd_vel),而 ros_gz_bridge 只支持「两端同名」的桥接,
|
||||
// 它无法把 ROS 的 /cmd_vel 映射到 gz 的 /model/sentry/cmd_vel。
|
||||
// 所以这里做一次 ROS 侧的改名转发。
|
||||
//
|
||||
// 平滑命令优先:Nav2 的速度链是「控制器发 /cmd_vel(原始)→ velocity_smoother
|
||||
// 订阅 /cmd_vel 并发布 /cmd_vel_smoothed(限加速度、去死区)」。车只该吃最终
|
||||
// 那条命令。之前三路都转发 → 平滑前后的命令在 gz 侧交替打架,车会抖、走着
|
||||
// 走着就 "Failed to make progress"。现在:/cmd_vel_smoothed 优先;它最近
|
||||
// 200 ms 内有消息时丢弃其它来源;只在平滑器没输出时(如 NAV2=0 手发 /cmd_vel)
|
||||
// 回退到原始命令。
|
||||
//
|
||||
// 参数:
|
||||
// out_topic /model/sentry/cmd_vel 转发目标
|
||||
// in_topics [/cmd_vel_smoothed, /cmd_vel, /cmd_vel_nav]
|
||||
|
||||
#include <cstdint>
|
||||
// Final actuator input only. Never bypass velocity smoothing or collision_monitor.
|
||||
#include "sentry_nav/core/motion_interlock.hpp"
|
||||
#include <action_msgs/srv/cancel_goal.hpp>
|
||||
#include <geometry_msgs/msg/twist.hpp>
|
||||
#include <std_msgs/msg/bool.hpp>
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <geometry_msgs/msg/twist.hpp>
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
|
||||
namespace sentry_nav
|
||||
{
|
||||
|
||||
class CmdVelRelay : public rclcpp::Node
|
||||
{
|
||||
namespace sentry_nav {
|
||||
class CmdVelRelay : public rclcpp::Node {
|
||||
public:
|
||||
CmdVelRelay() : Node("cmd_vel_relay")
|
||||
{
|
||||
const std::string out_topic =
|
||||
declare_parameter<std::string>("out_topic", "/model/sentry/cmd_vel");
|
||||
in_topics_ = declare_parameter<std::vector<std::string>>(
|
||||
"in_topics", std::vector<std::string>{"/cmd_vel_smoothed", "/cmd_vel", "/cmd_vel_nav"});
|
||||
|
||||
pub_ = create_publisher<geometry_msgs::msg::Twist>(out_topic, 10);
|
||||
for (const std::string & topic : in_topics_) {
|
||||
subs_.push_back(
|
||||
create_subscription<geometry_msgs::msg::Twist>(
|
||||
topic, 10,
|
||||
[this, topic](const geometry_msgs::msg::Twist::SharedPtr msg) {
|
||||
OnTwist(topic, msg);
|
||||
}));
|
||||
}
|
||||
|
||||
std::string joined;
|
||||
for (size_t i = 0; i < in_topics_.size(); ++i) {
|
||||
joined += (i == 0 ? "" : ", ") + in_topics_[i];
|
||||
}
|
||||
RCLCPP_INFO(
|
||||
get_logger(), "cmd_vel_relay: [%s] -> %s(平滑命令优先)",
|
||||
joined.c_str(), out_topic.c_str());
|
||||
CmdVelRelay():Node("cmd_vel_relay") {
|
||||
navigation_=declare_parameter<bool>("navigation_mode",true);
|
||||
const double timeout=declare_parameter<double>("command_timeout",0.3);
|
||||
if(!std::isfinite(timeout) || timeout<=0) throw std::invalid_argument("invalid command_timeout");
|
||||
require_health_=declare_parameter<bool>("require_localization_health",true);
|
||||
gate_=core::MotionInterlock(navigation_ && require_health_,timeout);
|
||||
const auto input=declare_parameter<std::string>("in_topic","/cmd_vel");
|
||||
const auto output=declare_parameter<std::string>("out_topic","/model/sentry/cmd_vel");
|
||||
pub_=create_publisher<geometry_msgs::msg::Twist>(output,1);
|
||||
sub_=create_subscription<geometry_msgs::msg::Twist>(input,rclcpp::QoS(1),[this](geometry_msgs::msg::Twist::ConstSharedPtr msg) {
|
||||
const auto &v=*msg;
|
||||
const bool finite=std::isfinite(v.linear.x) && std::isfinite(v.linear.y) && std::isfinite(v.linear.z) &&
|
||||
std::isfinite(v.angular.x) && std::isfinite(v.angular.y) && std::isfinite(v.angular.z);
|
||||
if(!finite) { pub_->publish(geometry_msgs::msg::Twist{}); return; }
|
||||
gate_.command(seconds());
|
||||
const bool allowed=gate_.allowed(seconds()) && !cancel_pending();
|
||||
pub_->publish(allowed ? v : geometry_msgs::msg::Twist{});
|
||||
if(navigation_ && !allowed && nonzero(v)) request_stop();
|
||||
});
|
||||
health_sub_=create_subscription<std_msgs::msg::Bool>("/field_localization/navigation_valid",rclcpp::QoS(1),
|
||||
[this](std_msgs::msg::Bool::ConstSharedPtr msg) { gate_.health(msg->data,seconds()); });
|
||||
const std::array<std::string,2> actions{"/navigate_to_pose","/navigate_through_poses"};
|
||||
for(std::size_t i=0;i<actions.size();++i)
|
||||
cancel_[i]=create_client<action_msgs::srv::CancelGoal>(actions[i]+"/_action/cancel_goal");
|
||||
timer_=create_wall_timer(std::chrono::milliseconds(20),[this] {
|
||||
const double time=seconds();
|
||||
const bool allowed=gate_.allowed(time);
|
||||
if(!allowed || cancel_pending()) pub_->publish(geometry_msgs::msg::Twist{});
|
||||
const bool localized=gate_.localization_valid(time);
|
||||
if(was_localized_ && !localized && navigation_) request_stop();
|
||||
was_localized_=localized;
|
||||
// A command timeout always stops motion, but can occur normally while a
|
||||
// recovery waits with zero output. Only localization loss cancels the goal.
|
||||
if(time-last_cancel_>=0.5) cancel_goals();
|
||||
});
|
||||
RCLCPP_INFO(get_logger(),"cmd_vel_relay: %s -> %s navigation_mode=%d timeout=%.3fs; final output only",
|
||||
input.c_str(),output.c_str(),navigation_,timeout);
|
||||
}
|
||||
|
||||
private:
|
||||
void OnTwist(
|
||||
const std::string & topic,
|
||||
const geometry_msgs::msg::Twist::SharedPtr & msg)
|
||||
{
|
||||
const int64_t now_ns = now().nanoseconds();
|
||||
if (topic == "/cmd_vel_smoothed") {
|
||||
last_smoothed_ns_ = now_ns;
|
||||
pub_->publish(*msg);
|
||||
return;
|
||||
}
|
||||
// 平滑器正在输出:丢弃原始/其它来源,避免两路命令打架
|
||||
if (last_smoothed_ns_ != 0 && now_ns - last_smoothed_ns_ < 200'000'000LL) {
|
||||
return;
|
||||
}
|
||||
pub_->publish(*msg);
|
||||
static double seconds() { return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count(); }
|
||||
static bool nonzero(const geometry_msgs::msg::Twist &v) {
|
||||
return v.linear.x!=0 || v.linear.y!=0 || v.linear.z!=0 || v.angular.x!=0 || v.angular.y!=0 || v.angular.z!=0;
|
||||
}
|
||||
|
||||
bool cancel_pending() const { return pending_[0] || pending_[1]; }
|
||||
void request_stop() {
|
||||
if(!cancel_pending()) {
|
||||
pending_.fill(true);
|
||||
RCLCPP_ERROR(get_logger(),"motion interlock: localization/command invalid; stopping and canceling navigation goals");
|
||||
}
|
||||
}
|
||||
void cancel_goals() {
|
||||
last_cancel_=seconds();
|
||||
for(std::size_t i=0;i<cancel_.size();++i) {
|
||||
if(inflight_[i] && last_cancel_-sent_at_[i]>1.0) {
|
||||
cancel_[i]->remove_pending_request(request_ids_[i]); inflight_[i]=false;
|
||||
}
|
||||
if(!pending_[i] || inflight_[i] || !cancel_[i]->service_is_ready()) continue;
|
||||
inflight_[i]=true;
|
||||
// Zero UUID/stamp cancels goals belonging to this Nav2 action server only.
|
||||
auto request=std::make_shared<action_msgs::srv::CancelGoal::Request>();
|
||||
const auto request_token=cancel_[i]->async_send_request(request,[this,i](rclcpp::Client<action_msgs::srv::CancelGoal>::SharedFuture response) {
|
||||
inflight_[i]=false;
|
||||
if(response.get()->return_code==action_msgs::srv::CancelGoal::Response::ERROR_NONE)
|
||||
pending_[i]=false;
|
||||
});
|
||||
request_ids_[i]=request_token.request_id; sent_at_[i]=last_cancel_;
|
||||
}
|
||||
}
|
||||
core::MotionInterlock gate_;
|
||||
bool navigation_{true},require_health_{true},was_localized_{false};
|
||||
double last_cancel_{-1};
|
||||
std::array<std::int64_t,2> request_ids_{};
|
||||
std::array<double,2> sent_at_{};
|
||||
std::array<bool,2> pending_{false,false},inflight_{false,false};
|
||||
std::array<rclcpp::Client<action_msgs::srv::CancelGoal>::SharedPtr,2> cancel_;
|
||||
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr pub_;
|
||||
std::vector<rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr> subs_;
|
||||
std::vector<std::string> in_topics_;
|
||||
int64_t last_smoothed_ns_ = 0;
|
||||
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr sub_;
|
||||
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr health_sub_;
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
} // namespace sentry_nav
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::spin(std::make_shared<sentry_nav::CmdVelRelay>());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
} // namespace sentry_nav
|
||||
int main(int argc,char **argv) {
|
||||
rclcpp::init(argc,argv);
|
||||
try { rclcpp::spin(std::make_shared<sentry_nav::CmdVelRelay>()); }
|
||||
catch(const std::exception &e) { std::fprintf(stderr,"cmd_vel_relay: %s\n",e.what()); rclcpp::shutdown(); return 1; }
|
||||
rclcpp::shutdown(); return 0;
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
// 导航测试客户端(C++ 版,替代原 tools/nav_client.py)。
|
||||
//
|
||||
// 用法(本工程不用 ament/colcon,直接跑 xmake 产物):
|
||||
// build/linux/x86_64/release/nav_client <x> <y> [yaw度]
|
||||
// build/linux/x86_64/release/nav_client 0.0 0.0 # 走到场地中心
|
||||
// build/linux/x86_64/release/nav_client 0.0 0.0 90 # 到位置后朝向 +90°
|
||||
// build/linux/x86_64/release/nav_client -4.0 0.0 --force # 明知在障碍里也发(调试用)
|
||||
// 产物目录随平台三元组变,先取到它:
|
||||
// BIN=$(python3 tools/project_env.py --bin-dir)
|
||||
// $BIN/nav_client <x> <y> [yaw度]
|
||||
// $BIN/nav_client 0.0 0.0 # 走到场地中心
|
||||
// $BIN/nav_client 0.0 0.0 90 # 到位置后朝向 +90°
|
||||
// $BIN/nav_client -4.0 0.0 --force # 明知在障碍里也发(调试用)
|
||||
//
|
||||
// 坐标是 map 帧(场地中心 = (0,0)):x∈[-6,6],y∈[-4,4]。
|
||||
//
|
||||
@@ -26,6 +28,7 @@
|
||||
#include <cstdlib>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -35,6 +38,7 @@
|
||||
#include <nav2_msgs/action/navigate_to_pose.hpp>
|
||||
#include <nav_msgs/msg/occupancy_grid.hpp>
|
||||
#include <geometry_msgs/msg/pose_stamped.hpp>
|
||||
#include <std_msgs/msg/bool.hpp>
|
||||
#include <tf2_ros/buffer.hpp>
|
||||
#include <tf2_ros/transform_listener.hpp>
|
||||
|
||||
@@ -54,6 +58,7 @@ constexpr int kOccupiedThreshold = 65;
|
||||
constexpr double kClearanceSearch = 2.0;
|
||||
// 圆周率(避开 M_PI —— 严格 C++ 里它不是标准宏)。
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
constexpr auto kLocalizationFreshness = 300ms;
|
||||
|
||||
struct Args
|
||||
{
|
||||
@@ -164,6 +169,14 @@ int main(int argc, char * argv[])
|
||||
|
||||
tf2_ros::Buffer tf_buffer(node->get_clock());
|
||||
tf2_ros::TransformListener tf_listener(tf_buffer);
|
||||
std::optional<std::chrono::steady_clock::time_point> last_health;
|
||||
bool localization_valid = false;
|
||||
auto health_sub = node->create_subscription<std_msgs::msg::Bool>(
|
||||
"/field_localization/navigation_valid", rclcpp::QoS(1),
|
||||
[&](const std_msgs::msg::Bool & msg) {
|
||||
last_health = std::chrono::steady_clock::now();
|
||||
localization_valid = msg.data;
|
||||
});
|
||||
|
||||
// /map 是 TRANSIENT_LOCAL 发布的,用默认 QoS 会一条都收不到。
|
||||
auto map_qos = rclcpp::QoS(rclcpp::KeepLast(1))
|
||||
@@ -183,16 +196,19 @@ int main(int argc, char * argv[])
|
||||
holder.got = true;
|
||||
});
|
||||
|
||||
rclcpp::executors::SingleThreadedExecutor map_executor;
|
||||
map_executor.add_node(node);
|
||||
const auto wait_start = std::chrono::steady_clock::now();
|
||||
while (!holder.got &&
|
||||
std::chrono::steady_clock::now() - wait_start < 15s)
|
||||
{
|
||||
rclcpp::spin_some(node);
|
||||
map_executor.spin_some();
|
||||
std::this_thread::sleep_for(20ms);
|
||||
}
|
||||
|
||||
map_executor.remove_node(node);
|
||||
if (!holder.got) {
|
||||
std::printf("⚠️ 15 秒内没收到 /map,跳过预检直接发目标\n");
|
||||
std::printf("⚠️ 15 秒内没收到 /map,跳过静态地图预检\n");
|
||||
} else {
|
||||
const auto & info = holder.last.info;
|
||||
const auto & data = holder.last.data;
|
||||
@@ -230,7 +246,7 @@ int main(int argc, char * argv[])
|
||||
std::printf(
|
||||
" 净空只有 %.2f m,车身半对角就有 %.2f m,挤进去会卡死。\n", clr, kHalfDiagonal);
|
||||
}
|
||||
std::printf(" 想找安全点:python3 tools/free_goals.py\n");
|
||||
std::printf(" 换一个开阔的点,或先在 RViz 里看一眼 /global_costmap/costmap。\n");
|
||||
if (!args.force) {
|
||||
std::printf(" (确实要发就加 --force)\n");
|
||||
rclcpp::shutdown();
|
||||
@@ -249,6 +265,54 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
std::printf("✅ 动作服务器可用\n");
|
||||
|
||||
// Give discovery and the TF listener a bounded window before sending a goal.
|
||||
// AMCL has no LIO heartbeat and uses the same fresh TF check.
|
||||
auto localization_error = [&]() -> const char * {
|
||||
if (last_health || health_sub->get_publisher_count() > 0) {
|
||||
if (!last_health || std::chrono::steady_clock::now() - *last_health > kLocalizationFreshness) {
|
||||
return "LIO 有效性心跳缺失或过期";
|
||||
}
|
||||
if (!localization_valid) {
|
||||
return "LIO 有效性心跳为 false";
|
||||
}
|
||||
}
|
||||
const auto now = node->now();
|
||||
if (now.nanoseconds() <= 0) {
|
||||
return "未收到仿真时钟";
|
||||
}
|
||||
try {
|
||||
const auto transform = tf_buffer.lookupTransform("map", "base_link", rclcpp::Time(0));
|
||||
const rclcpp::Time stamp(transform.header.stamp, now.get_clock_type());
|
||||
if (stamp.nanoseconds() <= 0 ||
|
||||
(now - stamp).nanoseconds() >
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(kLocalizationFreshness).count())
|
||||
{
|
||||
return "map → base_link TF 已过期";
|
||||
}
|
||||
} catch (const tf2::TransformException &) {
|
||||
return "map → base_link TF 不连通";
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
map_executor.add_node(node);
|
||||
const auto localization_deadline = std::chrono::steady_clock::now() + 5s;
|
||||
const char * reason = nullptr;
|
||||
do {
|
||||
map_executor.spin_some();
|
||||
reason = localization_error();
|
||||
if (reason == nullptr) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(20ms);
|
||||
} while (rclcpp::ok() && std::chrono::steady_clock::now() < localization_deadline);
|
||||
map_executor.remove_node(node);
|
||||
if (reason != nullptr) {
|
||||
std::printf("❌ 定位不可用:%s。未发送导航目标。\n", reason);
|
||||
rclcpp::shutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
NavigateToPose::Goal goal;
|
||||
goal.pose.header.frame_id = "map";
|
||||
goal.pose.header.stamp = node->now();
|
||||
@@ -283,7 +347,7 @@ int main(int argc, char * argv[])
|
||||
if (rclcpp::spin_until_future_complete(node, goal_future, 15s) !=
|
||||
rclcpp::FutureReturnCode::SUCCESS)
|
||||
{
|
||||
std::printf("❌ 目标被拒绝(耗时 %.1f s)\n", 0.0);
|
||||
std::printf("❌ 等待 Nav2 确认目标超时或中断\n");
|
||||
rclcpp::shutdown();
|
||||
return 1;
|
||||
}
|
||||
@@ -308,19 +372,34 @@ int main(int argc, char * argv[])
|
||||
const double elapsed =
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - t_goal).count();
|
||||
|
||||
int exit_code = 1;
|
||||
if (result_future.valid() && result_future.wait_for(0s) == std::future_status::ready) {
|
||||
const auto code = result_future.get().code;
|
||||
const auto result = result_future.get();
|
||||
const auto code = result.code;
|
||||
const char * name = "❌ 未知状态";
|
||||
if (code == rclcpp_action::ResultCode::SUCCEEDED) {
|
||||
name = "✅ SUCCEEDED";
|
||||
exit_code = 0;
|
||||
} else if (code == rclcpp_action::ResultCode::CANCELED) {
|
||||
name = "❌ CANCELED";
|
||||
} else if (code == rclcpp_action::ResultCode::ABORTED) {
|
||||
name = "❌ ABORTED";
|
||||
}
|
||||
std::printf("结果: %s 导航耗时 %.1f s\n", name, elapsed);
|
||||
if (result.result) {
|
||||
std::printf("Nav2 error_code=%u error_msg=%s\n",
|
||||
static_cast<unsigned>(result.result->error_code), result.result->error_msg.c_str());
|
||||
}
|
||||
} else {
|
||||
std::printf("超时未完成(180 s,已等待 %.0f s)\n", elapsed);
|
||||
std::printf("超时或中断(上限 180 s,已等待 %.0f s)\n", elapsed);
|
||||
if (rclcpp::ok()) {
|
||||
try {
|
||||
auto canceled = client->async_cancel_goal(handle);
|
||||
(void)rclcpp::spin_until_future_complete(node, canceled, 1s);
|
||||
} catch (const rclcpp_action::exceptions::UnknownGoalHandleError &) {
|
||||
// The server can finish the goal while the timeout is being handled.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -335,5 +414,5 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
return exit_code;
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
// 看起来像被拖着的箱子;真机上枪口在车头,朝向错了等于枪口朝后。
|
||||
//
|
||||
// 用法(本工程不用 ament/colcon,没有 ros2 run,直接跑 xmake 产物):
|
||||
// build/linux/x86_64/release/patrol --ros-args
|
||||
// build/bin/patrol --ros-args
|
||||
// -p waypoints:="[-5.1,0.0, -4.0,-2.0, -2.0,-2.0, 0.0,0.0]"
|
||||
// (`--ros-args` 后面原本有个行尾反斜杠,会触发 -Wcomment 警告,已去掉;
|
||||
// 真要换行请用 shell 的续行,别在注释里留反斜杠)
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -87,14 +89,30 @@ public:
|
||||
declare_parameter<double>("max_range", params.max_range));
|
||||
|
||||
core_ = std::make_unique<sentry_nav::SelfFilterCore>(params);
|
||||
const auto lio_topic = declare_parameter<std::string>("lio_output_topic", "/scan/points_lio");
|
||||
if (!lio_topic.empty()) {
|
||||
if (lio_topic == output_topic_) {
|
||||
throw std::invalid_argument("lio_output_topic must differ from the obstacle cloud topic");
|
||||
}
|
||||
auto lio_params = params;
|
||||
lio_params.keep_min_z = static_cast<float>(declare_parameter<double>("lio_keep_min_z", -0.25));
|
||||
// Keep the floor outside the body footprint without admitting underbody returns.
|
||||
lio_params.box_min_z = std::min(lio_params.box_min_z, lio_params.keep_min_z);
|
||||
lio_core_ = std::make_unique<sentry_nav::SelfFilterCore>(lio_params);
|
||||
lio_pub_ = create_publisher<sensor_msgs::msg::PointCloud2>(lio_topic, rclcpp::QoS(5).reliable());
|
||||
RCLCPP_INFO(get_logger(), "LIO cloud: %s (keep_min_z=%.2f)", lio_topic.c_str(), lio_params.keep_min_z);
|
||||
}
|
||||
|
||||
tf_buffer_ = std::make_unique<tf2_ros::Buffer>(get_clock());
|
||||
tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
|
||||
|
||||
// 用 SensorDataQoS:点云量大,BEST_EFFORT 更合适
|
||||
pub_ = create_publisher<sensor_msgs::msg::PointCloud2>(output_topic_, rclcpp::SensorDataQoS());
|
||||
// Reliable filtered output lets localization recover a lost UDP fragment.
|
||||
// Keep a best-effort input option for external sensor drivers.
|
||||
const bool reliable=declare_parameter<bool>("reliable_clouds",false);
|
||||
const rclcpp::QoS input_qos=reliable ? rclcpp::QoS(5).reliable() : rclcpp::SensorDataQoS();
|
||||
pub_ = create_publisher<sensor_msgs::msg::PointCloud2>(output_topic_, rclcpp::QoS(5).reliable());
|
||||
sub_ = create_subscription<sensor_msgs::msg::PointCloud2>(
|
||||
input_topic_, rclcpp::SensorDataQoS(),
|
||||
input_topic_, input_qos,
|
||||
[this](sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) { OnCloud(msg); });
|
||||
|
||||
// /scan2d:由过滤后的点云投影出的 2D 激光,AMCL 做定位用(collision_monitor 也吃它)。
|
||||
@@ -146,10 +164,18 @@ private:
|
||||
filtered.reserve(raw.size());
|
||||
|
||||
// 只做遍历和搬运,判定逻辑全在 core_ 里(可单测)。
|
||||
const bool publish_lio = lio_pub_ && lio_pub_->get_subscription_count() > 0;
|
||||
pcl::PointCloud<pcl::PointXYZ> lio_cloud;
|
||||
if (publish_lio) {
|
||||
lio_cloud.reserve(raw.size());
|
||||
}
|
||||
for (const auto & pt : raw) {
|
||||
if (core_->Keep(pt.x, pt.y, pt.z)) {
|
||||
filtered.push_back(pt);
|
||||
}
|
||||
if (publish_lio && lio_core_->Keep(pt.x, pt.y, pt.z)) {
|
||||
lio_cloud.push_back(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// 统计保留率,调参时有用(DEBUG 级别,默认不刷屏)
|
||||
@@ -163,16 +189,27 @@ private:
|
||||
static_cast<unsigned long long>(total_out_),
|
||||
static_cast<unsigned long long>(total_in_));
|
||||
|
||||
sensor_msgs::msg::PointCloud2 out;
|
||||
pcl::toROSMsg(filtered, out);
|
||||
out.header.stamp = msg->header.stamp;
|
||||
out.header.frame_id = target_frame_;
|
||||
pub_->publish(out);
|
||||
PublishCloud(filtered, msg->header.stamp, *pub_);
|
||||
if (publish_lio) {
|
||||
PublishCloud(lio_cloud, msg->header.stamp, *lio_pub_);
|
||||
}
|
||||
|
||||
// 同一份过滤结果再投影成 2D 激光:不新增订阅/进程,数据一致。
|
||||
PublishScan(filtered, msg->header.stamp);
|
||||
}
|
||||
|
||||
void PublishCloud(
|
||||
const pcl::PointCloud<pcl::PointXYZ> & cloud,
|
||||
const builtin_interfaces::msg::Time & stamp,
|
||||
rclcpp::Publisher<sensor_msgs::msg::PointCloud2> & publisher)
|
||||
{
|
||||
sensor_msgs::msg::PointCloud2 out;
|
||||
pcl::toROSMsg(cloud, out);
|
||||
out.header.stamp = stamp;
|
||||
out.header.frame_id = target_frame_;
|
||||
publisher.publish(out);
|
||||
}
|
||||
|
||||
// 把过滤后的点云(已在 base_link 系)投影成 2D 激光:
|
||||
// 每个方位格取该格内最小水平距离,z 只取车体碰撞带 [scan_height_min, scan_height_max]。
|
||||
// 这样投影结果与地图的「体积投影」在同一高度带,避免 AMCL 因高度失配把粒子整团迁走。
|
||||
@@ -220,6 +257,7 @@ private:
|
||||
std::string scan_topic_;
|
||||
|
||||
std::unique_ptr<sentry_nav::SelfFilterCore> core_;
|
||||
std::unique_ptr<sentry_nav::SelfFilterCore> lio_core_;
|
||||
|
||||
std::uint64_t total_in_{0};
|
||||
std::uint64_t total_out_{0};
|
||||
@@ -233,6 +271,7 @@ private:
|
||||
std::unique_ptr<tf2_ros::Buffer> tf_buffer_;
|
||||
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
|
||||
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_;
|
||||
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr lio_pub_;
|
||||
rclcpp::Publisher<sensor_msgs::msg::LaserScan>::SharedPtr scan_pub_;
|
||||
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_;
|
||||
};
|
||||
|
||||
@@ -17,10 +17,10 @@ int main() {
|
||||
const SelfFilterCore filter{FilterParams{}};
|
||||
|
||||
// ---------- 1. 车身包围盒内的点必须剔除 ----------
|
||||
// 雷达前方/侧面/上方,只要落在 x∈(-0.4,0.4) y∈(-0.38,0.38) z∈(-0.05,0.6) 就剔
|
||||
// Chassis and noisy forward gimbal returns.
|
||||
EXPECT_EQ(filter.Classify(0.0f, 0.0f, 0.30f), DropReason::kInsideEgoBox);
|
||||
EXPECT_EQ(filter.Classify(0.35f, 0.30f, 0.50f), DropReason::kInsideEgoBox);
|
||||
EXPECT_EQ(filter.Classify(-0.35f, -0.30f, 0.10f), DropReason::kInsideEgoBox);
|
||||
EXPECT_EQ(filter.Classify(0.28f, 0.25f, 0.50f), DropReason::kInsideEgoBox);
|
||||
EXPECT_EQ(filter.Classify(-0.28f, -0.25f, 0.10f), DropReason::kInsideEgoBox);
|
||||
EXPECT_FALSE(filter.Keep(0.0f, 0.0f, 0.30f));
|
||||
|
||||
// ---------- 2. 盒子外的点必须保留 ----------
|
||||
@@ -56,13 +56,17 @@ int main() {
|
||||
EXPECT_EQ(filter.Classify(1.0f, -kInf, 0.30f), DropReason::kNonFinite);
|
||||
|
||||
// ---------- 6. 边界:盒面用严格不等号,落在面上算保留 ----------
|
||||
EXPECT_TRUE(filter.Keep(0.40f, 0.0f, 0.30f)); // x == box_max_x
|
||||
EXPECT_TRUE(filter.Keep(-0.40f, 0.0f, 0.30f)); // x == box_min_x
|
||||
EXPECT_TRUE(filter.Keep(0.0f, 0.38f, 0.30f)); // y == box_max_y
|
||||
EXPECT_TRUE(filter.Keep(0.0f, 0.0f, 0.60f)); // z == box_max_z
|
||||
EXPECT_TRUE(filter.Keep(0.365f, 0.0f, 0.30f)); // x == box_max_x
|
||||
EXPECT_TRUE(filter.Keep(-0.294f, 0.0f, 0.30f)); // x == box_min_x
|
||||
EXPECT_TRUE(filter.Keep(0.0f, 0.2655f, 0.30f)); // y == box_max_y
|
||||
EXPECT_TRUE(filter.Keep(0.0f, 0.0f, 0.545f)); // z == box_max_z
|
||||
// 稍微往里一点就该被剔
|
||||
EXPECT_EQ(filter.Classify(0.39f, 0.0f, 0.30f), DropReason::kInsideEgoBox);
|
||||
EXPECT_EQ(filter.Classify(0.364f, 0.0f, 0.30f), DropReason::kInsideEgoBox);
|
||||
|
||||
EXPECT_TRUE(filter.Keep(0.37f, 0.0f, 0.30f)); // external obstacle before contact
|
||||
EXPECT_FALSE(filter.Keep(0.357f, 0.14f, 0.530f)); // measured gimbal return envelope
|
||||
EXPECT_TRUE(filter.Keep(0.0f, 0.30f, 0.30f));
|
||||
EXPECT_EQ(filter.Classify(0.319f, 0.14f, 0.49f), DropReason::kInsideEgoBox);
|
||||
// ---------- 7. 自定义参数的构造函数确实生效 ----------
|
||||
FilterParams small;
|
||||
small.max_range = 3.0f;
|
||||
|
||||
@@ -15,6 +15,7 @@ local ros_direct_packages = {
|
||||
"nav_msgs",
|
||||
"geometry_msgs",
|
||||
"sensor_msgs",
|
||||
"std_msgs",
|
||||
"tf2_ros",
|
||||
"tf2_sensor_msgs",
|
||||
"pcl_conversions",
|
||||
@@ -96,10 +97,28 @@ local function ros_common()
|
||||
end
|
||||
end
|
||||
|
||||
-- 再退一步:按发行版名找 /opt/ros/<发行版>。
|
||||
-- 这样换 ROS 版本不用改构建文件,而且**不写死任何发行版名字**
|
||||
-- ——ROS_DISTRO 是 ROS 自己的 setup.bash 导出的。
|
||||
if not ROS then
|
||||
local distro = os.getenv("ROS_DISTRO")
|
||||
if distro and distro ~= "" then
|
||||
local cand = "/opt/ros/" .. distro
|
||||
if os.isdir(cand .. "/include")
|
||||
and os.isdir(cand .. "/lib") then
|
||||
ROS = cand
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not ROS then
|
||||
raise(
|
||||
"ROS installation not found. "
|
||||
.. "Source ROS setup or set ROS_PREFIX."
|
||||
"ROS installation not found.\n"
|
||||
.. " 办法一:source 你的 ROS 环境再 xmake"
|
||||
.. "(会读 AMENT_PREFIX_PATH)\n"
|
||||
.. " 办法二:ROS_PREFIX=<ROS 安装前缀> xmake\n"
|
||||
.. " 办法三:ROS_DISTRO=<发行版名> xmake"
|
||||
.. "(会去 /opt/ros/<名字> 找)"
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -110,7 +129,7 @@ local function ros_common()
|
||||
|
||||
local script = path.join(
|
||||
target:scriptdir(),
|
||||
"../../tools/resolve_ros_includes.py"
|
||||
"../../tools/_internal/resolve_ros_includes.py"
|
||||
)
|
||||
|
||||
if not os.isfile(script) then
|
||||
@@ -296,7 +315,11 @@ local function ros_common()
|
||||
|
||||
local config = get_ros_config()
|
||||
|
||||
target:add("includedirs", config.includes)
|
||||
local project_include = path.join(target:scriptdir(), "include")
|
||||
for _, dir in ipairs(config.includes) do
|
||||
if dir ~= project_include then target:add("sysincludedirs", dir) end
|
||||
end
|
||||
target:add("includedirs", project_include)
|
||||
|
||||
target:add(
|
||||
"defines",
|
||||
@@ -327,9 +350,30 @@ end
|
||||
-- Targets
|
||||
-- ============================================================================
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 统一产物目录:build/bin/
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 为什么不用 xmake 默认的 build/<平台>/<架构>/<模式>/:
|
||||
-- 那一串平台三元组会被抄进文档、脚本、报错提示里,一旦换架构 / 换 OS /
|
||||
-- 换构建模式(release↔debug)就全部失效 —— 本工程已经因为这件事
|
||||
-- 反复出现「文档里的路径跑不通」。
|
||||
-- 固定成 build/bin/ 之后,文档里可以永远写 build/bin/nav_client。
|
||||
--
|
||||
-- 取舍:release 和 debug 会落在同一层,覆盖同一个文件。
|
||||
-- 要同时保留两种,用 xmake 的 -o 换构建目录,或者临时改这里。
|
||||
--
|
||||
-- 实现上**每个 target 里各写一行 `set_targetdir("$(builddir)/bin")`**。
|
||||
-- 试过包成 `nav_target()` helper,但 xmake 的 `target()` 不返回目标实例
|
||||
-- (返回 nil),那种写法会报 `attempt to index a nil value`。
|
||||
--
|
||||
-- ⚠️ **新增目标时必须自己补这一行**,否则它会掉回默认的
|
||||
-- `build/<平台>/<架构>/<模式>/`,和其它的分家。
|
||||
|
||||
|
||||
-- ---- ROS-independent algorithm core ----
|
||||
|
||||
target("sentry_nav_core")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("static")
|
||||
add_files("src/core/*.cpp")
|
||||
add_includedirs("include", {public = true})
|
||||
@@ -338,6 +382,7 @@ target("sentry_nav_core")
|
||||
-- ---- Unit tests ----
|
||||
|
||||
target("test_self_filter_core")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("tests/test_self_filter_core.cpp")
|
||||
add_includedirs("tests")
|
||||
@@ -346,6 +391,7 @@ target("test_self_filter_core")
|
||||
|
||||
|
||||
target("test_waypoint_sequencer")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("tests/test_waypoint_sequencer.cpp")
|
||||
add_includedirs("tests")
|
||||
@@ -354,6 +400,7 @@ target("test_waypoint_sequencer")
|
||||
|
||||
|
||||
target("test_geometry")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("tests/test_geometry.cpp")
|
||||
add_includedirs("tests")
|
||||
@@ -364,6 +411,7 @@ target("test_geometry")
|
||||
-- ---- Point cloud self-filter ----
|
||||
|
||||
target("self_filter")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("src/self_filter.cpp")
|
||||
add_deps("sentry_nav_core")
|
||||
@@ -374,6 +422,7 @@ target("self_filter")
|
||||
-- ---- Waypoint patrol ----
|
||||
|
||||
target("patrol")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("src/patrol.cpp")
|
||||
add_deps("sentry_nav_core")
|
||||
@@ -383,6 +432,7 @@ target("patrol")
|
||||
-- ---- Navigation test client ----
|
||||
|
||||
target("nav_client")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("src/nav_client.cpp")
|
||||
ros_common()
|
||||
@@ -391,12 +441,14 @@ target("nav_client")
|
||||
-- ---- Runtime nodes ----
|
||||
|
||||
target("odom_tf")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("src/odom_tf.cpp")
|
||||
ros_common()
|
||||
|
||||
|
||||
target("cmd_vel_relay")
|
||||
set_targetdir("$(builddir)/bin")
|
||||
set_kind("binary")
|
||||
add_files("src/cmd_vel_relay.cpp")
|
||||
ros_common()
|
||||
@@ -113,7 +113,7 @@ cd ~/Gazebo_projects/sentry_nav_dev && scripts/sentry_up.sh
|
||||
| 碰撞监控(临近障碍急停) | `config/nav2_params.yaml` → `collision_monitor`(FootprintApproach,source=`/scan2d`) | 在 smoothed 与 gz 之间兜底 |
|
||||
| 行为树(重试/恢复) | Nav2 默认 `nav2_bt_navigator/behavior_trees` 的 `navigate_to_pose_w_replanning_and_recovery.xml` | 规划失败 → 原地转/倒车重试 |
|
||||
| **多点巡逻(我们的决策层)** | `src/sentry_nav/src/patrol.cpp` + 纯逻辑 `src/core/waypoint_sequencer.cpp`(xmake 单测) | 依次发 `NavigateToPose`,走完循环回第一个点 |
|
||||
| **测试客户端** | `build/linux/x86_64/release/nav_client`(C++,源码 `src/sentry_nav/src/nav_client.cpp`) | 发单目标 + 目标点预检 + 输出导航耗时 |
|
||||
| **测试客户端** | `nav_client`(C++,源码 `src/sentry_nav/src/nav_client.cpp`,产物在 xmake 输出目录里) | 发单目标 + 目标点预检 + 输出导航耗时 |
|
||||
|
||||
### 发目标 / 测导航
|
||||
|
||||
@@ -124,13 +124,16 @@ cd ~/Gazebo_projects/sentry_nav_dev && xmake
|
||||
# 起仿真
|
||||
scripts/sentry_up.sh
|
||||
|
||||
# 产物固定落在 build/bin/(patrol / self_filter / odom_tf 也都在里面)
|
||||
BIN=build/bin
|
||||
|
||||
# 发目标(坐标是 map 帧,场地中心=(0,0))
|
||||
build/linux/x86_64/release/nav_client 0.0 0.0 # 到场地中心
|
||||
build/linux/x86_64/release/nav_client 0.0 0.0 90 # 到位置后朝向 +90°
|
||||
build/linux/x86_64/release/nav_client -4.0 -2.0 # 任意点
|
||||
$BIN/nav_client 0.0 0.0 # 到场地中心
|
||||
$BIN/nav_client 0.0 0.0 90 # 到位置后朝向 +90°
|
||||
$BIN/nav_client -4.0 -2.0 # 任意点
|
||||
|
||||
# 多点巡逻(Nav2 运行动作客户端)
|
||||
build/linux/x86_64/release/patrol --ros-args -p waypoints:="[-5.1,0.0, -4.0,-2.0, -2.0,-2.0, 0.0,0.0]"
|
||||
$BIN/patrol --ros-args -p waypoints:="[-5.1,0.0, -4.0,-2.0, -2.0,-2.0, 0.0,0.0]"
|
||||
```
|
||||
|
||||
`nav_client` 输出示例(含总耗时):
|
||||
@@ -166,7 +169,7 @@ ax_min: -3.5
|
||||
|
||||
## 代码语言约定(用户要求:能用 C++ 就别用 Python)
|
||||
|
||||
已迁移到 C++(xmake 编译,产物在 `build/linux/x86_64/release/`):
|
||||
已迁移到 C++(xmake 编译,产物在 `build/bin/`):
|
||||
|
||||
| 原 Python | 现 C++ | 用途 |
|
||||
|---|---|---|
|
||||
@@ -175,7 +178,8 @@ ax_min: -3.5
|
||||
| `scripts/cmd_vel_relay.py` | `src/sentry_nav/src/cmd_vel_relay.cpp` → `cmd_vel_relay` | 平滑命令优先转发到 gz |
|
||||
|
||||
`scripts/sentry_up.sh` 已经直接调用这三个二进制(不再 `python3`)。
|
||||
剩余 Python:`tools/free_goals.py`(离线目标点搜索)、`tools/check_stack.py`(栈自检)——逐步迁移中。
|
||||
剩余 Python 只有 `tools/check_stack.py`(栈自检)和 `tools/project_env.py`(路径探测)——
|
||||
两个都是**只读诊断**,不需要高性能,没有迁移成 C++ 的理由。
|
||||
`launch/sentry_arena.launch.py` 是 ROS launch 系统要求,**没法用 C++**。
|
||||
|
||||
## CPU 忙不过来怎么办(雷达是 CPU 射线)
|
||||
|
||||
@@ -278,7 +278,8 @@ local_costmap:
|
||||
footprint: "[[0.325, 0.270], [0.325, -0.270], [-0.325, -0.270], [-0.325, 0.270]]"
|
||||
# MID-360 的 3D 点云已接入(/scan/points,PointCloud2)
|
||||
# MID-360 点云经 sentry_nav/self_filter 自滤(剔除车身包围盒内的点)后接入
|
||||
plugins: ["voxel_layer", "inflation_layer"]
|
||||
# Retain known thin/occluded geometry when the live cloud sparsely samples it.
|
||||
plugins: ["static_layer", "voxel_layer", "inflation_layer"]
|
||||
voxel_layer:
|
||||
plugin: "nav2_costmap_2d::VoxelLayer"
|
||||
enabled: True
|
||||
@@ -310,7 +311,7 @@ local_costmap:
|
||||
inflation_layer:
|
||||
plugin: "nav2_costmap_2d::InflationLayer"
|
||||
cost_scaling_factor: 2.0
|
||||
inflation_radius: 0.45
|
||||
inflation_radius: 0.60 # Give the rectangular base room to turn around dynamic obstacles.
|
||||
static_layer:
|
||||
plugin: "nav2_costmap_2d::StaticLayer"
|
||||
map_subscribe_transient_local: true
|
||||
@@ -361,7 +362,7 @@ global_costmap:
|
||||
inflation_layer:
|
||||
plugin: "nav2_costmap_2d::InflationLayer"
|
||||
cost_scaling_factor: 2.0
|
||||
inflation_radius: 0.45
|
||||
inflation_radius: 0.60 # Give the rectangular base room to turn around dynamic obstacles.
|
||||
always_send_full_costmap: true
|
||||
introspection_mode: "disabled"
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ ros2 launch src/sentry_sim/launch/sentry_arena.launch.py --show-args # 看
|
||||
| `map` | 迁移包里的 `rmul_2027.yaml` | Nav2 用的栅格图 |
|
||||
| `field_root` | 仓库内 `field/RMUL2027_map_transfer_20261016_STEP_R1` | 迁移包目录(找不到才退回 `~/Gazebo_projects/` 下的旧路径) |
|
||||
|
||||
环境变量(`GZ_PARTITION` / `ROS_DOMAIN_ID` / `SENTRY_FIELD_ROOT` / `SENTRY_MAP_YAML`)
|
||||
会被继承,行为和 `sentry_up.sh` 一致。详见 `../scripts/README.md`。
|
||||
`map:=` 和 `field_root:=` 优先于对应的环境变量。未提供地图时,从实际选定的场地目录探测。
|
||||
两个启动入口使用同一套环境探测规则,`--show-args` 可独立查看参数。详见[环境变量](../../../docs/操作手册.md#6-环境变量)。
|
||||
|
||||
## 和 `scripts/sentry_up.sh` 的取舍
|
||||
|
||||
| | `sentry_up.sh` | 本 launch 文件 |
|
||||
|---|---|---|
|
||||
| 依赖 | 只要 bash | 要 `ros2 launch`(launch / launch_ros) |
|
||||
| 依赖 | Bash、Python 3 和 ROS | `ros2 launch`(launch / launch_ros) |
|
||||
| 参数可见性 | 看脚本 | `--show-args` 全列出来 |
|
||||
| 进程管理 | `trap` 收尾 | launch 统一收尾、能看进程树 |
|
||||
| 被别的 launch include | ❌ | ✅ |
|
||||
@@ -68,7 +68,7 @@ cmd = [run_gz, 'sim', '-s',
|
||||
|
||||
**③ 本工程的节点没有 ament 注册,不能用 `Node(package='sentry_nav', ...)`。**
|
||||
`self_filter` 用 `ExecuteProcess` 直接指 xmake 产物
|
||||
(`build/linux/x86_64/release/self_filter`),两个 Python 脚本用 `python3` 直接跑。
|
||||
(`build/bin/self_filter`),两个 Python 脚本用 `python3` 直接跑。
|
||||
系统包(`robot_state_publisher` / `nav2_map_server` / `rviz2` / `tf2_ros`)照常写 `Node()`。
|
||||
|
||||
## 相关
|
||||
|
||||
@@ -34,31 +34,33 @@
|
||||
|
||||
坐标系
|
||||
------
|
||||
同时发布两条静态变换:
|
||||
|
||||
map → odom 平移 (-5.0, 3.0) 仿真里用里程计当真值,替代 AMCL
|
||||
map → field 恒等变换 两者都已是「场地中心 = 零点」
|
||||
|
||||
`map` 是官方栅格图坐标系(西南内角 = (0,0)),`field` 是给决策代码用的直觉坐标系。
|
||||
map → odom 由显式选择的 LIO / AMCL 定位器发布,不能同时启动。
|
||||
map → field 为恒等变换。map / field 都以场地中心为原点。
|
||||
Nav2 等待仿真时钟和 odom/base/lidar TF 就绪后启动。
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import (
|
||||
DeclareLaunchArgument,
|
||||
ExecuteProcess,
|
||||
IncludeLaunchDescription,
|
||||
EmitEvent,
|
||||
RegisterEventHandler,
|
||||
LogInfo,
|
||||
OpaqueFunction,
|
||||
SetEnvironmentVariable,
|
||||
SetLaunchConfiguration,
|
||||
)
|
||||
from launch.conditions import IfCondition
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import (LaunchConfiguration,
|
||||
PathJoinSubstitution, PythonExpression)
|
||||
from launch.event_handlers import OnProcessExit
|
||||
from launch.events import Shutdown
|
||||
from launch.substitutions import (
|
||||
EqualsSubstitution, IfElseSubstitution, LaunchConfiguration, PathJoinSubstitution, PythonExpression,
|
||||
)
|
||||
from launch_ros.actions import Node
|
||||
from launch_ros.parameter_descriptions import ParameterValue
|
||||
|
||||
@@ -67,21 +69,62 @@ from launch_ros.parameter_descriptions import ParameterValue
|
||||
# ---------------------------------------------------------------------------
|
||||
PKG_SHARE = Path(__file__).resolve().parents[1] # src/sentry_sim
|
||||
WS = Path(__file__).resolve().parents[3] # 仓库根
|
||||
BIN_DIR = WS / 'build' / 'linux' / 'x86_64' / 'release' # xmake 产物
|
||||
SCRIPTS = PKG_SHARE / 'scripts'
|
||||
TOOLS_DIR = WS / 'tools'
|
||||
INTERNAL_TOOLS = TOOLS_DIR / '_internal'
|
||||
|
||||
# 场地迁移包:优先用仓库自带的 field/,没有才退回本机旧路径
|
||||
_FIELD_IN_REPO = WS / 'field' / 'RMUL2027_map_transfer_20261016_STEP_R1'
|
||||
_FIELD_FALLBACK = (Path.home() / 'Gazebo_projects' /
|
||||
'RMUL2027_map_transfer_20261016_STEP_R1')
|
||||
DEFAULT_FIELD_ROOT = os.environ.get(
|
||||
'SENTRY_FIELD_ROOT',
|
||||
str(_FIELD_IN_REPO if _FIELD_IN_REPO.is_dir() else _FIELD_FALLBACK))
|
||||
# 可移植探测:xmake 产物目录 / 场地包 / 地图 / gz 版本,一个都不写死。
|
||||
# 规则与 `scripts/env_common.sh` 完全一致(同样支持 SENTRY_BIN_DIR、
|
||||
# SENTRY_FIELD_ROOT、SENTRY_MAP_YAML、GZ_BIN、GZ_FORCE_VERSION 覆盖)。
|
||||
# 从仓库源码加载工具模块。
|
||||
if str(TOOLS_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_DIR))
|
||||
import project_env # noqa: E402 (必须在 sys.path 调整之后导入)
|
||||
from _internal.dds_environment import defaults as dds_defaults # noqa: E402
|
||||
|
||||
DEFAULT_MAP_YAML = os.environ.get(
|
||||
'SENTRY_MAP_YAML',
|
||||
str(Path(DEFAULT_FIELD_ROOT) / 'src' / 'guodong_sentry_sim' / 'maps' /
|
||||
'rmul_2027' / 'rmul_2027.yaml'))
|
||||
BIN_DIR = LaunchConfiguration('_sentry_bin_dir')
|
||||
GZ_MAJOR_VERSION = LaunchConfiguration('_sentry_gz_major_version')
|
||||
|
||||
|
||||
def _resolve_environment(context):
|
||||
field_root = project_env.find_field_root(
|
||||
WS, explicit=LaunchConfiguration('field_root').perform(context))
|
||||
map_yaml = project_env.find_map_yaml(
|
||||
field_root, explicit=LaunchConfiguration('map').perform(context))
|
||||
bin_dir = project_env.find_bin_dir(WS)
|
||||
nodes = ['odom_tf', 'cmd_vel_relay', 'self_filter']
|
||||
if LaunchConfiguration('localization').perform(context) == 'lio':
|
||||
nodes.append('field_localization_node')
|
||||
for name in nodes:
|
||||
project_env.require_executable(bin_dir / name, name)
|
||||
gz = project_env.find_gz_bin()
|
||||
versions = project_env.gz_version_args(gz)
|
||||
return [
|
||||
SetLaunchConfiguration('field_root', str(field_root)),
|
||||
SetLaunchConfiguration('map', str(map_yaml)),
|
||||
SetLaunchConfiguration('_sentry_bin_dir', str(bin_dir)),
|
||||
SetEnvironmentVariable('GZ_BIN', str(gz)),
|
||||
SetLaunchConfiguration('_sentry_gz_major_version', versions[1] if versions else ''),
|
||||
]
|
||||
|
||||
|
||||
def _start_gazebo(context):
|
||||
headless = LaunchConfiguration('headless').perform(context).lower() in ('true', '1')
|
||||
# Keep -r in both modes so that the world starts unpaused.
|
||||
args = ['-s', '-r'] if headless else ['-r']
|
||||
if major := GZ_MAJOR_VERSION.perform(context):
|
||||
args.extend(['--force-version', major])
|
||||
world_path = PathJoinSubstitution([str(PKG_SHARE / 'worlds'), LaunchConfiguration('world')])
|
||||
return [ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'run_gz.sh'), 'sim', *args, world_path],
|
||||
name='gazebo', output='screen',
|
||||
)]
|
||||
|
||||
|
||||
def _on_bridge_exit(event, context):
|
||||
if event.returncode != 0 and not context.is_shutdown:
|
||||
raise RuntimeError('Gazebo 桥启动或运行失败,请检查 /clock 与 ros_gz_bridge 日志。')
|
||||
return []
|
||||
|
||||
|
||||
def _robot_description():
|
||||
@@ -111,24 +154,99 @@ def _gz_resource_path():
|
||||
return parts
|
||||
|
||||
|
||||
def _validate_lio(context):
|
||||
if LaunchConfiguration('localization').perform(context) == 'lio':
|
||||
mode = LaunchConfiguration('lio_mode').perform(context)
|
||||
path = Path(LaunchConfiguration('lio_map').perform(context))
|
||||
if mode == 'localization' and not path.is_file():
|
||||
raise RuntimeError(f'Missing LIO map: {path}; first select lio_mode:=mapping')
|
||||
if mode == 'mapping':
|
||||
export = Path(LaunchConfiguration('lio_export_map').perform(context))
|
||||
export.parent.mkdir(parents=True, exist_ok=True)
|
||||
return []
|
||||
|
||||
|
||||
def _preflight_nav2(context):
|
||||
if LaunchConfiguration('nav2').perform(context).lower() in ('true', '1'):
|
||||
subprocess.run(['python3', str(INTERNAL_TOOLS / 'nav2_startup.py'), '--preflight'],
|
||||
env=dict(context.environment), check=True)
|
||||
return []
|
||||
|
||||
|
||||
def _start_velocity_relay(context):
|
||||
navigation = LaunchConfiguration('nav2').perform(context).lower() in ('true', '1')
|
||||
localization = LaunchConfiguration('localization').perform(context)
|
||||
input_topic = '/cmd_vel' if navigation else context.environment.get('MANUAL_CMD_VEL_TOPIC', '/cmd_vel')
|
||||
return [ExecuteProcess(
|
||||
cmd=[PathJoinSubstitution([BIN_DIR, 'cmd_vel_relay']),
|
||||
'--ros-args', '-p', 'use_sim_time:=true',
|
||||
'-p', f'navigation_mode:={str(navigation).lower()}',
|
||||
'-p', f'require_localization_health:={str(localization == "lio").lower()}',
|
||||
'-p', f'in_topic:={input_topic}'],
|
||||
name='cmd_vel_relay', output='screen',
|
||||
)]
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
headless = LaunchConfiguration('headless')
|
||||
nav2 = LaunchConfiguration('nav2')
|
||||
rviz = LaunchConfiguration('rviz')
|
||||
world = LaunchConfiguration('world')
|
||||
map_yaml = LaunchConfiguration('map')
|
||||
localization = LaunchConfiguration('localization')
|
||||
lio_mode = LaunchConfiguration('lio_mode')
|
||||
lio_map = LaunchConfiguration('lio_map')
|
||||
lio_export = LaunchConfiguration('lio_export_map')
|
||||
lio_default_map = IfElseSubstitution(
|
||||
EqualsSubstitution(lio_mode, 'mapping'),
|
||||
if_value=str(WS / 'generated' / 'field_mapping.flmap'),
|
||||
else_value=str(PKG_SHARE / 'maps' / 'field_full.flmap'),
|
||||
)
|
||||
|
||||
# 布尔参数统一用 PythonExpression 判,避免 launch 把 "false" 当真值
|
||||
is_headless = PythonExpression(["'", headless, "'.lower() in ('true', '1')"])
|
||||
is_gui = PythonExpression(["'", headless, "'.lower() not in ('true', '1')"])
|
||||
nav2_on = PythonExpression(["'", nav2, "'.lower() in ('true', '1')"])
|
||||
rviz_on = PythonExpression([
|
||||
"'", rviz, "'.lower() in ('true', '1') and '",
|
||||
headless, "'.lower() not in ('true', '1')"])
|
||||
|
||||
robot_description = _robot_description()
|
||||
bridge = ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'bridge_after_gz.sh')],
|
||||
name='ros_gz_bridge', output='screen',
|
||||
)
|
||||
|
||||
navigation_ready = ExecuteProcess(
|
||||
cmd=['python3', str(INTERNAL_TOOLS / 'wait_navigation_ready.py')],
|
||||
name='wait_navigation_ready', output='screen', condition=IfCondition(nav2_on),
|
||||
)
|
||||
# Use the same process boundary and options as the shell entry point.
|
||||
# The nested include path reproduced a Wait action discovery timeout on this setup.
|
||||
navigation = ExecuteProcess(
|
||||
cmd=['python3', str(INTERNAL_TOOLS / 'run_nav2.py'),
|
||||
'--timeout', os.environ.get('SENTRY_NAV2_TIMEOUT', '120'), '--',
|
||||
['map:=', map_yaml], 'use_sim_time:=true', 'autostart:=False',
|
||||
['params_file:=', str(PKG_SHARE / 'config' / 'nav2_params.yaml')],
|
||||
'use_composition:=False',
|
||||
['use_localization:=', PythonExpression(["'", localization, "' == 'amcl'"])],
|
||||
'serve_static_map:=True', 'use_keepout_zones:=False',
|
||||
'use_speed_zones:=False', 'slam:=False'],
|
||||
name='nav2', output='screen', condition=IfCondition(nav2_on), sigterm_timeout='20',
|
||||
)
|
||||
|
||||
actions = [
|
||||
DeclareLaunchArgument('localization', default_value='lio', choices=['lio', 'amcl']),
|
||||
DeclareLaunchArgument('lio_mode', default_value='localization', choices=['mapping', 'localization']),
|
||||
DeclareLaunchArgument(
|
||||
'lio_map', default_value=os.environ.get('LIO_MAP') or lio_default_map,
|
||||
description='Full-field localization map or generated/field_mapping.flmap in mapping mode',
|
||||
),
|
||||
DeclareLaunchArgument('lio_export_map', default_value=os.environ.get('LIO_EXPORT_MAP') or lio_map),
|
||||
DeclareLaunchArgument('lio_point_cloud_topic',
|
||||
default_value=os.environ.get('LIO_POINT_CLOUD_TOPIC') or '/scan/points_lio'),
|
||||
DeclareLaunchArgument('lio_initial_x', default_value='-5.0'),
|
||||
DeclareLaunchArgument('lio_initial_y', default_value='3.0'),
|
||||
DeclareLaunchArgument('lio_initial_z', default_value='0.0'),
|
||||
DeclareLaunchArgument('lio_initial_yaw', default_value='0.0'),
|
||||
OpaqueFunction(function=_validate_lio),
|
||||
# ---------------- 参数 ----------------
|
||||
DeclareLaunchArgument(
|
||||
'headless', default_value='false',
|
||||
@@ -141,57 +259,34 @@ def generate_launch_description():
|
||||
'world', default_value='sentry_arena.sdf',
|
||||
description='worlds/ 下的世界文件名'),
|
||||
DeclareLaunchArgument(
|
||||
'map', default_value=DEFAULT_MAP_YAML,
|
||||
description='Nav2 用的栅格图 yaml'),
|
||||
'map', default_value='',
|
||||
description='Nav2 栅格图 YAML,留空则从环境或场地包探测'),
|
||||
DeclareLaunchArgument(
|
||||
'field_root', default_value=DEFAULT_FIELD_ROOT,
|
||||
description='迁移包(guodong_sentry_sim)所在目录'),
|
||||
'field_root', default_value='',
|
||||
description='场地包目录,留空则从环境或仓库探测'),
|
||||
OpaqueFunction(function=_resolve_environment),
|
||||
|
||||
# ---------------- 环境变量 ----------------
|
||||
SetEnvironmentVariable('FASTDDS_BUILTIN_TRANSPORTS',
|
||||
dds_defaults(os.environ)['FASTDDS_BUILTIN_TRANSPORTS']),
|
||||
SetEnvironmentVariable('GZ_SIM_RESOURCE_PATH', _gz_resource_path()),
|
||||
SetEnvironmentVariable(
|
||||
'GZ_PARTITION', os.environ.get('GZ_PARTITION', 'sentry')),
|
||||
'GZ_PARTITION', os.environ.get('GZ_PARTITION') or 'sentry'),
|
||||
SetEnvironmentVariable(
|
||||
'ROS_DOMAIN_ID', os.environ.get('ROS_DOMAIN_ID', '0')),
|
||||
'ROS_DOMAIN_ID', dds_defaults(os.environ)['ROS_DOMAIN_ID']),
|
||||
# URDF 的网格路径靠它解析;tools/check_stack.py 也读它
|
||||
SetEnvironmentVariable('SENTRY_SIM_SHARE', str(PKG_SHARE)),
|
||||
OpaqueFunction(function=_preflight_nav2),
|
||||
|
||||
# ---------------- 1. Gazebo ----------------
|
||||
# 用 run_gz.sh 包一层:它会清掉 LD_LIBRARY_PATH,
|
||||
# 否则 source 过 ROS 之后连系统版 gz 也会加载 vendor 库(缺 cpu-lidar 插件)
|
||||
# ⚠️ cmd 列表里的每个元素是**独立 argv**,不会自动拼接。
|
||||
# world 是 LaunchConfiguration,所以必须用 PathJoinSubstitution
|
||||
# 合成成一个参数,否则 gz 会收到三个散参数
|
||||
# (报 "The following arguments were not expected: xxx.sdf /")。
|
||||
ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'run_gz.sh'), 'sim', '-r',
|
||||
'--force-version', '10',
|
||||
PathJoinSubstitution([str(PKG_SHARE / 'worlds'), world])],
|
||||
name='gazebo',
|
||||
output='screen',
|
||||
condition=IfCondition(is_gui),
|
||||
),
|
||||
# ⚠️ headless 也必须带 -r(启动即运行)。
|
||||
# 少了 -r 的话 gazebo 以**暂停**状态启动:物理引擎不步进 →
|
||||
# MecanumDrive 不发 /odom、传感器不出数据,但 /clock 照常发布,
|
||||
# 表面上一切正常,实际整条数据链是死的。
|
||||
ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'run_gz.sh'), 'sim', '-s', '-r',
|
||||
'--force-version', '10',
|
||||
PathJoinSubstitution([str(PKG_SHARE / 'worlds'), world])],
|
||||
name='gazebo',
|
||||
output='screen',
|
||||
condition=IfCondition(is_headless),
|
||||
),
|
||||
OpaqueFunction(function=_start_gazebo),
|
||||
|
||||
# ---------------- 2. ros_gz 桥 ----------------
|
||||
# bridge_after_gz.sh 自己轮询 /clock 再起桥:
|
||||
# gz-transport 的发现不回补,桥先于话题存在就订阅会一直收不到数据
|
||||
ExecuteProcess(
|
||||
cmd=[str(SCRIPTS / 'bridge_after_gz.sh')],
|
||||
name='ros_gz_bridge',
|
||||
output='screen',
|
||||
),
|
||||
# 等到 /clock 出现再加载桥,否则 gz-transport 可能漏掉话题。
|
||||
RegisterEventHandler(OnProcessExit(
|
||||
target_action=bridge, on_exit=_on_bridge_exit,
|
||||
)),
|
||||
bridge,
|
||||
|
||||
# ---------------- 3. TF 树 ----------------
|
||||
Node(
|
||||
@@ -213,7 +308,7 @@ def generate_launch_description():
|
||||
# 如果写成嵌套列表 ['-p', 'odom_scale:=', v],会被拼成 "-podom_scale:=1.15"(没空格),
|
||||
# rclpy 的参数解析会直接报错。
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'odom_tf'), '--ros-args',
|
||||
cmd=[PathJoinSubstitution([BIN_DIR, 'odom_tf']), '--ros-args',
|
||||
'-p', 'use_sim_time:=true',
|
||||
'-p', 'odom_scale:=' + os.environ.get('SENTRY_ODOM_SCALE', '1.0')],
|
||||
name='odom_tf',
|
||||
@@ -222,31 +317,33 @@ def generate_launch_description():
|
||||
|
||||
# ---------------- 5. /cmd_vel 改名转发 ----------------
|
||||
# 插件订阅 /model/sentry/cmd_vel,而桥只支持两端同名
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'cmd_vel_relay'),
|
||||
'--ros-args', '-p', 'use_sim_time:=true'],
|
||||
name='cmd_vel_relay',
|
||||
output='screen',
|
||||
),
|
||||
OpaqueFunction(function=_start_velocity_relay),
|
||||
|
||||
# ---------------- 6. 点云自滤 ----------------
|
||||
# 本工程没有 ament 注册,不能 ros2 run,直接跑 xmake 产物
|
||||
ExecuteProcess(
|
||||
cmd=[str(BIN_DIR / 'self_filter'),
|
||||
'--ros-args', '-p', 'use_sim_time:=true'],
|
||||
cmd=[PathJoinSubstitution([BIN_DIR, 'self_filter']),
|
||||
'--ros-args', '-p', 'use_sim_time:=true', '-p', 'reliable_clouds:=true'],
|
||||
name='self_filter',
|
||||
output='screen',
|
||||
),
|
||||
|
||||
# ---------------- 7. 静态变换 ----------------
|
||||
# map -> odom 由 AMCL 发布(use_localization:=True),这里**不能**再发一份,
|
||||
# 否则两个发布者打架。要回到"作弊定位"就把 use_localization 改 False 并放开下面:
|
||||
# Node(package='tf2_ros', executable='static_transform_publisher',
|
||||
# name='map_to_odom',
|
||||
# arguments=['--x','1.0','--y','1.0','--z','0.0',
|
||||
# '--yaw','0.0','--pitch','0.0','--roll','0.0',
|
||||
# '--frame-id','map','--child-frame-id','odom'],
|
||||
# parameters=[{'use_sim_time': True}], output='screen'),
|
||||
ExecuteProcess(
|
||||
cmd=[PathJoinSubstitution([BIN_DIR, 'field_localization_node']), '--ros-args',
|
||||
'-p', 'use_sim_time:=true', '-p', 'reliable_clouds:=true',
|
||||
'-p', ['point_cloud_topic:=', LaunchConfiguration('lio_point_cloud_topic')],
|
||||
'-p', ['mode:=', lio_mode], '-p', ['map_path:=', lio_map],
|
||||
'-p', ['export_map_path:=', lio_export], '-p', 'publish_map_to_odom:=true',
|
||||
'-p', "diagnostics_path:='" + os.environ.get('LIO_TRACE_PATH', '') + "'",
|
||||
'-p', ['initial_x:=', LaunchConfiguration('lio_initial_x')],
|
||||
'-p', ['initial_y:=', LaunchConfiguration('lio_initial_y')],
|
||||
'-p', ['initial_z:=', LaunchConfiguration('lio_initial_z')],
|
||||
'-p', ['initial_yaw:=', LaunchConfiguration('lio_initial_yaw')]],
|
||||
name='field_localization', output='screen',
|
||||
condition=IfCondition(PythonExpression(["'", localization, "' == 'lio'"])),
|
||||
),
|
||||
|
||||
# ---------------- 7. map -> field 恒等别名 ----------------
|
||||
# map -> field:恒等变换(map 已以场地中心为原点)
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
@@ -260,29 +357,20 @@ def generate_launch_description():
|
||||
),
|
||||
|
||||
# ---------------- 8. 静态地图服务 ----------------
|
||||
# 由 bringup 提供:serve_static_map 默认跟随 use_localization,
|
||||
# 所以 use_localization:=True 时 bringup 自己起 map_server + amcl。
|
||||
# 两个分支均由 bringup 提供 map_server,只有 AMCL 分支启动 amcl。
|
||||
# 这里再起一份会**同名冲突**(lifecycle_manager 崩在 createLifecycleServiceServers)。
|
||||
|
||||
# ---------------- 9. Nav2 ----------------
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(os.path.join(
|
||||
get_package_share_directory('nav2_bringup'),
|
||||
'launch', 'bringup_launch.py')),
|
||||
launch_arguments={
|
||||
'map': map_yaml,
|
||||
'use_sim_time': 'true',
|
||||
'params_file': str(PKG_SHARE / 'config' / 'nav2_params.yaml'),
|
||||
# 组合模式在本机起不来(容器一个组件都不加载),分进程更稳
|
||||
'use_composition': 'False',
|
||||
'use_localization': 'True',
|
||||
# 这两个子系统本工程用不上,少两个 lifecycle 节点少两处启动风险
|
||||
'use_keepout_zones': 'False',
|
||||
'use_speed_zones': 'False',
|
||||
'slam': 'False',
|
||||
}.items(),
|
||||
condition=IfCondition(nav2_on),
|
||||
),
|
||||
RegisterEventHandler(OnProcessExit(
|
||||
target_action=navigation,
|
||||
on_exit=[EmitEvent(event=Shutdown(reason='Nav2 supervisor exited'))],
|
||||
)),
|
||||
RegisterEventHandler(OnProcessExit(
|
||||
target_action=navigation_ready,
|
||||
on_exit=lambda event, context: [navigation] if event.returncode == 0 else [
|
||||
EmitEvent(event=Shutdown(reason='simulation clock/TF readiness failed'))],
|
||||
)),
|
||||
navigation_ready,
|
||||
|
||||
# ---------------- 10. RViz ----------------
|
||||
Node(
|
||||
|
||||
Binary file not shown.
@@ -387,5 +387,14 @@
|
||||
<frame name='lidar_link' attached_to='lidar_joint'>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
</frame>
|
||||
<!-- Evaluation only: independent world pose, never consumed by localization. -->
|
||||
<plugin filename="gz-sim-pose-publisher-system" name="gz::sim::systems::PosePublisher">
|
||||
<publish_model_pose>true</publish_model_pose>
|
||||
<publish_link_pose>false</publish_link_pose>
|
||||
<publish_nested_model_pose>false</publish_nested_model_pose>
|
||||
<use_pose_vector_msg>false</use_pose_vector_msg>
|
||||
<update_frequency>100</update_frequency>
|
||||
<topic>/evaluation/ground_truth</topic>
|
||||
</plugin>
|
||||
</model>
|
||||
</sdf>
|
||||
Loaded 100 of 150 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user