update
This commit is contained in:
@@ -144,6 +144,13 @@ struct WebSnapshot {
|
||||
TeleopSnapshot teleop;
|
||||
|
||||
LaserScanPtr scan;
|
||||
// Phep bien doi quy scan tu he laser LUC QUET ve pose HIEN TAI. Khac
|
||||
// `cloud_delta` o cho no KHONG duoc ap o server: scan la du lieu cuc
|
||||
// (range, goc) va mot phep doi SE(2) khong ap thang len do duoc. Gui len
|
||||
// trinh duyet, noi scan da thanh diem Descartes.
|
||||
Pose2D scan_delta;
|
||||
bool have_scan_delta = false;
|
||||
|
||||
PointCloudXYZPtr cloud;
|
||||
// Phep bien doi quy cloud tu he base_footprint LUC CHUP ve he
|
||||
// base_footprint HIEN TAI. Trinh duyet ve cloud bang pose moi nhat, nen
|
||||
|
||||
@@ -117,6 +117,20 @@ void WriteStateJson(const WebSnapshot& s, std::string* out) {
|
||||
Num("yaw", s.pose_map.theta, 4, out);
|
||||
out->push_back('}'); Comma(out);
|
||||
|
||||
// Bu do tre cua scan: quy tia tu pose HIEN TAI ve pose LUC QUET. Cloud
|
||||
// duoc bu san o server (EncodeCloud), scan thi khong -- no la du lieu cuc.
|
||||
//
|
||||
// Chi xuat khi CO. Khong co thi trinh duyet ve bang pose hien tai nhu truoc,
|
||||
// chu khong phai ve bang mot delta 0 gia mao la "da bu".
|
||||
if (s.have_scan_delta) {
|
||||
Key("scan_delta", out);
|
||||
out->push_back('{');
|
||||
Num("x", s.scan_delta.x, 4, out); Comma(out);
|
||||
Num("y", s.scan_delta.y, 4, out); Comma(out);
|
||||
Num("yaw", s.scan_delta.theta, 5, out);
|
||||
out->push_back('}'); Comma(out);
|
||||
}
|
||||
|
||||
// Ground truth chi xuat khi CO. Xuat 0 khi khong co la noi doi: client
|
||||
// khong phan biet duoc "dung o goc" voi "khong biet".
|
||||
if (s.have_ground_truth) {
|
||||
|
||||
@@ -73,8 +73,9 @@ const R_BLANKED = 0xFFFD; // bi sector mask cat (than robot che)
|
||||
|
||||
const state = {
|
||||
pose: null, gt: null, scan: null, cloud: null, path: null,
|
||||
// Pose tai thoi diem khung CLOUD toi. Xem cloudAnchorPose().
|
||||
cloudPose: null,
|
||||
// Pose ma tung lop du lieu THUOC VE, chot luc khung cua no toi. Xem
|
||||
// anchorPose(). `scanDelta` den tu khung state, dung ngay khung scan ke tiep.
|
||||
cloudPose: null, scanPose: null, scanDelta: null,
|
||||
map: null, mapImage: null, mapVersion: 0,
|
||||
bytes: 0, lastBytes: 0, wireRate: 0,
|
||||
};
|
||||
@@ -149,6 +150,10 @@ function onBinary(dv) {
|
||||
pts[m++] = r * Math.sin(a);
|
||||
}
|
||||
state.scan = pts.subarray(0, m);
|
||||
// Tia van o he laser LUC QUET -- server khong quy duoc, du lieu cuc.
|
||||
// `scan_delta` tu khung state cua cung lan Publish() cho biet pose luc
|
||||
// quet; neo scan vao do thay vi vao pose hien tai.
|
||||
state.scanPose = composePose(state.pose, state.scanDelta);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,6 +170,7 @@ function onBinary(dv) {
|
||||
state.cloud = pts;
|
||||
// Publish() gui khung STATE truoc khung CLOUD trong cung mot lan goi, nen
|
||||
// `state.pose` o day dung la pose ma server da dung de tinh `cloud_delta`.
|
||||
// Diem DA duoc quy ve pose do, nen neo thang vao no.
|
||||
state.cloudPose = state.pose;
|
||||
return;
|
||||
}
|
||||
@@ -256,6 +262,10 @@ function rasterize(map, pal) {
|
||||
|
||||
function onState(s) {
|
||||
state.pose = s.pose;
|
||||
// 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.
|
||||
state.scanDelta = s.scan_delta || null;
|
||||
state.mapVersion = s.slam.map_version;
|
||||
// Hinh hoc robot den TU SERVER (robot.yaml). File nay khong duoc chua mot
|
||||
// hang so kich thuoc nao -- xem ghi chu trong app3d.js.
|
||||
@@ -434,19 +444,31 @@ function drawRobot(ctx, x, y, yaw, color, alpha, pal) {
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// Pose de ve CLOUD, khong phai pose robot.
|
||||
// a ⊕ d -- dat `d` (he cua a) vao he the gioi.
|
||||
function composePose(a, d) {
|
||||
if (!a) return a;
|
||||
if (!d) return a;
|
||||
const c = Math.cos(a.yaw), s = Math.sin(a.yaw);
|
||||
return {
|
||||
x: a.x + c * d.x - s * d.y,
|
||||
y: a.y + s * d.x + c * d.y,
|
||||
yaw: a.yaw + d.yaw,
|
||||
};
|
||||
}
|
||||
|
||||
// Pose de ve MOT LOP DU LIEU, khong phai pose robot.
|
||||
//
|
||||
// Server da quy cloud ve he base_footprint tai thoi diem GUI (EncodeCloud +
|
||||
// cloud_delta). Nhung cloud chi toi 2 Hz con trang ve lai moi khung hinh: ve
|
||||
// bang pose moi nhat thi ngay sau khi nhan, sai so moc lai tu 0 len
|
||||
// `v * 0.5 s`. Phai neo dam may vao pose LUC KHUNG DO TOI.
|
||||
// Moi lop toi theo nhip rieng (cloud 2 Hz, scan 10 Hz) con trang ve lai moi
|
||||
// khung hinh. Ve bang pose moi nhat thi ngay sau khi nhan, sai so moc lai tu
|
||||
// 0 den `v * chu ky lop do`. Phai neo lop vao pose no THUOC VE.
|
||||
//
|
||||
// Tra ve pose TUONG DOI so voi `robotPose` dang ve, khong phai pose tuyet
|
||||
// doi: khung "the gioi" ve tai pose ground truth va no can cung phep bu nay.
|
||||
function cloudAnchorPose(robotPose) {
|
||||
if (!state.cloudPose || !state.pose || !robotPose) return robotPose;
|
||||
const dx = state.cloudPose.x - state.pose.x;
|
||||
const dy = state.cloudPose.y - state.pose.y;
|
||||
// `anchoredAt` la pose tuyet doi cua lop, chot luc khung cua no toi. Ham tra
|
||||
// ve pose TUONG DOI so voi `robotPose` dang ve chu khong phai pose tuyet doi:
|
||||
// khung "the gioi" ve tai pose ground truth va no can cung phep bu nay.
|
||||
function anchorPose(robotPose, anchoredAt) {
|
||||
if (!anchoredAt || !state.pose || !robotPose) return robotPose;
|
||||
const dx = anchoredAt.x - state.pose.x;
|
||||
const dy = anchoredAt.y - state.pose.y;
|
||||
const cn = Math.cos(state.pose.yaw), sn = Math.sin(state.pose.yaw);
|
||||
const lx = cn * dx + sn * dy;
|
||||
const ly = -sn * dx + cn * dy;
|
||||
@@ -454,7 +476,7 @@ function cloudAnchorPose(robotPose) {
|
||||
return {
|
||||
x: robotPose.x + c * lx - s * ly,
|
||||
y: robotPose.y + s * lx + c * ly,
|
||||
yaw: robotPose.yaw + (state.cloudPose.yaw - state.pose.yaw),
|
||||
yaw: robotPose.yaw + (anchoredAt.yaw - state.pose.yaw),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -515,10 +537,10 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// scan va cloud o frame robot -> xoay theo pose truoc khi ve.
|
||||
// scan va cloud o frame robot -> xoay theo pose truoc khi ve. Nhung KHONG
|
||||
// phai pose hien tai: moi lop neo vao pose no thuoc ve, xem anchorPose().
|
||||
const p = robotPose;
|
||||
if (p) {
|
||||
const c = Math.cos(p.yaw), s = Math.sin(p.yaw);
|
||||
|
||||
// Ground truth ve TRUOC pose uoc luong, de pose ve de len tren: cai ta
|
||||
// dang danh gia phai nhin ro hon cai lam chuan.
|
||||
@@ -527,8 +549,8 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
||||
}
|
||||
|
||||
if (state.cloud && on('lyCloud')) {
|
||||
// Cloud KHONG dung `p` -- xem cloudAnchorPose().
|
||||
const cp = cloudAnchorPose(p);
|
||||
// Cloud KHONG dung `p` -- xem anchorPose().
|
||||
const cp = anchorPose(p, state.cloudPose);
|
||||
const cc = Math.cos(cp.yaw), cs = Math.sin(cp.yaw);
|
||||
const pts = state.cloud;
|
||||
for (let i = 0; i < pts.length; i += 3) {
|
||||
@@ -551,10 +573,14 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
||||
// vao pose cua base. Xem ghi chu trong v3dSetScan().
|
||||
const lx = (state.robot && state.robot.laser_x) || 0;
|
||||
const ly = (state.robot && state.robot.laser_y) || 0;
|
||||
// Neo vao pose LUC QUET, khong phai `p` -- xem anchorPose(). Khi quay
|
||||
// 50 do/s thi 100 ms giu giua hai khung la 5 do, o 3 m la 26 cm.
|
||||
const sp = anchorPose(p, state.scanPose);
|
||||
const sc = Math.cos(sp.yaw), ss = Math.sin(sp.yaw);
|
||||
for (let i = 0; i < pts.length; i += 2) {
|
||||
const bx = pts[i] + lx, by = pts[i + 1] + ly;
|
||||
const x = p.x + c * bx - s * by;
|
||||
const y = p.y + s * bx + c * by;
|
||||
const x = sp.x + sc * bx - ss * by;
|
||||
const y = sp.y + ss * bx + sc * by;
|
||||
ctx.fillRect(sx(x, y) - 1.5, sy(x, y) - 1.5, 3, 3);
|
||||
}
|
||||
}
|
||||
@@ -1023,8 +1049,10 @@ function draw3d() {
|
||||
V3D.gtGroup.visible = false;
|
||||
}
|
||||
|
||||
v3dSetScan(on('lyScan') ? state.scan : null, state.pose, state.robot);
|
||||
v3dSetCloud(on('lyCloud') ? state.cloud : null, cloudAnchorPose(state.pose));
|
||||
v3dSetScan(on('lyScan') ? state.scan : null,
|
||||
anchorPose(state.pose, state.scanPose), state.robot);
|
||||
v3dSetCloud(on('lyCloud') ? state.cloud : null,
|
||||
anchorPose(state.pose, 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.
|
||||
|
||||
Reference in New Issue
Block a user