From c723397097930c424c2a09752d67f1f6c4692b48 Mon Sep 17 00:00:00 2001 From: trung09122002 Date: Sat, 19 Sep 2026 19:25:01 +0700 Subject: [PATCH] update --- app/src/app_config.cc | 17 +++++-- configuration_files/sensors.yaml | 49 ++++++++++++++++--- .../include/vslam/driver_config.h | 48 +++++++++--------- 3 files changed, 75 insertions(+), 39 deletions(-) diff --git a/app/src/app_config.cc b/app/src/app_config.cc index 571928d..4e47b4e 100644 --- a/app/src/app_config.cc +++ b/app/src/app_config.cc @@ -68,7 +68,8 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) { const StatusResponse r = Reject(l, "sensors.yaml lidar", {"host", "port", "expected_rate_hz", "range_min", "range_max", - "stamp_mismatch_warn", "sector_masks"}); + "stamp_mismatch_warn", "sector_masks", + "angle_offset_deg", "angle_flip"}); if (!r.ok()) return r; } out->sanitizer.range_min = l.get("range_min", 0.05); @@ -83,10 +84,16 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) { out->lidar_driver.frame_id = kLaserFrame; out->lidar_driver.sweep_duration_tolerance_sec = l.get("stamp_mismatch_warn", 0.005); - // ⚠️ range_unit_m, angle_offset_deg va inverted CO Y khong doc tu YAML. - // Ca ba deu suy ra duoc (xem driver_config.h): don vi mm tu SDK, va goc - // tu manual §8.1 + REP-103 + tu the gan up nguoc. De chung trong YAML moi - // la de nguoi van hanh go bua vao mot thu da co dap an dung. + // Goc DOC TU YAML, khong hardcode. + // + // Ban dau mac dinh o driver_config.h duoc coi la "da co dap an dung" nen + // khong cho doi. Sai: phep doi quy uoc phu thuoc TU THE GAN LiDAR, ma do + // la su that vat ly khong suy ra duoc tu tai lieu. De o YAML thi thu mot + // gia tri khac chi ton mot lan khoi dong lai, thay vi mot lan build. + out->lidar_driver.angle_offset_deg = + l.get("angle_offset_deg", out->lidar_driver.angle_offset_deg); + out->lidar_driver.inverted = + l.get("angle_flip", out->lidar_driver.inverted); // Sector mask ghi bang DO trong YAML (doc duoc bang mat), dung bang RAD. // Doi mot lan o day, khong de moi noi tu doi. diff --git a/configuration_files/sensors.yaml b/configuration_files/sensors.yaml index 56c13df..ba99d66 100644 --- a/configuration_files/sensors.yaml +++ b/configuration_files/sensors.yaml @@ -7,13 +7,39 @@ lidar: # LakiBeam 1L, giao thuc UDP. # - # ⚠️ CHUA XAC MINH byte layout cua goi -- day la thu DUY NHAT con thieu de - # viet driver. Chay `vslam_lidar_probe --seconds 10` tren may noi duoc voi - # LiDAR: no tu suy ra offset truong goc, vung mang range va so goi moi vong. + # Giai ma goi do SDK chinh hang lo (lidar_core + lakibeam_sdk, nhung trong + # libs/vslam_drivers/thirdparty/). Khong con byte layout nao phai doan. host: 0.0.0.0 port: 2368 expected_rate_hz: 25.0 + # --- Quy uoc goc --- + # + # Driver tinh: theta = (angle_flip ? -alpha : alpha) + angle_offset_deg + # + # Manual §8.1 cho X = R*sin(a), Y = R*cos(a); REP-103 dung x = R*cos(t). + # Phep doi giua hai quy uoc phu thuoc TU THE GAN LiDAR: + # + # gan xuoi t = 90 - a offset 90, flip true + # lat quanh truc X t = a - 90 offset -90, flip false <- CON NAY + # lat quanh truc Y t = a + 90 offset 90, flip false + # + # LiDAR tren robot nay QUAY QUANH TRUC X 180 DO, da xac nhan voi nguoi lap. + # X giu nguyen, Y -> -Y, Z -> -Z: + # x = X_dev = R*sin(a), y = -Y_dev = -R*cos(a) + # => cos t = sin a, sin t = -cos a => t = a - 90 + # + # ⚠️ KHAC mac dinh cua base_kit (offset 90, flip false). Khong phai base_kit + # sai: no chay voi mot tu the gan khac, hoac khong ai kiem huong scan cua no + # vi nhanh do khong dung de dung ban do. Dung lay no lam doi chung cho gia + # tri nay. + # + # Kiem nhanh: dat mot vat cach robot ~1 m CHINH DIEN PHIA TRUOC, mo web, + # cham phai hien ra phia truoc. Doi hai so nay chi ton mot lan khoi dong + # lai, khong phai build lai. + angle_offset_deg: -90.0 + angle_flip: false + # --- Ve sinh scan --- # ScanSanitizer gop header-fix va sector mask lam MOT ham. Hai bo loc rieng # thi thu tu chay giua chung la mot bay: mask truoc hay sua header truoc cho @@ -39,9 +65,6 @@ lidar: # chieu: mask thieu -> than robot bi doc thanh vat can, robot dung im; # mask thua -> mot vat can that bi cat mat, khong ai biet. # - # Huong 0 do THAT cua LiDAR thi da co dap an (khong con phai do): manual - # §8.1 cho X = R*sin(a), Y = R*cos(a), REP-103 dung x = R*cos(t) => t = 90 - # do - a. Da vao driver_config.h: angle_offset_deg = 90, inverted = true. sector_masks: - [118.0, 180.0] - [-180.0, -118.0] @@ -112,6 +135,16 @@ base: # dung duong dan tuyet doi -- nhung dung commit mot duong dan /home/. dcf_path: master.dcf - # Increment/vong cua encoder, doc qua 0x6064. 0 = hoi thiet bi luc Open() - # qua 0x608F:1 thay vi chep tay mot hang so. + # Count/vong cua encoder, dung de doi 0x6064 (don vi "count") sang radian. + # + # 0 = dung mac dinh 16384, suy tu 0x200E:01 = 4096 "wire" doc duoc tren + # thiet bi, nhan 4 theo quy uoc cau phuong. + # + # ⚠️ He so x4 CHUA KIEM CHUNG -- can_help.pdf khong cho nao noi quan he giua + # "wire" va "count". Sai he so nay lam odometry sai dung 4 lan. + # + # Cach do (2 phut): ke banh len khoi san, doc 0x6064:01, quay banh dung MOT + # vong bang tay, doc lai. Hieu so chinh la count/vong that -- dat vao day. + # cansend can0 601#40.64.60.01.00.00.00.00 + # candump can0,581:7FF -n 1 encoder_counts_per_rev: 0 diff --git a/libs/vslam_drivers/include/vslam/driver_config.h b/libs/vslam_drivers/include/vslam/driver_config.h index b2fa45c..d89a5d3 100644 --- a/libs/vslam_drivers/include/vslam/driver_config.h +++ b/libs/vslam_drivers/include/vslam/driver_config.h @@ -41,40 +41,36 @@ struct LidarConfig { // khoang cach deu gap doi. double range_unit_m = 0.001; - // 2 va 3. HUONG 0 DO + CHIEU QUAY (rui ro R5) -- SUY RA duoc, khong phai do. + // 2 va 3. HUONG 0 DO + CHIEU QUAY (rui ro R5). // - // ⚠️ LIDAR TREN ROBOT NAY GAN UP NGUOC. Hai gia tri duoi da tinh cho tu the - // do. Gan lai xuoi thi phai doi CA HAI, khong phai mot. + // lidar_core tinh: theta = (angle_flip ? -alpha : alpha) + angle_offset_deg // - // Manual §8.1: LakiBeam tra ve X_dev = R*sin(a), Y_dev = R*cos(a) - // REP-103: he nay dung x = R*cos(t), y = R*sin(t) + // Manual §8.1: LakiBeam tra ve X = R*sin(a), Y = R*cos(a) + // REP-103: he nay dung x = R*cos(t), y = R*sin(t) // - // Gan XUOI: x = X_dev, y = Y_dev - // cos t = sin a, sin t = cos a => t = 90do - a - // => angle_offset_deg = +90, inverted = true + // Phep doi phu thuoc TU THE GAN, va ba tu the cho ba ket qua khac nhau: + // gan xuoi t = 90 - a offset +90, flip true + // lat quanh truc X t = a - 90 offset -90, flip false <- CON NAY + // lat quanh truc Y t = a + 90 offset +90, flip false // - // Gan UP NGUOC = xoay 180do quanh truc X, tuc Y va Z doi dau: - // x = X_dev, y = -Y_dev - // cos t = sin a, sin t = -cos a => t = a - 90do - // => angle_offset_deg = -90, inverted = FALSE + // LiDAR tren robot nay QUAY QUANH TRUC X 180 DO, da xac nhan voi nguoi lap. + // X giu nguyen, Y -> -Y, Z -> -Z: + // x = X_dev = R*sin(a), y = -Y_dev = -R*cos(a) + // => cos t = sin a, sin t = -cos a => t = a - 90 // - // Hai phep dao dau -- cua QUY UOC va cua TU THE GAN -- triet tieu nhau. Do - // la ly do `inverted` o day la false DU thiet bi dang bi lat; doc luot qua - // rat de tuong nguoc lai. + // ⚠️ KHAC mac dinh cua base_kit (offset 90, flip false) -- dung lay no lam + // doi chung cho gia tri nay. + // + // ⚠️ "Up nguoc" KHONG du de suy ra phep doi -- lat quanh X va lat quanh Y + // cho hai ket qua lech nhau 180 do. Da mac loi o day mot lan: doc comment + // cua base_kit (noi flip phai la true), tu gia dinh lat quanh X, va bo qua + // GIA TRI ma code cua no thuc su dung. Scan bi xoay, tren web trong nhu + // LiDAR quay sai huong. + // + // Ca hai doc tu sensors.yaml nen doi chi ton mot lan khoi dong lai. double angle_offset_deg = -90.0; bool inverted = false; - // ⚠️⚠️ KHONG bu tu the up nguoc them mot lan nua trong TF. - // `laser_link` trong robot.yaml giu rpy = [0, 0, 0] CO Y: driver da tra ve - // goc theo quy uoc Z-huong-len roi. Them roll = pi vao TF la bu HAI LAN, va - // scan lat guong lai ve dung cho sai -- mot loi khong bao gio crash. - // Bu o driver chu khong o TF vi ScanSanitizer va sector_masks doc THANG goc - // cua scan, chung khong di qua TF. - // - // ⚠️ base_kit/lakibeam_driver.hpp de mac dinh `angle_flip = false`, trung - // gia tri voi o day nhung VI LY DO KHAC (no gan xuoi, va chinh comment cua - // no ket luan phai la true). Dung lay do lam xac nhan cho gia tri nay. - LidarStampMode stamp_mode = LidarStampMode::kFirstPacket; // Bu do tre da do duoc, cong vao stamp. Chua do -> 0. double stamp_offset_sec = 0.0;