From 61c3a75fb15b0df1408fdaefbb4f824c64e20db9 Mon Sep 17 00:00:00 2001 From: trung09122002 Date: Wed, 7 Oct 2026 14:57:49 +0700 Subject: [PATCH] slope: bu nghieng scan giu CA vong scan LakiBeam -- lidar_core phat goc [0, 2pi) (angle_min 0), LevelScan dua ve [-pi, pi) roi tru nen bo het nua -pi..0: ban do that tu 06/10 chi con nua scan (325 vs 620-730 diem); RayIndex lay goc theo vong tron + test scan LakiBeam; log slope/scan ti le tia giu --- app/src/wiring.cc | 7 +++++ libs/vslam_perception/src/scan_leveler.cc | 27 +++++++++++++++-- test/test_scan_leveler.cc | 36 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/app/src/wiring.cc b/app/src/wiring.cc index 0b85f58..255d280 100644 --- a/app/src/wiring.cc +++ b/app/src/wiring.cc @@ -60,6 +60,13 @@ StatusResponse Runtime::Wire() { LevelScan(*copy, laser_to_base_static_, roll, pitch, cfg_->robot.geometry().wheel_radius, od, z, elev_.get(), level_cfg_, lv.get(), &level_stats_); + // Ti le tia giu lai (cong don tu luc chay) -- san phang phai ~100%. + // 07/10: nua scan bi bo tu 06/10 ma khong dong log nao bao. + const ScanLevelStats& ls = level_stats_; + VSLAM_INFO_THROTTLE(30.0, "slope/scan: giu " << ls.kept << "/" << ls.rays << " tia (" + << (ls.rays > 0 ? 100 * ls.kept / ls.rays : 0) << "%), bo cham san " + << ls.dropped_floor << ", duoi dat " << ls.dropped_below << ", ngoai goc " + << ls.rays - ls.kept - ls.dropped_floor - ls.dropped_below); } slam_scan = lv; } diff --git a/libs/vslam_perception/src/scan_leveler.cc b/libs/vslam_perception/src/scan_leveler.cc index 092fc4c..904f0b2 100644 --- a/libs/vslam_perception/src/scan_leveler.cc +++ b/libs/vslam_perception/src/scan_leveler.cc @@ -9,6 +9,28 @@ namespace vslam { +namespace { + +// Chi so tia cua goc `a` (rad) BAT KE quy uoc goc cua scan: LakiBeam that phat +// [0, 2pi) (angle_min = 0, lidar_core scan_conversion.cpp), sim va test phat +// [-pi, pi). Lay hieu goc THEO VONG TRON roi moi chia; -1 = ngoai FOV. +// +// Truoc day NormalizeAngle(a) ve [-pi, pi) roi tru angle_min = 0: moi tia nua +// -pi..0 ra chi so AM va bi BO, khong log nao bao. Ban do robot that tu 06/10 +// (doc BAT mac dinh) chi con nua scan (0..+120 do), 325 diem / scan thay vi +// 620-730 (28/09, 01/10) -- sim khong thay vi scan sim la [-135, 135] do. +long RayIndex(double a, double angle_min, double inc, size_t n) { + const double two_pi = 2.0 * M_PI; + double rel = std::fmod(a - angle_min, two_pi); + if (rel * inc < 0.0) rel += std::copysign(two_pi, inc); // cung chieu quet + long j = std::lround(rel / inc); + // Goc ~2pi: tia dau (scan tron vong) hoac ngay truoc angle_min. + if (j >= static_cast(n)) j -= std::lround(two_pi / std::fabs(inc)); + return (j >= 0 && j < static_cast(n)) ? j : -1; +} + +} // namespace + void LevelScan(const LaserScan& in, const Transform& laser_to_base, double roll, double pitch, double wheel_radius, const Pose2D& odom, double z_robot, const ElevationMap* em, const ScanLevelerConfig& cfg, LaserScan* out, @@ -69,9 +91,8 @@ void LevelScan(const LaserScan& in, const Transform& laser_to_base, double roll, } const double dx = p.x - lx0, dy = p.y - ly0; const double rh = std::hypot(dx, dy); - const double ah = NormalizeAngle(std::atan2(dy, dx) - laser_yaw); - const long j = std::lround((ah - in.angle_min) / in.angle_increment); - if (j < 0 || j >= static_cast(n) || masked[static_cast(j)]) continue; + const long j = RayIndex(std::atan2(dy, dx) - laser_yaw, in.angle_min, in.angle_increment, n); + if (j < 0 || masked[static_cast(j)]) continue; if (static_cast(j) != i) st.rebinned++; float& slot = out->ranges[static_cast(j)]; if (!std::isfinite(slot) || rh < slot) { diff --git a/test/test_scan_leveler.cc b/test/test_scan_leveler.cc index 935587d..3f16349 100644 --- a/test/test_scan_leveler.cc +++ b/test/test_scan_leveler.cc @@ -196,6 +196,42 @@ TEST(ScanLeveler, PoseOdomDungTrongElevationMap) { EXPECT_TRUE(std::isnan(out.ranges[Bin(0)])); } +TEST(ScanLeveler, ScanLakiBeam0Den2PiGiuCaHaiNua) { + // LakiBeam that (lidar_core scan_conversion.cpp, crop_fov = false): 1440 tia + // tron vong, angle_min = 0, goc [0, 2pi), quat mu 90 do phia sau. Robot + // ngang -> MOI tia phai giu, dung o cu. Truoc day mat het nua -pi..0 (tia + // 720..1439): ban do robot that 07/10 chi con 325 diem / scan. + const size_t n = 1440; + const double inc = 2.0 * M_PI / static_cast(n); + LaserScan in; + in.angle_min = 0.0f; + in.angle_increment = static_cast(inc); + in.angle_max = static_cast(2.0 * M_PI - inc); + in.range_min = 0.05f; + in.range_max = 30.0f; + in.ranges.assign(n, std::numeric_limits::infinity()); + uint64_t finite = 0, right_half = 0; + for (size_t i = 0; i < n; ++i) { + const double a = NormalizeAngle(static_cast(i) * inc); + if (std::fabs(a) <= 135 * kDeg) { + in.ranges[i] = 3.0f; + ++finite; + if (a < 0.0) ++right_half; + } + } + ASSERT_GT(right_half, 500u); + LaserScan out; + ScanLevelStats st; + LevelScan(in, LaserToBase(), 0.0, 0.0, kWheel, Pose2D{}, 0.0, nullptr, ScanLevelerConfig{}, &out, &st); + EXPECT_EQ(st.kept, finite); + EXPECT_EQ(st.rebinned, 0u); + for (size_t i = 0; i < n; ++i) { + if (std::isfinite(in.ranges[i])) { + EXPECT_NEAR(out.ranges[i], 3.0, 1e-4) << "tia " << i; + } + } +} + TEST(ScanLeveler, SentinelSectorMaskGiuNguyen) { // Tia bi sector mask cat (range_max + 1 = than robot): giu nguyen, va khong // tia nao duoc xep de len o do.