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:
@@ -249,6 +249,12 @@ Bo `--slam-reloc-vpr` thi chi dung LiDAR (chua co engine TensorRT, hoac camera h
|
||||
nghieng IMU va LiDAR khong phan doi -- log `bang camera tren doc`; chi nhan ra cho ma ban do co
|
||||
anh chup **cung huong** (sim 06/10: dung 1.4-2.9 cm, huong nguoc thi khong chot). Tu chay: chua
|
||||
chot thi bo thang 0.5 m (cho mu doc truc 1.5 m), khong lui, tong toi da 12 m.
|
||||
- Dung **XIEN** tren doc (lech > 20 do so voi chieu doc): anh ban do chup doc theo doc nen camera
|
||||
khong nhan ra. Tu chay (co camera): vong dau chua chot thi robot **QUAY mat theo chieu doc** (len
|
||||
hoac xuong, phia gan hon -- huong doc lay tu IMU) roi khop lai -- log `QUAY ... de camera nhin doc
|
||||
theo doc`. Khong tu chay thi web nhac nguoi xoay robot. Sim 06/10 doc rong: 8/8 cho xien chot dung
|
||||
0.5-2.9 cm (11-100 s). Doc rong thi quet ca lan GIUA doc: ban do chi co hai lan sat tuong thi
|
||||
camera khong nhan ra o giua doc, phai cho LiDAR.
|
||||
- ⚠️ Dang nhin XUONG doc thi tu chay co the bao `phia truoc khong thoang` roi quay ngang tren doc
|
||||
(thay trong sim, chua sua): cam e-stop, hoac bo `--slam-reloc-auto` -- tren doc robot van tu
|
||||
khop tai cho, khong can nguoi xoay.
|
||||
|
||||
@@ -1619,6 +1619,9 @@ constexpr double kRelocCreepBlind = 1.5; // m
|
||||
// duoi chan doc truoc khi toi tuong xa -> mu toi khi ra gan chan doc.
|
||||
constexpr double kRelocSlopeCreepMax = kRelocMaxDrive; // m
|
||||
constexpr double kRelocCreepMargin = 0.6; // m chua truoc vat can (lop an toan dung 0.45)
|
||||
// Tu chay tren doc co camera: dung XIEN qua goc nay so voi chieu doc thi quay mat
|
||||
// theo doc (xem cho goi SlopeAlignTurn).
|
||||
constexpr double kRelocSlopeAlignRad = 20.0 * M_PI / 180.0;
|
||||
} // namespace
|
||||
|
||||
double Runtime::RelocFrontClear(const LaserScan& scan) const {
|
||||
@@ -1651,7 +1654,10 @@ bool Runtime::RelocPoseAdmissible(const Pose2D& p, double tilt_r, double tilt_p)
|
||||
const int r = static_cast<int>(std::lround((p.y - lf->origin_y()) / lf->resolution()));
|
||||
if (!lf->Free(r, c)) return false;
|
||||
double gx = 0.0, gy = 0.0;
|
||||
if (!FloorGradientAt(slam_->floor_model(), p.x, p.y, reloc_cfg_.tilt_node_radius, &gx, &gy)) {
|
||||
const FloorModel& fm = slam_->floor_model();
|
||||
if (!FloorGradientAt(fm, p.x, p.y, reloc_cfg_.tilt_node_radius, &gx, &gy) &&
|
||||
!FloorGradientBetween(fm, p.x, p.y, reloc_cfg_.tilt_between_radius,
|
||||
std::tan(reloc_cfg_.tilt_agree_deg * M_PI / 180.0), &gx, &gy)) {
|
||||
return true; // khong biet san o do -- khong loai
|
||||
}
|
||||
return TiltResidual(tilt_r, tilt_p, p.theta, gx, gy) <=
|
||||
@@ -1822,16 +1828,18 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
const double err = AngleDiff(reloc_turn_target_, odom.theta);
|
||||
const double t = std::chrono::duration<double>(now - reloc_phase_t0_).count();
|
||||
if (std::fabs(err) < 5.0 * M_PI / 180.0 || t > kRelocPhaseTimeout) {
|
||||
// Quay theo chieu doc: reloc_drive_len_ = 0 nen pha DI xong ngay, sang vong gom moi.
|
||||
reloc_exec_ = RelocExec::kDrive;
|
||||
reloc_drive_start_ = odom;
|
||||
reloc_phase_t0_ = now;
|
||||
reloc_aligning_ = false;
|
||||
if (!yielding) RelocCommand(0.0, 0.0);
|
||||
return;
|
||||
}
|
||||
if (!yielding) RelocCommand(0.0, err > 0.0 ? kRelocTurnRate : -kRelocTurnRate);
|
||||
SetRelocStatus("TU QUAY ve huong thoang (con " +
|
||||
std::to_string(static_cast<int>(std::fabs(err) * 180.0 / M_PI)) + " do)" +
|
||||
(yielding ? " -- NHUONG NGUOI" : ""),
|
||||
SetRelocStatus(std::string(reloc_aligning_ ? "QUAY THEO CHIEU DOC" : "TU QUAY ve huong thoang") +
|
||||
" (con " + std::to_string(static_cast<int>(std::fabs(err) * 180.0 / M_PI)) +
|
||||
" do)" + (yielding ? " -- NHUONG NGUOI" : ""),
|
||||
true);
|
||||
return;
|
||||
}
|
||||
@@ -2066,8 +2074,16 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
py.y, py.theta * 180.0 / M_PI);
|
||||
}
|
||||
VSLAM_WARN("slam: reloc chua chot -- " << buf << who);
|
||||
// Dung XIEN tren doc: anh ban do chup DOC doc (luc quet robot di len / xuong) nen camera
|
||||
// khong nhan ra goc xien (sim 06/10, doc rong: 8/8 cho xien khong chot, PnP 0-6 diem).
|
||||
// Huong doc lay tu IMU, khong can biet pose.
|
||||
double misalign = 0.0;
|
||||
const double align = SlopeAlignTurn(tilt_r, tilt_p, &misalign);
|
||||
const bool askew = vpr_ && reloc_static_round_ && misalign > kRelocSlopeAlignRad;
|
||||
if (!running) {
|
||||
SetRelocStatus(buf, true);
|
||||
SetRelocStatus(std::string(buf) +
|
||||
(askew ? " -- xoay robot DOC theo doc (len/xuong) de camera nhan ra" : ""),
|
||||
true);
|
||||
return;
|
||||
}
|
||||
// Tu chay: sang cho khac roi xoay tiep -- doi xung cuc bo thuong vo khi
|
||||
@@ -2086,6 +2102,25 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
// < min_ratio thi DecideStatic tra truoc khi kiem doc truc (sim: giua lan
|
||||
// dich 1 m giu 100% ma van bo tung 0.5 m sau 3 lan).
|
||||
const bool blind = admit && shift_ratio >= reloc_cfg_.tilt_max_shift_ratio;
|
||||
// Dung xien va LiDAR chua chac sau vong dau o cho nay -> quay mat theo chieu doc
|
||||
// (len / xuong, phia gan hon) roi khop lai tai cho: anh camera moi giong anh ban
|
||||
// do. Moi cho mot lan. Khong camera thi khong quay -- LiDAR khong loi gi ma them
|
||||
// truot banh.
|
||||
const bool lidar_sure = m.ok && m.ratio() >= reloc_cfg_.static_min_ratio && !blind;
|
||||
if (askew && !reloc_aligned_here_ && !lidar_sure) {
|
||||
reloc_aligned_here_ = true;
|
||||
reloc_aligning_ = true;
|
||||
reloc_static_here_ = 0;
|
||||
reloc_static_hist_.clear();
|
||||
reloc_turn_target_ = NormalizeAngle(odom.theta + align);
|
||||
reloc_drive_len_ = 0.0;
|
||||
reloc_exec_ = RelocExec::kTurn;
|
||||
reloc_phase_t0_ = now;
|
||||
VSLAM_INFO("reloc_exec: dung xien " << misalign * 180.0 / M_PI << " do so voi chieu doc -- QUAY "
|
||||
<< align * 180.0 / M_PI << " do de camera nhin doc theo doc, roi khop lai tai cho.");
|
||||
SetRelocStatus(std::string(buf) + " -- QUAY THEO CHIEU DOC", true);
|
||||
return;
|
||||
}
|
||||
if (!blind && reloc_static_here_ < kRelocStaticBeforeCreep) {
|
||||
RelocStartSweep();
|
||||
VSLAM_INFO("reloc_exec: vong " << reloc_cycle_ << " chua chot -- tren doc: khop lai tai cho ("
|
||||
@@ -2104,6 +2139,7 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
return;
|
||||
}
|
||||
reloc_static_here_ = 0;
|
||||
reloc_aligned_here_ = false; // cho moi
|
||||
reloc_creeping_ = true;
|
||||
// Chot CHO nay truoc khi bo: chot "hai cho" so cho moi voi no.
|
||||
if (!reloc_static_hist_.empty()) {
|
||||
@@ -2145,6 +2181,7 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
return;
|
||||
}
|
||||
reloc_static_here_ = 0;
|
||||
reloc_aligned_here_ = false;
|
||||
if (reloc_exec_cycles_ >= kRelocMaxCycles || reloc_total_drive_ >= kRelocMaxDrive) {
|
||||
RelocHalt("het tran " + std::to_string(kRelocMaxCycles) + " vong / " +
|
||||
std::to_string(static_cast<int>(kRelocMaxDrive)) + " m");
|
||||
@@ -2558,7 +2595,13 @@ void Runtime::RelocFinish(const Pose2D& map_from_odom, const Pose2D& odom,
|
||||
slam_->UpdateHeights(zc);
|
||||
}
|
||||
double z_ref = 0.0;
|
||||
if (slam_->HeightAt(pose.x, pose.y, 2.0, &z_ref)) {
|
||||
// Giua doc rong (node gan nhat xa hon 2 m -- sim 06/10: z lech 0.75 m sau khi chot)
|
||||
// thi noi suy giua hai lan cung mat doc. 0.3 m: z ban do hai lan da lech nhau 13 cm
|
||||
// (sim 06/10); hai MAT khac nhau thi do doc da loai, nguong z chi chan hai san song
|
||||
// song khac do cao (sanh 0 m / tang 1.5 m).
|
||||
if (slam_->HeightAt(pose.x, pose.y, 2.0, &z_ref) ||
|
||||
FloorZBetween(slam_->floor_model(), pose.x, pose.y, reloc_cfg_.tilt_between_radius,
|
||||
std::tan(reloc_cfg_.tilt_agree_deg * M_PI / 180.0), 0.30, &z_ref)) {
|
||||
std::lock_guard<std::mutex> lk(odom_mu_);
|
||||
height_->Reset(z_ref, cfg_->slope.sigma_anchor);
|
||||
height_anchored_ = true;
|
||||
@@ -2624,6 +2667,8 @@ void Runtime::RelocWatch(const LaserScan& scan, const Pose2D& pose_map) {
|
||||
reloc_static_hist_.clear();
|
||||
reloc_static_places_.clear();
|
||||
reloc_static_here_ = 0;
|
||||
reloc_aligned_here_ = false;
|
||||
reloc_aligning_ = false;
|
||||
reloc_slope_creep_ = 0.0;
|
||||
reloc_creeping_ = false;
|
||||
if (opts_.slam_reloc_auto) {
|
||||
|
||||
@@ -410,6 +410,10 @@ class Runtime {
|
||||
int reloc_static_here_ = 0;
|
||||
double reloc_slope_creep_ = 0.0;
|
||||
bool reloc_creeping_ = false;
|
||||
// Tu chay tren doc co camera: da quay mat theo chieu doc o CHO nay chua, va pha QUAY
|
||||
// hien tai co phai lan quay theo chieu doc khong (chu tren web).
|
||||
bool reloc_aligned_here_ = false;
|
||||
bool reloc_aligning_ = false;
|
||||
std::chrono::steady_clock::time_point reloc_t0_; // dau vong gom
|
||||
std::chrono::steady_clock::time_point reloc_epoch_; // moc thoi gian cho tracker
|
||||
// Truoc khi chot, web ve robot (mo) tu pose nay: node DAU TIEN cua ban do (cho bat dau
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -131,3 +131,69 @@ TEST(FloorModel, DoDocVaDoLechNghieng) {
|
||||
const double p = -std::atan(sf), r = std::atan(sl * std::cos(p));
|
||||
EXPECT_NEAR(TiltResidual(r, p, M_PI / 4, 0.0, g), 0.0, 1e-9);
|
||||
}
|
||||
|
||||
TEST(FloorModel, DocRongGiuaHaiLanNoiSuy) {
|
||||
// Doc 10 do len ve -x (node mui -x, mui ngoc = pitch am), quet hai lan sat tuong
|
||||
// y = 1.5 va y = 6.5 -- nhu world slope_two_ramps doc rong (sim 06/10).
|
||||
std::vector<FloorNode> nodes;
|
||||
for (int i = 0; i <= 80; ++i) {
|
||||
for (double y : {1.5, 6.5}) {
|
||||
FloorNode n;
|
||||
n.x = 6.0 + 0.1 * i;
|
||||
n.y = y;
|
||||
n.theta = M_PI;
|
||||
n.pitch = -10 * kDeg;
|
||||
n.z = (14.0 - n.x) * std::tan(10 * kDeg); // z = 0 o x = 14, len ve -x
|
||||
nodes.push_back(n);
|
||||
}
|
||||
}
|
||||
FloorModel fm;
|
||||
fm.Build(nodes);
|
||||
const double agree = std::tan(2.5 * kDeg);
|
||||
double gx = 0, gy = 0, z = 0;
|
||||
// Giua hai lan cach node gan nhat 2.5 m: node gan nhat khong du gan.
|
||||
EXPECT_FALSE(FloorGradientAt(fm, 10.0, 4.0, 1.5, &gx, &gy));
|
||||
ASSERT_TRUE(FloorGradientBetween(fm, 10.0, 4.0, 4.0, agree, &gx, &gy));
|
||||
EXPECT_NEAR(gx, -std::tan(10 * kDeg), 1e-9); // len doc ve -x
|
||||
EXPECT_NEAR(gy, 0.0, 1e-9);
|
||||
// Do cao cung noi suy duoc (neo z sau dinh vi lai).
|
||||
ASSERT_TRUE(FloorZBetween(fm, 10.0, 4.0, 4.0, agree, 0.1, &z));
|
||||
EXPECT_NEAR(z, 4.0 * std::tan(10 * kDeg), 1e-9);
|
||||
EXPECT_FALSE(FloorZBetween(fm, 10.0, 8.5, 4.0, agree, 0.1, &z));
|
||||
// Chi mot phia (ngoai lan y = 6.5): ngoai suy -> khong tin.
|
||||
EXPECT_FALSE(FloorGradientBetween(fm, 10.0, 8.5, 4.0, agree, &gx, &gy));
|
||||
// Xa hon max_dist: khong tin.
|
||||
EXPECT_FALSE(FloorGradientBetween(fm, 10.0, 4.0, 2.0, agree, &gx, &gy));
|
||||
// Hai phia KHAC mat (lan duoi phang, vd chan doc): khong dong y -> khong tin.
|
||||
for (FloorNode& n : nodes) {
|
||||
if (n.y < 4.0) n.pitch = 0.0;
|
||||
}
|
||||
fm.Build(nodes);
|
||||
EXPECT_FALSE(FloorGradientBetween(fm, 10.0, 4.0, 4.0, agree, &gx, &gy));
|
||||
}
|
||||
|
||||
TEST(FloorModel, QuayTheoChieuDoc) {
|
||||
double mis = 1.0;
|
||||
// Mui LEN doc (pitch am) hoac XUONG doc (pitch duong): da doc theo doc.
|
||||
EXPECT_NEAR(SlopeAlignTurn(0.0, -10 * kDeg, &mis), 0.0, 1e-9);
|
||||
EXPECT_NEAR(mis, 0.0, 1e-9);
|
||||
EXPECT_NEAR(SlopeAlignTurn(0.0, 10 * kDeg, &mis), 0.0, 1e-9);
|
||||
// Ngang doc, ben TRAI cao (roll duong): xa nhu nhau -> quay TRAI 90 do nhin LEN.
|
||||
EXPECT_NEAR(SlopeAlignTurn(10 * kDeg, 0.0, &mis), M_PI / 2, 1e-9);
|
||||
EXPECT_NEAR(mis, M_PI / 2, 1e-9);
|
||||
// Ben PHAI cao (roll am): quay PHAI.
|
||||
EXPECT_NEAR(SlopeAlignTurn(-10 * kDeg, 0.0), -M_PI / 2, 1e-9);
|
||||
// Mui len doc lech TRAI 45 do (sim 06/10: doc 15 do, IMU roll -10.7 / pitch -10.7):
|
||||
// quay PHAI 45 do.
|
||||
const double g = std::tan(15 * kDeg);
|
||||
const double sf = g * std::cos(M_PI / 4), sl = -g * std::sin(M_PI / 4);
|
||||
const double p = -std::atan(sf), r = std::atan(sl * std::cos(p));
|
||||
EXPECT_NEAR(SlopeAlignTurn(r, p, &mis), -M_PI / 4, 1e-9);
|
||||
// Mui XUONG doc lech 30 do: quay 30 do ve phia xuong, khong quay 150 do de nhin len.
|
||||
const double sf2 = -g * std::cos(M_PI / 6), sl2 = g * std::sin(M_PI / 6);
|
||||
const double p2 = -std::atan(sf2), r2 = std::atan(sl2 * std::cos(p2));
|
||||
EXPECT_NEAR(std::fabs(SlopeAlignTurn(r2, p2, &mis)), M_PI / 6, 1e-9);
|
||||
// San phang: khong quay.
|
||||
EXPECT_NEAR(SlopeAlignTurn(0.0, 0.0, &mis), 0.0, 1e-12);
|
||||
EXPECT_NEAR(mis, 0.0, 1e-12);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user