slam.yaml: profiles sim/real -- odom sigma va ICP ratio tach theo moi truong

This commit is contained in:
trung09122002
2026-09-28 14:40:48 +07:00
parent c8c08223ed
commit 89ab2e7868
6 changed files with 367 additions and 12 deletions

View File

@@ -3,10 +3,82 @@
#include <rtabmap/core/Optimizer.h>
#include <rtabmap/core/Parameters.h>
#include <set>
#include "vslam/log.h"
namespace vslam {
namespace {
const char* const kProfileNames[] = {"sim", "real"};
// Doc va KIEM khoi `profiles:`. Ba luat de hai moi truong khong bao gio dung
// nhau hay lech nhau:
// 1. Dung hai khoi `sim` va `real`, du ca hai.
// 2. Hai khoi CUNG tap key -- sua mot ben quen ben kia la loi khoi dong,
// khong phai mot lan chay sai tren robot.
// 3. Key trong profiles KHONG nam o phan chung -- mot key, mot cho. Neu
// khong, doc file se khong biet gia tri nao dang chay.
void LoadProfiles(const ConfigNode& node, const ConfigNode& block, RtabmapConfig* cfg) {
for (const std::string& k : block.Keys()) {
if (k != "sim" && k != "real") {
throw ConfigError("profiles: khoi la '" + k + "' -- chi co sim va real");
}
}
std::set<std::string> keys[2];
for (int i = 0; i < 2; ++i) {
const std::string name = kProfileNames[i];
const ConfigNode p = block[name];
if (p.IsNull()) {
throw ConfigError("profiles: thieu khoi '" + name + "' -- can ca sim va real");
}
SlamProfile sp;
for (const std::string& k : p.Keys()) {
if (k == "odom_sigma_m" || k == "odom_sigma_rad") {
if (!node[k].IsNull()) {
throw ConfigError(k + " vua o phan chung vua o profiles." + name +
" -- mot key chi duoc o mot cho");
}
const double v = p.get<double>(k, 0.0);
if (!(v > 0.0)) {
throw ConfigError("profiles." + name + "." + k + " phai > 0");
}
sp.numbers[k] = v;
keys[i].insert(k);
} else if (k == "rtabmap") {
for (const auto& kv : p["rtabmap"].AsStringMap()) {
if (cfg->overrides.count(kv.first) != 0) {
throw ConfigError("rtabmap " + kv.first + " vua o khoi rtabmap chung vua o "
"profiles." + name + " -- mot key chi duoc o mot cho");
}
sp.rtabmap[kv.first] = kv.second;
keys[i].insert("rtabmap." + kv.first);
}
} else {
throw ConfigError("profiles." + name + ": khoa la '" + k +
"' -- chi co odom_sigma_m, odom_sigma_rad, rtabmap");
}
}
cfg->profiles[name] = sp;
}
if (keys[0] != keys[1]) {
std::string diff;
for (int i = 0; i < 2; ++i) {
for (const std::string& k : keys[i]) {
if (keys[1 - i].count(k) == 0) {
diff += " " + k + " (chi co o " + kProfileNames[i] + ")";
}
}
}
throw ConfigError("profiles: sim va real phai co CUNG tap key, lech:" + diff);
}
}
} // namespace
const char* SlamModeName(SlamMode m) {
switch (m) {
case SlamMode::kMapping: return "mapping";
@@ -166,7 +238,29 @@ RtabmapConfig LoadRtabmapConfig(const ConfigNode& node) {
if (!block.IsNull()) {
for (const auto& kv : block.AsStringMap()) cfg.overrides[kv.first] = kv.second;
}
// SAU khoi rtabmap chung: luat "mot key, mot cho" can biet phan chung co gi.
const ConfigNode profiles = node["profiles"];
if (!profiles.IsNull()) LoadProfiles(node, profiles, &cfg);
return cfg;
}
StatusResponse ApplySlamProfile(const std::string& name, RtabmapConfig* cfg) {
const auto it = cfg->profiles.find(name);
if (it == cfg->profiles.end()) {
return StatusResponse::Error(
StatusCode::kInvalidArgument,
"slam.yaml: khong co profiles." + name + " -- can khoi `profiles:` voi ca sim "
"va real, neu khong sigma odom va ICP chay bang mac dinh cua code");
}
for (const auto& kv : it->second.numbers) {
if (kv.first == "odom_sigma_m") cfg->odom_sigma_m = kv.second;
else if (kv.first == "odom_sigma_rad") cfg->odom_sigma_rad = kv.second;
}
// Ten key RTAB-Map duoc kiem o BuildRtabmapParams, nhu moi key trong
// overrides.
for (const auto& kv : it->second.rtabmap) cfg->overrides[kv.first] = kv.second;
return StatusResponse::Ok();
}
} // namespace vslam