map,lidar,web: ban do theo lan nhin MOI NHAT + scan dung gio. Luoi 2D: GridGlobal/* (3 lan nhin xuyen qua -> trong, truoc ~9; truoc 07/10 khong truyen vao bo ghep luoi); lop camera + 3D: xoa voxel ma >= 2 node sau nhin xuyen qua (VoxelCarver) -- nguoi dung roi di thi quay lai quet la mat. LiDAR: stamp_offset -55 ms + chinh meo theo chieu quet (do tren ban do that 28/09 + 01/10); web: robot troi muot

This commit is contained in:
trung09122002
2026-10-07 16:04:28 +07:00
parent 61c3a75fb1
commit 31f84eb082
20 changed files with 855 additions and 50 deletions

View File

@@ -12,7 +12,7 @@ const MAGIC = 0x314C5356; // 'VSL1' little-endian
// Phien ban ma nguon giao dien. TANG khi doi app.js / app3d.js / style.css.
// Hien ngay tren thanh tren cung de phan biet "chua sua" voi "trinh duyet con
// cache ban cu".
const UI_VERSION = '2026-10-06a';
const UI_VERSION = '2026-10-07a';
// ⚠️ HAI bang mau, mot cho moi khung. Chung KHONG duoc giong nhau.
//
@@ -393,6 +393,7 @@ function rasterize(map, pal) {
function onState(s) {
state.pose = s.pose;
noteStatePose(s);
// Khong co truong nay = server khong bu duoc do tre scan. Dat null chu
// khong dat {0,0,0}: mot delta 0 gia mao la "da bu", con null thi lop ve
// biet la chua co gi va dung pose hien tai nhu truoc.
@@ -615,6 +616,61 @@ function composePose(a, d) {
};
}
// --- Pose HIEN THI: robot troi muot giua cac khung state ---------------------
//
// Server gui pose 10 Hz (system.yaml status_rate_hz) con trang ve ~60 Hz. Dat
// thang pose moi nhat thi robot NHAY tung buoc 100 ms -- 5 cm / 4.6 do o
// 0.5 m/s, 0.8 rad/s -- va nhay them moi lan SLAM chinh map_correction. O day:
// du doan theo van toc odom toi da DISP_LEAD_MAX giay, roi TRUOT ve dich voi
// hang so DISP_TAU. Xa hon DISP_SNAP (vua chot dinh vi lai) thi dat thang.
//
// CHI la hien thi: so lieu (px/py/pyaw, gap voi ground truth) van doc
// `state.pose` THAT.
const DISP_TAU = 0.08; // s
const DISP_LEAD_MAX = 0.15; // s
const DISP_SNAP_M = 1.0, DISP_SNAP_RAD = 0.8;
const disp = { pose: null, t: 0, rx: 0, vx: 0, vyaw: 0 };
function wrapPi(a) { return Math.atan2(Math.sin(a), Math.cos(a)); }
// Giay, don dieu. `performance` co o moi trinh duyet, nhung KHONG co trong
// sandbox vm cua test/www -- lui ve Date.now().
function nowSec() {
return (typeof performance !== 'undefined' ? performance.now() : Date.now()) / 1000;
}
// Goi moi khung state: luc toi + van toc odom (he than robot).
function noteStatePose(s) {
disp.rx = nowSec();
const o = s.odom || {};
disp.vx = Math.max(-1.5, Math.min(1.5, Number(o.vx) || 0));
disp.vyaw = Math.max(-2.0, Math.min(2.0, Number(o.vyaw) || 0));
}
// Goi MOT lan moi khung ve (draw()).
function displayPose() {
const p = state.pose;
if (!p) return null;
const now = nowSec();
const lead = Math.min(Math.max(now - disp.rx, 0), DISP_LEAD_MAX);
const yaw = p.yaw + disp.vyaw * lead;
const mid = p.yaw + 0.5 * disp.vyaw * lead;
const tx = p.x + disp.vx * lead * Math.cos(mid);
const ty = p.y + disp.vx * lead * Math.sin(mid);
const d = disp.pose;
if (!d || Math.hypot(tx - d.x, ty - d.y) > DISP_SNAP_M ||
Math.abs(wrapPi(yaw - d.yaw)) > DISP_SNAP_RAD) {
disp.pose = { x: tx, y: ty, yaw: wrapPi(yaw) };
} else {
const a = 1 - Math.exp(-Math.max(now - disp.t, 0) / DISP_TAU);
d.x += a * (tx - d.x);
d.y += a * (ty - d.y);
d.yaw = wrapPi(d.yaw + a * wrapPi(yaw - d.yaw));
}
disp.t = now;
// z / nghieng / sigma: theo pose that, chi x-y-yaw duoc lam muot.
return { ...p, x: disp.pose.x, y: disp.pose.y, yaw: disp.pose.yaw };
}
// Pose de ve MOT LOP DU LIEU, khong phai pose robot.
//
// Moi lop toi theo nhip rieng (cloud 2 Hz, scan 10 Hz) con trang ve lai moi
@@ -751,7 +807,7 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
// Dang DINH VI LAI (--slam-reloc): robot TAM o goc map (odom tu 0) -> ve MO.
// Chot xong moi nhay ve cho that. Dong chu trang thai nam o #relocBanner.
const faded = state.relocPending && robotPose === state.pose;
const faded = state.relocPending && robotPose === state.dispPose;
drawRobot(ctx, robotPose.x, robotPose.y, robotPose.yaw, pal.robot, faded ? 0.35 : 1.0, pal);
}
}
@@ -792,6 +848,9 @@ function updateSlamLabel() {
}
function draw() {
// Pose HIEN THI cho MOI khung ve duoi day -- tinh MOT lan moi khung hinh, vi
// displayPose() truot theo thoi gian giua hai lan goi.
state.dispPose = displayPose();
// Goi o DAY chu khong trong draw3d(): o so sanh uoc luong voi ground truth
// phai chay ca khi dang xem khung 2D.
updateGapChip();
@@ -807,7 +866,7 @@ function draw() {
// Khung phai VAN phai chay khi dang chia doi.
if (split) {
updateSlamLabel();
drawScene(cvR, ctxR, state.map, state.mapImage, state.pose, true, 'lyMap',
drawScene(cvR, ctxR, state.map, state.mapImage, state.dispPose, true, 'lyMap',
PALETTE.slam);
} else if (split3d) {
// Khong co canvas thu hai o che do nay: draw3d() da ve ca hai nua. Chi
@@ -821,10 +880,10 @@ function draw() {
updateSlamLabel();
// TRAI = THE GIOI: ban do that + pose THAT. Day la khung de LAI.
drawScene(cv, ctx, state.worldMap, state.worldMapImage,
state.gt || state.pose, false, 'lyWorld', PALETTE.world);
state.gt || state.dispPose, false, 'lyWorld', PALETTE.world);
// PHAI = SLAM: ban do dang dung + pose UOC LUONG. Khung de xem quet toi
// dau, va lech bao nhieu so voi khung trai.
drawScene(cvR, ctxR, state.map, state.mapImage, state.pose, true, 'lyMap',
drawScene(cvR, ctxR, state.map, state.mapImage, state.dispPose, true, 'lyMap',
PALETTE.slam);
} else {
// Mot khung: uu tien ban do SLAM neu co, khong thi ban do the gioi.
@@ -832,7 +891,7 @@ function draw() {
drawScene(cv, ctx,
haveSlam ? state.map : state.worldMap,
haveSlam ? state.mapImage : state.worldMapImage,
state.pose, true, haveSlam ? 'lyMap' : 'lyWorld',
state.dispPose, true, haveSlam ? 'lyMap' : 'lyWorld',
haveSlam ? PALETTE.slam : PALETTE.world);
}
requestAnimationFrame(draw);
@@ -1257,7 +1316,12 @@ function updateGapChip() {
// Sai so du lieu va khoang cach ve la HAI so. Bang nhau nghia la hinh ve
// trung thuc va cai nhin thay la sai so that. Khac nhau nghia la con loi o
// tang hien thi -- da xay ra hai lan (thieu lop boc, va quen laser_x).
const drift = dDraw !== null && Math.abs(dDraw - dData) > 0.01;
//
// So voi pose DA DUA DI VE (displayPose() lam muot co chu dich, lech pose
// that vai cm khi dang chay) -- van bat duoc loi lop boc / laser_x.
const drawn = state.drawnPose || state.pose;
const dRef = state.gt ? Math.hypot(drawn.x - state.gt.x, drawn.y - state.gt.y) : dData;
const drift = dDraw !== null && Math.abs(dDraw - dRef) > 0.01;
el.textContent = 'gap ' + dData.toFixed(3) + ' m' +
(drift ? ' / ve ' + dDraw.toFixed(3) : '');
el.title = drift
@@ -1275,7 +1339,10 @@ for (const b of document.querySelectorAll('.vbtn')) {
function draw3d() {
if (state.robot) v3dSetShape(state.robot);
if (state.pose) v3dSetPose(V3D.robotGroup, state.pose);
if (state.dispPose) {
v3dSetPose(V3D.robotGroup, state.dispPose);
state.drawnPose = state.dispPose; // updateGapChip() so voi pose NAY
}
// Chua dinh vi xong: robot TAM o goc map -> ve MO. Nho do mo goc cua tung
// vat lieu (vai overlay von trong suot) de tra lai dung khi da chot. Chay moi
// khung vi v3dSetShape() co the tao vat lieu moi.
@@ -1307,9 +1374,9 @@ function draw3d() {
}
v3dSetScan(on('lyScan') ? state.scan : null,
anchorPose(state.pose, state.scanPose), state.robot);
anchorPose(state.dispPose, state.scanPose), state.robot);
v3dSetCloud(on('lyCloud') ? state.cloud : null,
anchorPose(state.pose, state.cloudPose));
anchorPose(state.dispPose, state.cloudPose));
// THE GIOI: tuong 3D dung tu ban do mo phong -- day la phan "Gazebo".
// Dung MOT lan (ban do the gioi la tinh), roi chi bat/tat.