map,lidar,web: ban do theo lan nhin MOI NHAT + scan dung gio. Luoi 2D: GridGlobal/* (3 lan nhin xuyen qua -> trong, truoc ~9; truoc 07/10 khong truyen vao bo ghep luoi); lop camera + 3D: xoa voxel ma >= 2 node sau nhin xuyen qua (VoxelCarver) -- nguoi dung roi di thi quay lai quet la mat. LiDAR: stamp_offset -55 ms + chinh meo theo chieu quet (do tren ban do that 28/09 + 01/10); web: robot troi muot

This commit is contained in:
trung09122002
2026-10-07 16:04:28 +07:00
parent 61c3a75fb1
commit 31f84eb082
20 changed files with 855 additions and 50 deletions

View File

@@ -8,11 +8,18 @@
#include <gtest/gtest.h>
#include <rtabmap/core/LocalGrid.h>
#include <rtabmap/core/Parameters.h>
#include <rtabmap/core/global_map/OccupancyGrid.h>
#include <opencv2/core.hpp>
#include <cmath>
#include <map>
#include <cstdlib>
#include <limits>
#include <utility>
#include <vector>
#include "vslam/geometry.h"
#include "vslam/occupancy_export.h"
@@ -388,6 +395,68 @@ TEST(OccupancyExport, DbKhongTonTaiThiBaoKhongTonTai) {
EXPECT_FALSE(f.exists);
}
namespace {
// Luoi cuc bo 2D cua mot node: 1 x N, CV_32FC2 (x, y) trong frame node.
cv::Mat Cells(const std::vector<std::pair<float, float>>& xy) {
cv::Mat m(1, static_cast<int>(xy.size()), CV_32FC2);
for (size_t i = 0; i < xy.size(); ++i) {
m.at<cv::Vec2f>(0, static_cast<int>(i)) = cv::Vec2f(xy[i].first, xy[i].second);
}
return m;
}
// O tai (x, y) sau khi ghep 6 node: node 1-3 thay NGUOI o x = 1.0 (tia dung o
// do); node 4-6 tia di XUYEN qua x = 1.0 toi tuong x = 2.0.
int NguoiRoiDi(const rtabmap::ParametersMap& grid_global, float x, float y) {
rtabmap::LocalGridCache cache;
std::map<int, rtabmap::Transform> poses;
for (int id = 1; id <= 6; ++id) {
const bool nguoi = id <= 3;
const float hit = nguoi ? 1.0f : 2.0f;
std::vector<std::pair<float, float>> empty;
for (float e = 0.05f; e < hit - 0.01f; e += 0.05f) empty.emplace_back(e, 0.0f);
// Mot o lech ngang: RTAB-Map KHONG dung ban do khi moi o thang hang
// (khung ymin == ymax).
empty.emplace_back(0.05f, 0.5f);
cache.add(id, cv::Mat(), Cells({{hit, 0.0f}}), Cells(empty), 0.05f);
poses[id] = rtabmap::Transform::getIdentity();
}
rtabmap::ParametersMap p = grid_global;
p[rtabmap::Parameters::kGridCellSize()] = "0.05";
p[rtabmap::Parameters::kGrid3D()] = "false";
rtabmap::OccupancyGrid grid(&cache, p);
grid.update(poses);
float xmin = 0.0f, ymin = 0.0f;
const cv::Mat m = grid.getMap(xmin, ymin);
const int c = static_cast<int>(std::floor((x - xmin) / 0.05f));
const int r = static_cast<int>(std::floor((y - ymin) / 0.05f));
if (m.empty() || r < 0 || c < 0 || r >= m.rows || c >= m.cols) return -2;
return m.at<int8_t>(r, c);
}
} // namespace
TEST(OccupancyExport, LuoiTheoLanNhinMoiNhat) {
// 07/10: 3 nguoi dung tren duong luc quet, roi di; quay lai quet van con tren
// ban do. GridGlobal/* cua slam.yaml (repo): 3 lan nhin xuyen qua -> TRONG.
// Mac dinh RTAB-Map (kep 0.971, truot 0.4): van CHIEM -- do la loi cu.
const char* dir = std::getenv("VSLAM_CONFIG_SRC_DIR");
if (dir == nullptr) GTEST_SKIP() << "khong co VSLAM_CONFIG_SRC_DIR";
RtabmapConfig c = LoadRtabmapConfig(ConfigNode::LoadFile(std::string(dir) + "/slam.yaml"));
ASSERT_TRUE(ApplySlamProfile("real", &c).ok());
std::vector<std::string> unknown;
const std::map<std::string, std::string> all = BuildRtabmapParams(c, &unknown);
rtabmap::ParametersMap gg;
for (const auto& kv : all) {
if (kv.first.rfind("GridGlobal/", 0) == 0) gg.insert(kv);
}
ASSERT_FALSE(gg.empty());
EXPECT_EQ(NguoiRoiDi(gg, 1.0f, 0.0f), 0); // cho nguoi dung: TRONG
EXPECT_EQ(NguoiRoiDi(gg, 2.0f, 0.0f), 100); // tuong van CHIEM
EXPECT_EQ(NguoiRoiDi(rtabmap::ParametersMap(), 1.0f, 0.0f), 100); // mac dinh: loi cu
}
TEST(SensorDataBuilder, FrameLaserSaiLamMoiDiemLechDungBangNo) {
// Loi da mac: `RtabmapSlam` co bien `laser_to_base` nhung KHONG co setter.
// Moi scan bi dat o goc toa do thay vi o (0.24, 0, 0.20). ICP van hoi tu --