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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user