slam.yaml: profiles sim/real -- odom sigma va ICP ratio tach theo moi truong
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <rtabmap/core/Parameters.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
#include "vslam/geometry.h"
|
||||
@@ -144,6 +145,174 @@ TEST(RtabmapParams, G2oPhaiCoMat) {
|
||||
EXPECT_FALSE(OptimizerAvailable("9"));
|
||||
}
|
||||
|
||||
// ==================== slam.yaml profiles (sim / real) ====================
|
||||
//
|
||||
// Mo phong va robot that can bo so KHAC nhau (2026-09-28: bo so robot that
|
||||
// lam mo phong lech 8-12 cm thay vi 3-5 cm). Cac test duoi day khoa luat
|
||||
// "hai ben khong dung nhau".
|
||||
|
||||
namespace {
|
||||
|
||||
const char* kProfilesOk =
|
||||
"database_path: x.db\n"
|
||||
"rtabmap:\n"
|
||||
" Icp/VoxelSize: \"0.05\"\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" odom_sigma_m: 0.01\n"
|
||||
" odom_sigma_rad: 0.005\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.3\"\n"
|
||||
" real:\n"
|
||||
" odom_sigma_m: 0.1\n"
|
||||
" odom_sigma_rad: 0.1\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.05\"\n";
|
||||
|
||||
RtabmapConfig LoadYaml(const std::string& yaml) {
|
||||
return LoadRtabmapConfig(ConfigNode::LoadString(yaml));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(SlamProfiles, SimVaRealRaDungGiaTriRieng) {
|
||||
const RtabmapConfig base = LoadYaml(kProfilesOk);
|
||||
|
||||
RtabmapConfig sim = base;
|
||||
ASSERT_TRUE(ApplySlamProfile("sim", &sim).ok());
|
||||
EXPECT_DOUBLE_EQ(sim.odom_sigma_m, 0.01);
|
||||
EXPECT_DOUBLE_EQ(sim.odom_sigma_rad, 0.005);
|
||||
EXPECT_EQ(sim.overrides.at("Icp/CorrespondenceRatio"), "0.3");
|
||||
|
||||
RtabmapConfig real = base;
|
||||
ASSERT_TRUE(ApplySlamProfile("real", &real).ok());
|
||||
EXPECT_DOUBLE_EQ(real.odom_sigma_m, 0.1);
|
||||
EXPECT_DOUBLE_EQ(real.odom_sigma_rad, 0.1);
|
||||
EXPECT_EQ(real.overrides.at("Icp/CorrespondenceRatio"), "0.05");
|
||||
|
||||
// Phan chung giu nguyen o ca hai.
|
||||
EXPECT_EQ(sim.overrides.at("Icp/VoxelSize"), "0.05");
|
||||
EXPECT_EQ(real.overrides.at("Icp/VoxelSize"), "0.05");
|
||||
|
||||
// Key cua profile di qua CUNG phep kiem ten key nhu moi key khac.
|
||||
std::vector<std::string> unknown;
|
||||
EXPECT_EQ(BuildRtabmapParams(sim, &unknown).at("Icp/CorrespondenceRatio"), "0.3");
|
||||
EXPECT_TRUE(unknown.empty());
|
||||
}
|
||||
|
||||
TEST(SlamProfiles, ThieuKeyOMotBenLaLoi) {
|
||||
// Sua `sim` ma quen `real`: phai la loi khoi dong, khong phai mot lan chay
|
||||
// robot that bang so cua mo phong.
|
||||
const std::string yaml =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" odom_sigma_m: 0.01\n"
|
||||
" odom_sigma_rad: 0.005\n"
|
||||
" real:\n"
|
||||
" odom_sigma_m: 0.1\n";
|
||||
EXPECT_THROW(LoadYaml(yaml), std::exception);
|
||||
|
||||
const std::string rt =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.3\"\n"
|
||||
" real:\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/VoxelSize: \"0.05\"\n";
|
||||
EXPECT_THROW(LoadYaml(rt), std::exception);
|
||||
}
|
||||
|
||||
TEST(SlamProfiles, KeyVuaOChungVuaOProfileLaLoi) {
|
||||
// Mot key, mot cho: neu khong, doc file se khong biet gia tri nao dang chay.
|
||||
const std::string sigma =
|
||||
"database_path: x.db\n"
|
||||
"odom_sigma_m: 0.05\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" odom_sigma_m: 0.01\n"
|
||||
" real:\n"
|
||||
" odom_sigma_m: 0.1\n";
|
||||
EXPECT_THROW(LoadYaml(sigma), std::exception);
|
||||
|
||||
const std::string rt =
|
||||
"database_path: x.db\n"
|
||||
"rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.2\"\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.3\"\n"
|
||||
" real:\n"
|
||||
" rtabmap:\n"
|
||||
" Icp/CorrespondenceRatio: \"0.05\"\n";
|
||||
EXPECT_THROW(LoadYaml(rt), std::exception);
|
||||
}
|
||||
|
||||
TEST(SlamProfiles, TenKhoiHoacKeyLaLaLoi) {
|
||||
const std::string khoi =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" simulation:\n"
|
||||
" odom_sigma_m: 0.01\n"
|
||||
" real:\n"
|
||||
" odom_sigma_m: 0.1\n";
|
||||
EXPECT_THROW(LoadYaml(khoi), std::exception);
|
||||
|
||||
const std::string thieu =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" odom_sigma_m: 0.01\n";
|
||||
EXPECT_THROW(LoadYaml(thieu), std::exception);
|
||||
|
||||
const std::string key =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" mode: mapping\n"
|
||||
" real:\n"
|
||||
" mode: mapping\n";
|
||||
EXPECT_THROW(LoadYaml(key), std::exception);
|
||||
|
||||
const std::string am =
|
||||
"database_path: x.db\n"
|
||||
"profiles:\n"
|
||||
" sim:\n"
|
||||
" odom_sigma_m: 0\n"
|
||||
" real:\n"
|
||||
" odom_sigma_m: 0.1\n";
|
||||
EXPECT_THROW(LoadYaml(am), std::exception);
|
||||
}
|
||||
|
||||
TEST(SlamProfiles, KhongCoProfilesThiApLaLoi) {
|
||||
// KHONG lang le chay bang mac dinh cua struct: tren robot that do la
|
||||
// 0.01/0.005 -- bo so lam ban do xoan.
|
||||
RtabmapConfig cfg = LoadYaml("database_path: x.db\n");
|
||||
EXPECT_TRUE(cfg.profiles.empty());
|
||||
EXPECT_FALSE(ApplySlamProfile("real", &cfg).ok());
|
||||
}
|
||||
|
||||
TEST(SlamProfiles, SlamYamlCuaRepoApDuocCaHai) {
|
||||
// ctest dat VSLAM_CONFIG_SRC_DIR = configuration_files. Ai sua slam.yaml sai
|
||||
// luat thi test nay do ngay, khong doi toi luc chay tren robot.
|
||||
const char* dir = std::getenv("VSLAM_CONFIG_SRC_DIR");
|
||||
if (dir == nullptr) GTEST_SKIP() << "khong co VSLAM_CONFIG_SRC_DIR";
|
||||
const RtabmapConfig base =
|
||||
LoadRtabmapConfig(ConfigNode::LoadFile(std::string(dir) + "/slam.yaml"));
|
||||
for (const char* name : {"sim", "real"}) {
|
||||
RtabmapConfig c = base;
|
||||
ASSERT_TRUE(ApplySlamProfile(name, &c).ok()) << name;
|
||||
EXPECT_GT(c.odom_sigma_m, 0.0) << name;
|
||||
EXPECT_GT(c.odom_sigma_rad, 0.0) << name;
|
||||
std::vector<std::string> unknown;
|
||||
BuildRtabmapParams(c, &unknown);
|
||||
EXPECT_TRUE(unknown.empty()) << name << ": key RTAB-Map sai ten";
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== sensor_data_builder ====================
|
||||
|
||||
TEST(SensorDataBuilder, Pose2DDiVaVeKhongMatGi) {
|
||||
|
||||
Reference in New Issue
Block a user