reloc: dung XIEN tren doc -- tu chay quay mat theo chieu doc (IMU) de camera nhan ra; bo loc nghieng + neo z noi suy giua hai lan cung mat doc (doc rong) -- sim doc rong quet 3 lan: 8/8 cho xien chot dung 0.5-4.4 cm, 6/8 bang camera (11-55 s)

This commit is contained in:
trung09122002
2026-10-07 09:07:11 +07:00
parent 35fef155f5
commit b5574a17b5
7 changed files with 241 additions and 11 deletions

View File

@@ -92,6 +92,13 @@ struct GlobalLocalizerConfig {
// Chi tin do doc cua node trong ban kinh nay; xa hon = khong biet san o do
// (khong loai).
double tilt_node_radius = 1.5; // m
// Xa hon tilt_node_radius nhung NAM GIUA hai lan cung mot mat doc (node gan nhat
// hai phia doi dien, lech gradient <= tilt_agree_deg) thi dung do doc chung do --
// xem FloorGradientBetween. Sim 06/10, doc rong 8 m quet hai lan sat tuong: giua
// doc cach node 2-2.5 m, doi thu lat 180 do o doc kia lot bo loc, 8/8 cho xien
// khong chot.
double tilt_between_radius = 4.0; // m
double tilt_agree_deg = 2.5;
// Chot NHO do nghieng (tilt_used) con phai qua kiem suy bien doc truc: dich
// pose `tilt_shift_m` theo 8 huong ma diem LiDAR van >= ty le nay so voi
// pose chot -> hanh lang / doc deu, vi tri doc truc khong quan sat duoc ->

View File

@@ -83,6 +83,7 @@ class FloorModel {
bool NearestNode(double x, double y, FloorNode* node, double* dist = nullptr) const;
bool empty() const { return nodes_.empty(); }
size_t size() const { return nodes_.size(); }
const std::vector<FloorNode>& nodes() const { return nodes_; }
private:
std::vector<FloorNode> nodes_;
@@ -99,6 +100,20 @@ double PlaneZ(const FloorNode& n, double x, double y);
bool FloorGradientAt(const FloorModel& fm, double x, double y, double max_dist, double* gx,
double* gy);
// Do doc SAN GIUA HAI LAN da quet: node gan nhat va node gan nhat o PHIA DOI DIEN
// (huong lech >= 120 do), ca hai trong `max_dist`, cung mot gradient (lech <= `agree`,
// don vi tan) -> tra gradient trung binh. Doc rong quet theo vai lan thi giua hai
// lan khong co node gan (FloorGradientAt false) nhung van la mot mat doc -- NOI SUY
// thi tin duoc, NGOAI SUY (chi mot phia, vd ngoai chan doc) thi khong: false.
bool FloorGradientBetween(const FloorModel& fm, double x, double y, double max_dist, double agree,
double* gx, double* gy);
// Do cao SAN giua hai lan, cung cach chon node nhu FloorGradientBetween: hai mat phang
// node cung gradient (lech <= `agree`) va du doan z tai (x, y) lech <= `agree_z` (m) ->
// trung binh. Neo z sau dinh vi lai o giua doc rong (node gan nhat xa hon 2 m).
bool FloorZBetween(const FloorModel& fm, double x, double y, double max_dist, double agree,
double agree_z, double* z);
// Do lech giua do nghieng than DO DUOC (roll, pitch -- ROS, tu IMU) va do
// nghieng ma mat san gradient (gx, gy) GAY RA cho robot mui huong `yaw` (frame
// map). Don vi: do doc (tan) -- 0.087 ~ 5 do. Dinh vi lai dung no de loai gia
@@ -106,6 +121,11 @@ bool FloorGradientAt(const FloorModel& fm, double x, double y, double max_dist,
// sai goc.
double TiltResidual(double roll, double pitch, double yaw, double gx, double gy);
// Goc can quay (rad, duong = trai) de mui nhin DOC theo doc -- LEN hoac XUONG, phia
// gan hon (bang nhau thi LEN) -- chi tu do nghieng than (roll, pitch -- ROS, IMU),
// khong can biet pose. `misalign`: |goc quay|. San phang: 0.
double SlopeAlignTurn(double roll, double pitch, double* misalign = nullptr);
} // namespace vslam
#endif // VSLAM_HEIGHT_MAP_H

View File

@@ -147,16 +147,86 @@ bool FloorModel::FloorAt(double x, double y, double* z, double* dist) const {
return true;
}
namespace {
// Dao ham cua PlaneZ: z = z_n - fwd * tan(pitch) + left * tan(roll).
void NodeGradient(const FloorNode& n, double* gx, double* gy) {
const double c = std::cos(n.theta), s = std::sin(n.theta);
const double tp = std::tan(n.pitch), tr = std::tan(n.roll);
*gx = -tp * c - tr * s;
*gy = -tp * s + tr * c;
}
} // namespace
bool FloorGradientAt(const FloorModel& fm, double x, double y, double max_dist, double* gx,
double* gy) {
FloorNode n;
double d = 0.0;
if (!fm.NearestNode(x, y, &n, &d) || d > max_dist) return false;
// Dao ham cua PlaneZ: z = z_n - fwd * tan(pitch) + left * tan(roll).
const double c = std::cos(n.theta), s = std::sin(n.theta);
const double tp = std::tan(n.pitch), tr = std::tan(n.roll);
*gx = -tp * c - tr * s;
*gy = -tp * s + tr * c;
NodeGradient(n, gx, gy);
return true;
}
namespace {
// Node gan nhat va node gan nhat o PHIA DOI DIEN (huong lech >= 120 do), ca hai trong
// max_dist. false neu thieu mot trong hai.
bool OppositePair(const FloorModel& fm, double x, double y, double max_dist, FloorNode* a,
FloorNode* b) {
const std::vector<FloorNode>& nodes = fm.nodes();
int i1 = -1;
double d1 = max_dist;
for (size_t i = 0; i < nodes.size(); ++i) {
const double d = std::hypot(nodes[i].x - x, nodes[i].y - y);
if (d <= d1) {
d1 = d;
i1 = static_cast<int>(i);
}
}
if (i1 < 0 || d1 < 1e-6) return false;
const double ux = (nodes[i1].x - x) / d1, uy = (nodes[i1].y - y) / d1;
constexpr double kOpposite = -0.5; // cos(120 do)
int i2 = -1;
double d2 = max_dist;
for (size_t i = 0; i < nodes.size(); ++i) {
const double dx = nodes[i].x - x, dy = nodes[i].y - y;
const double d = std::hypot(dx, dy);
if (d > d2 || d < 1e-6 || (dx * ux + dy * uy) / d > kOpposite) continue;
d2 = d;
i2 = static_cast<int>(i);
}
if (i2 < 0) return false;
*a = nodes[static_cast<size_t>(i1)];
*b = nodes[static_cast<size_t>(i2)];
return true;
}
} // namespace
bool FloorGradientBetween(const FloorModel& fm, double x, double y, double max_dist, double agree,
double* gx, double* gy) {
FloorNode a, b;
if (!OppositePair(fm, x, y, max_dist, &a, &b)) return false;
double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0;
NodeGradient(a, &ax, &ay);
NodeGradient(b, &bx, &by);
if (std::hypot(ax - bx, ay - by) > agree) return false;
*gx = 0.5 * (ax + bx);
*gy = 0.5 * (ay + by);
return true;
}
bool FloorZBetween(const FloorModel& fm, double x, double y, double max_dist, double agree,
double agree_z, double* z) {
FloorNode a, b;
if (!OppositePair(fm, x, y, max_dist, &a, &b)) return false;
double ax = 0.0, ay = 0.0, bx = 0.0, by = 0.0;
NodeGradient(a, &ax, &ay);
NodeGradient(b, &bx, &by);
const double za = PlaneZ(a, x, y), zb = PlaneZ(b, x, y);
if (std::hypot(ax - bx, ay - by) > agree || std::fabs(za - zb) > agree_z) return false;
*z = 0.5 * (za + zb);
return true;
}
@@ -171,4 +241,16 @@ double TiltResidual(double roll, double pitch, double yaw, double gx, double gy)
return std::hypot(mf - sf, ml - sl);
}
double SlopeAlignTurn(double roll, double pitch, double* misalign) {
// Huong LEN doc trong frame than, cung quy uoc TiltResidual: mf doc theo mui,
// ml doc sang trai.
const double mf = -std::tan(pitch);
const double ml = std::tan(roll) / std::max(1e-6, std::cos(pitch));
const double up = std::atan2(ml, mf);
const double down = up > 0.0 ? up - M_PI : up + M_PI;
const double turn = std::fabs(up) <= std::fabs(down) ? up : down;
if (misalign != nullptr) *misalign = std::fabs(turn);
return turn;
}
} // namespace vslam