This commit is contained in:
trung09122002
2026-09-19 15:33:52 +07:00
parent 48bd5377dc
commit 3b281174d0
22 changed files with 1913 additions and 119 deletions

View File

@@ -30,6 +30,15 @@ Runtime::~Runtime() {
Join();
}
namespace {
// Tren muc nay thi canh bao rang odometry se kem chinh xac di. Lay tu PHEP DO
// chu khong tu mot nguong vat ly nao: accel 0.60 cho sai so 0.015 m, accel
// 0.86 cho 0.093 m -- dau goi nam giua hai gia tri do.
//
// Chi de CANH BAO, khong dieu khien gi.
constexpr double kFastAccelWarn = 0.7;
} // namespace
StatusResponse Runtime::OpenSource() {
switch (opts_.source) {
case SourceKind::kSim: {
@@ -50,7 +59,7 @@ StatusResponse Runtime::OpenSource() {
sc.camera_pitch = cfg_->robot.camera_pitch();
sc.max_linear = speed_limit_;
sc.max_angular = cfg_->robot.base().max_angular;
sc.accel_limit = cfg_->robot.base().accel_limit;
sc.accel_limit = accel_limit_;
sc.lidar_rate_hz = cfg_->sensors.lidar_hz;
sc.camera_rate_hz = cfg_->sensors.camera_hz;
sc.imu_rate_hz = cfg_->sensors.imu_hz;
@@ -87,6 +96,9 @@ StatusResponse Runtime::OpenSource() {
<< " m. LiDAR va depth se KHONG thay no -- chi sieu am va "
"bumper thay.");
}
// Ham lay ground truth, de `wiring.cc` chot no cung luc voi EKF.
gt_fn_ = [this]() { return source_->sim->ground_truth(); };
lidar_ = source_->sim->lidar();
camera_ = source_->sim->camera();
mcu_ = source_->sim->mcu();
@@ -161,8 +173,58 @@ StatusResponse Runtime::Start() {
// `RobotModel` khong cho sua truc tiep (co y: no la nguon su that tu
// robot.yaml). Gia tri cho sim va teleop lay tu bien duoi day.
speed_limit_ = v;
// ⚠️ Noi tran ma khong noi GIA TOC thi tran moi khong voi toi duoc.
//
// `accel_limit` 0.30 m/s^2 can 6.7 giay va ~6.7 m duong chay de len toi
// 2 m/s. Cho rong nhat trong toa nha benh vien chi 4.75 m, nen robot
// KHONG BAO GIO cham toi toc do da dat: do duoc 0.983 m/s khi dat 2.00.
// Nguoi van hanh keo thanh truot len het roi van thay cham, va khong co
// gi giai thich.
//
// Giu nguyen ti le giua gia toc va tran, dung nhu robot that.
const double base_v = cfg_->robot.base().max_linear;
accel_limit_ = base_v > 1e-9
? cfg_->robot.base().accel_limit * (v / base_v)
: cfg_->robot.base().accel_limit;
VSLAM_WARN("toc do: gia toc cung noi theo, " << cfg_->robot.base().accel_limit
<< " -> " << accel_limit_ << " m/s^2. Khong noi thi tran "
<< v << " m/s can " << (v / cfg_->robot.base().accel_limit)
<< " s va ~" << (v * v / (2 * cfg_->robot.base().accel_limit))
<< " m duong chay -- dai hon moi cho trong toa nha.");
// ⚠️ NOI GIA TOC LAM ODOMETRY KEM CHINH XAC HON.
//
// Do duoc tren the gioi benh vien, sai so uoc luong vs ground truth khi
// lai lien tuc (SLAM bat):
// --max-speed 0.35 (accel 0.30) -> 0.026 m
// --max-speed 0.7 (accel 0.60) -> 0.015 m
// --max-speed 1.0 (accel 0.86) -> 0.093 m
// --max-speed 2.0 (accel 1.71) -> 0.118 m
//
// ⚠️ KHONG phai do truot banh. Toi da doan vay va SAI: `slip_factor` va
// `slip_differential` mac dinh bang 0, va `vslam_node` KHONG BAO GIO dat
// chung -- mo hinh truot chi duoc bat trong `vslam_record` va
// `vslam_sim_run`. Trong duong chay cua node, banh khong he truot.
//
// Nguyen nhan la sai so ROI RAC cua wheel odometry: encoder lay mau o 50
// Hz, nen o 2 m/s moi buoc di 4 cm va do cong trong buoc do bi bo qua.
//
// ⚠️ Sai so nay CO GIOI HAN, khong tich luy: do qua 170 giay lai lien tuc
// o toc do toi da, no dao dong 0.026-0.057 m va dinh 0.100 m. Ke ca khi
// dam vao vat can, hay lai giat cuc kieu tay, hay dung DB that -- van duoi
// 0.10 m. Neu thay hinh ground truth tach ra XA HON the thi do la chuyen
// khac, va o `gap` tren web se noi ro la loi du lieu hay loi ve.
if (accel_limit_ > kFastAccelWarn) {
VSLAM_WARN("toc do: chay nhanh lam wheel odometry kem chinh xac hon -- "
"encoder lay mau 50 Hz nen do cong trong moi buoc bi bo qua. "
"Do duoc: sai so vs ground truth 0.015 m o --max-speed 0.7, "
"0.118 m o 2.0 (co gioi han, khong tich luy). Quet ban do thi "
"dung 0.7.");
}
} else {
speed_limit_ = cfg_->robot.base().max_linear;
accel_limit_ = cfg_->robot.base().accel_limit;
}
{
@@ -678,6 +740,11 @@ void Runtime::WebLoop() {
shape.wheel_radius = g.wheel_radius;
shape.wheel_separation = g.wheel_separation;
shape.body_half_width = g.body_half_width;
shape.body_length = g.body_length;
shape.body_width = g.body_width;
shape.body_height = g.body_height;
shape.body_offset_x = g.body_offset_x;
shape.ground_clearance = g.ground_clearance;
Transform t;
if (cfg_->robot.StaticTransform(kBaseLinkFrame, kLaserFrame, &t)) {
@@ -704,6 +771,8 @@ void Runtime::WebLoop() {
snap.robot = shape;
snap.stamp = clock_->Now();
Pose2D ekf_pose;
Pose2D gt_latched;
bool have_gt_latched = false;
{
std::lock_guard<std::mutex> lk(odom_mu_);
@@ -715,6 +784,8 @@ void Runtime::WebLoop() {
}
snap.pose_odom = wheel_odom_->pose();
ekf_pose = ekf_->pose();
gt_latched = gt_at_ekf_;
have_gt_latched = have_gt_at_ekf_;
}
{
@@ -763,7 +834,14 @@ void Runtime::WebLoop() {
// stage nao duoc doc no, do la ca dieu kien de no dung lam thuoc do.
if (source_->sim) {
snap.have_ground_truth = true;
snap.ground_truth = source_->sim->ground_truth();
// ⚠️ Dung ban CHOT cung luc voi EKF, khong doc tuoi.
//
// Doc tuoi roi dem voi `ekf_pose` (cu hon mot chu ky cam bien) bien do
// TRE thanh "sai so dinh vi": do duoc 0.118 m o 2 m/s va 0.0000 m khi
// dung yen -- ti le thang voi van toc, dung chu ky cua do tre chu khong
// phai cua sai so.
snap.ground_truth = have_gt_latched ? gt_latched
: source_->sim->ground_truth();
source_->sim->true_tilt(&snap.gt_roll, &snap.gt_pitch);
}
@@ -799,6 +877,31 @@ void Runtime::WebLoop() {
// Hau qua: lop `duong di` chi la MOT diem dung yen o goc the gioi, trong
// khi robot chay di cho khac. Khong mot loi nao: khung PATH van gui dung
// nhip, chi la no luon mang dung 1 diem (28 byte).
// ⚠️ Ghi dinh ky SAI SO vs ground truth vao log.
//
// Cau hoi "hinh xanh la lech that hay lech do ve" da mat nhieu luot trao
// doi, vi no chi tra loi duoc bang MOT con so ma con so do truoc day chi
// hien thoang qua tren man hinh. Gio no nam trong log, nen mot file
// `tee` la du de tra loi.
//
// `err` tinh o server tu `pose_map` va `ground_truth`. Neu no nho ma
// nguoi dung van thay hai hinh tach xa thi loi nam o tang HIEN THI, khong
// o uoc luong.
if (snap.have_ground_truth) {
const double err = Distance2D(snap.pose_map, snap.ground_truth);
if (err > gt_err_max_) gt_err_max_ = err;
const double now_s = snap.stamp.toSec();
if (gt_err_last_log_ == 0.0) gt_err_last_log_ = now_s;
if (now_s - gt_err_last_log_ >= 5.0) {
gt_err_last_log_ = now_s;
VSLAM_INFO("gt: sai so vs ground truth " << err << " m (lon nhat "
<< gt_err_max_ << " m). uoc=(" << snap.pose_map.x << ", "
<< snap.pose_map.y << ") that=(" << snap.ground_truth.x
<< ", " << snap.ground_truth.y << ")");
gt_err_max_ = 0.0;
}
}
{
std::lock_guard<std::mutex> lk(traj_mu_);
// Thua hoa: chi them diem khi da di du xa. Gui lai ca quy dao moi khung