update
This commit is contained in:
@@ -39,13 +39,13 @@ Use this file for verified target-repository facts only. Keep unknown values as
|
||||
|
||||
- Main nodes: one process — `vslam_node` (`build/app/vslam_node`). Owns all threads and all Channels. Source must be chosen explicitly, no default: `--sim` | `--replay FILE` | `--live` | `--check` (app/src/main.cc:39-69, docs/RUNTIME.md:1-20).
|
||||
- Tools: `vslam_record`, `vslam_replay`, `vslam_sim_run`, `vslam_slam_bench`, `vslam_web_demo`, `vslam_world_export`, `vslam_lidar_probe`, `probe_rtabmap`
|
||||
- Topics: none (no middleware). In-process `Channel<T>` (libs/vslam_common/include/vslam/channel.h) replaces pub/sub. External surface is HTTP/WebSocket on port 8080 — e.g. `GET /api/world.bin` (README.md:133-135). Binary WS frame types: 1 scan, 2 cloud, 3 map_full, 4 **retired** (was map_patch, removed 2026-09-23), 5 path, 6 world_map, 7 voxel_full (chunked), 8 voxel_delta; token auth is asymmetric by design: engage e-stop needs no token, release e-stop / bumper reset require one (configuration_files/system.yaml `web.auth_token`).
|
||||
- Topics: none (no middleware). In-process `Channel<T>` (libs/vslam_common/include/vslam/channel.h) replaces pub/sub. External surface is HTTP/WebSocket on port 8080 — e.g. `GET /api/world.bin` (README.md:133-135). Binary WS frame types: 1 scan, 2 cloud, 3 map_full, 4 **retired** (was map_patch, removed 2026-09-23), 5 path, 6 world_map, 7 voxel_full (chunked), 8 voxel_delta. Types 7/8 carry the accumulated 3D map as a voxel-hashed index set at 0.05 m; the browser renders it as a POINT CLOUD, not as boxes; token auth is asymmetric by design: engage e-stop needs no token, release e-stop / bumper reset require one (configuration_files/system.yaml `web.auth_token`).
|
||||
- Services / Actions: none.
|
||||
- Parameters: YAML only, one file per library. Selected verified values —
|
||||
- `robot.yaml`: wheel_radius 0.0865 m, wheel_separation 0.400 m, robot_radius 0.24, max_linear 0.35 m/s, max_angular 0.80 rad/s, accel_limit 0.30 m/s², base.cmd_timeout 0.30 s
|
||||
- `safety.yaml`: scan stop_distance 0.35 m, slow_distance 0.80 m, front_angle 0.5 rad, min_front_rays 20, cliff_hold 3.0 s, sensor_timeout 1.0 s, cmd_timeout 0.5 s (must stay > base.cmd_timeout), bumper escape_linear 0.10 / escape_angular 0.4
|
||||
- `pipeline.yaml`: depth_filter 0.22–4.0 m, voxel 0.03 m, 30 Hz in / 10 Hz out; cliff_detect window 1.15–1.70 m (geometric blind zone from level camera at 0.445 m), and `cliff_detect.enabled: false` — cliff detection is currently OFF (pipeline.yaml:100)
|
||||
- `slam.yaml`: enabled false, mode localization, Reg/Strategy=1 (ICP), Reg/Force3DoF=true, Optimizer/Strategy=1 (g2o), RGBD/NeighborLinkRefining=false, RGBD/ProximityPathMaxNeighbors=30, Rtabmap/DetectionRate=3, Grid/CellSize 0.05, `camera_3d` (default false) is the 3D-voxel-map switch: true forces Grid/Sensor=2 + Grid/3D=true + height-threshold ground split
|
||||
- `slam.yaml`: enabled false, mode localization, Reg/Strategy=1 (ICP), Reg/Force3DoF=true, Optimizer/Strategy=1 (g2o), RGBD/NeighborLinkRefining=false, RGBD/ProximityPathMaxNeighbors=30, Rtabmap/DetectionRate=3, Grid/CellSize 0.05, `camera_3d` (code default false; slam.yaml currently true) is the 3D scanned-cloud switch: true sends depth into RTAB-Map (stored in the DB) and turns on the voxel map, but does NOT touch Grid/* — the grid stays 2D, LiDAR-only. The voxel map is built outside `process()` from each node's depth (cached per node id, max 40 new nodes per export). Changed 2026-09-24: the old Grid/Sensor=2 + Grid/3D=true path raised sim pose error vs ground truth from 0.009 m to 0.06-0.11 m
|
||||
- `system.yaml`: web port 8080, status/scan 10 Hz, cloud 8 Hz, path 1 Hz, map_rebuild_rate_hz 4.0, voxel_chunk_bytes 16384 / voxel_sync_chunks_per_tick 1 (the voxel map has no send-rate knob by design); thread priorities safety 50 / driver 45 / estimator 40, safety_rate_hz 20
|
||||
- Unknown RTAB-Map keys are a **startup refusal**, not a silent ignore (`BuildRtabmapParams`, slam.yaml:10-16)
|
||||
- Config dir resolution: `$VSLAM_CONFIG_DIR`, else `/etc/vslam/configuration_files`; resources: `$VSLAM_RESOURCE_DIR`, else `/var/lib/vslam/resources` (libs/vslam_common/include/vslam/node_constants.h)
|
||||
@@ -111,4 +111,4 @@ All commands below are transcribed from README.md / CMakePresets.json / docs —
|
||||
9. `RGBD/NeighborLinkRefining=false` was tuned against **simulated** odometry (exact to ground truth). Real-robot odometry drifts 1-2%, where ICP link refinement may help. Re-measure on hardware.
|
||||
10. Real-hardware symmetric wheel slip is undetectable by the current `|omega_encoder - gyro_z|` test (0 events, 13.29% error in the `slip_sym` regression scenario).
|
||||
11. `imu_lag_sec` was re-measured 2026-09-23 and moved 0.08 -> 0.07 (estimator resolution is one 10 ms bin). The next live run must report `wheel_odom/lag: tot nhat ~0 ms`; if it still says -10 ms the model has bottomed out and must not be tuned further.
|
||||
12. The 3D voxel map (`camera_3d: true`) has NOT been run on hardware yet. Three numbers in it are reasoned estimates, not measurements: `voxel.emit_size_m` 0.10, `voxel.delta_max_ratio` 0.35, and the 150k `max_cells` ceiling. Also unmeasured: RAM/CPU cost of `Grid/3D=true` with ray tracing left ON (kept on deliberately — turning it off empties the 2D free-space map).
|
||||
12. The 3D scanned cloud (`camera_3d: true`) produced frames in sim on 2026-09-24 with the OLD Grid/3D path; the depth-per-node path that replaced it is not yet run (sim or hardware). Not on hardware at all. Three numbers in it are reasoned estimates, not measurements: `voxel.emit_size_m` 0.05, `voxel.delta_max_ratio` 0.35, and the 300k `max_cells` ceiling. The full-sync burst (2 x 32 kB x 10 Hz = 655 kB/s) also exceeds the documented 120 kB/s UI budget for 1-3 s per joining client — deliberate, but unmeasured on Jetson WiFi. Also unmeasured: RAM/CPU cost of `Grid/3D=true` with ray tracing left ON (kept on deliberately — turning it off empties the 2D free-space map).
|
||||
|
||||
72
README.md
72
README.md
@@ -498,35 +498,75 @@ kiem duoc loi hua "logic giu NGUYEN VEN" cua ban port.
|
||||
|
||||
## Ban do 3D tren web
|
||||
|
||||
Dam may diem MA CHINH ROBOT QUET RA, giu lai va nan theo pose da toi uu. Day la
|
||||
phan "RViz" that su: khac lop `cloud` von chi la MOT khung depth truc tiep, lop
|
||||
nay tich luy va song qua ca phien quet.
|
||||
|
||||
MAC DINH TAT. Bat bang `camera_3d: true` trong `slam.yaml`, roi mo web, bam
|
||||
**3D** va tick lop **voxel 3D**.
|
||||
**3D** va tick lop **cloud da quet**.
|
||||
|
||||
Bat no len keo theo ba thu, tu dong:
|
||||
Nut **chia doi** xoay vong qua ba kieu -- kieu thu ba la kieu de NHIN ban do 3D
|
||||
dung len theo thoi gian thuc:
|
||||
|
||||
| | |
|
||||
| Bam | Trai | Phai |
|
||||
|---|---|---|
|
||||
| lan 1 | 3D the gioi (Gazebo) | 2D ban do SLAM |
|
||||
| lan 2 | 3D the gioi (de lai) | **3D dam may SLAM quet ra** |
|
||||
| lan 3 | mot khung | |
|
||||
|
||||
Kieu thu hai tra loi "quet toi dau"; kieu thu ba tra loi "quet ra co giong that
|
||||
khong". Hai khung dung CHUNG goc nhin co y: xoay mot ben la ben kia theo, nen
|
||||
dat mat vao mot cai ban ngoai doi roi nhin sang phai xem SLAM dung ra gi.
|
||||
|
||||
Ky thuat: KHONG co canvas thu hai. Mot `WebGLRenderer`, render hai lan vao hai
|
||||
nua bang scissor (`v3dRender`), nua phai ep an mesh the gioi. Hai GL context
|
||||
tren cung mot trang la gap doi bo nho texture va mot nguon loi "context lost"
|
||||
tren Jetson.
|
||||
|
||||
Du lieu ben duoi la mot tap VOXEL o buoc 0.05 m -- do la cach khu trung lap va
|
||||
giu bang thong -- nhung web ve no bang **diem**, khong phai bang hop. Mot khoi
|
||||
hop 5 cm nhin ra Minecraft chu khong ra mot ban quet.
|
||||
|
||||
Bat no len thi depth vao RTAB-Map (va duoc luu trong DB), con dam may 3D dung
|
||||
**ngoai** `process()`: depth cua moi node chieu thanh diem MOT lan, cache theo
|
||||
id node, roi ghep theo pose da toi uu. Luoi cua RTAB-Map **van la 2D, chi tu
|
||||
LiDAR**.
|
||||
|
||||
Vi sao khong de RTAB-Map tu dung luoi 3D (`Grid/Sensor = 2` + `Grid/3D =
|
||||
true`, cach cu truoc 2026-09-24): no keo pose lech. Do trong mo phong
|
||||
(hospital, 0.7 m/s, sai so vs ground truth luc dung yen):
|
||||
|
||||
| Cau hinh | Sai so |
|
||||
|---|---|
|
||||
| `Grid/Sensor = 2` | RTAB-Map nap CA scan LiDAR lan depth vao luoi cuc bo |
|
||||
| `Grid/3D = true` | luoi cuc bo cua tung node thanh ba chieu |
|
||||
| nguong chieu cao | tach san/vat can bang 0.10 m va 2.0 m, khong bang phap tuyen (re hon nhieu, du cho robot 2.5D nay) |
|
||||
| 2D thuan | 0.009 m |
|
||||
| luoi 3D (cach cu) | 0.06-0.11 m |
|
||||
| luoi 3D, tat `Grid/RayTracing` | 0.035 m |
|
||||
| depth vao, luoi giu 2D (**cach hien tai**) | 0.024 m |
|
||||
|
||||
Ban do 3D duoc **dung lai tu dau** tu cac pose DA TOI UU moi lan do thi doi,
|
||||
Dam may nay duoc **dung lai tu dau** tu cac pose DA TOI UU moi lan do thi doi,
|
||||
nen sau mot vong dong no tu nan theo -- khong co buoc "sua ban do" rieng nao.
|
||||
Doi lai, luc do gan nhu moi voxel doi chi so, va server tu chuyen tu gui delta
|
||||
sang gui lai ca tap (`voxel.delta_max_ratio`).
|
||||
Doi lai, luc do gan nhu moi o doi chi so, va server tu chuyen tu gui delta sang
|
||||
gui lai ca tap (`voxel.delta_max_ratio`).
|
||||
|
||||
Lop `the gioi` (mesh Gazebo) la thu KHAC han va chi ton tai trong mo phong --
|
||||
no la su that de doi chieu. Bo tick no thi con lai dung nhung gi vslam tu dung.
|
||||
Tren robot that no khong ton tai.
|
||||
|
||||
Ba dieu can biet truoc khi bat:
|
||||
|
||||
1. **No doi ca luoi 2D.** Vat can thap ma LiDAR khong thay (ban, bac thang)
|
||||
tu nay hien tren ban do 2D. Do la y muon, nhung con so trong muc "dau hieu
|
||||
chay dung" o tren se khac.
|
||||
1. **Luoi 2D KHONG co vat can thap chi camera thay** (mat ban, bac thang):
|
||||
chung chi co trong ban do 3D. `Grid/Sensor: "2"` trong khoi `rtabmap:` se
|
||||
dua chung lai, nhung CHUA do xem no co keo pose lech khong.
|
||||
2. **Ton them RAM/CPU tren Jetson.** Ban xuat voxel chay CUNG ngan sach duty
|
||||
25% voi ban xuat luoi 2D (khong phai them mot ngan sach thu hai), nen no tu
|
||||
gian nhip ra khi do thi lon -- nhung tong cong viec thi nhieu hon.
|
||||
3. **Phai KHOP voi luc quet.** Mo ban do voxel tren mot DB quet phang chi ra
|
||||
MOT lop ngang o cao do LiDAR. Node canh bao khi lech.
|
||||
gian nhip ra khi do thi lon. Moi node chi doi depth -> diem MOT lan; moi
|
||||
lan xuat nap toi da 40 node moi, nen mo mot DB lon thi ban do 3D hien DAN.
|
||||
DB cung nang hon vi luu depth cua moi node.
|
||||
3. **DB phai quet voi `camera_3d: true`** thi moi co depth. DB quet voi false
|
||||
van mo duoc, chi la ban do 3D rong.
|
||||
|
||||
Kiem nhanh ma khong phai mo khung 3D: khung JSON cua WebSocket mang ba truong
|
||||
`slam.voxels_source` (`scan+depth` | `scan` | `off`), `slam.voxel_cells` va
|
||||
`slam.voxels_source` (`depth` | `thieu depth` | `off`), `slam.voxel_cells` va
|
||||
`slam.voxel_epoch`. (KHONG phai `/api/status` -- endpoint do chi tra thong ke
|
||||
cua web server: so client, frames_sent, frames_dropped.)
|
||||
|
||||
|
||||
@@ -453,6 +453,7 @@ StatusResponse Runtime::Start() {
|
||||
// ATE 0.2378 m thay vi 0.0146 m tren map_house.db, khong mot loi nao.
|
||||
Transform cam_to_base = TransformIdentity();
|
||||
cfg_->robot.StaticTransform(kBaseLinkFrame, kCameraDepthOpticalFrame, &cam_to_base);
|
||||
slam_cam_to_link_ = cam_to_base;
|
||||
slam_->SetExtrinsics(laser_to_base, cam_to_base);
|
||||
}
|
||||
#else
|
||||
@@ -959,6 +960,7 @@ void Runtime::SlamLoop() {
|
||||
// Dung tach doan nay thanh mot helper tra ve con tro tho.
|
||||
ImagePtr depth, infra1;
|
||||
std::shared_ptr<const CameraInfo> depth_info;
|
||||
double depth_roll = 0.0, depth_pitch = 0.0;
|
||||
if (slam_use_depth_) {
|
||||
std::lock_guard<std::mutex> lk(depth_mu_);
|
||||
// 50 ms = mac dinh cua ApproxTimeSync. Scan 25 Hz (40 ms) va depth 30 Hz
|
||||
@@ -971,8 +973,17 @@ void Runtime::SlamLoop() {
|
||||
depth = latest_depth_;
|
||||
infra1 = latest_infra1_;
|
||||
depth_info = latest_depth_info_;
|
||||
depth_roll = latest_depth_roll_;
|
||||
depth_pitch = latest_depth_pitch_;
|
||||
}
|
||||
}
|
||||
// Camera nghieng THEO than luc chup. Cung hinh hoc voi GravityAlign va
|
||||
// CliffDetect -- dung chung TiltLift(), khong tu dung mot ban thu ba.
|
||||
// TiltLift nang them wheel_radius, nen z cua ban do 3D tinh tu MAT SAN,
|
||||
// khop voi voxel.z_min va voi hinh robot tren web.
|
||||
const Transform cam_now = TransformCompose(
|
||||
TiltLift(depth_roll, depth_pitch, cfg_->robot.geometry().wheel_radius),
|
||||
slam_cam_to_link_);
|
||||
|
||||
SlamInput in;
|
||||
in.stamp = scan->header.stamp;
|
||||
@@ -981,6 +992,7 @@ void Runtime::SlamLoop() {
|
||||
in.depth = depth.get();
|
||||
in.depth_info = depth_info.get();
|
||||
in.infra1 = infra1.get();
|
||||
in.camera_to_base = depth ? &cam_now : nullptr;
|
||||
|
||||
// --- KHONG MOT MUTEX NAO duoc giu qua dong nay ---
|
||||
const SlamOutput out = slam_->Process(in);
|
||||
@@ -1301,7 +1313,9 @@ void Runtime::WebLoop() {
|
||||
const char* voxels_source = "off";
|
||||
if (voxel_enabled_) {
|
||||
std::lock_guard<std::mutex> dlk(depth_mu_);
|
||||
voxels_source = have_depth_ ? "scan+depth" : "scan";
|
||||
// Ban do voxel dung TU DEPTH cua tung node, khong con tu scan: khong co
|
||||
// depth thi no rong, va nhan phai noi dung dieu do.
|
||||
voxels_source = have_depth_ ? "depth" : "thieu depth";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "vslam/driver_interfaces.h"
|
||||
#include "vslam/ekf_se2.h"
|
||||
#include "vslam/gamepad.h"
|
||||
#include "vslam/geometry.h"
|
||||
#include "vslam/perception_pipeline.h"
|
||||
#include "vslam/safety_monitor.h"
|
||||
#include "vslam/scan_sanitizer.h"
|
||||
@@ -210,6 +211,12 @@ class Runtime {
|
||||
std::shared_ptr<const CameraInfo> latest_depth_info_;
|
||||
UnixTime latest_depth_stamp_;
|
||||
bool have_depth_ = false;
|
||||
// Nghieng (gravity_align) LUC chup khung depth tren -- xem
|
||||
// SlamInput::camera_to_base.
|
||||
double latest_depth_roll_ = 0.0;
|
||||
double latest_depth_pitch_ = 0.0;
|
||||
// base_link <- camera_depth_optical_frame, tinh. Doc-only sau Start().
|
||||
Transform slam_cam_to_link_ = TransformIdentity();
|
||||
|
||||
// mcu_mu_: sieu am va bumper.
|
||||
//
|
||||
|
||||
@@ -218,6 +218,10 @@ StatusResponse Runtime::Wire() {
|
||||
// SlamLoop cam duoc con tro ra ngoai lock.
|
||||
latest_depth_info_ = std::make_shared<const CameraInfo>(f.depth_info);
|
||||
latest_depth_stamp_ = f.header.stamp;
|
||||
// Qua atomic, khong doc thang GravityAlign: tren --live camera va IMU
|
||||
// chay tren HAI luong khac nhau.
|
||||
latest_depth_roll_ = tilt_roll_.load(std::memory_order_relaxed);
|
||||
latest_depth_pitch_ = tilt_pitch_.load(std::memory_order_relaxed);
|
||||
have_depth_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,22 +63,27 @@ visual_loop: false
|
||||
|
||||
# Cong tac cua BAN DO VOXEL 3D tren web UI.
|
||||
#
|
||||
# Bat len keo theo ba thu, tu dong, khong sua tay trong khoi `rtabmap:` ben
|
||||
# duoi (xem BuildRtabmapParams):
|
||||
# Grid/Sensor = 2 scan + depth (truoc do chi scan)
|
||||
# Grid/3D = true luoi cuc bo cua moi node thanh 3 chieu
|
||||
# tach san/vat can bang nguong chieu cao (0.10 m san, 2.0 m tran) thay vi
|
||||
# bang phap tuyen -- re hon nhieu va du cho robot 2.5D nay
|
||||
# Bat len thi:
|
||||
# * depth cua camera vao RTAB-Map cung scan, va duoc LUU trong DB;
|
||||
# * ban do voxel 3D dung NGOAI process(): depth cua moi node chieu thanh
|
||||
# diem MOT lan (cache theo node), roi ghep theo pose da toi uu.
|
||||
# KHONG doi luoi: Grid/* van la 2D, chi tu LiDAR (xem BuildRtabmapParams).
|
||||
#
|
||||
# ⚠️ Doi CA noi dung luoi 2D: vat can thap ma LiDAR khong thay (ban, bac
|
||||
# thang) tu nay hien tren ban do. Do la y muon, nhung no la mot thay doi that.
|
||||
# Vi sao khong de RTAB-Map dung luoi 3D (Grid/Sensor=2 + Grid/3D=true, cach
|
||||
# cu truoc 2026-09-24): no keo pose lech. Do trong mo phong, hospital,
|
||||
# 0.7 m/s, sai so vs ground truth luc dung yen:
|
||||
# 2D thuan 0.009 m
|
||||
# luoi 3D (cach cu) 0.06-0.11 m
|
||||
# luoi 3D, tat Grid/RayTracing 0.035 m
|
||||
# depth vao, luoi giu 2D 0.024 m <- cach hien tai
|
||||
#
|
||||
# ⚠️ Ton them RAM va CPU tren Jetson: moi node luu them o 3D, va ban xuat
|
||||
# voxel chay cung ngan sach duty 25% voi ban xuat luoi 2D.
|
||||
# ⚠️ Luoi 2D KHONG con vat can thap chi camera thay (mat ban, bac thang) --
|
||||
# chung chi con trong ban do 3D. `Grid/Sensor: "2"` trong khoi `rtabmap:`
|
||||
# se dua chung lai, nhung CHUA do xem no co keo pose lech khong.
|
||||
#
|
||||
# ⚠️ Phai KHOP voi luc quet: mo ban do voxel tren mot DB quet phang chi ra
|
||||
# mot lop ngang o cao do LiDAR. Init() canh bao khi lech.
|
||||
camera_3d: false
|
||||
# ⚠️ DB phai quet voi camera_3d: true thi moi co depth de dung ban do 3D.
|
||||
# DB quet voi false van mo duoc, chi la ban do 3D rong.
|
||||
camera_3d: true
|
||||
|
||||
# ============ BAN DO VOXEL 3D ============
|
||||
# Hinh hoc cua ban do 3D gui len web. Chi duoc dung khi camera_3d: true.
|
||||
@@ -86,10 +91,13 @@ camera_3d: false
|
||||
# Tham so TRUYEN (nhip gui, kich thuoc manh) nam o system.yaml khoi `web` --
|
||||
# mot ben la ban do, mot ben la duong day.
|
||||
voxel:
|
||||
# Kich thuoc o PHAT, doc lap voi Grid/CellSize (0.05) cua SLAM. Lam tho them
|
||||
# mot bac cat so voxel di 8 lan (the tich) ma mat rat it hinh dang o muc
|
||||
# "co cai ban o day".
|
||||
emit_size_m: 0.10
|
||||
# Kich thuoc o PHAT. Bang Grid/CellSize cua SLAM, co y.
|
||||
#
|
||||
# Day la buoc luoi de KHU TRUNG LAP, khong phai kich thuoc thu se ve ra: web
|
||||
# ve tap nay bang DIEM chu khong bang hop. Lam tho len 0.10 cat duoc 8 lan so
|
||||
# diem, nhung o tren man hinh no thanh mot khoi Minecraft chu khong con ra
|
||||
# mot ban quet.
|
||||
emit_size_m: 0.05
|
||||
|
||||
# Cat san va tran. z do tu mat san (base_footprint).
|
||||
#
|
||||
@@ -100,12 +108,23 @@ voxel:
|
||||
# khi nhin tu tren xuong.
|
||||
z_max: 2.00
|
||||
|
||||
# Tran cung. Cham tran thi ban do bi CAT BOT va co `truncated` bat len --
|
||||
# tinh ra o log va o /api/status, khong nuot im.
|
||||
# Tran SO O PHAT (khong phai tran cua ban do).
|
||||
#
|
||||
# Uoc luong: mot tang 30x30 m, tuong cao 2 m, o 0.10 m, chi be mat, la
|
||||
# ~24k voxel; phong that co do dac vao khoang 40-80k. 150k la cho thua.
|
||||
max_cells: 150000
|
||||
# Cham tran thi ban do duoc GIAM MAU DEU -- giu nguyen hinh dang, chi thua
|
||||
# di -- va log bao `GIAM MAU 1/k`. KHONG cat cut: cat cut mot danh sach da
|
||||
# sort theo x nghia la mot canh cua toa nha bien mat, va do dung la loi da
|
||||
# mac phai o ban dau.
|
||||
#
|
||||
# Nang so nay lam ban do min hon nhung lan dong bo dau nang hon theo ti le
|
||||
# thang: moi o la 6 byte tren day.
|
||||
#
|
||||
# Uoc luong o 0.05 m: mot tang 30x30 m, tuong cao 2 m, chi be mat, la ~96k o;
|
||||
# phong that co do dac vao khoang 150-250k. 300k la cho thua, KHONG phai
|
||||
# muc tieu.
|
||||
#
|
||||
# ⚠️ Con so nay keo theo bang thong lan dong bo dau: 300k o x 6 byte =
|
||||
# 1.8 MB. Xem phep tinh o system.yaml khoi `web`.
|
||||
max_cells: 300000
|
||||
|
||||
# (them + bot) / tong vuot nguong nay thi gui lai CA TAP thay vi delta.
|
||||
#
|
||||
|
||||
@@ -73,17 +73,23 @@ web:
|
||||
# ghim lai. Them mot cong tan so nua chi co the LAM MAT khung delta -- ma
|
||||
# mat mot delta la client giu ban do sai vinh vien.
|
||||
#
|
||||
# Mot manh cua lan dong bo day du. 16 kB = 2722 o.
|
||||
# Mot manh cua lan dong bo day du. 32 kB = 5461 o.
|
||||
#
|
||||
# ⚠️ Phep tinh bang thong, de canh doan 120 kB/s o tren:
|
||||
# manh full-sync KHONG di qua hang doi, moi lan Publish (10 Hz) bom
|
||||
# `voxel_sync_chunks_per_tick` manh. 1 manh x 16 kB x 10 Hz = 160 kB/s.
|
||||
# Mot ban do 60k o = 23 manh = 2.3 giay.
|
||||
# Tuc la trong 2.3 giay dau cua MOI client moi vao, ngan sach bi vuot. Khung
|
||||
# cloud drop duoc nen chung hap thu phan chenh. Muon em hon thi ha
|
||||
# voxel_chunk_bytes, doi lai dong bo lau hon.
|
||||
voxel_chunk_bytes: 16384
|
||||
voxel_sync_chunks_per_tick: 1
|
||||
# `voxel_sync_chunks_per_tick` manh. 2 x 32 kB x 10 Hz = 655 kB/s.
|
||||
# Mot ban do 150k o (0.05 m, mot tang) = 1.8 MB = 28 manh = 1.4 giay.
|
||||
#
|
||||
# Tuc la trong ~1-3 giay dau cua MOI client moi vao, ngan sach bi vuot NAM
|
||||
# LAN. Chap nhan duoc vi no la mot dot, khong phai nhip thuong truc, va khung
|
||||
# cloud (drop duoc) hap thu phan chenh. Nhung tren WiFi cua Jetson thi do
|
||||
# `frames_dropped` trong /api/status ngay sau khi mo trang: neu no nhay thi
|
||||
# ha `voxel_sync_chunks_per_tick` ve 1.
|
||||
#
|
||||
# Epoch doi (sau mot vong dong lon) lam MOI client dong bo lai tu dau -- do
|
||||
# la ly do `voxel.delta_max_ratio` phai du cao de chuyen do hiem xay ra.
|
||||
voxel_chunk_bytes: 32768
|
||||
voxel_sync_chunks_per_tick: 2
|
||||
|
||||
# ============ Tay cam (Logitech F710/F310, mode XInput) ============
|
||||
# Port 1-1 tu base_kit/src/joy_control -- ban dang chay that tren robot nay.
|
||||
|
||||
@@ -36,6 +36,8 @@ struct RtabmapConfig {
|
||||
// Reg/Strategy=1 (ICP tren LiDAR) van la thu TINH phep bien doi. Nen bat
|
||||
// thi giac khong danh doi do chinh xac.
|
||||
bool visual_loop = false;
|
||||
// Gui depth vao RTAB-Map (luu trong DB) va bat ban do voxel 3D. KHONG doi
|
||||
// luoi -- xem ghi chu trong BuildRtabmapParams.
|
||||
bool camera_3d = false;
|
||||
|
||||
// Optimizer. "1" = g2o. KHONG dung "2" (GTSAM): apt jammy arm64 khong co
|
||||
|
||||
@@ -39,6 +39,14 @@ struct SlamInput {
|
||||
const Image* depth = nullptr;
|
||||
const CameraInfo* depth_info = nullptr;
|
||||
const Image* infra1 = nullptr; // D410 KHONG co RGB -> dung IR trai lam "rgb"
|
||||
|
||||
// base_footprint <- camera_depth_optical_frame TAI luc chup depth, DA gom
|
||||
// nghieng do duoc (TiltLift). Null = dung ngoai lai tinh trong SetExtrinsics
|
||||
// (camera coi nhu luon nam ngang).
|
||||
//
|
||||
// Than robot chuc len/xuong khi tang/giam toc. Coi camera nam ngang thi san
|
||||
// o 3 m bi day len ~0.2 m va thanh vat can gia trong ban do 3D.
|
||||
const Transform* camera_to_base = nullptr;
|
||||
};
|
||||
|
||||
struct SlamOutput {
|
||||
|
||||
@@ -6,26 +6,30 @@
|
||||
// Khac occupancy_export.cc o mot cho ban le: o day KHONG dung
|
||||
// rtabmap::OccupancyGrid. `BuildFromCache` ep Grid/3D="false" ngay trong ham
|
||||
// (occupancy_export.cc) va do la dung cho duong 2D -- no chieu moi thu xuong
|
||||
// mot mat phang. Ban do 3D phai lay o BI CHIEM o he cuc bo cua tung node roi
|
||||
// tu bien doi bang pose DA TOI UU.
|
||||
// mot mat phang. Ban do 3D lay DEPTH cua tung node, chieu thanh diem MOT lan
|
||||
// (cache theo id node), roi moi lan xuat chi bien doi cac diem do bang pose
|
||||
// DA TOI UU. Khong dung luoi cuc bo 3D cua RTAB-Map: dung no trong process()
|
||||
// keo pose lech (xem BuildRtabmapParams).
|
||||
//
|
||||
// ⚠️ Chinh vi dung pose da toi uu ma ban do 3D tu NAN lai sau moi vong dong:
|
||||
// khong co buoc "sua ban do" nao ca, ta dung lai tu dau tu do thi moi. Doi
|
||||
// lai, sau mot lan toi uu thi gan nhu MOI voxel doi chi so -- xem `epoch`
|
||||
// trong VoxelGrid va luat 35% o phia web.
|
||||
//
|
||||
// ⚠️ `data.uncompressData()` la BAT BUOC truoc khi doc gridObstacleCellsRaw().
|
||||
// ⚠️ `data.uncompressData()` la BAT BUOC truoc khi doc depthOrRightRaw().
|
||||
// Quen no thi moi node tra ve ma tran RONG, va trieu chung la "1990 node, 0 o"
|
||||
// -- y het cai bay da co trong occupancy_export.h.
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace rtabmap {
|
||||
class Rtabmap;
|
||||
class SensorData;
|
||||
}
|
||||
|
||||
namespace vslam {
|
||||
@@ -39,13 +43,31 @@ struct VoxelExportOptions {
|
||||
double z_min = 0.05;
|
||||
double z_max = 2.00;
|
||||
|
||||
// Tran cung. Cham tran thi cat bot va bat `truncated` chu khong am tham
|
||||
// nuot: mot ban do 3D thieu mot nua trong im lang la kieu hong te nhat.
|
||||
// Tran SO O PHAT. Cham tran thi GIAM MAU DEU (buoc `stride`), khong cat cut
|
||||
// -- ban do giu nguyen hinh dang, chi thua di. Xem Finish().
|
||||
size_t max_cells = 150000;
|
||||
|
||||
// Gom bao nhieu khoa thi sort+unique mot lan. Doi bo nho dinh lay so lan
|
||||
// tron: 2M khoa = 16 MB tam thoi.
|
||||
size_t flush_every = 2000000;
|
||||
|
||||
// Chieu depth cua node thanh diem. Cung dai voi depth_filter (pipeline.yaml
|
||||
// 0.22-4.0 m): xa hon 4 m nhieu cua D410 tang theo binh phuong.
|
||||
double depth_min_m = 0.22;
|
||||
double depth_max_m = 4.0;
|
||||
// Bang Grid/DepthDecimation (4) ma luoi 3D cu da dung.
|
||||
int depth_decimation = 4;
|
||||
// So node MOI toi da doi depth -> diem trong MOT lan xuat. Localization nap
|
||||
// ca nghin node mot luc; khong gioi han thi lan xuat dau chan luong slam
|
||||
// hang chuc giay. Ban do day dan qua cac lan xuat.
|
||||
size_t max_new_nodes = 40;
|
||||
};
|
||||
|
||||
// Diem cua tung node, o frame CUA NODE, da gom voxel. Tinh MOT lan roi giu:
|
||||
// depth cua node khong doi, chi pose cua no doi sau moi lan toi uu.
|
||||
// CHI luong slam cham vao.
|
||||
struct VoxelNodeCache {
|
||||
std::unordered_map<int, std::vector<float>> nodes; // id -> x,y,z,x,y,z...
|
||||
};
|
||||
|
||||
// Gom diem -> tap voxel. KHONG chua kieu nao cua RTAB-Map, nen test duoc ma
|
||||
@@ -67,6 +89,9 @@ class VoxelAccumulator {
|
||||
// So diem bi cat vi nam ngoai [z_min, z_max].
|
||||
size_t z_rejected() const { return z_rejected_; }
|
||||
|
||||
// Buoc giam mau da dung o lan Finish() gan nhat. 1 = khong giam.
|
||||
size_t stride() const { return stride_; }
|
||||
|
||||
private:
|
||||
void Flush();
|
||||
|
||||
@@ -76,6 +101,7 @@ class VoxelAccumulator {
|
||||
std::vector<uint64_t> acc_; // luon o trang thai da sort+unique
|
||||
size_t clamped_ = 0;
|
||||
size_t z_rejected_ = 0;
|
||||
size_t stride_ = 1;
|
||||
};
|
||||
|
||||
// Quet toan bo pose da toi uu va dung lai tap voxel tu dau.
|
||||
@@ -83,7 +109,15 @@ class VoxelAccumulator {
|
||||
// `out->epoch` KHONG duoc dat o day -- nguoi goi quan ly vong doi epoch, vi
|
||||
// chi ho moi biet tap truoc do la gi.
|
||||
StatusResponse ExportVoxelGrid(rtabmap::Rtabmap& slam,
|
||||
const VoxelExportOptions& opt, VoxelGrid* out);
|
||||
const VoxelExportOptions& opt,
|
||||
VoxelNodeCache* cache, VoxelGrid* out);
|
||||
|
||||
// Depth trong `data` (da uncompressData) -> diem o frame base cua node, cat
|
||||
// theo depth_min/max va z_min/z_max, gom theo emit_size_m. Rong neu node
|
||||
// khong co depth. Tach rieng de test duoc ma khong can Rtabmap.
|
||||
void NodeCloudFromSensorData(const rtabmap::SensorData& data,
|
||||
const VoxelExportOptions& opt,
|
||||
std::vector<float>* out);
|
||||
|
||||
// Hieu hai tap DA SAP XEP: `added` co trong `now` ma khong co trong `prev`,
|
||||
// `removed` thi nguoc lai. O(n + m), mot luot.
|
||||
|
||||
@@ -116,41 +116,16 @@ std::map<std::string, std::string> BuildRtabmapParams(
|
||||
// Kp/MaxFeatures: -1 = tat han tui tu. >0 = so dac trung moi anh.
|
||||
out["Kp/MaxFeatures"] = cfg.visual_loop ? "400" : "-1";
|
||||
|
||||
// --- camera_3d: luoi cuc bo 3D de dung ban do voxel cho web ---
|
||||
// --- camera_3d KHONG dung vao Grid/* ---
|
||||
//
|
||||
// Nam o muc 3 chu khong o `project_defaults`: slam.yaml dat THANG
|
||||
// `Grid/Sensor: "0"` va `Grid/3D: "false"`, ma muc 2 (YAML) ghi de len muc
|
||||
// 1. De o day thi ba key nay la HE QUA cua co, dung nhu Mem/IncrementalMemory
|
||||
// la he qua cua mode.
|
||||
if (cfg.camera_3d) {
|
||||
// 0=scan 1=depth 2=ca hai. Can "2": LiDAR van la trong tai cho ICP, con
|
||||
// depth la thu duy nhat co chieu cao.
|
||||
out["Grid/Sensor"] = "2";
|
||||
out["Grid/3D"] = "true";
|
||||
|
||||
// Tach san/vat can bang NGUONG CHIEU CAO, khong bang phap tuyen.
|
||||
// NormalsSegmentation mac dinh true va la duong DAT: no uoc luong phap
|
||||
// tuyen (Grid/NormalK = 20 lang gieng) cho moi diem, moi khung. Robot nay
|
||||
// la 2.5D (Reg/Force3DoF), san phang, nen mot nguong chieu cao la du.
|
||||
// RTAB-Map cung noi thang: MaxGroundHeight "should be set if
|
||||
// NormalsSegmentation is false".
|
||||
out["Grid/NormalsSegmentation"] = "false";
|
||||
out["Grid/MaxGroundHeight"] = "0.10"; // duoi nguong = san
|
||||
out["Grid/MaxObstacleHeight"] = "2.0"; // tren nguong = tran, vut di
|
||||
|
||||
// ⚠️ Grid/RayTracing GIU NGUYEN "true" (mac dinh cua du an), khong tat.
|
||||
//
|
||||
// Tat no re hon that -- voi Grid/3D=true, ray tracing dien o KHONG GIAN
|
||||
// chu khong phai mat phang, va ban do voxel chi doc o BI CHIEM nen o
|
||||
// trong la chi phi thuan. Nhung no cung chinh la thu sinh ra o "trong"
|
||||
// cua luoi 2D: do tren robot that 2026-09-23, mot phien 3.5 phut cho
|
||||
// 84961 o trong / 5049 o bi chiem. Tat di thi khung ban do tren web gan
|
||||
// nhu chi con mau "chua biet".
|
||||
//
|
||||
// Muon danh doi nguoc lai thi dat `Grid/RayTracing: "false"` trong khoi
|
||||
// `rtabmap:` cua slam.yaml -- do la viec cua nguoi van hanh, khong phai
|
||||
// mot he qua am tham cua camera_3d.
|
||||
}
|
||||
// Truoc 2026-09-24 camera_3d ep Grid/Sensor=2 + Grid/3D=true de RTAB-Map
|
||||
// dung luoi cuc bo 3D TRONG process(). Do trong mo phong (hospital, 0.7 m/s,
|
||||
// sai so vs ground truth luc dung yen): 2D 0.009 m; luoi 3D 0.06-0.11 m;
|
||||
// luoi 3D tat ray tracing 0.035 m; depth vao nhung luoi 2D 0.024 m. Luoi 3D
|
||||
// trong process() keo pose lech -- co che ben trong RTAB-Map CHUA ro.
|
||||
//
|
||||
// Nen luoi giu 2D, depth van vao SensorData (luu trong DB), va ban do 3D
|
||||
// dung NGOAI process() tu depth cua tung node -- xem voxel_export.h.
|
||||
|
||||
// Optimizer: dat TUONG MINH, luon luon.
|
||||
//
|
||||
|
||||
@@ -40,6 +40,9 @@ class RtabmapSlamImpl {
|
||||
|
||||
SlamStats stats;
|
||||
|
||||
// Diem depth theo node cho ban do voxel. Chi ExportVoxels (luong slam) cham.
|
||||
VoxelNodeCache voxel_cache;
|
||||
|
||||
void RecordMs(double ms) {
|
||||
stats.last_ms = ms;
|
||||
stats.max_ms = std::max(stats.max_ms, ms);
|
||||
@@ -167,12 +170,15 @@ StatusResponse RtabmapSlam::Init(const RtabmapConfig& cfg) {
|
||||
"visual_loop=true nhung DB khong co tu vung (Word = 0). Ban do nay "
|
||||
"duoc quet voi visual_loop=false; hai co phai khop nhau.");
|
||||
}
|
||||
if (cfg.camera_3d && facts.exists && !facts.grid_3d) {
|
||||
VSLAM_WARN("slam: camera_3d=true nhung DB nay duoc quet voi Grid/3D=false "
|
||||
"-- ban do voxel se chi co MOT lop ngang o cao do LiDAR. Quet "
|
||||
"lai vao DB moi neu can ban do 3D that.");
|
||||
}
|
||||
if (facts.exists && facts.optimizer_strategy != cfg.optimizer_strategy) {
|
||||
// ⚠️ Canh bao duoi day hoi `nodes > 0`, khong chi `exists`.
|
||||
//
|
||||
// `facts.exists` nghia la MO DUOC, khong phai CO BAN DO: sqlite tao file
|
||||
// ngay khi `InspectDatabase` mo no, nen mot duong dan moi tinh cung ra
|
||||
// exists=true voi nodes=0 va moi tham so rong. Chi kiem `exists` thi moi lan
|
||||
// quet moi deu keu "DB nay quet voi Grid/3D=false" va "DB luu
|
||||
// Optimizer/Strategy=" (gia tri rong) -- do dung la cai da in ra o lan chay
|
||||
// dau tien cua ban do 3D.
|
||||
if (facts.nodes > 0 && facts.optimizer_strategy != cfg.optimizer_strategy) {
|
||||
VSLAM_WARN("slam: DB luu Optimizer/Strategy=" << facts.optimizer_strategy
|
||||
<< ", dang ep ve " << cfg.optimizer_strategy
|
||||
<< " (loadDatabaseParameters=false)");
|
||||
@@ -264,7 +270,10 @@ SlamOutput RtabmapSlam::Process(const SlamInput& in) {
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
|
||||
rtabmap::SensorData data =
|
||||
BuildSensorData(in, impl_->laser_to_base, impl_->camera_to_base, impl_->next_id++);
|
||||
BuildSensorData(in, impl_->laser_to_base,
|
||||
in.camera_to_base != nullptr ? *in.camera_to_base
|
||||
: impl_->camera_to_base,
|
||||
impl_->next_id++);
|
||||
|
||||
bool ok = false;
|
||||
try {
|
||||
@@ -352,7 +361,7 @@ StatusResponse RtabmapSlam::ExportVoxels(const VoxelExportOptions& opt,
|
||||
if (!impl_->inited) {
|
||||
return StatusResponse::Error(StatusCode::kFailedPrecondition, "chua init");
|
||||
}
|
||||
return ExportVoxelGrid(impl_->rtabmap, opt, out);
|
||||
return ExportVoxelGrid(impl_->rtabmap, opt, &impl_->voxel_cache, out);
|
||||
}
|
||||
|
||||
StatusResponse RtabmapSlam::Close(bool save_database) {
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
#include <rtabmap/core/Rtabmap.h>
|
||||
#include <rtabmap/core/SensorData.h>
|
||||
#include <rtabmap/core/Transform.h>
|
||||
#include <rtabmap/core/util3d.h>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "vslam/log.h"
|
||||
#include "vslam/node_constants.h"
|
||||
@@ -113,12 +116,27 @@ void VoxelAccumulator::Finish(VoxelGrid* out) {
|
||||
out->origin_y = 0.0;
|
||||
out->origin_z = 0.0;
|
||||
out->header.frame_id = kMapFrame;
|
||||
out->truncated = acc_.size() > opt_.max_cells;
|
||||
|
||||
const size_t n = std::min(acc_.size(), opt_.max_cells);
|
||||
// ⚠️ Cham tran thi GIAM MAU DEU, tuyet doi khong cat cut danh sach.
|
||||
//
|
||||
// `acc_` sort theo khoa goi, ma khoa goi sort theo x truoc -- nen lay
|
||||
// `max_cells` phan tu DAU la chat mot lat khong gian: nguyen mot canh cua
|
||||
// toa nha bien mat khoi ban do trong khi phan con lai van day du. Da mac
|
||||
// dung loi nay: nguoi dung bao "goc tren ben trai quet roi ma gio mat".
|
||||
//
|
||||
// Giam mau deu thi ban do GIU NGUYEN hinh dang, chi thua di. Cung khuon mau
|
||||
// ma EncodeCloud dung cho `cloud_max_points` (binary_codec.cc) -- buoc deu,
|
||||
// khong cat duoi.
|
||||
const size_t total = acc_.size();
|
||||
stride_ = 1;
|
||||
if (opt_.max_cells > 0 && total > opt_.max_cells) {
|
||||
stride_ = (total + opt_.max_cells - 1) / opt_.max_cells;
|
||||
}
|
||||
out->truncated = stride_ > 1;
|
||||
|
||||
out->cells.clear();
|
||||
out->cells.reserve(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
out->cells.reserve(total / stride_ + 1);
|
||||
for (size_t i = 0; i < total; i += stride_) {
|
||||
int32_t x = 0, y = 0, z = 0;
|
||||
UnpackKey(acc_[i], &x, &y, &z);
|
||||
VoxelIndex k;
|
||||
@@ -154,8 +172,33 @@ void DiffVoxelGrids(const std::vector<VoxelIndex>& prev,
|
||||
for (; j < now.size(); ++j) added->push_back(now[j]);
|
||||
}
|
||||
|
||||
void NodeCloudFromSensorData(const rtabmap::SensorData& data,
|
||||
const VoxelExportOptions& opt,
|
||||
std::vector<float>* out) {
|
||||
out->clear();
|
||||
if (data.depthOrRightRaw().empty() || data.cameraModels().empty()) return;
|
||||
// cloudFromSensorData ap localTransform cua camera (base <- optical), nen
|
||||
// diem ra o frame base cua node -- cung frame voi pose cua no.
|
||||
const auto cloud = rtabmap::util3d::cloudFromSensorData(
|
||||
data, opt.depth_decimation, static_cast<float>(opt.depth_max_m),
|
||||
static_cast<float>(opt.depth_min_m));
|
||||
if (!cloud) return;
|
||||
VoxelAccumulator acc(opt);
|
||||
for (const auto& p : cloud->points) acc.AddPoint(p.x, p.y, p.z);
|
||||
VoxelGrid vg;
|
||||
acc.Finish(&vg);
|
||||
const double s = opt.emit_size_m;
|
||||
out->reserve(vg.cells.size() * 3);
|
||||
for (const VoxelIndex& k : vg.cells) {
|
||||
out->push_back(static_cast<float>((k.x + 0.5) * s));
|
||||
out->push_back(static_cast<float>((k.y + 0.5) * s));
|
||||
out->push_back(static_cast<float>((k.z + 0.5) * s));
|
||||
}
|
||||
}
|
||||
|
||||
StatusResponse ExportVoxelGrid(rtabmap::Rtabmap& slam,
|
||||
const VoxelExportOptions& opt, VoxelGrid* out) {
|
||||
const VoxelExportOptions& opt,
|
||||
VoxelNodeCache* cache, VoxelGrid* out) {
|
||||
const std::map<int, rtabmap::Transform>& poses = slam.getLocalOptimizedPoses();
|
||||
if (poses.empty()) {
|
||||
return StatusResponse::Error(StatusCode::kFailedPrecondition,
|
||||
@@ -167,35 +210,37 @@ StatusResponse ExportVoxelGrid(rtabmap::Rtabmap& slam,
|
||||
"rtabmap chua co Memory");
|
||||
}
|
||||
|
||||
// Bo node khong con trong do thi (bi gop/xoa) -- khong thi cache phinh mai.
|
||||
for (auto it = cache->nodes.begin(); it != cache->nodes.end();) {
|
||||
it = poses.count(it->first) ? std::next(it) : cache->nodes.erase(it);
|
||||
}
|
||||
|
||||
VoxelAccumulator acc(opt);
|
||||
size_t nodes_with_grid = 0;
|
||||
int channels_seen = 0;
|
||||
size_t nodes_used = 0, fetched = 0, pending = 0, no_points = 0;
|
||||
|
||||
for (const auto& kv : poses) {
|
||||
if (kv.second.isNull()) continue;
|
||||
rtabmap::SensorData data = mem->getNodeData(kv.first, false, false, false, true);
|
||||
// ⚠️ BAT BUOC. Thieu dong nay thi gridObstacleCellsRaw() tra ma tran RONG
|
||||
// o moi node va ban do 3D im lang rong khong.
|
||||
data.uncompressData();
|
||||
if (data.gridCellSize() <= 0.0f) continue;
|
||||
|
||||
const cv::Mat& obs = data.gridObstacleCellsRaw();
|
||||
if (obs.empty()) continue;
|
||||
if (obs.depth() != CV_32F) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInternal,
|
||||
"o luoi cuc bo khong phai float32 (depth=" +
|
||||
std::to_string(obs.depth()) + ") -- phien ban RTAB-Map la");
|
||||
auto it = cache->nodes.find(kv.first);
|
||||
if (it == cache->nodes.end()) {
|
||||
if (fetched >= opt.max_new_nodes) {
|
||||
++pending;
|
||||
continue;
|
||||
}
|
||||
++fetched;
|
||||
// images=true, con lai false: chi can depth + camera model.
|
||||
rtabmap::SensorData data = mem->getNodeData(kv.first, true, false, false, false);
|
||||
// ⚠️ BAT BUOC. Thieu dong nay thi depthOrRightRaw() tra ma tran RONG o
|
||||
// moi node va ban do 3D im lang rong khong.
|
||||
data.uncompressData();
|
||||
std::vector<float> pts;
|
||||
NodeCloudFromSensorData(data, opt, &pts);
|
||||
it = cache->nodes.emplace(kv.first, std::move(pts)).first;
|
||||
}
|
||||
|
||||
const int ch = obs.channels();
|
||||
if (ch < 2) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInternal,
|
||||
"o luoi cuc bo co " + std::to_string(ch) +
|
||||
" kenh, cho doi 2 (XY) hoac 3/4 (XYZ[+RGB])");
|
||||
const std::vector<float>& pts = it->second;
|
||||
if (pts.empty()) {
|
||||
++no_points;
|
||||
continue;
|
||||
}
|
||||
if (channels_seen == 0) channels_seen = ch;
|
||||
|
||||
// Pose da toi uu: node -> map. Dung ma tran 3x4 dung san, 12 phep nhan
|
||||
// cho moi diem, thay vi dung mot rtabmap::Transform cho tung diem.
|
||||
@@ -204,37 +249,34 @@ StatusResponse ExportVoxelGrid(rtabmap::Rtabmap& slam,
|
||||
const float r10 = T.r21(), r11 = T.r22(), r12 = T.r23(), ty = T.y();
|
||||
const float r20 = T.r31(), r21 = T.r32(), r22 = T.r33(), tz = T.z();
|
||||
|
||||
const int n = obs.cols * obs.rows;
|
||||
const float* p = obs.ptr<float>();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const float px = p[0];
|
||||
const float py = p[1];
|
||||
// 2 kenh = luoi PHANG (DB quet voi Grid/3D=false). Van ve duoc, chi la
|
||||
// ra mot lop ngang -- Init() da canh bao truong hop nay.
|
||||
const float pz = (ch >= 3) ? p[2] : 0.0f;
|
||||
p += ch;
|
||||
|
||||
for (size_t i = 0; i + 2 < pts.size(); i += 3) {
|
||||
const float px = pts[i], py = pts[i + 1], pz = pts[i + 2];
|
||||
acc.AddPoint(r00 * px + r01 * py + r02 * pz + tx,
|
||||
r10 * px + r11 * py + r12 * pz + ty,
|
||||
r20 * px + r21 * py + r22 * pz + tz);
|
||||
}
|
||||
++nodes_with_grid;
|
||||
++nodes_used;
|
||||
}
|
||||
|
||||
if (nodes_with_grid == 0) {
|
||||
if (nodes_used == 0) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kFailedPrecondition,
|
||||
"khong node nao co luoi cuc bo -- RGBD/CreateOccupancyGrid tat, hoac "
|
||||
"DB quet truoc khi bat camera_3d");
|
||||
pending > 0 ? "dang nap depth cua node"
|
||||
: "khong node nao co depth -- DB quet voi camera_3d=false, "
|
||||
"hoac khong co camera");
|
||||
}
|
||||
|
||||
acc.Finish(out);
|
||||
|
||||
// Mot dong, mot lan moi 30 giay: so kenh la thu duy nhat trong ca duong nay
|
||||
// khong doc duoc tu header RTAB-Map, nen no phai hien ra o log that.
|
||||
// Mot dong, mot lan moi 30 giay. `khong co diem` cao bat thuong nghia la
|
||||
// getNodeData khong tra depth -- thu dau tien can nhin khi ban do 3D rong.
|
||||
VSLAM_INFO_THROTTLE(30.0, "slam: voxel " << out->cells.size() << " o tu "
|
||||
<< nodes_with_grid << " node (" << channels_seen
|
||||
<< " kenh/o" << (out->truncated ? ", DA CAT BOT" : "")
|
||||
<< nodes_used << " node (dang nap " << pending << ", "
|
||||
<< no_points << " node khong co diem"
|
||||
<< (out->truncated
|
||||
? ", GIAM MAU 1/" + std::to_string(acc.stride()) +
|
||||
" -- cham tran max_cells"
|
||||
: std::string())
|
||||
<< ")");
|
||||
if (acc.clamped() > 0) {
|
||||
VSLAM_WARN_THROTTLE(30.0, "slam: " << acc.clamped()
|
||||
|
||||
@@ -46,7 +46,7 @@ struct SlamSnapshot {
|
||||
uint32_t map_version = 0;
|
||||
double process_ms = 0.0;
|
||||
|
||||
// Ban do voxel 3D den tu dau: "scan+depth" | "scan" | "off".
|
||||
// Ban do voxel 3D den tu dau: "depth" | "thieu depth" | "off".
|
||||
// Hien trong JSON status de mot ban do 3D RONG doc duoc ma khong phai mo
|
||||
// khung 3D len xem -- cung ly do voi dong dem o/trong/chua-biet cua luoi 2D.
|
||||
std::string voxels_source = "off";
|
||||
|
||||
@@ -12,7 +12,7 @@ const MAGIC = 0x314C5356; // 'VSL1' little-endian
|
||||
// Phien ban ma nguon giao dien. TANG khi doi app.js / app3d.js / style.css.
|
||||
// Hien ngay tren thanh tren cung de phan biet "chua sua" voi "trinh duyet con
|
||||
// cache ban cu".
|
||||
const UI_VERSION = '2026-09-23a';
|
||||
const UI_VERSION = '2026-09-23d';
|
||||
|
||||
// ⚠️ HAI bang mau, mot cho moi khung. Chung KHONG duoc giong nhau.
|
||||
//
|
||||
@@ -722,6 +722,16 @@ function updateSlamLabel() {
|
||||
labR.textContent = 'SLAM TAT -- chay lai voi --slam';
|
||||
return;
|
||||
}
|
||||
// Che do 3D|3D: khung phai la DAM MAY, khong phai luoi 2D -- dem o cua dam
|
||||
// may moi la con so noi len no dang dung toi dau.
|
||||
if (split3d) {
|
||||
const v = state.voxels;
|
||||
labR.textContent = v && v.set.size
|
||||
? 'SLAM 3D ' + v.set.size.toLocaleString() + ' o @ ' + v.res.toFixed(2) + ' m' +
|
||||
(v.syncing ? ' (dang tai...)' : '')
|
||||
: 'SLAM 3D (chua co diem -- can camera_3d: true va lai them)';
|
||||
return;
|
||||
}
|
||||
const m = state.map;
|
||||
labR.textContent = m
|
||||
? 'SLAM ' + state.slamMode + ' ' + (m.w * m.res).toFixed(1) + ' x ' +
|
||||
@@ -747,6 +757,10 @@ function draw() {
|
||||
updateSlamLabel();
|
||||
drawScene(cvR, ctxR, state.map, state.mapImage, state.pose, true, 'lyMap',
|
||||
PALETTE.slam);
|
||||
} else if (split3d) {
|
||||
// Khong co canvas thu hai o che do nay: draw3d() da ve ca hai nua. Chi
|
||||
// con cap nhat nhan.
|
||||
updateSlamLabel();
|
||||
}
|
||||
requestAnimationFrame(draw);
|
||||
return;
|
||||
@@ -1030,23 +1044,51 @@ connect();
|
||||
const btnSplit = document.getElementById('btnSplit');
|
||||
const labR = document.getElementById('labR');
|
||||
const wrap = document.querySelector('.canvas-wrap');
|
||||
// Hai co, KHONG phai mot: chung la hai LAYOUT khac han nhau.
|
||||
// split -> khung phai la canvas 2D that (#mainR)
|
||||
// split3d -> mot canvas 3D duy nhat, tu cat lam doi bang scissor
|
||||
let split = false;
|
||||
let split3d = false;
|
||||
|
||||
function applySplitMode() {
|
||||
wrap.classList.toggle('split', split);
|
||||
wrap.classList.toggle('split3d', split3d);
|
||||
const chia = split || split3d;
|
||||
document.getElementById('labL').style.display = chia ? '' : 'none';
|
||||
labR.style.display = chia ? '' : 'none';
|
||||
btnSplit.textContent = split ? 'chia doi 3D' : (split3d ? 'mot khung' : 'chia doi');
|
||||
btnSplit.title = split
|
||||
? 'Bam nua: khung phai thanh DAM MAY 3D do SLAM quet ra'
|
||||
: (split3d ? 'Bam nua: ve mot khung'
|
||||
: 'Hai khung: THE GIOI (de lai) va SLAM (de xem ban do dang dung)');
|
||||
}
|
||||
|
||||
// Nut xoay vong BA kieu thay vi bat/tat:
|
||||
// tat -> the gioi | ban do 2D -> the gioi | dam may 3D -> tat
|
||||
//
|
||||
// Kieu thu hai giu nguyen vi code cu goi no la "to hop huu ich nhat khi dang
|
||||
// quet". Kieu thu ba la de NHIN ban do 3D dung len theo thoi gian thuc, canh
|
||||
// chinh cai the gioi that -- do la cau hoi khac: khong phai "quet toi dau" ma
|
||||
// "quet ra co giong that khong".
|
||||
btnSplit.addEventListener('click', () => {
|
||||
if (!state.worldMap) {
|
||||
// Khong co su that de doi chieu -- chay that, khong phai mo phong.
|
||||
btnSplit.textContent = 'khong co su that';
|
||||
setTimeout(() => { btnSplit.textContent = 'chia doi'; }, 1800);
|
||||
setTimeout(applySplitMode, 1800);
|
||||
return;
|
||||
}
|
||||
split = !split;
|
||||
wrap.classList.toggle('split', split);
|
||||
document.getElementById('labL').style.display = split ? '' : 'none';
|
||||
labR.style.display = split ? '' : 'none';
|
||||
btnSplit.textContent = split ? 'mot khung' : 'chia doi';
|
||||
// 3D va chia doi KHONG loai tru nhau: `.split.three` cho ra
|
||||
// trai = the gioi 3D (Gazebo) | phai = ban do SLAM 2D (RViz)
|
||||
// -- dung to hop huu ich nhat khi dang quet.
|
||||
if (!split && !split3d) {
|
||||
split = true;
|
||||
} else if (split) {
|
||||
split = false;
|
||||
split3d = true;
|
||||
// Kieu nay VO NGHIA o 2D. Tu bat 3D thay vi de nguoi dung bam mot nut
|
||||
// khong lam gi ca -- dung cach cac nut goc nhin dang lam.
|
||||
setThreeD(true);
|
||||
} else {
|
||||
split3d = false;
|
||||
}
|
||||
applySplitMode();
|
||||
});
|
||||
|
||||
{
|
||||
@@ -1104,6 +1146,14 @@ function setThreeD(on) {
|
||||
// stylesheet -- dung cai bay da lam khung phai den xi mot lan.
|
||||
wrap.classList.toggle('three', use3d);
|
||||
btn3d.textContent = use3d ? '2D' : '3D';
|
||||
// Tat 3D thi kieu chia doi 3D|3D khong con cho dua: canvas 3D ngung duoc ve
|
||||
// nhung CSS van cho no hien, nen man hinh se dong bang o khung hinh cuoi
|
||||
// cung. Roi ve kieu chia doi thuong.
|
||||
if (!use3d && split3d) {
|
||||
split3d = false;
|
||||
split = true;
|
||||
applySplitMode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1184,10 +1234,10 @@ function draw3d() {
|
||||
|
||||
// SLAM: lop phu tren san, hien DAN khi quet -- day la phan "RViz". O chua
|
||||
// quet trong suot nen tuong 3D van nhin xuyen qua.
|
||||
// VOXEL: "cai gi dung tren san", bu cho tam phang cua v3dSetMap ("da quet
|
||||
// toi dau"). Hai lop khong tranh nhau: tam phang o y = -0.002, voxel bat
|
||||
// dau tu z_min = 0.05.
|
||||
v3dSetVoxels(state.voxels, on('lyVoxel'));
|
||||
// Dam may DA QUET: nhung gi camera nhin thay, giu lai va nan theo pose toi
|
||||
// uu. Bu cho tam phang cua v3dSetMap ("da quet toi dau"); hai lop khong
|
||||
// tranh nhau vi tam phang o y = -0.002 con dam may bat dau tu z_min = 0.05.
|
||||
v3dSetMapCloud(state.voxels, on('lyMapCloud'));
|
||||
|
||||
if (state.map && on('lyMap')) {
|
||||
v3dSetMap({ ...state.map, data: state.map.cells, version: state.mapVersion });
|
||||
@@ -1196,7 +1246,7 @@ function draw3d() {
|
||||
if (on('lyPath')) v3dSetPath(state.path);
|
||||
else if (V3D.pathLine) V3D.pathLine.visible = false;
|
||||
|
||||
v3dRender(cv3d, on('lyFollow'));
|
||||
v3dRender(cv3d, on('lyFollow'), split3d);
|
||||
}
|
||||
|
||||
requestAnimationFrame(draw);
|
||||
|
||||
@@ -24,7 +24,7 @@ const V3D = {
|
||||
ready: false,
|
||||
scene: null, camera: null, renderer: null, root: null,
|
||||
robotGroup: null, scanPts: null, cloudPts: null, mapMesh: null,
|
||||
voxelMesh: null, voxelCap: 0, voxelEpoch: -1,
|
||||
mapCloud: null, mapCloudCap: 0, mapCloudRes: 0,
|
||||
worldMesh: null, worldKey: null,
|
||||
meshWorld: null, // nhom mesh THAT doc tu .world; co thi khong dung khoi hop
|
||||
gtGroup: null, pathLine: null,
|
||||
@@ -497,91 +497,98 @@ function v3dSetCloud(arr, pose) {
|
||||
V3D.cloudPts.geometry.setAttribute('color', new THREE.BufferAttribute(col, 3));
|
||||
}
|
||||
|
||||
// --- Ban do voxel 3D -------------------------------------------------------
|
||||
// --- Ban do 3D da quet (dam may diem tich luy) -----------------------------
|
||||
//
|
||||
// Nguon: SLAM, khong phai bo mo phong. Day la "cai gi dung tren san" do chinh
|
||||
// robot do duoc, bu cho tam phang cua v3dSetMap ("da quet toi dau").
|
||||
// Nguon: SLAM, khong phai bo mo phong. Day la nhung gi CHINH CON ROBOT quet
|
||||
// duoc, giu lai va nan theo pose da toi uu -- phan "RViz" that su, bu cho tam
|
||||
// phang cua v3dSetMap ("da quet toi dau").
|
||||
//
|
||||
// Ba cho CO Y khac v3dSetWorld va v3dSetCloud, moi cho vi mot ly do:
|
||||
// VE BANG DIEM, khong phai bang hop. Du lieu ben duoi van la tap voxel (do la
|
||||
// cach khu trung lap va giu bang thong), nhung mot khoi hop 5-10 cm nhin ra
|
||||
// Minecraft chu khong ra mot ban quet. Diem cho dung cam giac cua dam may
|
||||
// camera, va dung bang mau voi lop cloud truc tiep nen hai thu doc nhu mot.
|
||||
//
|
||||
// 1. Dung lai theo NOI DUNG (`v.dirty`), khong theo kich thuoc. v3dSetWorld
|
||||
// cache theo `w x h @ ox,oy` -- dung cho mot ban do TINH, sai hoan toan o
|
||||
// day vi tap voxel doi lien tuc trong khi bao ngoai dung yen.
|
||||
// Ba cho CO Y khac v3dSetCloud (dam may TRUC TIEP, mot khung):
|
||||
//
|
||||
// 2. KHONG dispose/dung lai hinh moi khung nhu v3dSetCloud. InstancedMesh co
|
||||
// so luong co dinh, nen cap phat du `capacity` roi chi doi `count`. O
|
||||
// 100k the thi kieu cua cloud khong song noi.
|
||||
// 1. Dung lai theo NOI DUNG (`v.dirty`), khong phai moi khung. Tap nay doi
|
||||
// toi da ~4 lan/giay chu khong 8-10, va no to gap tram lan.
|
||||
//
|
||||
// 3. KHONG do bong. v3dSetWorld bat ca castShadow lan receiveShadow; nem
|
||||
// 100k the vao shadow map 2048^2 la mat frame rate. Dung "sua" lai.
|
||||
function v3dSetVoxels(v, visible) {
|
||||
// 2. Cap phat theo CAPACITY roi dung setDrawRange, khong dispose/dung lai
|
||||
// BufferGeometry moi lan. v3dSetCloud lam vay voi 2000 diem thi khong sao;
|
||||
// o 100k diem do la 1.2 MB rac moi lan cap nhat.
|
||||
//
|
||||
// 3. Toa do la TUYET DOI trong frame map -- khong nhan pose. Dam may truc
|
||||
// tiep nam o base_footprint nen phai xoay theo robot; tap nay da o he ban
|
||||
// do tu luc xuat.
|
||||
function v3dSetMapCloud(v, visible) {
|
||||
if (!V3D.ready) return;
|
||||
if (!v || !visible || v.set.size === 0) {
|
||||
if (V3D.voxelMesh) V3D.voxelMesh.visible = false;
|
||||
if (V3D.mapCloud) V3D.mapCloud.visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const n = v.set.size;
|
||||
const needNew = !V3D.voxelMesh || n > V3D.voxelCap ||
|
||||
(V3D.voxelMesh && V3D.voxelRes !== v.res);
|
||||
const needNew = !V3D.mapCloud || n > V3D.mapCloudCap || V3D.mapCloudRes !== v.res;
|
||||
if (needNew) {
|
||||
if (V3D.voxelMesh) {
|
||||
V3D.root.remove(V3D.voxelMesh);
|
||||
V3D.voxelMesh.geometry.dispose();
|
||||
V3D.voxelMesh.material.dispose();
|
||||
if (V3D.mapCloud) {
|
||||
V3D.root.remove(V3D.mapCloud);
|
||||
V3D.mapCloud.geometry.dispose();
|
||||
V3D.mapCloud.material.dispose();
|
||||
}
|
||||
// Cap phat du de lon them mot doan ma khong phai cap phat lai moi khung.
|
||||
let cap = 1024;
|
||||
let cap = 4096;
|
||||
while (cap < Math.ceil(n * 1.5)) cap *= 2;
|
||||
const geo = new THREE.BoxGeometry(v.res, v.res, v.res);
|
||||
const mat = new THREE.MeshStandardMaterial({ roughness: 0.9, metalness: 0.0 });
|
||||
V3D.voxelMesh = new THREE.InstancedMesh(geo, mat, cap);
|
||||
// Bounding sphere cua InstancedMesh lay tu hinh GOC (mot hop 0.1 m), nen
|
||||
// de mac dinh thi three.js cull ca ban do ngay khi goc toa do ra khoi khung.
|
||||
V3D.voxelMesh.frustumCulled = false;
|
||||
V3D.voxelMesh.castShadow = false;
|
||||
V3D.voxelMesh.receiveShadow = false;
|
||||
V3D.voxelCap = cap;
|
||||
V3D.voxelRes = v.res;
|
||||
V3D.root.add(V3D.voxelMesh);
|
||||
v.dirty = true; // hinh moi -> phai do lai du lieu
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(cap * 3), 3));
|
||||
geo.setAttribute('color', new THREE.BufferAttribute(new Float32Array(cap * 3), 3));
|
||||
// Co diem theo do phan giai: o 0.05 m thi 0.04 cho ra mot mat lien chu
|
||||
// khong phai mot ram cham roi rac.
|
||||
const mat = new THREE.PointsMaterial({ size: v.res * 0.8, vertexColors: true });
|
||||
V3D.mapCloud = new THREE.Points(geo, mat);
|
||||
// Bounding sphere tinh tu capacity con thua (toan so 0 o goc), nen cull se
|
||||
// sai. Tap nay trai ca toa nha, cull no khong tiet kiem duoc gi.
|
||||
V3D.mapCloud.frustumCulled = false;
|
||||
V3D.mapCloudCap = cap;
|
||||
V3D.mapCloudRes = v.res;
|
||||
V3D.root.add(V3D.mapCloud);
|
||||
v.dirty = true; // bo dem moi -> phai do lai
|
||||
}
|
||||
|
||||
V3D.voxelMesh.visible = true;
|
||||
V3D.mapCloud.visible = true;
|
||||
if (!v.dirty) return;
|
||||
v.dirty = false;
|
||||
|
||||
const m4 = new THREE.Matrix4();
|
||||
const col = new THREE.Color();
|
||||
const pos = V3D.mapCloud.geometry.attributes.position.array;
|
||||
const col = V3D.mapCloud.geometry.attributes.color.array;
|
||||
const half = v.res * 0.5;
|
||||
let i = 0;
|
||||
for (const key of v.set) {
|
||||
// Giai khoa tai cho: goi voxelUnpack() 100k lan moi lan dung lai la
|
||||
// 100k mang tam.
|
||||
// Giai khoa TAI CHO: goi voxelUnpack() 100k lan la 100k mang tam.
|
||||
const z = (key % 65536) - 32768;
|
||||
const k1 = (key - (z + 32768)) / 65536;
|
||||
const y = (k1 % 65536) - 32768;
|
||||
const x = (k1 - (y + 32768)) / 65536 - 32768;
|
||||
|
||||
// Tam o, khong phai goc o. ROS (x, y, z) -> three (x, z, -y) -- giong
|
||||
// toScene(), nhung noi thang vao day: toScene() cap phat mot Vector3 moi
|
||||
// lan goi, va 100k lan cap phat moi lan dung lai la mot con bao GC.
|
||||
// Tam o. ROS (x, y, z) -> three (x, z, -y), noi thang thay vi goi
|
||||
// toScene(): ham do cap phat mot Vector3 moi lan.
|
||||
const wx = v.ox + x * v.res + half;
|
||||
const wy = v.oy + y * v.res + half;
|
||||
const wz = v.oz + z * v.res + half;
|
||||
m4.makeTranslation(wx, wz, -wy);
|
||||
V3D.voxelMesh.setMatrixAt(i, m4);
|
||||
const b = i * 3;
|
||||
pos[b] = wx;
|
||||
pos[b + 1] = wz;
|
||||
pos[b + 2] = -wy;
|
||||
|
||||
// Cung thang mau voi point cloud, gian ra toi 2 m: hai lop phai doc nhu
|
||||
// mot he, khong phai hai he mau canh nhau.
|
||||
// Cung thang mau voi lop cloud truc tiep (v3dSetCloud), gian ra toi 2 m.
|
||||
const t = Math.max(0, Math.min(1, wz / 2.0));
|
||||
col.setRGB((80 + 175 * t) / 255, (200 - 90 * t) / 255, (120 + 60 * t) / 255);
|
||||
V3D.voxelMesh.setColorAt(i, col);
|
||||
col[b] = (80 + 175 * t) / 255;
|
||||
col[b + 1] = (200 - 90 * t) / 255;
|
||||
col[b + 2] = (120 + 60 * t) / 255;
|
||||
++i;
|
||||
}
|
||||
V3D.voxelMesh.count = i;
|
||||
V3D.voxelMesh.instanceMatrix.needsUpdate = true;
|
||||
if (V3D.voxelMesh.instanceColor) V3D.voxelMesh.instanceColor.needsUpdate = true;
|
||||
|
||||
V3D.mapCloud.geometry.setDrawRange(0, i);
|
||||
V3D.mapCloud.geometry.attributes.position.needsUpdate = true;
|
||||
V3D.mapCloud.geometry.attributes.color.needsUpdate = true;
|
||||
}
|
||||
|
||||
// The gioi 3D: o BI CHIEM -> hop, dung nhu Gazebo dung tuong tu ban do.
|
||||
@@ -939,12 +946,27 @@ function v3dSetOverlays(on) {
|
||||
});
|
||||
}
|
||||
|
||||
function v3dRender(canvas, follow) {
|
||||
// `splitSlam` = ve HAI viewport trong cung mot canvas:
|
||||
// trai = canh nhu dang co (the gioi + moi thu, theo lop nguoi dung chon)
|
||||
// phai = CHI nhung gi SLAM dung ra (the gioi bi ep an)
|
||||
//
|
||||
// Mot renderer, hai lan render, cat bang scissor -- KHONG mo WebGLRenderer thu
|
||||
// hai. Hai GL context tren cung mot trang la gap doi bo nho texture va mot
|
||||
// nguon loi "context lost" kinh dien tren Jetson.
|
||||
//
|
||||
// Camera dung CHUNG co y: hai khung cung goc nhin thi moi doi chieu duoc "ngoai
|
||||
// doi cho nay co cai ban, SLAM quet ra gi". Lech goc la mat ca y nghia.
|
||||
function v3dRender(canvas, follow, splitSlam) {
|
||||
if (!V3D.ready) return;
|
||||
const w = canvas.clientWidth, h = canvas.clientHeight;
|
||||
if (canvas.width !== w || canvas.height !== h) {
|
||||
V3D.renderer.setSize(w, h, false);
|
||||
V3D.camera.aspect = w / Math.max(1, h);
|
||||
}
|
||||
// Ti le khung hinh tinh theo NUA chieu rong khi chia doi, khong thi hinh bi
|
||||
// keo ngang o ca hai ben.
|
||||
const aspect = (splitSlam ? w / 2 : w) / Math.max(1, h);
|
||||
if (V3D.camera.aspect !== aspect) {
|
||||
V3D.camera.aspect = aspect;
|
||||
V3D.camera.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
@@ -960,5 +982,50 @@ function v3dRender(canvas, follow) {
|
||||
o.dist * Math.sin(o.el),
|
||||
cz + o.dist * Math.cos(o.el) * Math.sin(o.az));
|
||||
V3D.camera.lookAt(cx, 0.2, cz);
|
||||
V3D.renderer.render(V3D.scene, V3D.camera);
|
||||
|
||||
const r = V3D.renderer;
|
||||
if (!splitSlam) {
|
||||
r.setScissorTest(false);
|
||||
r.setViewport(0, 0, w, h);
|
||||
r.render(V3D.scene, V3D.camera);
|
||||
return;
|
||||
}
|
||||
|
||||
const half = Math.floor(w / 2);
|
||||
r.setScissorTest(true);
|
||||
|
||||
// Hai nua an hai thu KHAC NHAU, va phep an nay chi la MOT CHIEU: no tat bot,
|
||||
// khong bao gio bat len. Nguoi dung tick lop nao thi lop do moi co cua de
|
||||
// hien -- khong dung v3dSetWorldVisible()/visible=true o day, vi mot cai
|
||||
// `= true` se lam nut tick tren thanh cong cu thanh noi doi.
|
||||
const hide = (list) => {
|
||||
const hid = [];
|
||||
for (const o of list) {
|
||||
if (o && o.visible) { o.visible = false; hid.push(o); }
|
||||
}
|
||||
return hid;
|
||||
};
|
||||
const show = (hid) => { for (const o of hid) o.visible = true; };
|
||||
|
||||
// --- Nua TRAI: THE GIOI, khong co dau ra cua SLAM ---
|
||||
//
|
||||
// Dam may da quet va tam ban do SLAM deu bi tat o day. Chung la thu SLAM
|
||||
// DUNG RA; de chung chong len su that thi khung trai het tra loi duoc cau
|
||||
// hoi cua no ("ngoai doi cho nay co gi"), va bat lop `cloud da quet` se thay
|
||||
// no sang o CA HAI ben -- dung cai da bi bao la sai.
|
||||
let hid = hide([V3D.mapCloud, V3D.mapMesh]);
|
||||
r.setViewport(0, 0, half, h);
|
||||
r.setScissor(0, 0, half, h);
|
||||
r.render(V3D.scene, V3D.camera);
|
||||
show(hid);
|
||||
|
||||
// --- Nua PHAI: chi SLAM, khong co the gioi ---
|
||||
hid = hide([V3D.meshWorld, V3D.worldMesh]);
|
||||
r.setViewport(half, 0, w - half, h);
|
||||
r.setScissor(half, 0, w - half, h);
|
||||
r.render(V3D.scene, V3D.camera);
|
||||
show(hid);
|
||||
|
||||
r.setScissorTest(false);
|
||||
r.setViewport(0, 0, w, h);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
<div class="layers">
|
||||
<label><input type="checkbox" id="lyWorld" checked> the gioi</label>
|
||||
<label><input type="checkbox" id="lyMap" checked> map SLAM</label>
|
||||
<!-- Ban do voxel 3D. TAT mac dinh: no chi co du lieu khi slam.yaml dat
|
||||
camera_3d: true, va bat san se lam nguoi dung tuong tinh nang hong
|
||||
trong khi that ra no dang tat o cau hinh. -->
|
||||
<label><input type="checkbox" id="lyVoxel"> voxel 3D</label>
|
||||
<!-- Dam may DA QUET (tich luy, nan theo pose toi uu) -- khac lop `cloud`
|
||||
ben duoi von chi la MOT khung truc tiep. TAT mac dinh: no chi co du
|
||||
lieu khi slam.yaml dat camera_3d: true, va bat san se lam nguoi dung
|
||||
tuong tinh nang hong trong khi that ra no dang tat o cau hinh. -->
|
||||
<label><input type="checkbox" id="lyMapCloud"> cloud da quet</label>
|
||||
<label><input type="checkbox" id="lyScan" checked> scan</label>
|
||||
<label><input type="checkbox" id="lyCloud" checked> cloud</label>
|
||||
<label><input type="checkbox" id="lyPath" checked> path</label>
|
||||
|
||||
@@ -152,7 +152,9 @@ button.danger:hover { background: var(--bad); color: #fff; }
|
||||
(khong gi) : #main -- 2D mot khung
|
||||
.three : #main3d -- 3D mot khung
|
||||
.split : #main | #mainR -- 2D | 2D
|
||||
.split.three : #main3d | #mainR -- 3D (Gazebo) | 2D SLAM (RViz) */
|
||||
.split.three : #main3d | #mainR -- 3D (Gazebo) | 2D SLAM (RViz)
|
||||
.split3d : #main3d mot minh, tu cat lam doi bang scissor
|
||||
-- 3D the gioi | 3D dam may SLAM */
|
||||
#mainR, #main3d { display: none; }
|
||||
.canvas-wrap.three #main { display: none; }
|
||||
.canvas-wrap.three #main3d { display: block; }
|
||||
@@ -162,6 +164,17 @@ button.danger:hover { background: var(--bad); color: #fff; }
|
||||
.canvas-wrap.split #mainR { display: block; position: absolute;
|
||||
right: 0; top: 0; width: 50%; height: 100%;
|
||||
border-left: 1px solid #2a3442; }
|
||||
/* Chia doi 3D|3D: KHONG co canvas thu hai. `#main3d` chiem ca be ngang va
|
||||
`v3dRender()` ve hai lan vao hai nua bang scissor. Duong ke giua la CSS chu
|
||||
khong phai mot border cua the, vi khong co the nao o day ma vien. */
|
||||
.canvas-wrap.split3d #main { display: none; }
|
||||
.canvas-wrap.split3d #mainR { display: none; }
|
||||
.canvas-wrap.split3d #main3d { display: block; width: 100%; }
|
||||
.canvas-wrap.split3d::after {
|
||||
content: ''; position: absolute; left: 50%; top: 0; bottom: 0;
|
||||
width: 1px; background: #2a3442; pointer-events: none;
|
||||
}
|
||||
|
||||
.pane-label {
|
||||
position: absolute; top: 6px;
|
||||
font: 11px/1.4 ui-monospace, monospace;
|
||||
|
||||
@@ -87,33 +87,18 @@ TEST(RtabmapParams, CheDoGhiDeLenCaYaml) {
|
||||
<< "localization ma khong nap het node -> vung chua tung den khong duoc xet";
|
||||
}
|
||||
|
||||
TEST(RtabmapParams, Camera3dBatLuoiCucBo3D) {
|
||||
// `camera_3d` la CONG TAC cua ban do voxel 3D tren web. No phai thang ca
|
||||
// YAML: slam.yaml dat thang Grid/Sensor va Grid/3D, va mot file cu con hai
|
||||
// dong do se am tham lam ban do 3D rong khong.
|
||||
RtabmapConfig cfg;
|
||||
cfg.camera_3d = true;
|
||||
cfg.overrides["Grid/3D"] = "false"; // YAML co gang tat
|
||||
cfg.overrides["Grid/Sensor"] = "0"; // YAML co gang bo depth
|
||||
|
||||
TEST(RtabmapParams, Camera3dKhongDungVaoLuoi) {
|
||||
// camera_3d chi bat depth + ban do voxel. Tham so RTAB-Map PHAI y het 2D:
|
||||
// luoi 3D trong process() keo pose lech 0.009 -> 0.06-0.11 m (2026-09-24).
|
||||
RtabmapConfig with3d;
|
||||
with3d.camera_3d = true;
|
||||
std::vector<std::string> unknown;
|
||||
const auto p = BuildRtabmapParams(cfg, &unknown);
|
||||
EXPECT_TRUE(unknown.empty()) << "ten key Grid/* phai dung y het RTAB-Map";
|
||||
|
||||
EXPECT_EQ(p.at("Grid/3D"), "true");
|
||||
EXPECT_EQ(p.at("Grid/Sensor"), "2") << "0=scan 1=depth 2=ca hai";
|
||||
EXPECT_EQ(p.at("Grid/NormalsSegmentation"), "false");
|
||||
EXPECT_EQ(p.at("Grid/MaxGroundHeight"), "0.10");
|
||||
EXPECT_EQ(p.at("Grid/MaxObstacleHeight"), "2.0");
|
||||
|
||||
// Ray tracing KHONG bi tat kem theo: no la thu sinh ra o "trong" cua luoi
|
||||
// 2D (84961 o tren robot that), va ban do 3D khong duoc phep lam rong khung
|
||||
// ban do 2D.
|
||||
EXPECT_EQ(p.at("Grid/RayTracing"), "true");
|
||||
|
||||
// Khong them key la nao -- go sai ten Grid/* se lam bang nay phinh ra.
|
||||
const auto def = rtabmap::Parameters::getDefaultParameters();
|
||||
EXPECT_EQ(p.size(), def.size());
|
||||
const auto p3 = BuildRtabmapParams(with3d, &unknown);
|
||||
const auto p2 = BuildRtabmapParams(RtabmapConfig(), &unknown);
|
||||
EXPECT_TRUE(unknown.empty());
|
||||
EXPECT_EQ(p3, p2) << "camera_3d khong duoc doi bat ky tham so RTAB-Map nao";
|
||||
EXPECT_EQ(p3.at("Grid/3D"), "false");
|
||||
EXPECT_EQ(p3.at("Grid/Sensor"), "0");
|
||||
}
|
||||
|
||||
TEST(RtabmapParams, MacDinhKhongDungToiLuoi3D) {
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
// VoxelAccumulator va DiffVoxelGrids: phan THUAN cua duong xuat ban do 3D.
|
||||
//
|
||||
// Khong mot kieu nao cua RTAB-Map o day, va do la chu y: `ExportOccupancyGrid`
|
||||
// Khong can mot `Rtabmap` dang chay, va do la chu y: `ExportOccupancyGrid`
|
||||
// den nay khong co unit test nao chinh vi no can mot `Rtabmap` dang chay.
|
||||
// Phan tinh toan tach ra thi kiem duoc bang so.
|
||||
// Phan tinh toan tach ra thi kiem duoc bang so. Test NodeCloud o cuoi dung
|
||||
// kieu RTAB-Map (SensorData, CameraModel) nhung tu dung, khong can Rtabmap.
|
||||
|
||||
#include "vslam/voxel_export.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <rtabmap/core/CameraModel.h>
|
||||
#include <rtabmap/core/SensorData.h>
|
||||
#include <rtabmap/core/Transform.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@@ -107,16 +112,44 @@ TEST(VoxelAccumulator, DauRaDaSapXep) {
|
||||
EXPECT_TRUE(DaSapXep(g.cells)) << "DiffVoxelGrids dua vao dung tinh chat nay";
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, ChamTranThiCatVaBaoTruncated) {
|
||||
TEST(VoxelAccumulator, ChamTranThiGiamMauDeuChuKhongCatCut) {
|
||||
// ⚠️ Bai kiem NAY la bai kiem quan trong nhat trong file.
|
||||
//
|
||||
// Ban dau Finish() lay `max_cells` phan tu DAU cua danh sach da sort. Khoa
|
||||
// sort theo x truoc, nen no chat mot LAT KHONG GIAN: nguyen mot canh cua toa
|
||||
// nha bien mat trong khi phan con lai van day du. Nguoi dung phat hien bang
|
||||
// mat ("goc tren ben trai quet roi ma gio mat"), khong mot log nao bao.
|
||||
//
|
||||
// Bat bien phai giu: ban do MONG di deu, KHONG cut mot dau.
|
||||
VoxelExportOptions o = Opt(0.10);
|
||||
o.max_cells = 4;
|
||||
o.max_cells = 5;
|
||||
VoxelAccumulator acc(o);
|
||||
for (int i = 0; i < 20; ++i) acc.AddPoint(i * 1.0, 0.0, 1.0); // x = 0..19 m
|
||||
VoxelGrid g;
|
||||
acc.Finish(&g);
|
||||
|
||||
EXPECT_TRUE(g.truncated) << "giam mau ma khong bao la kieu hong te nhat";
|
||||
EXPECT_EQ(acc.stride(), 4u); // ceil(20 / 5)
|
||||
ASSERT_EQ(g.cells.size(), 5u);
|
||||
|
||||
// Chi so = met / 0.05... o day emit 0.10 nen x = 0, 4, 8, 12, 16 m -> 0, 40,
|
||||
// 80, 120, 160. Hai DAU deu con: do la dieu phep cat cut khong lam duoc.
|
||||
EXPECT_EQ(g.cells.front().x, 0) << "mat dau ban do";
|
||||
EXPECT_EQ(g.cells.back().x, 160) << "mat duoi ban do -- dung loi cu quay lai";
|
||||
EXPECT_TRUE(DaSapXep(g.cells)) << "giam mau khong duoc pha thu tu";
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, DuoiTranThiKhongDongGi) {
|
||||
VoxelExportOptions o = Opt(0.10);
|
||||
o.max_cells = 1000;
|
||||
VoxelAccumulator acc(o);
|
||||
for (int i = 0; i < 20; ++i) acc.AddPoint(i * 1.0, 0.0, 1.0);
|
||||
VoxelGrid g;
|
||||
acc.Finish(&g);
|
||||
|
||||
EXPECT_EQ(g.cells.size(), 4u);
|
||||
EXPECT_TRUE(g.truncated) << "cat bot ma khong bao la kieu hong te nhat";
|
||||
EXPECT_EQ(g.cells.size(), 20u);
|
||||
EXPECT_FALSE(g.truncated);
|
||||
EXPECT_EQ(acc.stride(), 1u);
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, FlushNhieuLanVanRaCungKetQua) {
|
||||
@@ -208,3 +241,38 @@ TEST(DiffVoxelGrids, SauVongDongThiDoiGanHet) {
|
||||
static_cast<double>(now.size());
|
||||
EXPECT_GT(ratio, 0.35) << "vuot nguong -> nguoi goi phai doi epoch";
|
||||
}
|
||||
|
||||
TEST(NodeCloud, DepthRaDiemOFrameBase) {
|
||||
// Tuong phang cach camera 2 m; camera cao 0.36 m so voi base, nhin +x.
|
||||
// Diem phai co x ~ 2 (frame base), KHONG phai z ~ 2 (frame quang hoc) --
|
||||
// ca ban do 3D dua vao gia thiet cloudFromSensorData ap localTransform.
|
||||
const int w = 64, h = 48;
|
||||
cv::Mat depth(h, w, CV_32FC1, cv::Scalar(2.0f));
|
||||
cv::Mat gray = cv::Mat::zeros(h, w, CV_8UC1);
|
||||
const rtabmap::Transform base_to_optical =
|
||||
rtabmap::Transform(0, 0, 0.36f, 0, 0, 0) *
|
||||
rtabmap::CameraModel::opticalRotation();
|
||||
rtabmap::CameraModel model(50.0, 50.0, w / 2.0, h / 2.0, base_to_optical,
|
||||
0.0, cv::Size(w, h));
|
||||
rtabmap::SensorData data(gray, depth, model, 1, 0.0);
|
||||
|
||||
VoxelExportOptions opt = Opt(0.05);
|
||||
opt.depth_decimation = 1;
|
||||
std::vector<float> pts;
|
||||
NodeCloudFromSensorData(data, opt, &pts);
|
||||
ASSERT_FALSE(pts.empty());
|
||||
ASSERT_EQ(pts.size() % 3, 0u);
|
||||
for (size_t i = 0; i < pts.size(); i += 3) {
|
||||
EXPECT_NEAR(pts[i], 2.0, opt.emit_size_m);
|
||||
EXPECT_GE(pts[i + 2], opt.z_min - opt.emit_size_m);
|
||||
EXPECT_LE(pts[i + 2], opt.z_max + opt.emit_size_m);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(NodeCloud, KhongCoDepthThiRong) {
|
||||
// Node quet voi camera_3d=false: khong co depth -> rong, khong nem loi.
|
||||
rtabmap::SensorData data;
|
||||
std::vector<float> pts{1.0f, 2.0f, 3.0f};
|
||||
NodeCloudFromSensorData(data, Opt(0.05), &pts);
|
||||
EXPECT_TRUE(pts.empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user