reloc,web: dinh vi lai TREN DOC (slope.enabled) -- loc gia thuyet bang do nghieng IMU vs do doc ban do, chan mu doc truc (ShiftScoreRatio), vong DUNG YEN khong xoay (ty le nho nhat >= 3 vong / hai cho cung pose), tu chay bo thang tren doc; camera VPR+PnP tren doc (>= 2 anh trung, khop nghieng, LiDAR khong phan doi, pose = trung binh camera) -- sim 10 cho chot dung 1.4-2.9 cm, 0 chot sai; web 3D: ban do uon theo san (FLH1), scan/quy dao theo z, het nen lung, sua ro GPU; CMake: TensorRT tren CMake < 3.17
This commit is contained in:
@@ -59,6 +59,35 @@ namespace {
|
||||
//
|
||||
// Chi de CANH BAO, khong dieu khien gi.
|
||||
constexpr double kFastAccelWarn = 0.7;
|
||||
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
// Do cao SAN cho web (che do doc): luoi 0.2 m phu CUNG khung voi luoi 2D, moi
|
||||
// o lay mat phang node gan nhat. Web uon mat phang ban do theo no -- khong co
|
||||
// thi mat doc va san tang tren ve o z = 0, duoi tuong voxel (o z that), trong
|
||||
// nhu san bi thung.
|
||||
std::shared_ptr<const MapFloorGrid> BuildMapFloorGrid(const FloorModel& fm,
|
||||
const OccupancyGrid& grid) {
|
||||
if (fm.empty() || grid.resolution <= 0.0f) return nullptr;
|
||||
auto fg = std::make_shared<MapFloorGrid>();
|
||||
fg->resolution = 0.2f;
|
||||
fg->origin_x = static_cast<float>(grid.origin.position.x);
|
||||
fg->origin_y = static_cast<float>(grid.origin.position.y);
|
||||
fg->width = static_cast<uint32_t>(std::ceil(grid.width * grid.resolution / fg->resolution));
|
||||
fg->height = static_cast<uint32_t>(std::ceil(grid.height * grid.resolution / fg->resolution));
|
||||
fg->mm.assign(static_cast<size_t>(fg->width) * fg->height, kFloorUnknown);
|
||||
for (uint32_t r = 0; r < fg->height; ++r) {
|
||||
for (uint32_t c = 0; c < fg->width; ++c) {
|
||||
double fz = 0.0;
|
||||
if (fm.FloorAt(fg->origin_x + (c + 0.5) * fg->resolution,
|
||||
fg->origin_y + (r + 0.5) * fg->resolution, &fz)) {
|
||||
fg->mm[static_cast<size_t>(r) * fg->width + c] = static_cast<int16_t>(
|
||||
std::max(-32000.0, std::min(32000.0, std::round(fz * 1000.0))));
|
||||
}
|
||||
}
|
||||
}
|
||||
return fg;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
StatusResponse Runtime::OpenSource() {
|
||||
@@ -564,7 +593,11 @@ StatusResponse Runtime::Start() {
|
||||
vverif_.reset(new VisualVerifier);
|
||||
VSLAM_INFO("slam: camera cho dinh vi lai -- mo ta VPR " << vpr_ids_.size()
|
||||
<< " anh ban do trong " << dv << " s; chot khi PnP >= 12 inlier TRUNG"
|
||||
" LiDAR (0.5 m / 10 do).");
|
||||
" LiDAR (0.5 m / 10 do)"
|
||||
<< (cfg_->slope.enabled
|
||||
? "; tren doc: >= 2 anh trung nhau, khop do nghieng IMU, LiDAR "
|
||||
"khong phan doi -> pose camera."
|
||||
: "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,6 +607,19 @@ StatusResponse Runtime::Start() {
|
||||
{
|
||||
OccupancyGrid shown = g;
|
||||
VoxelGridPtr vptr;
|
||||
// Ban do quet o che do doc: z node nam san trong DB. Giai do thi z
|
||||
// TRUOC khi xuat, khong thi tang tren + mat doc ve het o z = 0 cho toi
|
||||
// khi chot (slope_on_ chi bat o duoi doan nay).
|
||||
const FloorModel* floor = nullptr;
|
||||
if (cfg_->slope.enabled) {
|
||||
ZGraphConfig zc;
|
||||
zc.clamp_rad = cfg_->slope.clamp_deg * M_PI / 180.0;
|
||||
zc.sigma_rel = cfg_->slope.sigma_rel;
|
||||
slam_->SetUseHeights(true);
|
||||
if (slam_->UpdateHeights(zc).ok() && !slam_->floor_model().empty()) {
|
||||
floor = &slam_->floor_model();
|
||||
}
|
||||
}
|
||||
if (voxel_enabled_) {
|
||||
VoxelExportOptions vo;
|
||||
vo.emit_size_m = cfg_->voxel.emit_size_m;
|
||||
@@ -589,8 +635,12 @@ StatusResponse Runtime::Start() {
|
||||
VoxelGrid vg;
|
||||
const StatusResponse vst = slam_->ExportVoxels(vo, &vg);
|
||||
if (vst.ok()) {
|
||||
if (floor != nullptr) {
|
||||
ClearLidarOnSeenRamps(&shown, slam_->floor_cells(), cfg_->voxel.emit_size_m,
|
||||
*floor, cfg_->slope.clamp_deg * M_PI / 180.0, 1.0);
|
||||
}
|
||||
MarkVoxelObstacles(vg, cfg_->voxel.obstacle_z_min,
|
||||
cfg_->voxel.obstacle_z_max, &shown);
|
||||
cfg_->voxel.obstacle_z_max, &shown, floor);
|
||||
vg.epoch = ++voxel_epoch_;
|
||||
prev_voxel_cells_ = vg.cells;
|
||||
vptr = std::make_shared<const VoxelGrid>(std::move(vg));
|
||||
@@ -599,8 +649,11 @@ StatusResponse Runtime::Start() {
|
||||
<< ") -- 3D se hien sau khi DA DINH VI, 2D van hien ngay.");
|
||||
}
|
||||
}
|
||||
std::shared_ptr<const MapFloorGrid> floor_ptr;
|
||||
if (floor != nullptr) floor_ptr = BuildMapFloorGrid(*floor, shown);
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
slam_map_ = std::make_shared<const OccupancyGrid>(std::move(shown));
|
||||
slam_map_floor_ = floor_ptr;
|
||||
slam_published_version_ = 1;
|
||||
slam_voxels_ = vptr;
|
||||
}
|
||||
@@ -1487,9 +1540,13 @@ void Runtime::SlamLoop() {
|
||||
// ban chua gop roi thay bang ban da gop CUNG version la web khong bao
|
||||
// gio thay ban da gop.
|
||||
if (st.ok()) {
|
||||
// Di tren doc: do cao san de web uon mat phang ban do.
|
||||
std::shared_ptr<const MapFloorGrid> floor_ptr;
|
||||
if (slope_on_) floor_ptr = BuildMapFloorGrid(slam_->floor_model(), grid);
|
||||
auto ptr = std::make_shared<const OccupancyGrid>(std::move(grid));
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
slam_map_ = ptr;
|
||||
slam_map_floor_ = floor_ptr;
|
||||
slam_published_version_ = slam_map_version_;
|
||||
}
|
||||
}
|
||||
@@ -1523,8 +1580,100 @@ constexpr double kRelocSpeed = 0.12; // m/s
|
||||
constexpr int kRelocMaxCycles = 6;
|
||||
constexpr double kRelocMaxDrive = 12.0; // m
|
||||
constexpr double kRelocPhaseTimeout = 20.0; // s -- bi lop an toan chan thi thoi
|
||||
// Tren doc: vong DUNG YEN -- khong xoay robot, khop scan tai cho (bo khop da
|
||||
// thu moi huong bang phan mem). Sim 2026-10-05: xoay tai cho tren doc 15-30 do
|
||||
// lam scan meo (6 vong deu MAU THUAN / khop sai cho); dung yen thi chon dung
|
||||
// lan + huong. Doc that con truot banh khi xoay. Tu chay cung KHONG tu di tren
|
||||
// doc: chua chot thi khop lai tai cho roi goi nguoi.
|
||||
constexpr double kRelocStaticTiltDeg = 3.0; // nghieng hon nguong nay = tren doc
|
||||
constexpr double kRelocStaticWindow = 3.0; // s gom scan tai cho moi vong
|
||||
constexpr double kRelocTiltStableDeg = 0.3; // do nghieng coi la on dinh: doi duoi
|
||||
constexpr double kRelocTiltStableSec = 1.0; // nguong nay trong chung nay giay
|
||||
// Nguoi xoay robot qua goc nay trong vong dung yen -> doi thanh vong xoay thuong.
|
||||
constexpr double kRelocStaticMaxTurn = 15.0 * M_PI / 180.0;
|
||||
// Tu chay tren doc: khop tai cho kRelocStaticBeforeCreep lan chua chot thi BO
|
||||
// THANG kRelocCreepStep (khong quay -- phia truoc khong thoang moi quay ve cho
|
||||
// thoang; khong lui -- sau lung la vung mu LiDAR), tong toi da
|
||||
// kRelocSlopeCreepMax. Hai goc nhin o hai cho khac nhau cung chi mot pose =
|
||||
// luat chuoi sau khi di chuyen (Decide). Sim 2026-10-05: dung yen gan dinh doc
|
||||
// 5 do, nguoi thang DUNG ca 6 vong nhung ty le 1.57-1.60 (bat --sim-gl) <
|
||||
// chuan mot goc nhin 1.60 -> dung han goi nguoi.
|
||||
constexpr int kRelocStaticBeforeCreep = 3;
|
||||
constexpr double kRelocCreepStep = 0.5; // m
|
||||
// Mu doc truc (dich 1 m van khop >= 95%): moi cho gan day nhin y het -> khop
|
||||
// lai tai cho vo ich, bo NGAY va xa hon. Sim: giua lan doc bo 4 x 0.5 m van
|
||||
// mu, dung han giua lan.
|
||||
constexpr double kRelocCreepBlind = 1.5; // m
|
||||
// = kRelocMaxDrive: lan doc dai 17 m, nhin XUONG doc thoai thi tia cam vao san
|
||||
// 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)
|
||||
} // namespace
|
||||
|
||||
double Runtime::RelocFrontClear(const LaserScan& scan) const {
|
||||
constexpr double kHalf = 15.0 * M_PI / 180.0; // = 3 o 10 do cua RelocPlanDrive
|
||||
double near = reloc_cfg_.max_range;
|
||||
bool seen = false;
|
||||
for (size_t i = 0; i < scan.ranges.size(); ++i) {
|
||||
const float r = scan.ranges[i];
|
||||
if (std::isnan(r)) continue; // khong do duoc / bi bo
|
||||
if (!std::isinf(r) && (r > scan.range_max || r <= scan.range_min)) continue; // bi cat
|
||||
const double a = scan.angle_min + static_cast<double>(i) * scan.angle_increment;
|
||||
const double d = std::isinf(r) ? reloc_cfg_.max_range : static_cast<double>(r);
|
||||
Point pl;
|
||||
pl.x = d * std::cos(a);
|
||||
pl.y = d * std::sin(a);
|
||||
const Point pb = TransformPoint(slam_laser_to_base_, pl);
|
||||
if (std::fabs(std::atan2(pb.y, pb.x)) > kHalf) continue;
|
||||
seen = true;
|
||||
if (!std::isinf(r)) near = std::min(near, std::hypot(pb.x, pb.y));
|
||||
}
|
||||
return seen ? near : 0.0;
|
||||
}
|
||||
|
||||
bool Runtime::RelocPoseAdmissible(const Pose2D& p, double tilt_r, double tilt_p) const {
|
||||
// Robot phai DUNG duoc o do: o TRONG cua ban do. Gia thuyet dat robot trong tuong /
|
||||
// ngoai vung da quet khong duoc canh tranh (sim: doi thu cua cho dung nam ngoai tuong
|
||||
// nha, y = -0.04).
|
||||
const LikelihoodField* lf = reloc_field_.get();
|
||||
const int c = static_cast<int>(std::lround((p.x - lf->origin_x()) / lf->resolution()));
|
||||
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)) {
|
||||
return true; // khong biet san o do -- khong loai
|
||||
}
|
||||
return TiltResidual(tilt_r, tilt_p, p.theta, gx, gy) <=
|
||||
std::tan(reloc_cfg_.tilt_tol_deg * M_PI / 180.0);
|
||||
}
|
||||
|
||||
bool Runtime::RelocOnSlope(double* deg) const {
|
||||
// Goc giua truc z than va trong luc: cos = cos(roll) * cos(pitch).
|
||||
const double r = tilt_roll_.load(std::memory_order_relaxed);
|
||||
const double p = tilt_pitch_.load(std::memory_order_relaxed);
|
||||
const double t = std::acos(std::min(1.0, std::cos(r) * std::cos(p)));
|
||||
if (deg != nullptr) *deg = t * 180.0 / M_PI;
|
||||
return slope_on_ && t > kRelocStaticTiltDeg * M_PI / 180.0;
|
||||
}
|
||||
|
||||
RelocVerdict Runtime::RelocStaticDecide(const RelocMatch& m, const Pose2D& odom, double shift_ratio,
|
||||
bool use_shift, bool* along_axis, std::string* why) {
|
||||
*along_axis = false;
|
||||
if (!m.ok) {
|
||||
reloc_static_hist_.clear();
|
||||
*why = "khong khop duoc";
|
||||
return RelocVerdict::kFailed;
|
||||
}
|
||||
StaticRound r;
|
||||
r.robot = Pose2DCompose(m.map_from_odom, odom);
|
||||
r.map_from_odom = m.map_from_odom;
|
||||
r.ratio = m.ratio();
|
||||
r.ratio_yaw = m.ratio_yaw();
|
||||
r.shift = shift_ratio;
|
||||
return DecideStatic(&reloc_static_hist_, r, reloc_static_places_, reloc_cfg_, use_shift,
|
||||
along_axis, why);
|
||||
}
|
||||
|
||||
void Runtime::RelocCommand(double v, double w) {
|
||||
std::lock_guard<std::mutex> lk(cmd_mu_);
|
||||
raw_cmd_.linear.x = v;
|
||||
@@ -1682,25 +1831,60 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
// Het quang duong, hoac lop an toan chan qua lau (vat can, sieu am) -> xoay.
|
||||
if (moved >= reloc_drive_len_ || t > kRelocPhaseTimeout) {
|
||||
reloc_total_drive_ += moved;
|
||||
if (reloc_creeping_) {
|
||||
reloc_slope_creep_ += moved;
|
||||
reloc_creeping_ = false;
|
||||
}
|
||||
if (!yielding) RelocCommand(0.0, 0.0);
|
||||
RelocStartSweep();
|
||||
return;
|
||||
}
|
||||
if (!yielding) RelocCommand(kRelocSpeed, 0.0);
|
||||
char buf[96];
|
||||
std::snprintf(buf, sizeof(buf), "TU DI %.1f/%.1f m%s", moved, reloc_drive_len_,
|
||||
char buf[128];
|
||||
std::snprintf(buf, sizeof(buf), "%s %.1f/%.1f m%s",
|
||||
reloc_creeping_ ? "BO THANG TREN DOC" : "TU DI", moved, reloc_drive_len_,
|
||||
yielding ? " -- NHUONG NGUOI" : "");
|
||||
SetRelocStatus(buf, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- GOM (tu chay: pha XOAY; tay: nguoi xoay) ---
|
||||
// --- GOM (tu chay: pha XOAY; tay: nguoi xoay; tren doc: DUNG YEN) ---
|
||||
double tilt_deg = 0.0;
|
||||
// Che do doc: CHO do nghieng IMU hop le VA ON DINH roi moi quyet xoay hay dung
|
||||
// yen. Ngay luc khoi dong roll/pitch con = 0 gia -> vong dau tuong san phang,
|
||||
// xoay 300 do roi TU DI 1 m tren doc (sim 2026-10-05). valid() bat tu mau IMU
|
||||
// DAU, khi bo loc bu con dang hoi tu: sim 2026-10-06 vong dau thay 3.2 do tren
|
||||
// doc 10 do -> anh camera dau bi xet theo luat san phang. On dinh = doi duoi
|
||||
// kRelocTiltStableDeg trong kRelocTiltStableSec. Qua 8 s thi chay nhu cu.
|
||||
if (!reloc_have_prev_ && slope_on_ &&
|
||||
std::chrono::duration<double>(now - reloc_epoch_).count() < 8.0) {
|
||||
double tdeg = 0.0;
|
||||
RelocOnSlope(&tdeg);
|
||||
if (!tilt_valid_.load(std::memory_order_relaxed) ||
|
||||
std::fabs(tdeg - reloc_tilt_ref_deg_) > kRelocTiltStableDeg) {
|
||||
reloc_tilt_ref_deg_ = tdeg;
|
||||
reloc_tilt_ref_t_ = now;
|
||||
}
|
||||
if (std::chrono::duration<double>(now - reloc_tilt_ref_t_).count() < kRelocTiltStableSec) {
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
char tb[96];
|
||||
std::snprintf(tb, sizeof(tb), "CHO IMU on dinh (nghieng %.1f do) truoc khi dinh vi lai", tdeg);
|
||||
SetRelocStatus(tb, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!reloc_have_prev_) {
|
||||
reloc_t0_ = now;
|
||||
reloc_swept_ = 0.0;
|
||||
reloc_cam_have_last_ = false; // chup ngay anh dau cua vong gom
|
||||
reloc_cam_shots_ = 0;
|
||||
reloc_cam_best_inl_ = 0;
|
||||
reloc_static_round_ = RelocOnSlope(&tilt_deg);
|
||||
if (reloc_static_round_) {
|
||||
VSLAM_INFO("slam: reloc vong " << reloc_cycle_ + 1 << " DUNG YEN tren doc (nghieng "
|
||||
<< tilt_deg << " do) -- khong xoay, khop scan tai cho sau "
|
||||
<< kRelocStaticWindow << " s.");
|
||||
}
|
||||
} else {
|
||||
// Goc da quet do bang odom: xoay tai cho thi odometry rat chinh xac (ban
|
||||
// ROS do: 0.1 do troi tren 1086 do xoay).
|
||||
@@ -1710,8 +1894,13 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
reloc_have_prev_ = true;
|
||||
const std::vector<Point> p = ScanToFrame(scan, odom);
|
||||
reloc_pts_.insert(reloc_pts_.end(), p.begin(), p.end());
|
||||
// Camera: chot SOM ngay giua vong xoay neu anh + LiDAR cung chi mot pose.
|
||||
if (vpr_ && RelocCamera(scan, odom, now)) {
|
||||
// Camera: chot SOM ngay giua vong xoay neu anh + LiDAR cung chi mot pose. Vong
|
||||
// DUNG YEN: chup trong giay CUOI cua cua so -- LiDAR da gom du diem de kiem anh,
|
||||
// do nghieng da lang sau khi robot vua dung (bo xong / vua khoi dong).
|
||||
const bool cam_turn =
|
||||
!reloc_static_round_ ||
|
||||
std::chrono::duration<double>(now - reloc_t0_).count() >= kRelocStaticWindow - 1.0;
|
||||
if (vpr_ && cam_turn && RelocCamera(scan, odom, now)) {
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
return;
|
||||
}
|
||||
@@ -1723,7 +1912,36 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
constexpr double kTimeout = 30.0;
|
||||
const double elapsed = std::chrono::duration<double>(now - reloc_t0_).count();
|
||||
const int swept_deg = static_cast<int>(reloc_swept_ * 180.0 / M_PI);
|
||||
if (reloc_swept_ < kSweep && elapsed < kTimeout) {
|
||||
if (reloc_static_round_ && reloc_swept_ > kRelocStaticMaxTurn) {
|
||||
// Nguoi dang xoay robot -> de nguoi xoay het, khop nhu vong xoay thuong.
|
||||
reloc_static_round_ = false;
|
||||
VSLAM_INFO("slam: reloc -- robot dang duoc xoay, vong nay khop sau khi xoay du.");
|
||||
} else if (!reloc_static_round_ && reloc_swept_ < kRelocStaticMaxTurn && RelocOnSlope(&tilt_deg)) {
|
||||
// Moi xoay vai do ma da thay dang tren doc (do nghieng vua on dinh) -> dung.
|
||||
reloc_static_round_ = true;
|
||||
reloc_t0_ = now;
|
||||
reloc_cam_have_last_ = false; // anh luc con xoay khong tinh -- chup lai cuoi cua so
|
||||
VSLAM_INFO("slam: reloc -- phat hien dang tren doc (nghieng " << tilt_deg
|
||||
<< " do) khi moi xoay " << reloc_swept_ * 180.0 / M_PI << " do -> DUNG YEN.");
|
||||
}
|
||||
if (reloc_static_round_ && elapsed < kRelocStaticWindow) {
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
RelocOnSlope(&tilt_deg);
|
||||
char sb[160];
|
||||
if (running) {
|
||||
std::snprintf(sb, sizeof(sb),
|
||||
"DUNG YEN TREN DOC (nghieng %.1f do) -- khop tai cho, lan %d/%d, da bo %.1f/%.0f m",
|
||||
tilt_deg, reloc_static_here_ + 1, kRelocStaticBeforeCreep, reloc_slope_creep_,
|
||||
kRelocSlopeCreepMax);
|
||||
} else {
|
||||
std::snprintf(sb, sizeof(sb), "%sDUNG YEN TREN DOC (nghieng %.1f do) -- khop tai cho, lan %d",
|
||||
reloc_exec_ == RelocExec::kHalted ? "DUNG HAN tu chay -- " : "", tilt_deg,
|
||||
reloc_cycle_ + 1);
|
||||
}
|
||||
SetRelocStatus(std::string(sb) + (yielding ? " -- NHUONG NGUOI" : "") + cam_note(), true);
|
||||
return;
|
||||
}
|
||||
if (!reloc_static_round_ && reloc_swept_ < kSweep && elapsed < kTimeout) {
|
||||
if (running) {
|
||||
if (!yielding) RelocCommand(0.0, kRelocTurnRate);
|
||||
SetRelocStatus("TU XOAY " + std::to_string(swept_deg) + "/300 do (vong " +
|
||||
@@ -1745,17 +1963,64 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
|
||||
// --- Khop toan cuc ---
|
||||
const auto tm = std::chrono::steady_clock::now();
|
||||
const RelocMatch m = GlobalMatch(*reloc_field_, reloc_pts_, reloc_cfg_);
|
||||
// Che do doc: do nghieng IMU (theo trong luc, khong can ban do) loai gia
|
||||
// thuyet ma mat san ban do o do khong the gay ra -- lat 180 do tren doc, doc
|
||||
// o cho phang, sai lan. Chi phan xu giua cac gia thuyet LiDAR ngang diem
|
||||
// (xem GlobalMatch). Robot vua dung xoay nen do nghieng la luc dung yen.
|
||||
RelocAdmit admit;
|
||||
const double tilt_r = tilt_roll_.load(std::memory_order_relaxed);
|
||||
const double tilt_p = tilt_pitch_.load(std::memory_order_relaxed);
|
||||
if (slope_on_ && !slam_->floor_model().empty()) {
|
||||
admit = [this, odom, tilt_r, tilt_p](const Pose2D& T) {
|
||||
return RelocPoseAdmissible(Pose2DCompose(T, odom), tilt_r, tilt_p);
|
||||
};
|
||||
}
|
||||
const RelocMatch m = GlobalMatch(*reloc_field_, reloc_pts_, reloc_cfg_, admit);
|
||||
const double ms = std::chrono::duration<double, std::milli>(
|
||||
std::chrono::steady_clock::now() - tm).count();
|
||||
reloc_tracker_->Add(m, odom, std::chrono::duration<double>(now - reloc_epoch_).count());
|
||||
const int streak = m.ok ? reloc_tracker_->Streak(m.map_from_odom) : 0;
|
||||
const RelocVerdict v = Decide(m, streak, reloc_cfg_);
|
||||
RelocVerdict v = Decide(m, streak, reloc_cfg_);
|
||||
// Chot NHO do nghieng con phai qua kiem suy bien doc truc: bo loc loai het
|
||||
// doi thu XA, nhung o hanh lang / doc deu vi tri doc truc van mu (doi thu
|
||||
// nam trong reject_radius, cong ty le khong thay) -- xem ShiftScoreRatio.
|
||||
double shift_ratio = -1.0;
|
||||
bool along_axis = false;
|
||||
std::string static_why;
|
||||
if (admit && m.ok) {
|
||||
shift_ratio = ShiftScoreRatio(*reloc_field_, reloc_pts_, m.map_from_odom, reloc_cfg_.tilt_shift_m);
|
||||
}
|
||||
if (reloc_static_round_) {
|
||||
// Dung yen: ty le NHO NHAT qua moi vong cung cho; hoac hai cho (truoc / sau
|
||||
// khi bo) cung pose, moi cho deu qua -- xem DecideStatic. KHONG dung streak
|
||||
// cua tracker: no da cho chot sai 1.5-2 m o chan doc (ty le nhay 1.32).
|
||||
v = RelocStaticDecide(m, odom, shift_ratio, static_cast<bool>(admit), &along_axis, &static_why);
|
||||
} else {
|
||||
reloc_static_hist_.clear();
|
||||
reloc_static_places_.clear();
|
||||
if (admit && m.ok && v == RelocVerdict::kAccept && m.tilt_used &&
|
||||
shift_ratio >= reloc_cfg_.tilt_max_shift_ratio) {
|
||||
v = RelocVerdict::kAmbiguous;
|
||||
along_axis = true;
|
||||
}
|
||||
}
|
||||
++reloc_cycle_;
|
||||
VSLAM_INFO("slam: reloc vong " << reloc_cycle_ << " -- quet " << swept_deg << " do / "
|
||||
<< elapsed << " s, " << m.points << " diem, ty le " << m.ratio() << " / huong "
|
||||
<< m.ratio_yaw() << ", streak " << streak << " -> " << RelocVerdictName(v)
|
||||
<< " (" << ms << " ms)");
|
||||
std::string tilt_note;
|
||||
if (admit) {
|
||||
char tb[160];
|
||||
std::snprintf(tb, sizeof(tb), "; nghieng IMU roll %.1f / pitch %.1f do: %s; dich %.1f m giu %.0f%% diem",
|
||||
tilt_r * 180.0 / M_PI, tilt_p * 180.0 / M_PI,
|
||||
m.tilt_used ? (std::to_string(m.tilt_rejected) + " ung vien mau thuan bi loai").c_str()
|
||||
: m.tilt_conflict ? "MAU THUAN voi LiDAR -- bo qua, giu ket qua LiDAR"
|
||||
: "khong loai ung vien nao",
|
||||
reloc_cfg_.tilt_shift_m, 100.0 * shift_ratio);
|
||||
tilt_note = tb;
|
||||
}
|
||||
VSLAM_INFO("slam: reloc vong " << reloc_cycle_ << (reloc_static_round_ ? " (DUNG YEN)" : "")
|
||||
<< " -- quet " << swept_deg << " do / " << elapsed << " s, " << m.points
|
||||
<< " diem, ty le " << m.ratio() << " / huong " << m.ratio_yaw() << ", streak "
|
||||
<< streak << " -> " << RelocVerdictName(v) << " (" << ms << " ms)" << tilt_note
|
||||
<< (static_why.empty() ? "" : "; " + static_why));
|
||||
|
||||
// Vong gom moi, du ket qua the nao.
|
||||
reloc_pts_.clear();
|
||||
@@ -1766,20 +2031,109 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
// Nhap nhang la ket qua DUNG, khong phai loi: tra loi sai tu tin te hon
|
||||
// nhieu so voi im lang. Noi ro phai lam gi.
|
||||
const char* hint =
|
||||
v == RelocVerdict::kNeedCycles ? "DAI BIEN -- di chuyen >= 0.2 m roi xoay tiep"
|
||||
along_axis ? "NHAP NHANG DOC TRUC (hanh lang / doc deu) -- di chuyen toi cho co dac diem"
|
||||
: reloc_static_round_
|
||||
? (v == RelocVerdict::kNeedCycles ? "DUNG YEN TREN DOC -- chua du tin cay"
|
||||
: "DUNG YEN TREN DOC -- nhap nhang")
|
||||
: v == RelocVerdict::kNeedCycles ? "DAI BIEN -- di chuyen >= 0.2 m roi xoay tiep"
|
||||
: v == RelocVerdict::kAmbiguousYaw ? "NHAP NHANG HUONG -- di chuyen vai met roi xoay tiep"
|
||||
: v == RelocVerdict::kAmbiguous ? "NHAP NHANG VI TRI -- di chuyen vai met roi xoay tiep"
|
||||
: "KHONG KHOP -- xoay tiep";
|
||||
char buf[160];
|
||||
std::snprintf(buf, sizeof(buf), "%s (ty le %.2f / huong %.2f)", hint, m.ratio(), m.ratio_yaw());
|
||||
VSLAM_WARN("slam: reloc chua chot -- " << buf);
|
||||
char buf[220];
|
||||
std::snprintf(buf, sizeof(buf), "%s (ty le %.2f / huong %.2f%s%s)", hint, m.ratio(),
|
||||
m.ratio_yaw(), static_why.empty() ? "" : "; ", static_why.c_str());
|
||||
// Nhap nhang voi CHO NAO: pose robot cua nguoi thang va hai doi thu.
|
||||
char who[200] = "";
|
||||
if (m.ok) {
|
||||
const Pose2D w = Pose2DCompose(m.map_from_odom, odom);
|
||||
const Pose2D p2 = Pose2DCompose(m.s2_from_odom, odom);
|
||||
const Pose2D py = Pose2DCompose(m.s2_yaw_from_odom, odom);
|
||||
std::snprintf(who, sizeof(who),
|
||||
"; thang (%.2f, %.2f, %.0f do), doi thu vi tri (%.2f, %.2f, %.0f do), doi thu "
|
||||
"huong (%.2f, %.2f, %.0f do)",
|
||||
w.x, w.y, w.theta * 180.0 / M_PI, p2.x, p2.y, p2.theta * 180.0 / M_PI, py.x,
|
||||
py.y, py.theta * 180.0 / M_PI);
|
||||
}
|
||||
VSLAM_WARN("slam: reloc chua chot -- " << buf << who);
|
||||
if (!running) {
|
||||
SetRelocStatus(buf, true);
|
||||
return;
|
||||
}
|
||||
// Tu chay: sang cho khac roi xoay tiep -- doi xung cuc bo thuong vo khi
|
||||
// doi goc nhin, va streak chi tang khi DA DI >= 0.2 m.
|
||||
++reloc_exec_cycles_;
|
||||
// ⚠️ Vong tren doc KHONG tinh vao tran kRelocMaxCycles (chung co tran rieng
|
||||
// = quang bo): sim, bo xuong toi sanh roi vong xoay dau o sanh (ty le 1.43,
|
||||
// can them mot vong) bi dung han ngay vi bo dem da len 20 tu cac vong doc.
|
||||
if (!reloc_static_round_) ++reloc_exec_cycles_;
|
||||
if (reloc_static_round_) {
|
||||
// Tren doc: khop lai TAI CHO vai lan; chua chot thi BO 0.5 m roi khop
|
||||
// tiep o cho moi (xem kRelocStaticBeforeCreep). Het tran bo / khong co
|
||||
// huong nao thoang thi goi nguoi.
|
||||
++reloc_static_here_;
|
||||
// Mu doc truc -> bo ngay, xa hon; chi thieu tin cay -> khop lai tai cho vai lan.
|
||||
// ⚠️ Xet THANG chi so dich cua vong nay, khong qua `along_axis`: ty le
|
||||
// < 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;
|
||||
if (!blind && reloc_static_here_ < kRelocStaticBeforeCreep) {
|
||||
RelocStartSweep();
|
||||
VSLAM_INFO("reloc_exec: vong " << reloc_cycle_ << " chua chot -- tren doc: khop lai tai cho ("
|
||||
<< reloc_static_here_ << "/" << kRelocStaticBeforeCreep << ").");
|
||||
SetRelocStatus(std::string(buf) + " -- tren doc: khop lai tai cho", true);
|
||||
return;
|
||||
}
|
||||
char hb[160];
|
||||
const double budget = std::min(kRelocSlopeCreepMax - reloc_slope_creep_,
|
||||
kRelocMaxDrive - reloc_total_drive_);
|
||||
double step = std::min(blind ? kRelocCreepBlind : kRelocCreepStep, budget);
|
||||
if (step < 0.3) {
|
||||
std::snprintf(hb, sizeof(hb), "tren doc: da bo %.1f m, %d lan khop tai cho chua chot",
|
||||
reloc_slope_creep_, reloc_static_here_);
|
||||
RelocHalt(hb);
|
||||
return;
|
||||
}
|
||||
reloc_static_here_ = 0;
|
||||
reloc_creeping_ = true;
|
||||
// Chot CHO nay truoc khi bo: chot "hai cho" so cho moi voi no.
|
||||
if (!reloc_static_hist_.empty()) {
|
||||
reloc_static_places_.push_back(SummarizePlace(reloc_static_hist_));
|
||||
while (reloc_static_places_.size() > 4) reloc_static_places_.erase(reloc_static_places_.begin());
|
||||
reloc_static_hist_.clear();
|
||||
}
|
||||
const double clear = RelocFrontClear(scan);
|
||||
if (clear - kRelocCreepMargin >= std::min(step, kRelocCreepStep)) {
|
||||
// Thang toi, KHONG quay: quay tai cho tren doc lam truot banh.
|
||||
step = std::min(step, clear - kRelocCreepMargin);
|
||||
reloc_exec_ = RelocExec::kDrive;
|
||||
reloc_drive_start_ = odom;
|
||||
reloc_drive_len_ = step;
|
||||
reloc_phase_t0_ = now;
|
||||
VSLAM_INFO("reloc_exec: tren doc chua chot" << (blind ? " (MU doc truc)" : "") << " -- BO THANG "
|
||||
<< step << " m (khong quay; da bo " << reloc_slope_creep_ << "/"
|
||||
<< kRelocSlopeCreepMax << " m) roi khop tiep.");
|
||||
char cb[64];
|
||||
std::snprintf(cb, sizeof(cb), " -- BO THANG %.1f m tren doc", step);
|
||||
SetRelocStatus(std::string(buf) + cb, true);
|
||||
return;
|
||||
}
|
||||
// Phia truoc khong thoang (vd nhin xuong doc: tia cham san da bi bo) ->
|
||||
// quay ve huong thoang nhat roi moi bo.
|
||||
if (!RelocPlanDrive(scan, odom)) {
|
||||
reloc_creeping_ = false;
|
||||
RelocHalt("tren doc: phia truoc chi thoang " + std::to_string(clear) +
|
||||
" m va khong co huong nao thoang >= 1 m");
|
||||
return;
|
||||
}
|
||||
reloc_drive_len_ = std::min(reloc_drive_len_, step);
|
||||
reloc_exec_ = RelocExec::kTurn;
|
||||
reloc_phase_t0_ = now;
|
||||
VSLAM_INFO("reloc_exec: tren doc chua chot, phia truoc khong thoang (" << clear
|
||||
<< " m) -- quay ve huong " << reloc_turn_target_ * 180.0 / M_PI << " do (odom) roi bo "
|
||||
<< reloc_drive_len_ << " m.");
|
||||
SetRelocStatus(std::string(buf) + " -- QUAY roi BO tren doc", true);
|
||||
return;
|
||||
}
|
||||
reloc_static_here_ = 0;
|
||||
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");
|
||||
@@ -1800,8 +2154,15 @@ void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
|
||||
// --- CHOT -> dung yen roi tinh chinh (RelocSettle) ---
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
char src[48];
|
||||
std::snprintf(src, sizeof(src), "LiDAR, ty le %.2f", m.ratio());
|
||||
// Lan dinh vi lai SAU (vd canh lac) khong duoc dung lai cac vong dung yen cu.
|
||||
reloc_static_hist_.clear();
|
||||
reloc_static_places_.clear();
|
||||
char src[96];
|
||||
std::snprintf(src, sizeof(src),
|
||||
reloc_static_round_ ? "LiDAR + do nghieng IMU, DUNG YEN tren doc, ty le %.2f"
|
||||
: m.tilt_used ? "LiDAR + do nghieng IMU, ty le %.2f"
|
||||
: "LiDAR, ty le %.2f",
|
||||
m.ratio());
|
||||
RelocBeginSettle(m.map_from_odom, m.ratio(), odom, now, src);
|
||||
}
|
||||
|
||||
@@ -1841,6 +2202,15 @@ constexpr double kCamAgreeM = 0.5;
|
||||
constexpr double kCamAgreeRad = 10.0 * M_PI / 180.0;
|
||||
constexpr double kCamLidarRadius = 2.5; // LiDAR cuc bo quanh node anh VPR
|
||||
constexpr double kCamLidarYaw = 45.0 * M_PI / 180.0;
|
||||
// --- Tren DOC (RelocOnSlope): luat rieng ---
|
||||
// Sim 2026-10-06 (5 cho giua lan doc, robot dung yen): 3/5 cho ca 5 ung vien VPR+PnP
|
||||
// DUNG toi 1-5 cm, 2/5 cho sai het (nham lan khac / lat 180 do -- do nghieng IMU loai
|
||||
// duoc). Luat phang (LiDAR cuc bo quanh node phai TRUNG PnP) chan ca ung vien dung
|
||||
// (LiDAR mu doc lan) va mot lan con chot pose LiDAR roi tinh chinh keo lech 0.75 m.
|
||||
// Tren doc: LiDAR chi can KHONG PHAN DOI; pose chot la TRUNG BINH cac pose CAMERA, khong
|
||||
// tinh chinh LiDAR (do: tinh chinh keo pose 8-13 cm doc lan, diem chi nhich 0.996 -> 0.999).
|
||||
constexpr double kCamSlopeLidarKeep = 0.9; // diem LiDAR tai pose camera / tot nhat quanh do
|
||||
constexpr size_t kCamSlopeMinAgree = 2; // ung vien tu node KHAC nhau phai trung nhau
|
||||
|
||||
cv::Matx44d MatxFromTransform(const Transform& t) {
|
||||
const Vector3 ex = RotateVector(t.rotation, Vector3{1.0, 0.0, 0.0});
|
||||
@@ -1919,7 +2289,21 @@ bool Runtime::RelocCamera(const LaserScan& scan, const Pose2D& odom,
|
||||
TiltLift(roll, pitch, cfg_->robot.geometry().wheel_radius), slam_cam_to_link_));
|
||||
|
||||
std::vector<Pose2D> acc; // T_map_odom (pose LiDAR) cua ung vien DUOC CHOT
|
||||
std::vector<Pose2D> cams; // tren doc: pose robot theo camera cua ung vien duoc chot
|
||||
std::string why;
|
||||
// Tren doc: luat rieng (xem kCamSlopeLidarKeep). Phang: luat da kiem, giu nguyen.
|
||||
const bool slope_cam = !slam_->floor_model().empty() && RelocOnSlope();
|
||||
const double tilt_r = tilt_roll_.load(std::memory_order_relaxed);
|
||||
const double tilt_p = tilt_pitch_.load(std::memory_order_relaxed);
|
||||
auto lidar_at = [this](const Pose2D& T) {
|
||||
const double c = std::cos(T.theta), s = std::sin(T.theta);
|
||||
std::vector<Point> m(reloc_pts_.size());
|
||||
for (size_t i = 0; i < reloc_pts_.size(); ++i) {
|
||||
m[i].x = T.x + c * reloc_pts_[i].x - s * reloc_pts_[i].y;
|
||||
m[i].y = T.y + s * reloc_pts_[i].x + c * reloc_pts_[i].y;
|
||||
}
|
||||
return reloc_field_->MeanScore(m);
|
||||
};
|
||||
for (size_t k = 0; k < topk; ++k) {
|
||||
const int id = vpr_ids_[sc[k].second];
|
||||
auto it = vpr_shots_.find(id);
|
||||
@@ -1936,13 +2320,64 @@ bool Runtime::RelocCamera(const LaserScan& scan, const Pose2D& odom,
|
||||
}
|
||||
const PnpResult r = vverif_->Solve(qf, it->second.f, it->second.T_map_base);
|
||||
reloc_cam_best_inl_ = std::max(reloc_cam_best_inl_, r.inliers);
|
||||
if (r.inliers < kCamMinInliers || std::fabs(r.dz) > kCamMaxDz || r.tilt_deg > kCamMaxTiltDeg) {
|
||||
// `dz` = do cao robot SO VOI node anh (ca hai da can trong luc). San phang: ~0. Tren
|
||||
// doc: = chenh san giua hai cho theo mo hinh san -- hai diem cach 2 m tren doc 15 do
|
||||
// chenh 0.5 m, dung nguong phang 0.3 m la loai oan nghiem DUNG.
|
||||
double dz_expect = 0.0;
|
||||
if (slope_on_ && !slam_->floor_model().empty() && r.inliers > 0) {
|
||||
double zq = 0.0, zn = 0.0;
|
||||
const cv::Matx44d& Tm = it->second.T_map_base;
|
||||
if (slam_->floor_model().FloorAt(r.x, r.y, &zq) &&
|
||||
slam_->floor_model().FloorAt(Tm(0, 3), Tm(1, 3), &zn)) {
|
||||
dz_expect = zq - zn;
|
||||
}
|
||||
}
|
||||
if (r.inliers > 0) {
|
||||
VSLAM_INFO("slam: reloc camera -- node " << id << " giong " << sc[k].first << ", PnP "
|
||||
<< r.inliers << "/" << r.matches << " inlier, pose (" << r.x << ", " << r.y << ", "
|
||||
<< r.yaw * 180.0 / M_PI << " do), dz " << r.dz << " (ky vong " << dz_expect
|
||||
<< "), nghieng " << r.tilt_deg << " do");
|
||||
}
|
||||
if (r.inliers < kCamMinInliers || std::fabs(r.dz - dz_expect) > kCamMaxDz ||
|
||||
r.tilt_deg > kCamMaxTiltDeg) {
|
||||
continue;
|
||||
}
|
||||
Pose2D cam;
|
||||
cam.x = r.x;
|
||||
cam.y = r.y;
|
||||
cam.theta = r.yaw;
|
||||
if (slope_cam) {
|
||||
// 1. Do nghieng IMU khop do doc ban do tai pose camera + dung tren o trong: loai
|
||||
// nham lan (doc goc khac) va lat 180 do (doc nguoc dau).
|
||||
if (!RelocPoseAdmissible(cam, tilt_r, tilt_p)) {
|
||||
VSLAM_INFO("slam: reloc camera -- node " << id << " loai: do nghieng / o trong khong khop");
|
||||
continue;
|
||||
}
|
||||
// 2. LiDAR KHONG PHAN DOI: diem tai pose camera >= kCamSlopeLidarKeep x tot nhat
|
||||
// quanh do. Hanh lang/doc deu: LiDAR dung moi cho doc truc -> khong phan doi.
|
||||
const Pose2D Tcam = Pose2DCompose(cam, Pose2DInverse(odom));
|
||||
Point cc;
|
||||
cc.x = cam.x;
|
||||
cc.y = cam.y;
|
||||
const RelocHypothesis hb = LocalMatch(*reloc_field_, reloc_pts_, odom, cc, kCamLidarRadius,
|
||||
reloc_cfg_);
|
||||
const double s_cam = lidar_at(Tcam);
|
||||
const double s_best = hb.score > 0.0 ? lidar_at(hb.map_from_odom) : -1.0;
|
||||
if (s_cam <= 0.0 || (s_best > 0.0 && s_cam < kCamSlopeLidarKeep * s_best)) {
|
||||
VSLAM_INFO("slam: reloc camera -- node " << id << " loai: LiDAR phan doi (diem " << s_cam
|
||||
<< " / tot nhat " << s_best << ")");
|
||||
continue;
|
||||
}
|
||||
acc.push_back(Tcam); // pose CAMERA -- LiDAR mu doc lan, khong lay pose LiDAR
|
||||
cams.push_back(cam);
|
||||
if (why.empty()) {
|
||||
char b[120];
|
||||
std::snprintf(b, sizeof(b), "node %d, giong %.2f, PnP %d inlier, LiDAR %.0f%%", id,
|
||||
sc[k].first, r.inliers, s_best > 0.0 ? 100.0 * s_cam / s_best : 100.0);
|
||||
why = b;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// LiDAR cuc bo quanh node anh VPR: gioi han huong truoc, tu do huong sau (nhu da do).
|
||||
const cv::Matx44d& Tn = it->second.T_map_base;
|
||||
Point center;
|
||||
@@ -1966,6 +2401,10 @@ bool Runtime::RelocCamera(const LaserScan& scan, const Pose2D& odom,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reloc_cam_best_inl_ == 0 && topk > 0) {
|
||||
VSLAM_INFO("slam: reloc camera -- anh " << reloc_cam_shots_ << ": top-" << topk << " node giong "
|
||||
<< sc[0].first << ".." << sc[topk - 1].first << ", khong PnP nao ra inlier.");
|
||||
}
|
||||
if (acc.empty()) return false;
|
||||
for (const Pose2D& T : acc) {
|
||||
if (!CamAgree(Pose2DCompose(T, odom), Pose2DCompose(acc[0], odom))) {
|
||||
@@ -1974,11 +2413,37 @@ bool Runtime::RelocCamera(const LaserScan& scan, const Pose2D& odom,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (slope_cam && acc.size() < kCamSlopeMinAgree) {
|
||||
VSLAM_INFO("slam: reloc camera -- tren doc moi " << acc.size() << " ung vien dat, can "
|
||||
<< kCamSlopeMinAgree << " trung nhau -- chua chot.");
|
||||
return false;
|
||||
}
|
||||
// Chot: vong gom nay coi nhu xong.
|
||||
++reloc_cycle_;
|
||||
reloc_pts_.clear();
|
||||
reloc_have_prev_ = false;
|
||||
reloc_swept_ = 0.0;
|
||||
if (slope_cam) {
|
||||
// Moi ung vien la PnP voi mot anh ban do KHAC -> lay trung binh. Anh va scan cung luc,
|
||||
// robot dung yen: dat pose ngay, khong qua buoc tinh chinh LiDAR.
|
||||
const double n = static_cast<double>(cams.size());
|
||||
Pose2D mean;
|
||||
double dth = 0.0;
|
||||
for (const Pose2D& c : cams) {
|
||||
mean.x += c.x / n;
|
||||
mean.y += c.y / n;
|
||||
dth += AngleDiff(c.theta, cams[0].theta) / n;
|
||||
}
|
||||
mean.theta = NormalizeAngle(cams[0].theta + dth);
|
||||
const Pose2D T = Pose2DCompose(mean, Pose2DInverse(odom));
|
||||
RelocBeginSettle(T, 0.0, odom, now,
|
||||
"camera tren doc (" + std::to_string(cams.size()) + " ung vien trung; " + why + ")");
|
||||
reloc_static_hist_.clear();
|
||||
reloc_static_places_.clear();
|
||||
RelocFinish(T, odom, scan, "trung binh " + std::to_string(cams.size()) +
|
||||
" pose camera, khong tinh chinh LiDAR -- mu doc lan");
|
||||
return true;
|
||||
}
|
||||
RelocBeginSettle(acc[0], 0.0, odom, now, "camera+LiDAR (" + why + ")");
|
||||
return true;
|
||||
}
|
||||
@@ -2145,6 +2610,11 @@ void Runtime::RelocWatch(const LaserScan& scan, const Pose2D& pose_map) {
|
||||
reloc_tracker_->Clear();
|
||||
reloc_ref_score_ = -1.0;
|
||||
reloc_lost_pending_ = false;
|
||||
reloc_static_hist_.clear();
|
||||
reloc_static_places_.clear();
|
||||
reloc_static_here_ = 0;
|
||||
reloc_slope_creep_ = 0.0;
|
||||
reloc_creeping_ = false;
|
||||
if (opts_.slam_reloc_auto) {
|
||||
// Lan dinh vi MOI: dat lai tran cung.
|
||||
reloc_exec_cycles_ = 0;
|
||||
@@ -2355,7 +2825,10 @@ void Runtime::WebLoop() {
|
||||
}
|
||||
snap.slam.voxels_source = voxels_source;
|
||||
#endif
|
||||
if (slam_map_) snap.map = slam_map_;
|
||||
if (slam_map_) {
|
||||
snap.map = slam_map_;
|
||||
snap.map_floor = slam_map_floor_;
|
||||
}
|
||||
} else {
|
||||
snap.pose_map = ekf_pose;
|
||||
snap.slam.mode = !snap.slam.reloc.empty() ? "dinh vi lai"
|
||||
@@ -2365,6 +2838,7 @@ void Runtime::WebLoop() {
|
||||
// Dang dinh vi lai: ban do DB dung san luc Init.
|
||||
if (slam_map_) {
|
||||
snap.map = slam_map_;
|
||||
snap.map_floor = slam_map_floor_;
|
||||
snap.slam.map_version = static_cast<uint32_t>(slam_published_version_);
|
||||
}
|
||||
snap.voxels = slam_voxels_;
|
||||
|
||||
@@ -179,6 +179,19 @@ class Runtime {
|
||||
bool RelocPlanDrive(const LaserScan& scan, const Pose2D& odom);
|
||||
void RelocStartSweep();
|
||||
void RelocHalt(const std::string& why);
|
||||
// Dang dung tren doc (che do doc bat, nghieng than so voi trong luc qua
|
||||
// nguong) -> vong dinh vi lai DUNG YEN, khong xoay robot. `deg`: goc nghieng.
|
||||
bool RelocOnSlope(double* deg = nullptr) const;
|
||||
// Khoang thoang PHIA TRUOC (+-15 do, frame base) theo scan; 0 = khong co tia
|
||||
// nao trong quat do (khong biet -> khong di).
|
||||
double RelocFrontClear(const LaserScan& scan) const;
|
||||
// Che do doc: pose robot `p` (map) co hop khong -- dung tren o TRONG cua ban do, va
|
||||
// do doc ban do tai do gay ra dung do nghieng IMU (roll/pitch) dang do.
|
||||
bool RelocPoseAdmissible(const Pose2D& p, double tilt_r, double tilt_p) const;
|
||||
// Quyet dinh cho vong DUNG YEN: trung vi `static_rounds` vong lien tiep cung
|
||||
// nguoi thang thay cho mot vong. `*along_axis` = bi chan vi mu doc truc.
|
||||
RelocVerdict RelocStaticDecide(const RelocMatch& m, const Pose2D& odom, double shift_ratio,
|
||||
bool use_shift, bool* along_axis, std::string* why);
|
||||
// Sau khi CHOT: cho robot DUNG YEN, gom scan luc dung yen (khong nhoe do
|
||||
// quay), khop cuc bo quanh pose vua chot roi moi dat pose ban dau.
|
||||
void RelocSettle(const LaserScan& scan, const Pose2D& odom,
|
||||
@@ -350,6 +363,8 @@ class Runtime {
|
||||
size_t last_map_occ_ = 0;
|
||||
size_t last_map_free_ = 0;
|
||||
OccupancyGridPtr slam_map_;
|
||||
// Do cao san cua ban do (che do doc), cung phien ban voi slam_map_.
|
||||
std::shared_ptr<const MapFloorGrid> slam_map_floor_;
|
||||
double slam_process_ms_ = 0.0;
|
||||
int slam_loops_ = 0;
|
||||
// Phat hien KE CAN -- co che cat sai so cong don that su cua SLAM scan-only.
|
||||
@@ -380,6 +395,21 @@ class Runtime {
|
||||
double reloc_swept_ = 0.0; // rad da xoay trong vong gom nay
|
||||
Pose2D reloc_prev_odom_;
|
||||
bool reloc_have_prev_ = false;
|
||||
// Vong gom nay DUNG YEN tren doc (chot luc dau vong, xem RelocOnSlope): khong
|
||||
// xoay, gom scan tai cho vai giay roi khop -- bo khop da thu moi huong.
|
||||
bool reloc_static_round_ = false;
|
||||
// Do nghieng (do) va luc no doi qua nguong lan cuoi -- cho on dinh truoc vong dau.
|
||||
double reloc_tilt_ref_deg_ = -1.0;
|
||||
std::chrono::steady_clock::time_point reloc_tilt_ref_t_;
|
||||
// Ket qua cac vong DUNG YEN lien tiep cung nguoi thang (xem DecideStatic),
|
||||
// va tom tat cac CHO dung truoc (moi lan bo tren doc chot mot cho).
|
||||
std::vector<StaticRound> reloc_static_hist_;
|
||||
std::vector<StaticPlace> reloc_static_places_;
|
||||
// Tu chay tren doc: so lan khop tai cho o CHO hien tai, quang da BO tren doc
|
||||
// (tong, co tran), va pha DI hien tai co phai la mot lan BO khong.
|
||||
int reloc_static_here_ = 0;
|
||||
double reloc_slope_creep_ = 0.0;
|
||||
bool reloc_creeping_ = 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
|
||||
int reloc_cycle_ = 0;
|
||||
@@ -497,6 +527,9 @@ class Runtime {
|
||||
std::atomic<double> tilt_roll_{0.0};
|
||||
std::atomic<double> tilt_pitch_{0.0};
|
||||
std::atomic<bool> tilt_accel_ok_{false};
|
||||
// GravityAlign da khoi tao (co mau IMU) -- truoc do roll/pitch = 0 gia. Dinh
|
||||
// vi lai tren doc CHO co nay roi moi quyet xoay hay dung yen.
|
||||
std::atomic<bool> tilt_valid_{false};
|
||||
|
||||
// ---- Di tren doc (slam.yaml `slope:`) ----
|
||||
// slope_on_ doc-only sau Start(). Tat thi KHONG doi tuong nao duoi day
|
||||
|
||||
@@ -83,6 +83,7 @@ StatusResponse Runtime::Wire() {
|
||||
tilt_pitch_.store(perception_->gravity().pitch(), std::memory_order_relaxed);
|
||||
tilt_accel_ok_.store(perception_->gravity().accel_ok(),
|
||||
std::memory_order_relaxed);
|
||||
tilt_valid_.store(perception_->gravity().valid(), std::memory_order_relaxed);
|
||||
|
||||
std::lock_guard<std::mutex> lk(odom_mu_);
|
||||
wheel_odom_->FeedGyroZ(m->header.stamp, m->angular_velocity.z);
|
||||
|
||||
Reference in New Issue
Block a user