reloc: --slam-reloc(-auto) tu dinh vi lai trong node (tu xoay/tu di, nguoi luon thang); web ve robot mo o vi tri doan; sieu am cho xoay; LocalMatch gioi han huong
This commit is contained in:
@@ -69,6 +69,13 @@ void Usage(const char* argv0) {
|
||||
" pose ban dau cho localization -- tuong duong\n"
|
||||
" /initialpose. BAT BUOC tren robot that: RTAB-Map\n"
|
||||
" khong dinh vi toan cuc duoc bang scan khong.\n"
|
||||
" --slam-reloc localization KHONG can pose ban dau: XOAY TAI CHO\n"
|
||||
" ~300 do, node tu tim vi tri bang khop scan LiDAR\n"
|
||||
" voi toan ban do. Khong di cung --slam-init-pose.\n"
|
||||
" --slam-reloc-auto kem --slam-reloc: robot TU XOAY + TU DI (0.12 m/s,\n"
|
||||
" 0.4 rad/s, toi da 6 vong / 12 m) toi khi chot.\n"
|
||||
" Lenh van qua lop an toan; tay cam/web ra lenh\n"
|
||||
" la tu chay nhuong ngay. THU TREN MO PHONG TRUOC.\n"
|
||||
" --check nap va KIEM cau hinh roi thoat, khong chay gi\n",
|
||||
argv0, vslam::ConfigDir().c_str());
|
||||
}
|
||||
@@ -165,6 +172,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
opts.have_slam_init_pose = true;
|
||||
}
|
||||
else if (a == "--slam-reloc") opts.slam_reloc = true;
|
||||
else if (a == "--slam-reloc-auto") opts.slam_reloc_auto = true;
|
||||
else if (a == "--check") check_only = true;
|
||||
else if (a == "--help" || a == "-h") { Usage(argv[0]); return 0; }
|
||||
else {
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
|
||||
@@ -15,6 +17,9 @@
|
||||
#include "vslam/node_constants.h"
|
||||
#include "vslam/replay_source.h"
|
||||
#include "vslam/sim_source.h"
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
#include "vslam/occupancy_export.h"
|
||||
#endif
|
||||
|
||||
namespace vslam {
|
||||
|
||||
@@ -312,7 +317,11 @@ StatusResponse Runtime::Start() {
|
||||
//
|
||||
// Gieo pose xuat phat la tuong duong mo phong cua "robot biet no khoi dong
|
||||
// o dau" -- tren phan cung that do la viec cua dock, xem --slam-init-pose.
|
||||
if (opts_.source == SourceKind::kSim &&
|
||||
//
|
||||
// --slam-reloc thi KHONG gieo: robot "khong biet minh o dau", odom bat dau
|
||||
// tu 0 -- phep thu dinh vi lai moi la that, va dong CHECK sai so bat dau LON
|
||||
// roi tut xuong khi chot.
|
||||
if (opts_.source == SourceKind::kSim && !opts_.slam_reloc &&
|
||||
(opts_.sim_start_x != 0.0 || opts_.sim_start_y != 0.0 ||
|
||||
opts_.sim_start_yaw != 0.0)) {
|
||||
Pose2D start;
|
||||
@@ -365,6 +374,23 @@ StatusResponse Runtime::Start() {
|
||||
if (opts_.have_slam_db) sc.database_path = opts_.slam_db;
|
||||
if (opts_.slam_mode_override == "mapping") sc.mode = SlamMode::kMapping;
|
||||
else if (opts_.slam_mode_override == "localization") sc.mode = SlamMode::kLocalization;
|
||||
if (opts_.slam_reloc) {
|
||||
// Dinh vi lai can MOT ban do da quet de khop vao.
|
||||
if (sc.mode != SlamMode::kLocalization) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"--slam-reloc chi dung voi --slam-mode localization (tren ban do da quet)");
|
||||
}
|
||||
if (opts_.have_slam_init_pose) {
|
||||
return StatusResponse::Error(
|
||||
StatusCode::kInvalidArgument,
|
||||
"--slam-reloc va --slam-init-pose: chon MOT -- da biet pose thi khong can tim");
|
||||
}
|
||||
}
|
||||
if (opts_.slam_reloc_auto && !opts_.slam_reloc) {
|
||||
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||
"--slam-reloc-auto chi di kem --slam-reloc");
|
||||
}
|
||||
slam_.reset(new RtabmapSlam);
|
||||
const StatusResponse st = slam_->Init(sc);
|
||||
if (!st.ok()) {
|
||||
@@ -429,8 +455,10 @@ StatusResponse Runtime::Start() {
|
||||
// no o (0,0) trong khi robot dang o (-5.99, -2.91) thi ban do SLAM LECH
|
||||
// voi ban do the gioi dung bang vi tri xuat phat -- hai khung o che do
|
||||
// "chia doi" khong con chong khop duoc.
|
||||
if (sc.mode == SlamMode::kLocalization || opts_.have_slam_init_pose ||
|
||||
opts_.source == SourceKind::kSim) {
|
||||
// --slam-reloc: KHONG dat pose ban dau nao -- RelocStep() tu tim roi dat.
|
||||
if (!opts_.slam_reloc &&
|
||||
(sc.mode == SlamMode::kLocalization || opts_.have_slam_init_pose ||
|
||||
opts_.source == SourceKind::kSim)) {
|
||||
Pose2D init;
|
||||
const char* src = nullptr;
|
||||
if (opts_.have_slam_init_pose) {
|
||||
@@ -468,6 +496,37 @@ StatusResponse Runtime::Start() {
|
||||
cfg_->robot.StaticTransform(kBaseLinkFrame, kCameraDepthOpticalFrame, &cam_to_base);
|
||||
slam_cam_to_link_ = cam_to_base;
|
||||
slam_->SetExtrinsics(laser_to_base, cam_to_base);
|
||||
slam_laser_to_base_ = laser_to_base;
|
||||
|
||||
// --- Dinh vi lai tu dong ---
|
||||
// Luoi cho khop dung THANG tu file DB (cung cach tools/vslam_reloc_bench
|
||||
// do: 0 chot sai / 400 cau hoi mo phong, 0 / 249 tren robot that).
|
||||
if (opts_.slam_reloc) {
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
OccupancyGrid g;
|
||||
const StatusResponse gst =
|
||||
ExportOccupancyGridFromDb(slam_->database_path(), 0.05, reloc_cfg_.max_range, &g);
|
||||
if (!gst.ok()) {
|
||||
return StatusResponse::Error(gst.code, "--slam-reloc: dung luoi tu DB: " + gst.message);
|
||||
}
|
||||
reloc_field_.reset(new LikelihoodField(LikelihoodField::FromGrid(g, reloc_cfg_.sigma)));
|
||||
reloc_tracker_.reset(new HypothesisTracker(reloc_cfg_));
|
||||
reloc_active_ = true;
|
||||
reloc_epoch_ = std::chrono::steady_clock::now();
|
||||
const double dt = std::chrono::duration<double>(reloc_epoch_ - t0).count();
|
||||
VSLAM_INFO("slam: DINH VI LAI TU DONG -- ban do " << g.width << "x" << g.height
|
||||
<< " o (dung trong " << dt << " s). "
|
||||
<< (opts_.slam_reloc_auto
|
||||
? "Robot TU XOAY/TU DI (0.12 m/s, 0.4 rad/s, toi da 6 vong / 12 m); "
|
||||
"tay cam/web ra lenh la nhuong ngay. "
|
||||
: "XOAY TAI CHO ~300 do (tay cam/web). ")
|
||||
<< "RTAB-Map CHUA nhan gi cho toi khi chot.");
|
||||
if (opts_.slam_reloc_auto) {
|
||||
RelocStartSweep();
|
||||
} else {
|
||||
SetRelocStatus("XOAY TAI CHO de dinh vi lai (0/300 do)", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (opts_.force_slam) {
|
||||
@@ -965,6 +1024,16 @@ void Runtime::SlamLoop() {
|
||||
last_used = scan->header.stamp;
|
||||
have_last = true;
|
||||
|
||||
// --- Dinh vi lai tu dong: TRUOC khi dua gi cho RTAB-Map ---
|
||||
// Chua chot thi RTAB-Map KHONG nhan khung nao: localization khong pose ban
|
||||
// dau se tu nhan la dang o pose cuoi phien quet va bao `localized` ca khi
|
||||
// sai 1 m (docs/SLAM.md). Chot roi thi pose ban dau tinh tu CHINH odom
|
||||
// nay -- khong tre, khong phai cho robot dung nhu ban ROS.
|
||||
if (reloc_active_) {
|
||||
RelocStep(*scan, odom);
|
||||
if (reloc_active_) continue;
|
||||
}
|
||||
|
||||
// --- Ghep depth gan nhat voi scan nay ---
|
||||
//
|
||||
// ⚠️ Ba shared_ptr duoi day PHAI con song qua `Process()`:
|
||||
@@ -1030,6 +1099,9 @@ void Runtime::SlamLoop() {
|
||||
slam_map_version_ = out.map_version;
|
||||
}
|
||||
|
||||
// Canh "da lac": scan tai pose DANG TIN con khop ban do khong.
|
||||
if (reloc_field_ && !reloc_active_) RelocWatch(*scan, out.pose_map);
|
||||
|
||||
// Xuat ban do CHI khi do thi doi, VA khong qua `map_rebuild_rate_hz`.
|
||||
//
|
||||
// Chi kiem "do thi doi" la khong du: o che do mapping do thi doi o gan
|
||||
@@ -1193,6 +1265,477 @@ void Runtime::SlamLoop() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
// ============ DINH VI LAI TU DONG (--slam-reloc) ============
|
||||
//
|
||||
// Port cua global_scan_init.py (ban ROS): gom scan khi XOAY TAI CHO, khop
|
||||
// TOAN ban do, cong chong nhan nham, roi dat pose ban dau cho RTAB-Map. Xem
|
||||
// vslam/global_localizer.h cho cac so da do va vi sao.
|
||||
|
||||
void Runtime::SetRelocStatus(const std::string& s, bool pending) {
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
reloc_status_ = s;
|
||||
reloc_pending_ = pending;
|
||||
}
|
||||
|
||||
// ---------------- Tu chay (reloc_exec cua ban ROS) ----------------
|
||||
//
|
||||
// Cac chan KHONG duoc go (ban ROS, README "enable_reloc_exec"):
|
||||
// - mac dinh TAT, phai bat co y (--slam-reloc-auto);
|
||||
// - lenh ghi vao raw_cmd_ nhu tay cam/web -> VAN qua lop an toan;
|
||||
// - NGUOI LUON THANG: ai khac ra lenh la nhuong ngay + khoa 5 s;
|
||||
// - cham: 0.12 m/s, 0.4 rad/s; tran cung 6 vong / 12 m roi DUNG HAN.
|
||||
namespace {
|
||||
constexpr double kRelocTurnRate = 0.4; // rad/s
|
||||
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
|
||||
} // namespace
|
||||
|
||||
void Runtime::RelocCommand(double v, double w) {
|
||||
std::lock_guard<std::mutex> lk(cmd_mu_);
|
||||
raw_cmd_.linear.x = v;
|
||||
raw_cmd_.angular.z = w;
|
||||
raw_cmd_stamp_ = clock_->Now();
|
||||
have_raw_cmd_ = true;
|
||||
reloc_cmd_stamp_ = raw_cmd_stamp_;
|
||||
}
|
||||
|
||||
bool Runtime::RelocHumanCommanding() {
|
||||
std::lock_guard<std::mutex> lk(cmd_mu_);
|
||||
if (!have_raw_cmd_) return false;
|
||||
// raw_cmd_ moi hon lan ta ghi -> co nguon KHAC vua ghi (tay cam, web).
|
||||
if (raw_cmd_stamp_.toSec() <= reloc_cmd_stamp_.toSec() + 1e-9) return false;
|
||||
return SecondsBetween(clock_->Now(), raw_cmd_stamp_) < 0.5;
|
||||
}
|
||||
|
||||
void Runtime::RelocStartSweep() {
|
||||
reloc_exec_ = RelocExec::kSweep;
|
||||
reloc_pts_.clear();
|
||||
reloc_have_prev_ = false;
|
||||
reloc_swept_ = 0.0;
|
||||
SetRelocStatus("TU XOAY 0/300 do (vong " + std::to_string(reloc_exec_cycles_ + 1) + "/" +
|
||||
std::to_string(kRelocMaxCycles) + ")",
|
||||
true);
|
||||
}
|
||||
|
||||
void Runtime::RelocHalt(const std::string& why) {
|
||||
reloc_exec_ = RelocExec::kHalted;
|
||||
RelocCommand(0.0, 0.0);
|
||||
VSLAM_WARN("reloc_exec: DUNG HAN -- " << why << ". Can NGUOI: lai toi cho khac roi "
|
||||
"xoay tai cho bang tay -- dinh vi lai van chay.");
|
||||
SetRelocStatus("DUNG HAN (" + why + ") -- can nguoi: lai toi cho khac roi xoay tay", true);
|
||||
}
|
||||
|
||||
bool Runtime::RelocPlanDrive(const LaserScan& scan, const Pose2D& odom) {
|
||||
// 36 o 10 do quanh robot (frame BASE): khoang trong gan nhat moi o. O khong
|
||||
// co tia nao (vung mu sau lung, quat bi cat) la CHUA BIET -> khong chon.
|
||||
constexpr int kBins = 36;
|
||||
std::vector<double> near(kBins, reloc_cfg_.max_range);
|
||||
std::vector<bool> seen(kBins, false);
|
||||
auto bin_of = [&](double ang) {
|
||||
int b = static_cast<int>(std::floor((NormalizeAngle(ang) + M_PI) / (2.0 * M_PI) * kBins));
|
||||
return std::min(kBins - 1, std::max(0, b));
|
||||
};
|
||||
for (size_t i = 0; i < scan.ranges.size(); ++i) {
|
||||
const float r = scan.ranges[i];
|
||||
if (std::isnan(r)) continue; // khong do duoc
|
||||
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);
|
||||
const int b = bin_of(std::atan2(pb.y, pb.x));
|
||||
seen[b] = true;
|
||||
if (!std::isinf(r)) near[b] = std::min(near[b], std::hypot(pb.x, pb.y));
|
||||
}
|
||||
// Hanh lang cho CA than robot: lay min ba o lien (30 do).
|
||||
int best = -1;
|
||||
double best_clear = 0.0;
|
||||
for (int b = 0; b < kBins; ++b) {
|
||||
double c = reloc_cfg_.max_range;
|
||||
bool ok = true;
|
||||
for (int d = -1; d <= 1; ++d) {
|
||||
const int k = (b + d + kBins) % kBins;
|
||||
if (!seen[k]) { ok = false; break; }
|
||||
c = std::min(c, near[k]);
|
||||
}
|
||||
if (ok && c > best_clear) { best_clear = c; best = b; }
|
||||
}
|
||||
if (best < 0 || best_clear < 1.0) return false;
|
||||
const double ang = -M_PI + (best + 0.5) * (2.0 * M_PI / kBins);
|
||||
reloc_turn_target_ = NormalizeAngle(odom.theta + ang);
|
||||
// Di toi 1 m, chua 0.6 m truoc vat can (lop an toan dung o 0.45 m).
|
||||
reloc_drive_len_ = std::min(1.0, best_clear - 0.6);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Point> Runtime::ScanToFrame(const LaserScan& scan, const Pose2D& pose) const {
|
||||
std::vector<Point> out;
|
||||
out.reserve(scan.ranges.size());
|
||||
const double rmax = std::min<double>(scan.range_max, reloc_cfg_.max_range);
|
||||
const double c = std::cos(pose.theta), s = std::sin(pose.theta);
|
||||
for (size_t i = 0; i < scan.ranges.size(); ++i) {
|
||||
const float r = scan.ranges[i];
|
||||
// NaN (khong do duoc), inf (khong phan xa) va sentinel range_max + 1 (bi
|
||||
// cat quat) deu KHONG phai diem tuong -- bo ca ba.
|
||||
if (!std::isfinite(r) || r <= scan.range_min || r >= rmax) continue;
|
||||
const double a = scan.angle_min + static_cast<double>(i) * scan.angle_increment;
|
||||
Point pl;
|
||||
pl.x = r * std::cos(a);
|
||||
pl.y = r * std::sin(a);
|
||||
const Point pb = TransformPoint(slam_laser_to_base_, pl);
|
||||
Point p;
|
||||
p.x = pose.x + c * pb.x - s * pb.y;
|
||||
p.y = pose.y + s * pb.x + c * pb.y;
|
||||
out.push_back(p);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void Runtime::RelocStep(const LaserScan& scan, const Pose2D& odom) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const bool running = opts_.slam_reloc_auto && reloc_exec_ != RelocExec::kHalted &&
|
||||
reloc_exec_ != RelocExec::kOff;
|
||||
|
||||
// --- Tu chay: NGUOI LUON THANG ---
|
||||
bool yielding = false;
|
||||
if (running) {
|
||||
if (RelocHumanCommanding()) {
|
||||
if (now >= reloc_yield_until_) {
|
||||
VSLAM_WARN("reloc_exec: NGUOI dang lai -- nhuong, tam dung tu chay 5 s.");
|
||||
}
|
||||
reloc_yield_until_ = now + std::chrono::seconds(5);
|
||||
}
|
||||
yielding = now < reloc_yield_until_;
|
||||
}
|
||||
|
||||
// --- Da chot, dang cho dung yen de tinh chinh ---
|
||||
if (reloc_settle_) {
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
RelocSettle(scan, odom, now);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Pha QUAY / DI: chi dieu khien, KHONG gom scan ---
|
||||
if (running && reloc_exec_ == RelocExec::kTurn) {
|
||||
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) {
|
||||
reloc_exec_ = RelocExec::kDrive;
|
||||
reloc_drive_start_ = odom;
|
||||
reloc_phase_t0_ = now;
|
||||
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" : ""),
|
||||
true);
|
||||
return;
|
||||
}
|
||||
if (running && reloc_exec_ == RelocExec::kDrive) {
|
||||
const double moved =
|
||||
std::hypot(odom.x - reloc_drive_start_.x, odom.y - reloc_drive_start_.y);
|
||||
const double t = std::chrono::duration<double>(now - reloc_phase_t0_).count();
|
||||
// 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 (!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_,
|
||||
yielding ? " -- NHUONG NGUOI" : "");
|
||||
SetRelocStatus(buf, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- GOM (tu chay: pha XOAY; tay: nguoi xoay) ---
|
||||
if (!reloc_have_prev_) {
|
||||
reloc_t0_ = now;
|
||||
reloc_swept_ = 0.0;
|
||||
} 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).
|
||||
reloc_swept_ += std::fabs(AngleDiff(odom.theta, reloc_prev_odom_.theta));
|
||||
}
|
||||
reloc_prev_odom_ = odom;
|
||||
reloc_have_prev_ = true;
|
||||
const std::vector<Point> p = ScanToFrame(scan, odom);
|
||||
reloc_pts_.insert(reloc_pts_.end(), p.begin(), p.end());
|
||||
|
||||
// 300 do = yaw_sweep cua ban ROS: mot scan thieu ~124 do (vung mu), xoay
|
||||
// 300 do de phu kin co du. 30 s = timeout cua ban ROS: dung yen thi van
|
||||
// khop voi nhung gi da co.
|
||||
constexpr double kSweep = 300.0 * M_PI / 180.0;
|
||||
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 (running) {
|
||||
if (!yielding) RelocCommand(0.0, kRelocTurnRate);
|
||||
SetRelocStatus("TU XOAY " + std::to_string(swept_deg) + "/300 do (vong " +
|
||||
std::to_string(reloc_exec_cycles_ + 1) + "/" +
|
||||
std::to_string(kRelocMaxCycles) + ")" +
|
||||
(yielding ? " -- NHUONG NGUOI" : ""),
|
||||
true);
|
||||
} else {
|
||||
// Tu chay da DUNG HAN thi giu chu do tren web -- nguoi van hanh phai
|
||||
// biet vi sao robot dung.
|
||||
SetRelocStatus(std::string(reloc_exec_ == RelocExec::kHalted ? "DUNG HAN tu chay -- " : "") +
|
||||
"XOAY TAI CHO " + std::to_string(swept_deg) + "/300 do (vong " +
|
||||
std::to_string(reloc_cycle_ + 1) + ")",
|
||||
true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0); // dung xoay trong luc khop
|
||||
|
||||
// --- Khop toan cuc ---
|
||||
const auto tm = std::chrono::steady_clock::now();
|
||||
const RelocMatch m = GlobalMatch(*reloc_field_, reloc_pts_, reloc_cfg_);
|
||||
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;
|
||||
if (m.ok) {
|
||||
// Chi de VE robot mo o cho doan tot nhat -- xem reloc_guess_T_.
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
reloc_guess_T_ = m.map_from_odom;
|
||||
have_reloc_guess_ = true;
|
||||
}
|
||||
const RelocVerdict v = Decide(m, streak, reloc_cfg_);
|
||||
++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)");
|
||||
|
||||
// Vong gom moi, du ket qua the nao.
|
||||
reloc_pts_.clear();
|
||||
reloc_have_prev_ = false;
|
||||
reloc_swept_ = 0.0;
|
||||
|
||||
if (v != RelocVerdict::kAccept) {
|
||||
// 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"
|
||||
: 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);
|
||||
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_;
|
||||
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");
|
||||
return;
|
||||
}
|
||||
if (!RelocPlanDrive(scan, odom)) {
|
||||
RelocHalt("khong co huong nao thoang >= 1 m");
|
||||
return;
|
||||
}
|
||||
reloc_exec_ = RelocExec::kTurn;
|
||||
reloc_phase_t0_ = now;
|
||||
VSLAM_INFO("reloc_exec: vong " << reloc_exec_cycles_ << " chua chot -- quay ve huong "
|
||||
<< reloc_turn_target_ * 180.0 / M_PI << " do (odom) roi di "
|
||||
<< reloc_drive_len_ << " m.");
|
||||
SetRelocStatus(std::string(buf) + " -- TU QUAY roi DI", true);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- CHOT -> dung yen roi tinh chinh (RelocSettle) ---
|
||||
if (running && !yielding) RelocCommand(0.0, 0.0);
|
||||
reloc_settle_ = true;
|
||||
reloc_settle_T_ = m.map_from_odom;
|
||||
reloc_settle_ratio_ = m.ratio();
|
||||
reloc_settle_t0_ = now;
|
||||
reloc_still_ = false;
|
||||
reloc_settle_prev_odom_ = odom;
|
||||
reloc_settle_pts_.clear();
|
||||
reloc_settle_scans_ = 0;
|
||||
const Pose2D est = Pose2DCompose(m.map_from_odom, odom);
|
||||
VSLAM_INFO("slam: reloc TIM THAY (" << est.x << ", " << est.y << ", "
|
||||
<< est.theta * 180.0 / M_PI << " do), ty le " << m.ratio()
|
||||
<< " -- cho dung yen de tinh chinh truoc khi dat pose.");
|
||||
SetRelocStatus("TIM THAY -- dung yen de tinh chinh", true);
|
||||
}
|
||||
|
||||
void Runtime::RelocSettle(const LaserScan& scan, const Pose2D& odom,
|
||||
std::chrono::steady_clock::time_point now) {
|
||||
// Dung yen = gan nhu khong doi giua hai scan lien tiep (~40 ms): < 2 mm va
|
||||
// < 0.002 rad, tuc ~0.05 m/s va ~0.05 rad/s.
|
||||
const double dxy = std::hypot(odom.x - reloc_settle_prev_odom_.x,
|
||||
odom.y - reloc_settle_prev_odom_.y);
|
||||
const double dth = std::fabs(AngleDiff(odom.theta, reloc_settle_prev_odom_.theta));
|
||||
reloc_settle_prev_odom_ = odom;
|
||||
if (dxy > 0.002 || dth > 0.002) {
|
||||
reloc_still_ = false;
|
||||
reloc_settle_pts_.clear();
|
||||
reloc_settle_scans_ = 0;
|
||||
} else if (!reloc_still_) {
|
||||
reloc_still_ = true;
|
||||
reloc_still_since_ = now;
|
||||
}
|
||||
|
||||
// T_map_odom KHONG doi theo thoi gian, nen cho bao lau cung khong lam sai
|
||||
// pose da chot -- chi mat co hoi tinh chinh.
|
||||
if (std::chrono::duration<double>(now - reloc_settle_t0_).count() > 10.0) {
|
||||
VSLAM_WARN("slam: reloc -- robot khong dung yen sau 10 s, dat pose CHUA tinh chinh.");
|
||||
RelocFinish(reloc_settle_T_, odom, scan, "chua tinh chinh -- robot khong dung yen");
|
||||
return;
|
||||
}
|
||||
if (!reloc_still_ ||
|
||||
std::chrono::duration<double>(now - reloc_still_since_).count() < 0.5) {
|
||||
SetRelocStatus("TIM THAY -- dung yen de tinh chinh", true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 5 scan LUC DUNG YEN: khong nhoe do quay.
|
||||
const std::vector<Point> p = ScanToFrame(scan, odom);
|
||||
reloc_settle_pts_.insert(reloc_settle_pts_.end(), p.begin(), p.end());
|
||||
if (++reloc_settle_scans_ < 5) return;
|
||||
|
||||
auto apply = [](const Pose2D& T, const std::vector<Point>& pts) {
|
||||
std::vector<Point> out;
|
||||
out.reserve(pts.size());
|
||||
const double c = std::cos(T.theta), s = std::sin(T.theta);
|
||||
for (const Point& q : pts) {
|
||||
Point r;
|
||||
r.x = T.x + c * q.x - s * q.y;
|
||||
r.y = T.y + s * q.x + c * q.y;
|
||||
out.push_back(r);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const Pose2D est = Pose2DCompose(reloc_settle_T_, odom);
|
||||
Point center;
|
||||
center.x = est.x;
|
||||
center.y = est.y;
|
||||
const RelocHypothesis h = LocalMatch(*reloc_field_, reloc_settle_pts_, odom, center, 0.5,
|
||||
reloc_cfg_, est.theta, 10.0 * M_PI / 180.0);
|
||||
Pose2D T = reloc_settle_T_;
|
||||
char how[160];
|
||||
std::snprintf(how, sizeof(how), "khong tinh chinh duoc");
|
||||
if (h.score > 0.0) {
|
||||
// Chi nhan khi diem TRUNG BINH tren CUNG dam diem dung yen tot hon.
|
||||
const double s_old = reloc_field_->MeanScore(apply(reloc_settle_T_, reloc_settle_pts_));
|
||||
const double s_new = reloc_field_->MeanScore(apply(h.map_from_odom, reloc_settle_pts_));
|
||||
const Pose2D ref = Pose2DCompose(h.map_from_odom, odom);
|
||||
const double sh = std::hypot(ref.x - est.x, ref.y - est.y);
|
||||
const double sd = AngleDiff(ref.theta, est.theta) * 180.0 / M_PI;
|
||||
if (s_new >= s_old) {
|
||||
T = h.map_from_odom;
|
||||
std::snprintf(how, sizeof(how), "tinh chinh %.3f m / %.2f do, diem %.3f -> %.3f", sh, sd,
|
||||
s_old, s_new);
|
||||
} else {
|
||||
std::snprintf(how, sizeof(how), "tinh chinh KEM hon (%.3f < %.3f) -- giu pose chot",
|
||||
s_new, s_old);
|
||||
}
|
||||
}
|
||||
RelocFinish(T, odom, scan, how);
|
||||
}
|
||||
|
||||
void Runtime::RelocFinish(const Pose2D& map_from_odom, const Pose2D& odom,
|
||||
const LaserScan& scan, const std::string& how) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
// T_map_odom KHONG doi theo thoi gian; ghep voi CHINH odom ma khung RTAB-Map
|
||||
// ke tiep se nhan -> pose ban dau khop dung khung do.
|
||||
const Pose2D pose = Pose2DCompose(map_from_odom, odom);
|
||||
reloc_settle_ = false;
|
||||
const StatusResponse st = slam_->SetInitialPose(pose);
|
||||
if (!st.ok()) {
|
||||
VSLAM_ERROR("slam: reloc da chot nhung SetInitialPose loi: " << st.message
|
||||
<< " -- gom lai.");
|
||||
return;
|
||||
}
|
||||
reloc_active_ = false;
|
||||
if (opts_.slam_reloc_auto && reloc_exec_ != RelocExec::kOff) {
|
||||
// Chot roi thi DUNG HAN tu chay, ke ca dang nhuong nguoi.
|
||||
if (reloc_exec_ != RelocExec::kHalted) RelocCommand(0.0, 0.0);
|
||||
VSLAM_INFO("reloc_exec: DA CHOT -- dung tu chay (da di " << reloc_total_drive_
|
||||
<< " m, " << reloc_exec_cycles_ + 1 << " vong).");
|
||||
reloc_exec_ = RelocExec::kOff;
|
||||
}
|
||||
reloc_ref_score_ = reloc_field_->MeanScore(ScanToFrame(scan, pose));
|
||||
reloc_lost_pending_ = false;
|
||||
reloc_watch_next_ = now + std::chrono::seconds(1);
|
||||
char buf[160];
|
||||
std::snprintf(buf, sizeof(buf), "DA DINH VI (%.2f, %.2f, %.0f do) sau %d vong, ty le %.2f",
|
||||
pose.x, pose.y, pose.theta * 180.0 / M_PI, reloc_cycle_, reloc_settle_ratio_);
|
||||
SetRelocStatus(buf, false);
|
||||
VSLAM_INFO("slam: " << buf << " (" << how << ") -- dat pose ban dau cho RTAB-Map; diem "
|
||||
"tham chieu " << reloc_ref_score_ << ", se dinh vi lai neu tut duoi "
|
||||
<< 100.0 * reloc_cfg_.lost_score_ratio << "% trong " << reloc_cfg_.lost_hold << " s.");
|
||||
}
|
||||
|
||||
void Runtime::RelocWatch(const LaserScan& scan, const Pose2D& pose_map) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (reloc_ref_score_ <= 0.0 || now < reloc_watch_next_) return;
|
||||
reloc_watch_next_ = now + std::chrono::seconds(1);
|
||||
|
||||
// Hoan toan doc lap voi RTAB-Map: tu hoi "pose toi dang tin co giai thich
|
||||
// duoc cai toi dang thay khong". -1 = qua it diem roi vao luoi -> chua noi
|
||||
// duoc gi, KHONG coi la lac.
|
||||
const double sc = reloc_field_->MeanScore(ScanToFrame(scan, pose_map));
|
||||
if (sc < 0.0) return;
|
||||
const double thr = reloc_cfg_.lost_score_ratio * reloc_ref_score_;
|
||||
if (sc >= thr) {
|
||||
reloc_lost_pending_ = false;
|
||||
return;
|
||||
}
|
||||
// Phai tut LIEN TUC lost_hold giay: nguoi di ngang qua LiDAR khong duoc
|
||||
// kich hoat dinh vi lai.
|
||||
if (!reloc_lost_pending_) {
|
||||
reloc_lost_pending_ = true;
|
||||
reloc_lost_since_ = now;
|
||||
return;
|
||||
}
|
||||
if (std::chrono::duration<double>(now - reloc_lost_since_).count() < reloc_cfg_.lost_hold) {
|
||||
return;
|
||||
}
|
||||
VSLAM_WARN("slam: NGHI DA LAC -- diem " << sc << " < " << thr << " ("
|
||||
<< 100.0 * reloc_cfg_.lost_score_ratio << "% cua " << reloc_ref_score_
|
||||
<< ") trong " << reloc_cfg_.lost_hold << " s. XOAY TAI CHO de dinh vi lai.");
|
||||
reloc_active_ = true;
|
||||
reloc_pts_.clear();
|
||||
reloc_have_prev_ = false;
|
||||
reloc_swept_ = 0.0;
|
||||
reloc_tracker_->Clear();
|
||||
reloc_ref_score_ = -1.0;
|
||||
reloc_lost_pending_ = false;
|
||||
{
|
||||
// Ve robot MO o cho dang tin cuoi cung cho toi vong khop moi.
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
reloc_guess_T_ = map_correction_;
|
||||
have_reloc_guess_ = true;
|
||||
}
|
||||
if (opts_.slam_reloc_auto) {
|
||||
// Lan dinh vi MOI: dat lai tran cung.
|
||||
reloc_exec_cycles_ = 0;
|
||||
reloc_total_drive_ = 0.0;
|
||||
RelocStartSweep();
|
||||
} else {
|
||||
SetRelocStatus("NGHI DA LAC -- XOAY TAI CHO de dinh vi lai", true);
|
||||
}
|
||||
}
|
||||
#endif // VSLAM_HAVE_SLAM
|
||||
|
||||
void Runtime::WebLoop() {
|
||||
const auto period = std::chrono::duration<double>(
|
||||
cfg_->web.state_hz > 0.0 ? 1.0 / cfg_->web.state_hz : 0.1);
|
||||
@@ -1354,6 +1897,10 @@ void Runtime::WebLoop() {
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(slam_mu_);
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
snap.slam.reloc = reloc_status_;
|
||||
snap.slam.reloc_pending = reloc_pending_;
|
||||
#endif
|
||||
if (slam_map_version_ > 0) {
|
||||
snap.pose_map = Pose2DCompose(map_correction_, ekf_pose);
|
||||
snap.slam.localized = slam_localized_;
|
||||
@@ -1381,8 +1928,17 @@ void Runtime::WebLoop() {
|
||||
if (slam_map_) snap.map = slam_map_;
|
||||
} else {
|
||||
snap.pose_map = ekf_pose;
|
||||
snap.slam.mode = slam_enabled_ ? "dang cho" : "off";
|
||||
snap.slam.mode = !snap.slam.reloc.empty() ? "dinh vi lai"
|
||||
: slam_enabled_ ? "dang cho"
|
||||
: "off";
|
||||
}
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
// Chua chot: ve robot tai cho DOAN tot nhat (web ve MO). T_map_odom
|
||||
// khong doi nen robot di chuyen dung theo odom trong luc tu xoay/tu di.
|
||||
if (reloc_pending_ && have_reloc_guess_) {
|
||||
snap.pose_map = Pose2DCompose(reloc_guess_T_, ekf_pose);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ---- Bu do tre cua cloud ----
|
||||
@@ -1534,8 +2090,11 @@ void Runtime::WebLoop() {
|
||||
// Thua hoa: chi them diem khi da di du xa. Gui lai ca quy dao moi khung
|
||||
// la 8 kB/s vo ich.
|
||||
const Pose2D p = snap.pose_map;
|
||||
if (trajectory_.empty() ||
|
||||
Distance2D(trajectory_.back(), p) > cfg_->web.path_min_step_m) {
|
||||
// Chua dinh vi xong: pose chi la DOAN (nhay moi vong khop) -- khong ghi
|
||||
// vao quy dao, neu khong duong di se co vach noi toi goc toa do.
|
||||
if (!snap.slam.reloc_pending &&
|
||||
(trajectory_.empty() ||
|
||||
Distance2D(trajectory_.back(), p) > cfg_->web.path_min_step_m)) {
|
||||
trajectory_.push_back(p);
|
||||
}
|
||||
snap.trajectory = trajectory_;
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "vslam/wheel_odometry.h"
|
||||
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
#include "vslam/global_localizer.h"
|
||||
#include "vslam/rtabmap_slam.h"
|
||||
#include "vslam/voxel_export.h"
|
||||
#endif
|
||||
@@ -95,6 +96,12 @@ struct RuntimeOptions {
|
||||
// ROS, thu ma `dock_init.py` phat tu dock.
|
||||
bool have_slam_init_pose = false;
|
||||
Pose2D slam_init_pose;
|
||||
// --slam-reloc: localization KHONG pose ban dau -- tu dinh vi lai bang khop
|
||||
// scan LiDAR toan ban do (vslam/global_localizer.h).
|
||||
bool slam_reloc = false;
|
||||
// --slam-reloc-auto: robot TU XOAY va TU DI de gom scan (reloc_exec cua ban
|
||||
// ROS). Mac dinh TAT: robot tu chay khi CHUA biet minh o dau.
|
||||
bool slam_reloc_auto = false;
|
||||
};
|
||||
|
||||
class Runtime {
|
||||
@@ -132,6 +139,35 @@ class Runtime {
|
||||
void ReportCloudScanAlign(const PointCloudXYZ& cloud);
|
||||
void WebLoop();
|
||||
void SlamLoop();
|
||||
#ifdef VSLAM_HAVE_SLAM
|
||||
// Dinh vi lai tu dong (--slam-reloc). CHI luong slam goi, TRUOC Process():
|
||||
// gom scan theo goc da xoay, du thi khop toan cuc, chot thi SetInitialPose.
|
||||
void RelocStep(const LaserScan& scan, const Pose2D& odom);
|
||||
// Sau Process(): scan tai pose dang tin con khop ban do khong -- tut lau
|
||||
// thi quay lai gom (nghi da lac).
|
||||
void RelocWatch(const LaserScan& scan, const Pose2D& pose_map);
|
||||
// Diem scan (frame laser) -> frame cua `pose` (odom hoac map), cat max_range.
|
||||
std::vector<Point> ScanToFrame(const LaserScan& scan, const Pose2D& pose) const;
|
||||
// `pending` = CHUA dinh vi xong: web khong ve robot theo pose uoc luong.
|
||||
void SetRelocStatus(const std::string& s, bool pending);
|
||||
|
||||
// --- Tu chay (--slam-reloc-auto) ---
|
||||
// Lenh di qua `raw_cmd_` NHU MOI NGUON KHAC -> van qua lop an toan.
|
||||
void RelocCommand(double v, double w);
|
||||
// Co ai KHAC ghi raw_cmd_ trong 0.5 s qua khong (tay cam, web).
|
||||
bool RelocHumanCommanding();
|
||||
// Chon huong thoang nhat trong scan, dat muc tieu QUAY + DI. false = khong
|
||||
// co cho nao du rong.
|
||||
bool RelocPlanDrive(const LaserScan& scan, const Pose2D& odom);
|
||||
void RelocStartSweep();
|
||||
void RelocHalt(const 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,
|
||||
std::chrono::steady_clock::time_point now);
|
||||
void RelocFinish(const Pose2D& map_from_odom, const Pose2D& odom, const LaserScan& scan,
|
||||
const std::string& how);
|
||||
#endif
|
||||
void ApplyThreadPriority(std::thread* t, int prio, const char* name);
|
||||
|
||||
AppConfig* cfg_;
|
||||
@@ -239,6 +275,9 @@ class Runtime {
|
||||
Twist raw_cmd_;
|
||||
UnixTime raw_cmd_stamp_;
|
||||
bool have_raw_cmd_ = false;
|
||||
// Stamp cua lan GHI GAN NHAT boi dinh vi lai tu chay. raw_cmd_stamp_ moi hon
|
||||
// cai nay nghia la NGUOI (tay cam/web) vua ra lenh -> tu chay nhuong.
|
||||
UnixTime reloc_cmd_stamp_;
|
||||
|
||||
// teleop_mu_: TeleopModel co trang thai (toc do dieu chinh duoc luc chay).
|
||||
mutable std::mutex teleop_mu_;
|
||||
@@ -291,6 +330,57 @@ class Runtime {
|
||||
std::vector<VoxelIndex> prev_voxel_cells_;
|
||||
uint32_t voxel_epoch_ = 0;
|
||||
uint32_t voxel_seq_ = 0;
|
||||
|
||||
// ⚠️ Dinh vi lai tu dong: RIENG cua luong SlamLoop, KHONG duoi mutex nao --
|
||||
// tru `reloc_status_` (duoi slam_mu_, WebLoop doc).
|
||||
std::unique_ptr<LikelihoodField> reloc_field_; // null = khong bat --slam-reloc
|
||||
GlobalLocalizerConfig reloc_cfg_;
|
||||
std::unique_ptr<HypothesisTracker> reloc_tracker_;
|
||||
bool reloc_active_ = false; // dang gom/khop: CHUA dua gi cho RTAB-Map
|
||||
std::vector<Point> reloc_pts_; // diem da gom, frame odom
|
||||
double reloc_swept_ = 0.0; // rad da xoay trong vong gom nay
|
||||
Pose2D reloc_prev_odom_;
|
||||
bool reloc_have_prev_ = 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;
|
||||
double reloc_ref_score_ = -1.0; // diem luc chot -- moc cho canh "da lac"
|
||||
bool reloc_lost_pending_ = false;
|
||||
std::chrono::steady_clock::time_point reloc_lost_since_;
|
||||
std::chrono::steady_clock::time_point reloc_watch_next_;
|
||||
Transform slam_laser_to_base_ = TransformIdentity(); // doc-only sau Start()
|
||||
std::string reloc_status_; // duoi slam_mu_
|
||||
bool reloc_pending_ = false; // duoi slam_mu_: chua dinh vi xong
|
||||
// Duoi slam_mu_: ung vien SO 1 cua vong khop gan nhat (ke ca bi tu choi).
|
||||
// CHI de VE: khi chua chot, web ve robot MO tai `guess * odom` -- thay cho
|
||||
// odom tu 0 nam ngoai toa nha. KHONG dua cho RTAB-Map.
|
||||
Pose2D reloc_guess_T_;
|
||||
bool have_reloc_guess_ = false;
|
||||
|
||||
// Tu chay: XOAY (gom) -> khop -> chua chot thi QUAY ve cho thoang -> DI ->
|
||||
// XOAY... Tran cung 6 vong / 12 m roi DUNG HAN goi nguoi (nhu ban ROS).
|
||||
enum class RelocExec { kOff, kSweep, kTurn, kDrive, kHalted };
|
||||
RelocExec reloc_exec_ = RelocExec::kOff;
|
||||
double reloc_turn_target_ = 0.0; // huong odom can quay toi (rad)
|
||||
Pose2D reloc_drive_start_;
|
||||
double reloc_drive_len_ = 0.0; // quang duong du dinh cua pha DI
|
||||
double reloc_total_drive_ = 0.0; // cong don cho mot lan dinh vi
|
||||
int reloc_exec_cycles_ = 0;
|
||||
std::chrono::steady_clock::time_point reloc_phase_t0_;
|
||||
std::chrono::steady_clock::time_point reloc_yield_until_; // nguoi thang -> nhuong
|
||||
|
||||
// Pha "dung yen roi tinh chinh" (RelocSettle). Gom luc DANG QUAY lam dam
|
||||
// diem nhoe 1-2 do moi scan (odom doc tre hon luc quet) -- mo phong
|
||||
// 2026-09-29: chot lech 0.12 m va RTAB-Map khong sua vi robot dung ngay.
|
||||
bool reloc_settle_ = false;
|
||||
Pose2D reloc_settle_T_; // T_map_odom luc chot, chua tinh chinh
|
||||
double reloc_settle_ratio_ = 0.0;
|
||||
std::chrono::steady_clock::time_point reloc_settle_t0_;
|
||||
std::chrono::steady_clock::time_point reloc_still_since_;
|
||||
bool reloc_still_ = false;
|
||||
Pose2D reloc_settle_prev_odom_;
|
||||
std::vector<Point> reloc_settle_pts_;
|
||||
int reloc_settle_scans_ = 0;
|
||||
#endif
|
||||
|
||||
// Doc-only sau Start(), nen khong can mutex.
|
||||
|
||||
Reference in New Issue
Block a user