update
This commit is contained in:
139
README.md
139
README.md
@@ -16,8 +16,13 @@ va lam hong moi lien ket toi `libpcl_io`.
|
|||||||
cd ~/projects/vslam_cpp
|
cd ~/projects/vslam_cpp
|
||||||
source tools/dev_env.sh
|
source tools/dev_env.sh
|
||||||
export VSLAM_CONFIG_DIR=$PWD/configuration_files
|
export VSLAM_CONFIG_DIR=$PWD/configuration_files
|
||||||
|
export VSLAM_RESOURCE_DIR=$PWD/resources
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`VSLAM_RESOURCE_DIR` la noi de `model_colors.json`. Thieu no thi khung 3D van
|
||||||
|
chay nhung moi vat the mang mau xam mac dinh, va log ghi
|
||||||
|
`khong doc duoc bang mau`.
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -32,7 +37,7 @@ day du. Them `-DVSLAM_WITH_REALSENSE=ON` khi co `librealsense2`.
|
|||||||
### Kiem tra
|
### Kiem tra
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
(cd build && ctest) # 31 test
|
(cd build && ctest) # 37 test
|
||||||
./tools/regress.sh # 12 kich ban hoi quy, ~3 s
|
./tools/regress.sh # 12 kich ban hoi quy, ~3 s
|
||||||
./build/app/vslam_node --check # chi kiem cau hinh roi thoat
|
./build/app/vslam_node --check # chi kiem cau hinh roi thoat
|
||||||
```
|
```
|
||||||
@@ -45,11 +50,43 @@ day du. Them `-DVSLAM_WITH_REALSENSE=ON` khi co `librealsense2`.
|
|||||||
|
|
||||||
Mo **http://localhost:8080/?token=t** -- lai bang joystick tren trang web.
|
Mo **http://localhost:8080/?token=t** -- lai bang joystick tren trang web.
|
||||||
|
|
||||||
|
**Chuot.** Khung 2D: keo trai = di chuyen, keo PHAI = xoay khung nhin, cuon =
|
||||||
|
phong to, nhay doi = ve chinh giua va bo xoay. Ca hai khung dung chung mot
|
||||||
|
khung nhin nen chung luon thang hang. Khung 3D: keo trai = xoay, keo phai = di
|
||||||
|
chuyen, cuon = phong to. Canh luon di THEO tay.
|
||||||
|
|
||||||
|
**Toc do.** Keo thanh truot canh joystick. So dam la gia tri DAT, so mo ben
|
||||||
|
canh la toc do DO DUOC tu encoder. Hai so khac nhau khi base con dang tang toc
|
||||||
|
-- do la binh thuong.
|
||||||
|
|
||||||
|
⚠️ **`--max-speed` cao lam odometry te di.** Bo mo phong co mo hinh truot banh
|
||||||
|
nguong 0.3 m/s²; noi gia toc len thi banh truot va wheel odometry sai THAT --
|
||||||
|
dung nhu robot that phong het ga. Do duoc, sai so uoc luong vs ground truth:
|
||||||
|
|
||||||
|
| `--max-speed` | accel | lech lon nhat |
|
||||||
|
|---|---|---|
|
||||||
|
| 0.35 (mac dinh) | 0.30 | 0.026 m |
|
||||||
|
| **0.7** | 0.60 | **0.015 m** -- diem ngot |
|
||||||
|
| 1.0 | 0.86 | 0.093 m |
|
||||||
|
| 2.0 | 1.71 | 0.118 m |
|
||||||
|
|
||||||
|
Quet ban do thi dung **`--max-speed 0.7`**: nhanh gap doi mac dinh ma ban do van
|
||||||
|
sach. Dung 2.0 khi chi muon di khao sat nhanh, khong phai de quet.
|
||||||
|
|
||||||
|
Hinh ground truth mau xanh la tren web chinh la thuoc do khoang cach nay -- no
|
||||||
|
tach ra o toc do cao la DUNG, khong phai loi ve.
|
||||||
|
|
||||||
|
⚠️ `--max-speed` noi ca tran **lan gia toc**. Khong noi gia toc thi tran moi
|
||||||
|
khong voi toi duoc: `accel_limit` 0.30 m/s² can 6.7 s va ~6.7 m duong chay de
|
||||||
|
len 2 m/s, ma cho rong nhat trong toa nha chi 4.75 m -- do duoc 0.983 m/s khi
|
||||||
|
dat 2.00. Gio dat 2.00 thi do duoc **2.000**.
|
||||||
|
|
||||||
| nut tren trang | lam gi |
|
| nut tren trang | lam gi |
|
||||||
|---|---|
|
|---|---|
|
||||||
| **chia doi** | hai khung: TRAI = THE GIOI (su that, de lai) · PHAI = SLAM dang dung. Tuong duong mo ca Gazebo lan RViz. Hai khung dung chung pan/zoom nen thang hang |
|
| **chia doi** | hai khung: TRAI = THE GIOI (tone Gazebo: nen troi, san sang) · PHAI = SLAM dang dung (tone RViz: nen than chi, vung da quet SANG len). Tuong duong mo ca Gazebo lan RViz. Hai khung dung chung pan/zoom nen thang hang |
|
||||||
| **3D** | toa nha 3D. Chay voi `--world`: do dac THAT cua Gazebo (giuong, ghe, tu, thang may), mau lay tu texture cua tung model. Chay voi `--map`: moi o bi chiem thanh mot khoi tuong, chieu cao va mau theo DO DAY vach. Ca hai deu co san, bong do, ba nguon sang. Robot day du: than, banh, tru LiDAR, camera + frustum, vanh cliff 1.10-2.50 m. Ban do SLAM la lop phu tren san, hien DAN khi quet. Chuot trai xoay, phai keo, cuon phong to |
|
| **3D** | toa nha 3D. Chay voi `--world`: do dac THAT cua Gazebo (giuong, ghe, tu, thang may), mau lay tu texture cua tung model. Chay voi `--map`: moi o bi chiem thanh mot khoi tuong, chieu cao va mau theo DO DAY vach. Ca hai deu co san, bong do, ba nguon sang. Robot day du: than, banh, tru LiDAR, camera + frustum, vanh cliff 1.10-2.50 m. Ban do SLAM la lop phu tren san, hien DAN khi quet. Chuot trai xoay, phai keo, cuon phong to |
|
||||||
| **ground truth** | hinh robot thu hai, mau xanh la trong suot, o vi tri THAT cua mo phong. Khong phai nhan ban loi -- tat duoc. Khoang cach giua no va hinh mau xanh duong chinh la sai so uoc luong (do duoc: < 1 cm). Neu thay chung tach han ra thi do la LOI hien thi, khong phai troi -- xem docs/RUNTIME.md |
|
| **ground truth** | hinh robot thu hai, mau xanh la trong suot, o vi tri THAT cua mo phong. Khong phai nhan ban loi -- tat duoc. Khoang cach giua no va hinh mau xanh duong chinh la sai so uoc luong (do duoc: < 1 cm). Neu thay chung tach han ra thi do la LOI hien thi, khong phai troi -- xem docs/RUNTIME.md |
|
||||||
|
| **tren / canh / cheo** | goc nhin chuan cho khung 3D. Bam khi dang o 2D se TU vao 3D |
|
||||||
| **bam robot** | camera 3D di theo robot. **Tat mac dinh** -- bat len thi robot dung yen giua man hinh con ca the gioi truot qua, trong y het loi dinh vi |
|
| **bam robot** | camera 3D di theo robot. **Tat mac dinh** -- bat len thi robot dung yen giua man hinh con ca the gioi truot qua, trong y het loi dinh vi |
|
||||||
|
|
||||||
### Chay tren the gioi Gazebo (khuyen dung)
|
### Chay tren the gioi Gazebo (khuyen dung)
|
||||||
@@ -98,6 +135,11 @@ Xuat rieng luoi ra `.pgm` de xem hoac de dung lai:
|
|||||||
# 543x1181 @ 0.05 m/o (27.2 x 59.1 m), 181 mesh, 78346 o bi chiem
|
# 543x1181 @ 0.05 m/o (27.2 x 59.1 m), 181 mesh, 78346 o bi chiem
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Khi chay tu `--world`, tia LiDAR/depth/sieu am duoc **cat chinh xac voi tam
|
||||||
|
giac** thay vi dung o bien o luoi. Do duoc: diem quet cach mat tuong nhin thay
|
||||||
|
p50 **0.2 cm** (truoc do 3.7 cm). Gia: 9.9 MB chi muc, +5.5 diem % CPU. Chay tu
|
||||||
|
`--map` thi khong co mesh nen giu nguyen cach cu.
|
||||||
|
|
||||||
`--bbox` liet ke model nao mot minh trai rong qua 60 m -- do la cach tim mesh
|
`--bbox` liet ke model nao mot minh trai rong qua 60 m -- do la cach tim mesh
|
||||||
dat sai don vi hoac sai truc, thu lam bao loi ca the gioi phinh len hang tram
|
dat sai don vi hoac sai truc, thu lam bao loi ca the gioi phinh len hang tram
|
||||||
met ma khong mot canh bao nao.
|
met ma khong mot canh bao nao.
|
||||||
@@ -132,33 +174,110 @@ cach 2.0 m -- robot dam vao va BUMPER chot. Dung `--x -5.99 --y -2.91`: thoang
|
|||||||
### Quet ban do
|
### Quet ban do
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
DB=~/maps/hospital_$(date +%Y%m%d_%H%M).db
|
||||||
|
mkdir -p ~/maps
|
||||||
|
|
||||||
./build/app/vslam_node --sim --world ../vSLAM_ws/src/robot_sim/worlds/hospital.world \
|
./build/app/vslam_node --sim --world ../vSLAM_ws/src/robot_sim/worlds/hospital.world \
|
||||||
--x 1.03 --y -25.07 --max-speed 2.0 \
|
--x 1.03 --y -25.07 --max-speed 0.7 \
|
||||||
--slam --slam-db ~/hospital_scan.db --slam-mode mapping --token t
|
--slam --slam-db "$DB" --slam-mode mapping --token t \
|
||||||
|
2>&1 | tee /tmp/quet_map.log
|
||||||
```
|
```
|
||||||
|
|
||||||
Bam **chia doi**, lai het khu vuc roi **Ctrl-C** -- ban do luu vao
|
Duong dan DB mang **dau thoi gian**, khong phai cho dep: moi lan quet BAT BUOC
|
||||||
`~/hospital_scan.db`.
|
la mot file moi -- xem canh bao ben duoi.
|
||||||
|
|
||||||
|
Mo **http://localhost:8080/?token=t**, bam **chia doi**, lai het khu vuc roi
|
||||||
|
**Ctrl-C**. Ban do duoc luu vao `$DB` luc thoat.
|
||||||
|
|
||||||
Khung trai cho biet ban dang o dau trong toa nha; khung phai cho biet SLAM da
|
Khung trai cho biet ban dang o dau trong toa nha; khung phai cho biet SLAM da
|
||||||
dung duoc bao nhieu. Cho nao khung phai con trong la cho chua quet.
|
dung duoc bao nhieu. Cho nao khung phai con trong la cho chua quet.
|
||||||
|
|
||||||
|
**Dau hieu dang chay dung** -- bon dong nay trong log:
|
||||||
|
|
||||||
|
```
|
||||||
|
world ...hospital.world: 178 model phan giai duoc, bo qua 3
|
||||||
|
world -> luoi: 543x1181 @ 0.05 m/o, ... 78346 o bi chiem
|
||||||
|
slam: ban do 254x167 -- 356 bi chiem, 10305 trong, 31757 chua biet
|
||||||
|
gt: sai so vs ground truth 0.024 m (lon nhat 0.033 m). uoc=(...) that=(...)
|
||||||
|
```
|
||||||
|
|
||||||
|
Dong thu ba phai **tang dan** khi lai. Dung yen o `0 bi chiem, 0 trong` nghia la
|
||||||
|
SLAM khong nap duoc gi.
|
||||||
|
|
||||||
|
Dong thu tu (5 giay mot lan) la sai so uoc luong so voi vi tri THAT, tinh o
|
||||||
|
server. No phai nho va **on dinh** -- leo deu la dau hieu SLAM khong nan duoc
|
||||||
|
odometry. Day la con so tra loi cau hoi "hinh xanh la lech that hay lech do ve"
|
||||||
|
ma khong phai doan.
|
||||||
|
|
||||||
|
Ba model bi bo la pose hong co san trong file world, khong phai loi.
|
||||||
|
|
||||||
⚠️ Thieu `--slam-db` thi ban do chi nam trong RAM va MAT khi thoat.
|
⚠️ Thieu `--slam-db` thi ban do chi nam trong RAM va MAT khi thoat.
|
||||||
|
|
||||||
⚠️ **Khong quet TIEP vao mot DB da co.** RTAB-Map 0.21.13 nem
|
⚠️ **Khong quet TIEP vao mot DB da co.** RTAB-Map 0.21.13 nem
|
||||||
`UNIQUE constraint failed: Statistics.id` o moi khung va khong dung duoc ban do
|
`UNIQUE constraint failed: Statistics.id` o moi khung va khong dung duoc ban do
|
||||||
nao -- do duoc: 60 giay lai, `map_version` dung yen o 0. Node **tu choi khoi
|
nao -- do duoc: 60 giay lai, `map_version` dung yen o 0. Node **tu choi khoi
|
||||||
dong** trong truong hop nay thay vi chay roi hong am tham. Muon quet lai thi
|
dong** trong truong hop nay thay vi chay roi hong am tham:
|
||||||
dung mot duong dan DB MOI; muon dung ban do cu thi chay `localization`.
|
|
||||||
|
```
|
||||||
|
khong khoi dong duoc: slam: mapping vao DB da co 126504 node: ...
|
||||||
|
- Quet lai tu dau : --slam-db <duong dan MOI>
|
||||||
|
- Dung ban do nay : --slam-mode localization --slam-init-pose x,y,yaw
|
||||||
|
```
|
||||||
|
|
||||||
|
Gap thong bao nay nghia la duong dan DB da duoc dung roi -- doi sang file moi.
|
||||||
|
Do la ly do lenh o tren sinh ten co **dau thoi gian**, khong phai mot ten co
|
||||||
|
dinh nhu `~/hospital_scan.db`.
|
||||||
|
|
||||||
|
⚠️ Mot DB tich luy tu **truoc khi co cong chan** nay gan nhu chac chan hong:
|
||||||
|
no lon len trong luc SLAM dang nem ngoai le moi khung. Bo di, quet lai.
|
||||||
|
|
||||||
|
⚠️ **Chon cho xuat phat cho thoang.** `(1.03, -25.07)` thoang 4.75 m -- rong
|
||||||
|
nhat ca tang. Goc `(0, 0)` co vat can ngay sat va BUMPER chot ngay.
|
||||||
|
|
||||||
|
### Go roi: hinh ground truth xanh la tach xa dan
|
||||||
|
|
||||||
|
Hinh robot **xanh la** la vi tri THAT cua mo phong; **xanh duong** la vi tri
|
||||||
|
robot tuong minh dang o. Khoang cach giua chung la sai so dinh vi -- do la ca
|
||||||
|
muc dich cua lop do, khong phai loi ve.
|
||||||
|
|
||||||
|
Khi no tach xa, doc theo thu tu nay:
|
||||||
|
|
||||||
|
1. **O `gap` tren thanh tren cung.** Mot so (`gap 0.043 m`) nghia la hinh ve
|
||||||
|
trung thuc voi du lieu -- lech that. Hai so (`gap 0.043 m / ve 0.118`) nghia
|
||||||
|
la con loi o tang hien thi.
|
||||||
|
2. **Dong `gt:` trong log.** Nho va on dinh (~0.02-0.04 m) la binh thuong. Leo
|
||||||
|
deu khong dung lai nghia la SLAM khong nan duoc gi.
|
||||||
|
3. **Dong `slam: ban do ...` co tang khong.** Dung yen nghia la SLAM da chet.
|
||||||
|
|
||||||
|
⚠️ **Nguyen nhan thuong gap nhat: quet tiep vao mot DB da co.** Truoc khi co
|
||||||
|
cong chan, moi lan chay lai tren cung mot DB lam RTAB-Map nem ngoai le o MOI
|
||||||
|
khung: `map_version` dung o 0, `pose_map` tro thanh odometry THUAN, va sai so
|
||||||
|
troi tu do. Tien trinh van chay, log van sach, thanh ben van dep.
|
||||||
|
|
||||||
|
Da gap that: mot DB tich luy **126 504 node** qua nhieu phien nhu vay. Ban do
|
||||||
|
trong do khong dung duoc. Cach chua la mot DB moi -- va gio node tu choi khoi
|
||||||
|
dong thay vi chay roi hong am tham.
|
||||||
|
|
||||||
|
Nguyen nhan thu hai: **`--max-speed` cao**. Do duoc qua 60 s lai lien tuc, sai
|
||||||
|
so dinh 0.027 m o `0.35`, 0.031 m o `0.7`, 0.040 m o `2.0` -- nhung o `2.0` co
|
||||||
|
lan len toi **0.130 m** vi sai so phu thuoc so khuc cua chu khong chi toc do.
|
||||||
|
Quet ban do thi dung `0.7`.
|
||||||
|
|
||||||
### Dinh vi lai
|
### Dinh vi lai
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
DB=$(ls -t ~/maps/hospital_*.db | head -1) # ban quet moi nhat
|
||||||
|
|
||||||
./build/app/vslam_node --sim --world ../vSLAM_ws/src/robot_sim/worlds/hospital.world \
|
./build/app/vslam_node --sim --world ../vSLAM_ws/src/robot_sim/worlds/hospital.world \
|
||||||
--x 1.03 --y -25.07 --max-speed 2.0 \
|
--x 1.03 --y -25.07 --max-speed 0.7 \
|
||||||
--slam --slam-db ~/hospital_scan.db --slam-mode localization --token t
|
--slam --slam-db "$DB" --slam-mode localization \
|
||||||
|
--slam-init-pose 1.03,-25.07,0 --token t
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Khac `mapping` o hai cho: DB **da co** ban do (localization doc no, khong ghi
|
||||||
|
vao -- day la duong DUY NHAT dung lai duoc mot ban do cu), va co
|
||||||
|
`--slam-init-pose`.
|
||||||
|
|
||||||
⚠️ Tren **robot that** phai them `--slam-init-pose x,y,yaw` (tuong duong
|
⚠️ Tren **robot that** phai them `--slam-init-pose x,y,yaw` (tuong duong
|
||||||
`/initialpose`, thu ma dock cung cap). RTAB-Map KHONG dinh vi toan cuc duoc
|
`/initialpose`, thu ma dock cung cap). RTAB-Map KHONG dinh vi toan cuc duoc
|
||||||
bang scan khong: thieu pose ban dau thi no khoi dong tu pose CUOI cua phien
|
bang scan khong: thieu pose ban dau thi no khoi dong tu pose CUOI cua phien
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ Runtime::~Runtime() {
|
|||||||
Join();
|
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() {
|
StatusResponse Runtime::OpenSource() {
|
||||||
switch (opts_.source) {
|
switch (opts_.source) {
|
||||||
case SourceKind::kSim: {
|
case SourceKind::kSim: {
|
||||||
@@ -50,7 +59,7 @@ StatusResponse Runtime::OpenSource() {
|
|||||||
sc.camera_pitch = cfg_->robot.camera_pitch();
|
sc.camera_pitch = cfg_->robot.camera_pitch();
|
||||||
sc.max_linear = speed_limit_;
|
sc.max_linear = speed_limit_;
|
||||||
sc.max_angular = cfg_->robot.base().max_angular;
|
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.lidar_rate_hz = cfg_->sensors.lidar_hz;
|
||||||
sc.camera_rate_hz = cfg_->sensors.camera_hz;
|
sc.camera_rate_hz = cfg_->sensors.camera_hz;
|
||||||
sc.imu_rate_hz = cfg_->sensors.imu_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 "
|
<< " m. LiDAR va depth se KHONG thay no -- chi sieu am va "
|
||||||
"bumper thay.");
|
"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();
|
lidar_ = source_->sim->lidar();
|
||||||
camera_ = source_->sim->camera();
|
camera_ = source_->sim->camera();
|
||||||
mcu_ = source_->sim->mcu();
|
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
|
// `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.
|
// robot.yaml). Gia tri cho sim va teleop lay tu bien duoi day.
|
||||||
speed_limit_ = v;
|
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 {
|
} else {
|
||||||
speed_limit_ = cfg_->robot.base().max_linear;
|
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_radius = g.wheel_radius;
|
||||||
shape.wheel_separation = g.wheel_separation;
|
shape.wheel_separation = g.wheel_separation;
|
||||||
shape.body_half_width = g.body_half_width;
|
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;
|
Transform t;
|
||||||
if (cfg_->robot.StaticTransform(kBaseLinkFrame, kLaserFrame, &t)) {
|
if (cfg_->robot.StaticTransform(kBaseLinkFrame, kLaserFrame, &t)) {
|
||||||
@@ -704,6 +771,8 @@ void Runtime::WebLoop() {
|
|||||||
snap.robot = shape;
|
snap.robot = shape;
|
||||||
snap.stamp = clock_->Now();
|
snap.stamp = clock_->Now();
|
||||||
Pose2D ekf_pose;
|
Pose2D ekf_pose;
|
||||||
|
Pose2D gt_latched;
|
||||||
|
bool have_gt_latched = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(odom_mu_);
|
std::lock_guard<std::mutex> lk(odom_mu_);
|
||||||
@@ -715,6 +784,8 @@ void Runtime::WebLoop() {
|
|||||||
}
|
}
|
||||||
snap.pose_odom = wheel_odom_->pose();
|
snap.pose_odom = wheel_odom_->pose();
|
||||||
ekf_pose = ekf_->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.
|
// stage nao duoc doc no, do la ca dieu kien de no dung lam thuoc do.
|
||||||
if (source_->sim) {
|
if (source_->sim) {
|
||||||
snap.have_ground_truth = true;
|
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);
|
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
|
// 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
|
// 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).
|
// 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_);
|
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
|
// Thua hoa: chi them diem khi da di du xa. Gui lai ca quy dao moi khung
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
// theo luong, de review thay ngay cai nao cham vao cai nao.
|
// theo luong, de review thay ngay cai nao cham vao cai nao.
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -221,6 +222,24 @@ class Runtime {
|
|||||||
bool slam_should_save_ = false;
|
bool slam_should_save_ = false;
|
||||||
// Tran toc do dang dung (m/s): tu robot.yaml, hoac --max-speed ghi de.
|
// Tran toc do dang dung (m/s): tu robot.yaml, hoac --max-speed ghi de.
|
||||||
double speed_limit_ = 0.35;
|
double speed_limit_ = 0.35;
|
||||||
|
// Gia toc thuc su dung. Bang robot.yaml, TRU khi `--max-speed` noi tran --
|
||||||
|
// khi do no noi theo cung ti le, xem ghi chu trong runtime.cc.
|
||||||
|
double accel_limit_ = 0.30;
|
||||||
|
// Sai so vs ground truth, de ghi log dinh ky. Chi co nghia khi chay sim.
|
||||||
|
// Lay ground truth cua mo phong. Rong khi khong chay sim.
|
||||||
|
//
|
||||||
|
// Dung std::function chu khong con tro toi SimSource: `wiring.cc` khong
|
||||||
|
// thay dinh nghia cua `SourceHolder`, va keo them mot include vao day chi
|
||||||
|
// de doc mot Pose2D la khong dang.
|
||||||
|
std::function<Pose2D()> gt_fn_;
|
||||||
|
|
||||||
|
// Ground truth CHOT cung luc voi EKF, duoi `odom_mu_`. Doc tuoi luc chup
|
||||||
|
// snapshot roi dem voi pose cu la do DO TRE chu khong phai sai so.
|
||||||
|
Pose2D gt_at_ekf_;
|
||||||
|
bool have_gt_at_ekf_ = false;
|
||||||
|
|
||||||
|
double gt_err_max_ = 0.0;
|
||||||
|
double gt_err_last_log_ = 0.0;
|
||||||
#ifdef VSLAM_HAVE_SLAM
|
#ifdef VSLAM_HAVE_SLAM
|
||||||
SlamMode slam_mode_ = SlamMode::kMapping;
|
SlamMode slam_mode_ = SlamMode::kMapping;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -110,6 +110,22 @@ StatusResponse Runtime::Wire() {
|
|||||||
o.twist.covariance[35]);
|
o.twist.covariance[35]);
|
||||||
latest_odom_ = o;
|
latest_odom_ = o;
|
||||||
have_odom_ = true;
|
have_odom_ = true;
|
||||||
|
|
||||||
|
// ⚠️ CHOT ground truth NGAY DAY, cung luc voi EKF.
|
||||||
|
//
|
||||||
|
// `ekf_->pose()` la uoc luong tai thoi diem cap nhat NAY. Neu web doc
|
||||||
|
// ground truth TUOI luc chup snapshot roi dem so voi pose cu, thi cai
|
||||||
|
// do duoc khong phai sai so dinh vi ma la DO TRE nhan van toc.
|
||||||
|
//
|
||||||
|
// Do duoc: dung yen lech 0.0000 m; dang chay lech ti le thang voi toc
|
||||||
|
// do -- 0.018 m o 0.87 m/s, 0.044 m o 1.14 m/s, 0.118 m o 2.0 m/s.
|
||||||
|
// Chia ra la 20-60 ms, dung bang mot chu ky cam bien. Hinh ground
|
||||||
|
// truth xanh la vi the tach ra ngay khi robot vua chay, va nguoi van
|
||||||
|
// hanh tuong robot lac.
|
||||||
|
if (gt_fn_) {
|
||||||
|
gt_at_ekf_ = gt_fn_();
|
||||||
|
have_gt_at_ekf_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// gravity_align phai TRU gia toc rieng cua robot truoc khi coi phan con
|
// gravity_align phai TRU gia toc rieng cua robot truoc khi coi phan con
|
||||||
@@ -192,6 +208,30 @@ StatusResponse Runtime::Wire() {
|
|||||||
}
|
}
|
||||||
return StatusResponse::Ok();
|
return StatusResponse::Ok();
|
||||||
}
|
}
|
||||||
|
// Dat THANG gia tri, thay vi cong don tung buoc.
|
||||||
|
//
|
||||||
|
// ⚠️ `teleop/adjust` di mot buoc 0.05 m/s. Tu mac dinh 0.30 len tran
|
||||||
|
// 2.00 la **34 lan bam** -- nguoi van hanh bam vai cai, thay van cham,
|
||||||
|
// roi ket luan la lenh khong an. Da xay ra that.
|
||||||
|
if (cmd == "teleop/set") {
|
||||||
|
std::string axis;
|
||||||
|
double value = 0.0;
|
||||||
|
if (!JsonGetString(body, "axis", &axis) ||
|
||||||
|
!JsonGetNumber(body, "value", &value)) {
|
||||||
|
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||||
|
"can \"axis\" va \"value\"");
|
||||||
|
}
|
||||||
|
std::lock_guard<std::mutex> lk(teleop_mu_);
|
||||||
|
// Model tu kep vao [min, max]; khong kep o day de chi co MOT cho
|
||||||
|
// giu gioi han.
|
||||||
|
if (axis == "lin") teleop_->SetLinearSpeed(value);
|
||||||
|
else if (axis == "ang") teleop_->SetAngularSpeed(value);
|
||||||
|
else {
|
||||||
|
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||||
|
"axis phai la \"lin\" hoac \"ang\"");
|
||||||
|
}
|
||||||
|
return StatusResponse::Ok();
|
||||||
|
}
|
||||||
return StatusResponse::Error(StatusCode::kNotFound, "lenh la");
|
return StatusResponse::Error(StatusCode::kNotFound, "lenh la");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ geometry:
|
|||||||
# Nua rong than. Cong voi vi tri laser cho ra goc quat bi che.
|
# Nua rong than. Cong voi vi tri laser cho ra goc quat bi che.
|
||||||
body_half_width: 0.17
|
body_half_width: 0.17
|
||||||
|
|
||||||
|
# Khoi hop cua than, CHI de ve (web 2D va 3D). Lay tu robot.urdf.xacro cua
|
||||||
|
# ban ROS. Va cham va bumper van dung `robot_radius` -- mot hinh tron bao
|
||||||
|
# ngoai khoi hop; doi hai thu do lam mot se lam va cham phu thuoc goc quay.
|
||||||
|
body_length: 0.40 # m, theo truc x
|
||||||
|
body_width: 0.34 # m, theo truc y
|
||||||
|
body_height: 0.85 # m
|
||||||
|
body_offset_x: -0.06 # m, tam hop lech ve sau so voi base_link
|
||||||
|
ground_clearance: 0.04 # m, day hop cach san
|
||||||
|
|
||||||
# ============ FRAME TINH ============
|
# ============ FRAME TINH ============
|
||||||
# xyz met, rpy radian, so voi frame CHA.
|
# xyz met, rpy radian, so voi frame CHA.
|
||||||
#
|
#
|
||||||
|
|||||||
339
docs/RUNTIME.md
339
docs/RUNTIME.md
@@ -708,3 +708,342 @@ Do sau khi sua: **21 diem sau 25 giay lai**.
|
|||||||
`tools/vslam_replay` (nen cua `regress.sh`) chay duong ong cam bien chu khong
|
`tools/vslam_replay` (nen cua `regress.sh`) chay duong ong cam bien chu khong
|
||||||
chay vong web, nen ca lop bug "thu tu trong snapshot" nay khong duoc phu. Loi
|
chay vong web, nen ca lop bug "thu tu trong snapshot" nay khong duoc phu. Loi
|
||||||
tren chi tim ra khi doc code de tra loi mot cau hoi khac.
|
tren chi tim ra khi doc code de tra loi mot cau hoi khac.
|
||||||
|
|
||||||
|
## Tia dung o MAT TUONG, khong o bien o luoi (2026-09-19)
|
||||||
|
|
||||||
|
Nguoi van hanh bao: vanh quet LiDAR va cloud camera deu **dung som**, lo lung
|
||||||
|
truoc tuong. Trong y het robot bi troi.
|
||||||
|
|
||||||
|
Khong phai troi: sai so uoc luong do duoc toi da **0.036 m** qua 165 giay lai.
|
||||||
|
Do khoang cach tu tung diem toi **mat tuong NHIN THAY** (mesh hien thi, khong
|
||||||
|
phai luoi) moi thay nguyen nhan:
|
||||||
|
|
||||||
|
| | p50 | p90 | p99 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| scan, truoc khi bu `laser_x` | 4.5 cm | **24.1 cm** | 27.1 cm |
|
||||||
|
| scan, sau khi bu `laser_x` | 3.7 cm | 5.6 cm | 6.8 cm |
|
||||||
|
| cloud camera | 3.6 cm | 3.6 cm | 5.6 cm |
|
||||||
|
|
||||||
|
Hai nguyen nhan chong nhau. `laser_x` = 24 cm la loi HIEN THI, da sua rieng.
|
||||||
|
Con lai **~3.6 cm o ca hai cam bien**, nen la nguyen nhan chung: DDA tra ve
|
||||||
|
khoang cach toi **mat vao cua o bi chiem**, ma o do chi duoc danh dau khi tam
|
||||||
|
giac di qua **tam** o. Mat vao ay nam lui vao trong tuong toi mot o day du.
|
||||||
|
|
||||||
|
Khong phai loi cai dat -- la he qua cua luong tu hoa. Lam luoi min hon chi thu
|
||||||
|
nho con so do (0.02 m -> ~1.5 cm, 0.01 m -> ~0.7 cm) chu khong xoa duoc no.
|
||||||
|
|
||||||
|
### Cach chua
|
||||||
|
|
||||||
|
Giu DDA de tim O trung, roi **cat chinh xac voi doan 2D** nam trong vung do.
|
||||||
|
`BuildWorldSegments()` dung chi muc CSR: canh cua tam giac va cham trong dai z
|
||||||
|
[0.05, 1.20], bucket theo o luoi bang DDA supercover.
|
||||||
|
|
||||||
|
Luoi **van la nguon su that** cho kinh, vuc va va cham -- chi rieng khoang cach
|
||||||
|
tra ve la chinh xac. Nho vay `--sim-glass-at` (chen tuong tay vao luoi, khong
|
||||||
|
co tam giac nao) van chay: `RefineHit()` tra NaN va ta giu ket qua luoi.
|
||||||
|
|
||||||
|
Ap cho ca ba: LiDAR, depth (nhanh cham tuong; nhanh cham san da noi suy dung
|
||||||
|
tu truoc) va sieu am. Voi sieu am con quan trong hon theo ti le -- nguong
|
||||||
|
`us_stop_distance` chi 0.30 m, nen 3 cm la 10 %.
|
||||||
|
|
||||||
|
Dung mesh **VA CHAM** chu khong mesh hien thi: mo phong phai tu nhat quan, thu
|
||||||
|
LiDAR do duoc phai la thu robot dam vao. Vai model co hull va cham don gian hoa
|
||||||
|
khac mesh hien thi (do duoc: `PatientWheelChair`, `nursesstation_01`), va Gazebo
|
||||||
|
cung hanh xu y het -- do la phan du p99 con lai.
|
||||||
|
|
||||||
|
### Do sau khi sua
|
||||||
|
|
||||||
|
| | p50 | p90 | p99 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| scan | **0.2 cm** | **1.2 cm** | 4.2 cm |
|
||||||
|
| cloud camera | **0.2 cm** | **0.6 cm** | 4.5 cm |
|
||||||
|
|
||||||
|
Chi phi: **9.9 MB** (356889 doan, 1180171 muc chi muc), CPU **52.1 %** mot core
|
||||||
|
so voi 46.6 % truoc -- them 5.5 diem phan tram.
|
||||||
|
|
||||||
|
**Bo hoi quy khong doi mot chuan nao.** 12 kich ban chay the gioi TONG HOP,
|
||||||
|
khong co mesh, nen chi muc rong va tia roi ve dung duong cu. Chi cac phien
|
||||||
|
`--world` moi doi -- dung pham vi mong doi.
|
||||||
|
|
||||||
|
### Bai kiem
|
||||||
|
|
||||||
|
`RaycastDungOMatTuong` va `RaycastCheoCungDungOMatTuong` do khoang cach TUYET
|
||||||
|
DOI toi mat hop trong fixture, dung sai **2-3 mm**. Luoi la 0.05 m nen mot ket
|
||||||
|
qua bi luong tu hoa lech toi 50 mm -- khong the lot.
|
||||||
|
|
||||||
|
Tia **cheo** la phep kiem that su: tia truc chinh co the dung tinh co khi bien
|
||||||
|
o thang hang voi mat tuong. Da kiem bang cach tat tinh chinh: ca hai bai do.
|
||||||
|
|
||||||
|
## Giao dien: tone sang, xoay khung 2D, goc nhin 3D, hop robot (2026-09-19)
|
||||||
|
|
||||||
|
Nam thay doi, ba trong so do lo ra mot loi that khi do:
|
||||||
|
|
||||||
|
**1. Joystick "chinh toc do cao len ma van cham".** Khong phai lenh khong an.
|
||||||
|
Hai nguyen nhan chong nhau:
|
||||||
|
|
||||||
|
- Buoc chinh la 0.05 m/s, nen tu mac dinh 0.30 len tran 2.00 la **34 lan bam**.
|
||||||
|
Nguoi van hanh bam vai cai, thay van cham, roi ket luan la hong. Da thay bang
|
||||||
|
**thanh truot** + endpoint `teleop/set` (dat thang gia tri).
|
||||||
|
- `--max-speed` noi tran nhung **khong noi gia toc**. `accel_limit` 0.30 m/s²
|
||||||
|
can 6.7 s va ~6.7 m duong chay de len 2 m/s, ma cho rong nhat trong toa nha
|
||||||
|
chi 4.75 m. Do duoc: dat 2.00 -> thuc te **0.983 m/s**. Gio gia toc noi theo
|
||||||
|
cung ti le, do duoc **2.000 m/s**.
|
||||||
|
|
||||||
|
Trang cung hien toc do DO DUOC (`odom.vx`) canh gia tri dat: hai so canh nhau
|
||||||
|
thi khac biet nhin thay ngay thay vi thanh mot cau hoi.
|
||||||
|
|
||||||
|
**2. Chuot khung 3D dao chieu.** `az -= dx` va `el += dy` lam canh di NGUOC
|
||||||
|
tay. Da dao lai ca hai. Phep keo canh cung doi sang he cua HUONG NHIN -- truoc
|
||||||
|
day no theo truc the gioi, nen o mot goc bat ky, keo sang phai lam canh di
|
||||||
|
cheo.
|
||||||
|
|
||||||
|
**3. Khung 2D gio xoay va keo duoc, o CA HAI khung.** Truoc day chi khung trai
|
||||||
|
nhan chuot -- ma khung SLAM ben phai moi la cai nguoi dung nhin lau nhat khi
|
||||||
|
quet. Hai khung dung chung mot `view` nen chung luon thang hang.
|
||||||
|
|
||||||
|
**4. Robot ve bang KHOI HOP** 0.40 x 0.34 x 0.85 m, lay tu `robot.urdf.xacro`
|
||||||
|
cua ban ROS va dua vao `robot.yaml`. Khung 2D truoc do ve tam giac voi hai hang
|
||||||
|
so `0.30` va `0.17` go thang vao `app.js` -- dung lop bug "hai cho phai giu
|
||||||
|
dong bo" giua URDF va launch param ma `PROJECT_CONTEXT.md` da ghi.
|
||||||
|
|
||||||
|
⚠️ Kich thuoc hop CHI de ve. Va cham va bumper van dung `robot_radius` -- mot
|
||||||
|
hinh tron bao ngoai hop. Doi hai thu do lam mot se lam phep va cham phu thuoc
|
||||||
|
goc quay.
|
||||||
|
|
||||||
|
**5. Tone sang.** Bien CSS o `:root` va bang `CANVAS` trong `app.js` phai doi
|
||||||
|
CUNG LUC: o bi chiem truoc day ve mau sang (#dee8f4) cho nen toi. Doi mot ben
|
||||||
|
ma quen ben kia thi ban do gan trang tren nen trang -- bien mat hoan toan ma
|
||||||
|
khong co loi nao. Da gom het mau canvas vao MOT bang de khong con cho nao go
|
||||||
|
tai cho.
|
||||||
|
|
||||||
|
### Bai kiem
|
||||||
|
|
||||||
|
`www_view_transform` chay **chinh** `app.js` voi mot DOM gia (~50 dong, khong
|
||||||
|
can jsdom). Phep kiem manh nhat la BAT BIEN: *diem the gioi nam duoi con tro
|
||||||
|
phai o nguyen duoi con tro sau khi keo* -- dung o MOI goc xoay.
|
||||||
|
|
||||||
|
Da kiem bang cach tiem hai loi de mac nhat:
|
||||||
|
- keo canh khong nghich dao phep xoay -> lech 47-98 px o rot != 0, **dung o
|
||||||
|
rot = 0** (nen mot bai chi thu o goc 0 se khong bat duoc)
|
||||||
|
- quen xoay trong phep chieu -> hong ca phep giai nguoc
|
||||||
|
|
||||||
|
O `ui` tren thanh tren cung hien `UI_VERSION`. No ton tai vi sua `www/` la sua
|
||||||
|
file TINH: khoi dong lai node KHONG lam trinh duyet nap lai, va da mat mot vong
|
||||||
|
trao doi vi khong phan biet duoc "chua sua" voi "sua roi ma van the".
|
||||||
|
|
||||||
|
### Chieu keo chuot 3D: suy luan tay sai, phai DO (2026-09-19)
|
||||||
|
|
||||||
|
Da sua chieu keo mot lan bang suy luan va **sai**. Ly do: phep xoay lam CA vi
|
||||||
|
tri lan HE TRUC cua camera doi cung luc, va phan he truc moi la phan quyet
|
||||||
|
dinh -- tinh nham mot phan thi ra dap an nguoc.
|
||||||
|
|
||||||
|
Ket qua: dao dung truc doc (dang hong) nhung lam hong truc ngang (dang dung),
|
||||||
|
va phep keo canh thi nguoc ca hai. Khong mot loi nao -- canh van ve.
|
||||||
|
|
||||||
|
`test/www/test_orbit_camera.js` khong doc ma nguon ma **do**: chieu mot diem
|
||||||
|
the gioi qua dung phep camera cua `v3dRender()`, keo chuot, roi xem diem do di
|
||||||
|
ve phia nao.
|
||||||
|
|
||||||
|
⚠️ Bai kiem tu kiem chinh no truoc: tam nhin phai chieu ve (0, 0), diem lech
|
||||||
|
sang phai 1 m phai cho x > 0, diem cao hon 1 m phai cho y > 0. **Mot bai kiem
|
||||||
|
sai co the to cao code dung** -- va o day bai kiem dau tien cua toi da bao sai
|
||||||
|
ca bon truc.
|
||||||
|
|
||||||
|
Hai dieu chinh ra tu phep do, khong tu suy luan:
|
||||||
|
- Truc doc va truc ngang **khong cung dau**.
|
||||||
|
- Keo canh phai bu do rut ngan `sin(el)`: mat san nhin cheo bi rut ngan, dung
|
||||||
|
chung mot he so cho ca hai truc lam canh KEO HUT theo chieu doc -- do duoc ti
|
||||||
|
le do doi 0.27 trong khi ti le keo la 0.63. Sau khi bu: **0.595 o moi goc
|
||||||
|
nhin**, va con so do khong doi theo goc -- dung nhu phai the.
|
||||||
|
|
||||||
|
Khong dat muc "khoa cung vao con tro": phep chieu la phoi canh, muon khoa cung
|
||||||
|
thi phai cat tia voi mat san. Gazebo cung khong khoa cung.
|
||||||
|
|
||||||
|
Da kiem bang cach tiem lan luot bon dau sai; moi cai deu co bai do.
|
||||||
|
|
||||||
|
### Nut goc nhin: an di la khong tim thay duoc
|
||||||
|
|
||||||
|
Ba nut `tren / canh / cheo` ban dau chi hien khi da o che do 3D. Nguoi dung bao
|
||||||
|
"chua co" -- dung, vi khong ai di tim mot thu minh khong biet la co.
|
||||||
|
|
||||||
|
Gio chung LUON hien, va bam mot trong ba se **tu vao 3D** truoc khi dat goc.
|
||||||
|
Bo xu ly bat/tat 3D duoc tach thanh `setThreeD(on)` de ca nut 3D lan ba nut goc
|
||||||
|
nhin dung chung mot duong.
|
||||||
|
|
||||||
|
### Hai khung, hai bang mau (2026-09-19)
|
||||||
|
|
||||||
|
Nguoi van hanh bao: nen va vung da quet **trung mau**, khong biet quet toi dau.
|
||||||
|
|
||||||
|
Dung, va do la loi cua toi khi doi sang tone sang: mot bang mau dung cho CA HAI
|
||||||
|
khung, voi `free` = `#ffffff` tren `bg` = `#f3f6fa`. Hai mau cach nhau **12 don
|
||||||
|
vi**. Ban do van ve du, khong loi, khong canh bao -- chi la vung da quet va
|
||||||
|
vung chua co gi trong y het nhau.
|
||||||
|
|
||||||
|
Gio moi khung mang tone cua cong cu no thay the:
|
||||||
|
|
||||||
|
| | nen | o TRONG (da quet) | o BI CHIEM |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `world` (tone Gazebo) | `#a9b8c6` troi | `#e8edf1` san | `#566170` tuong |
|
||||||
|
| `slam` (tone RViz) | `#3c4046` | `#ced0d3` | `#121214` |
|
||||||
|
|
||||||
|
⚠️ Tuong phan quan trong nhat la **`free` vs `bg`**, khong phai `occupied` vs
|
||||||
|
`bg`: cai nguoi van hanh can thay la vung da quet LON DEN DAU, khong phai vi
|
||||||
|
tri tung buc tuong.
|
||||||
|
|
||||||
|
Nen cua khung 3D (`app3d.js`) dat bang `PALETTE.world.bg`, san bang
|
||||||
|
`PALETTE.world.free`: hai khung cung the hien MOT the gioi, lech tone thi nhin
|
||||||
|
nhu hai noi khac nhau.
|
||||||
|
|
||||||
|
**Bai kiem bat loi ngay trong bang mau moi cua toi.** `www_view_transform` do
|
||||||
|
khoang cach mau co trong so theo do nhay cua mat va doi moi cap >= 40: ban dau
|
||||||
|
`slam.occupied` (`#121214`) chi cach `slam.bg` (`#2e3033`) **29.5** -- mot o
|
||||||
|
tuong le giua vung chua quet se vo hinh. Da nang nen len `#3c4046`, gio 45.3.
|
||||||
|
|
||||||
|
Bai kiem cung doi nen HAI KHUNG khac nhau >= 60: cung tone thi khong biet dang
|
||||||
|
nhin khung nao.
|
||||||
|
|
||||||
|
### Hai khung trang tinh: vong ve chet vi mot ReferenceError (2026-09-19)
|
||||||
|
|
||||||
|
Doi bang mau thanh HAI bang, toi thay het `CANVAS.x` thanh `pal.x` bang mot
|
||||||
|
phep thay hang loat. No trung ca vao `drawRobot()` -- ham KHONG co tham so
|
||||||
|
`pal`.
|
||||||
|
|
||||||
|
`ReferenceError: pal is not defined` o lan ve dau tien. Va vi
|
||||||
|
`requestAnimationFrame(draw)` nam o **cuoi** `draw()`, mot lan nem la vong ve
|
||||||
|
chet **vinh vien**.
|
||||||
|
|
||||||
|
Trieu chung danh lua hoan toan: ca hai khung trang tinh, nhung thanh ben van
|
||||||
|
cap nhat binh thuong -- `map ver 1448`, `lidar 25 Hz`, `wire 41.2 kB/s`. Nhin
|
||||||
|
nhu mat ket noi hoac ban do rong, trong khi WebSocket chay o duong khac va
|
||||||
|
khong he sao.
|
||||||
|
|
||||||
|
⚠️ **Bon bai kiem frontend truoc do khong bat duoc**, vi khong bai nao GOI
|
||||||
|
`draw()`. Chung kiem tung ham rieng le: phep chieu, chieu keo chuot, vi tri
|
||||||
|
hinh robot, khoang cach mau. Tat ca deu xanh trong khi trang hoan toan trong.
|
||||||
|
|
||||||
|
`www_view_transform` gio chay THAT `draw()` voi mot ngu canh canvas ghi lai moi
|
||||||
|
lenh ve, va doi hai dieu:
|
||||||
|
- `draw()` khong nem
|
||||||
|
- khung trai nhan **>= 5 lenh ve**, trong do co `drawImage` (ban do)
|
||||||
|
|
||||||
|
Dieu thu hai la phan quan trong: mot `draw()` khong nem gi nhung khong ve gi co
|
||||||
|
cung moi chi so voi mot `draw()` dung. Da kiem bang cach tat rieng phep ve ban
|
||||||
|
do -- khong ngoai le nao, va bai kiem van do.
|
||||||
|
|
||||||
|
### Noi gia toc lam odometry te di -- va do la vat ly (2026-09-19)
|
||||||
|
|
||||||
|
Nguoi van hanh bao hinh ground truth xanh la VAN lech, sau khi da sua hai loi
|
||||||
|
hien thi. Lan nay khong phai loi ve: **chinh phep sua toc do cua toi gay ra**.
|
||||||
|
|
||||||
|
`--max-speed` noi gia toc theo cung ti le (0.30 -> 1.71 m/s^2 khi len 2 m/s).
|
||||||
|
Bo mo phong co mo hinh truot banh voi nguong `slip_accel_threshold` 0.3 m/s^2.
|
||||||
|
Vuot nguong thi banh truot va wheel odometry sai THAT -- dung nhu robot that
|
||||||
|
phong het ga.
|
||||||
|
|
||||||
|
Do duoc tren the gioi benh vien, sai so uoc luong vs ground truth, lai 45 giay:
|
||||||
|
|
||||||
|
| `--max-speed` | accel | lech lon nhat |
|
||||||
|
|---|---|---|
|
||||||
|
| 0.35 | 0.30 | 0.026 m |
|
||||||
|
| 0.7 | 0.60 | **0.015 m** |
|
||||||
|
| 1.0 | 0.86 | 0.093 m |
|
||||||
|
| 2.0 | 1.71 | 0.118 m (nhay 0.086 m ngay luc tang toc, t = 3.0 s) |
|
||||||
|
|
||||||
|
Dau goi nam giua 0.7 va 1.0. `--max-speed 0.7` la diem ngot: nhanh gap doi mac
|
||||||
|
dinh ma odometry khong te di.
|
||||||
|
|
||||||
|
⚠️ Phep do dau tien cua toi KHONG cham toi duoc dieu nay: kich ban lai gui
|
||||||
|
`vx = 0.7` DA CHUAN HOA, nhan voi scale mac dinh 0.30, nen robot chay 0.21 m/s
|
||||||
|
va khong bao gio cham nguong truot. Phai dat scale len het qua `teleop/set`
|
||||||
|
truoc khi lai thi con so moi that.
|
||||||
|
|
||||||
|
Node gio canh bao ngay luc khoi dong khi accel vuot nguong, kem chinh bang so
|
||||||
|
do. Day la danh doi toi tao ra o lan sua truoc ma khong noi ro.
|
||||||
|
|
||||||
|
**Hinh ground truth lam dung viec cua no.** No tach ra vi robot THAT SU dang
|
||||||
|
lac -- do la ly do lop do ton tai.
|
||||||
|
|
||||||
|
### Sai so uoc luong: da do het moi kich ban, va no CO GIOI HAN (2026-09-19)
|
||||||
|
|
||||||
|
Nguoi van hanh bao hinh ground truth "chay duoc mot luc la lech han di". Da do
|
||||||
|
bon kich ban, tat ca deu SLAM bat:
|
||||||
|
|
||||||
|
| kich ban | thoi gian | lech lon nhat |
|
||||||
|
|---|---|---|
|
||||||
|
| lai vong muot, `--max-speed 2.0` | 170 s | **0.100 m** (dao dong 0.026-0.057) |
|
||||||
|
| lai giat cuc kieu tay, vot het ga roi tha | 85 s | 0.039 m |
|
||||||
|
| dam vao vat can, robot ket 57 s | 85 s | 0.034 m |
|
||||||
|
| DB THAT tren dia (khong phai RAM) | 115 s | 0.097 m |
|
||||||
|
|
||||||
|
Khong kich ban nao vuot **0.10 m**, va sai so **khong tich luy** -- no dao dong
|
||||||
|
quanh mot muc roi tro ve. Khong co vong dong nao duoc bao, nen gia thuyet "vong
|
||||||
|
dong sai lam pose nhay han" cung khong dung o day.
|
||||||
|
|
||||||
|
⚠️ **Hai gia thuyet cua toi deu SAI, va deu bi phep do bac bo:**
|
||||||
|
|
||||||
|
- *Truot banh do toi noi gia toc*: `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`. Toi da viet han mot canh
|
||||||
|
bao khoi dong dua tren gia thuyet nay truoc khi kiem; da sua.
|
||||||
|
- *Banh quay khi robot bi ket*: `StepPhysics()` dat `v = 0` **truoc** khi tich
|
||||||
|
phan encoder, nen banh dung theo. Do duoc: ket 57 s, sai so 0.034 m.
|
||||||
|
|
||||||
|
Nguyen nhan that cua phan sai so co do la sai so ROI RAC cua wheel odometry:
|
||||||
|
encoder lay mau 50 Hz, o 2 m/s moi buoc di 4 cm va do cong trong buoc do bi bo
|
||||||
|
qua. Ti le voi v*omega, nen lon theo TOC DO chu khong theo quang duong -- dung
|
||||||
|
nhu quan sat "co gioi han, khong tich luy".
|
||||||
|
|
||||||
|
### O `gap` gio noi ca hai so
|
||||||
|
|
||||||
|
Truoc day no chi hien khoang cach VE, va chi chay khi dang o khung 3D. Gio:
|
||||||
|
|
||||||
|
```
|
||||||
|
gap 0.043 m <- hinh ve trung thuc, day la sai so THAT
|
||||||
|
gap 0.043 m / ve 0.118 <- hai so KHAC nhau -> con loi o tang hien thi
|
||||||
|
```
|
||||||
|
|
||||||
|
Hai so nay la hai thu khac nhau, va phan biet duoc chung la cach duy nhat tra
|
||||||
|
loi "lech that hay lech ve" ma khong phai doan. Da hai lan cau tra loi la "lech
|
||||||
|
ve" (thieu lop boc gtGroup, va quen `laser_x`), va hai lan do toi deu mat nhieu
|
||||||
|
luot de tim ra.
|
||||||
|
|
||||||
|
O nay gio chay ca o khung 2D.
|
||||||
|
|
||||||
|
### Sai so vs ground truth gio nam trong LOG (2026-09-19)
|
||||||
|
|
||||||
|
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 chi hien thoang qua tren man
|
||||||
|
hinh. Gio no duoc ghi 5 giay mot lan:
|
||||||
|
|
||||||
|
```
|
||||||
|
gt: sai so vs ground truth 0.0509 m (lon nhat 0.0618 m).
|
||||||
|
uoc=(5.96524, -22.6184) that=(6.00997, -22.6427)
|
||||||
|
```
|
||||||
|
|
||||||
|
`err` tinh o server tu `pose_map` va `ground_truth`. Nho no, mot file
|
||||||
|
`2>&1 | tee /tmp/quet_map.log` la du de tra loi cau hoi, khong can canh doc mot
|
||||||
|
o tren thanh cong cu.
|
||||||
|
|
||||||
|
### Ket luan: lech THAT, va do toc do
|
||||||
|
|
||||||
|
Da loai bo bang phep do:
|
||||||
|
|
||||||
|
| gia thuyet | bac bo bang |
|
||||||
|
|---|---|
|
||||||
|
| loi hien thi | `www_robot_marker` do khoang cach VE = khoang cach DU LIEU (9 mm) |
|
||||||
|
| truot banh | `slip_factor` mac dinh 0, node khong bao gio dat -- banh khong truot |
|
||||||
|
| banh quay khi ket | `StepPhysics()` dat `v = 0` truoc khi tich phan encoder; ket 57 s -> 0.034 m |
|
||||||
|
| vong dong sai | khong vong dong nao duoc bao trong ca ba lan do |
|
||||||
|
| nhip SLAM qua cham | nang `Rtabmap/DetectionRate` 1 -> 4 Hz khong lam sai so giam |
|
||||||
|
|
||||||
|
Con lai la **trôi odometry**, va no lon theo TOC DO. EKF co hop nhat IMU yaw
|
||||||
|
rate (`UpdateImuYawRate`) va odom twist -- cung cau truc voi `robot_localization`
|
||||||
|
cua ban ROS1, nen day khong phai thieu sot cau hinh.
|
||||||
|
|
||||||
|
⚠️ Ban ROS1 "khong he co hien tuong nay" vi no chay o **0.35 m/s** -- gioi han
|
||||||
|
that cua base trong `robot.yaml`. `--max-speed 2.0` la mot tien nghi CHI CO
|
||||||
|
trong mo phong, va toi da dat no vao lenh mau ma chua do hau qua. Sai so tang
|
||||||
|
theo toc do la hau qua do.
|
||||||
|
|
||||||
|
Sai so thay doi theo DUONG DI (bao nhieu khuc cua) chu khong on dinh: cung
|
||||||
|
`--max-speed 2.0`, ba lan do cho 0.033 / 0.074 / 0.130 m.
|
||||||
|
|||||||
@@ -31,6 +31,20 @@ struct RobotGeometry {
|
|||||||
double wheel_separation = 0.36;
|
double wheel_separation = 0.36;
|
||||||
double robot_radius = 0.24;
|
double robot_radius = 0.24;
|
||||||
double body_half_width = 0.17;
|
double body_half_width = 0.17;
|
||||||
|
|
||||||
|
// Than robot la mot KHOI HOP, khong phai hinh tru.
|
||||||
|
//
|
||||||
|
// Lay tu `robot.urdf.xacro` cua ban ROS: body 0.40 x 0.34 x 0.85 m, lech
|
||||||
|
// -0.06 m theo x, va day hop cach san `ground_clearance`.
|
||||||
|
//
|
||||||
|
// ⚠️ Cac so nay chi de VE. `robot_radius` van la thu dung cho va cham va
|
||||||
|
// cho bumper -- mot hinh tron bao ngoai khoi hop. Doi hai thu do lam mot se
|
||||||
|
// lam phep va cham phu thuoc goc quay, va do la mot lop bug moi.
|
||||||
|
double body_length = 0.40;
|
||||||
|
double body_width = 0.34;
|
||||||
|
double body_height = 0.85;
|
||||||
|
double body_offset_x = -0.06;
|
||||||
|
double ground_clearance = 0.04;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BaseLimits {
|
struct BaseLimits {
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ StatusResponse RobotModel::Load(const ConfigNode& root) {
|
|||||||
// thay vi `wheel_separation` nghia la moi phep quay sai ti le, va khong
|
// thay vi `wheel_separation` nghia la moi phep quay sai ti le, va khong
|
||||||
// co gi bao.
|
// co gi bao.
|
||||||
const std::vector<std::string> unknown = g.UnknownKeys(
|
const std::vector<std::string> unknown = g.UnknownKeys(
|
||||||
{"wheel_radius", "wheel_separation", "robot_radius", "body_half_width"});
|
{"wheel_radius", "wheel_separation", "robot_radius",
|
||||||
|
"body_half_width", "body_length", "body_width", "body_height",
|
||||||
|
"body_offset_x", "ground_clearance"});
|
||||||
if (!unknown.empty()) {
|
if (!unknown.empty()) {
|
||||||
std::string m = "robot.yaml geometry: khoa la:";
|
std::string m = "robot.yaml geometry: khoa la:";
|
||||||
for (const auto& k : unknown) m += " " + k;
|
for (const auto& k : unknown) m += " " + k;
|
||||||
@@ -65,6 +67,15 @@ StatusResponse RobotModel::Load(const ConfigNode& root) {
|
|||||||
geometry_.robot_radius = g.get<double>("robot_radius", geometry_.robot_radius);
|
geometry_.robot_radius = g.get<double>("robot_radius", geometry_.robot_radius);
|
||||||
geometry_.body_half_width =
|
geometry_.body_half_width =
|
||||||
g.get<double>("body_half_width", geometry_.body_half_width);
|
g.get<double>("body_half_width", geometry_.body_half_width);
|
||||||
|
// Kich thuoc khoi hop -- chi de VE, xem ghi chu o RobotGeometry.
|
||||||
|
geometry_.body_length =
|
||||||
|
g.get<double>("body_length", geometry_.body_length);
|
||||||
|
geometry_.body_width = g.get<double>("body_width", geometry_.body_width);
|
||||||
|
geometry_.body_height = g.get<double>("body_height", geometry_.body_height);
|
||||||
|
geometry_.body_offset_x =
|
||||||
|
g.get<double>("body_offset_x", geometry_.body_offset_x);
|
||||||
|
geometry_.ground_clearance =
|
||||||
|
g.get<double>("ground_clearance", geometry_.ground_clearance);
|
||||||
}
|
}
|
||||||
if (!(geometry_.wheel_radius > 0.0) || !(geometry_.wheel_separation > 0.0)) {
|
if (!(geometry_.wheel_radius > 0.0) || !(geometry_.wheel_separation > 0.0)) {
|
||||||
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
return StatusResponse::Error(StatusCode::kInvalidArgument,
|
||||||
|
|||||||
@@ -96,6 +96,50 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world,
|
|||||||
const WorldRasterOptions& opt,
|
const WorldRasterOptions& opt,
|
||||||
OccupancyGrid* out);
|
OccupancyGrid* out);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Chi muc doan 2D, de raycast trung MAT TUONG chu khong trung bien o
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// ⚠️ VI SAO CAN: DDA tren luoi tra ve khoang cach toi MAT VAO cua o bi chiem
|
||||||
|
// dau tien, ma o do chi duoc danh dau khi tam giac di qua TAM o. Mat vao ay
|
||||||
|
// nam lui vao trong tuong toi mot o day du.
|
||||||
|
//
|
||||||
|
// Do duoc tren the gioi benh vien, khoang cach tu diem quet toi mat tuong
|
||||||
|
// NHIN THAY, o luoi 0.05 m: p50 = 3.7 cm, p90 = 5.6 cm. MOI tia deu dung som.
|
||||||
|
// Do khong phai loi cai dat -- do la he qua cua luong tu hoa.
|
||||||
|
//
|
||||||
|
// Cach chua khong phai lam luoi min hon (van luong tu, chi nho hon) ma la giu
|
||||||
|
// DDA de tim O trung, roi CAT chinh xac voi doan nam trong o do. Luoi van la
|
||||||
|
// nguon su that cho kinh, vuc va va cham -- chi rieng khoang cach tra ve la
|
||||||
|
// chinh xac.
|
||||||
|
struct WorldSegments {
|
||||||
|
// Doan thang 2D: 4 float moi doan (x0, y0, x1, y1), he toa do THE GIOI.
|
||||||
|
// Lay tu canh cua tam giac va cham nam trong dai z cua LiDAR.
|
||||||
|
std::vector<float> seg;
|
||||||
|
|
||||||
|
// Chi muc CSR theo O CUA LUOI: o `i` chua cac doan
|
||||||
|
// cell_items[cell_start[i] .. cell_start[i + 1]).
|
||||||
|
std::vector<uint32_t> cell_start;
|
||||||
|
std::vector<uint32_t> cell_items;
|
||||||
|
|
||||||
|
uint32_t width = 0, height = 0;
|
||||||
|
double resolution = 0.05;
|
||||||
|
double origin_x = 0.0, origin_y = 0.0;
|
||||||
|
|
||||||
|
bool empty() const { return seg.empty(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Dung chi muc tu mesh VA CHAM cua world, khop luoi voi `grid`.
|
||||||
|
//
|
||||||
|
// Dung mesh VA CHAM chu khong mesh hien thi: mo phong phai TU NHAT QUAN -- thu
|
||||||
|
// LiDAR do duoc phai la thu robot dam vao. Vai model trong bo nay co hull va
|
||||||
|
// cham don gian hoa khac han mesh hien thi (do duoc: PatientWheelChair,
|
||||||
|
// nursesstation_01), va Gazebo cung hanh xu y het.
|
||||||
|
StatusResponse BuildWorldSegments(const GazeboWorld& world,
|
||||||
|
const WorldRasterOptions& opt,
|
||||||
|
const OccupancyGrid& grid,
|
||||||
|
WorldSegments* out);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Xuat hinh hoc cho khung 3D
|
// Xuat hinh hoc cho khung 3D
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -292,6 +292,13 @@ class SimSource {
|
|||||||
// khong dong bo voi bat ky thu gi dang chay, nen goi truoc khi Run().
|
// khong dong bo voi bat ky thu gi dang chay, nen goi truoc khi Run().
|
||||||
void SetMapForTest(const OccupancyGrid& m);
|
void SetMapForTest(const OccupancyGrid& m);
|
||||||
|
|
||||||
|
// Khoang cach LiDAR do duoc tu MOT DIEM bat ky, khong qua than robot.
|
||||||
|
//
|
||||||
|
// Chi dung cho test: no la cach duy nhat kiem duoc rang tia dung o MAT
|
||||||
|
// TUONG chu khong o bien o luoi. Do qua duong ong day du thi phai lai robot
|
||||||
|
// toi dung cho, va khi do sai so dat cho lan at sai so dang muon do.
|
||||||
|
double RangeForTest(double x, double y, double angle) const;
|
||||||
|
|
||||||
// Model doc duoc tu `.world`; rong neu khong chay tu world. Khung 3D dung
|
// Model doc duoc tu `.world`; rong neu khong chay tu world. Khung 3D dung
|
||||||
// no de ve do dac that thay vi khoi hop dung tu luoi.
|
// no de ve do dac that thay vi khoi hop dung tu luoi.
|
||||||
const GazeboWorld& world() const;
|
const GazeboWorld& world() const;
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <functional>
|
||||||
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -736,6 +739,133 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world,
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
StatusResponse BuildWorldSegments(const GazeboWorld& world,
|
||||||
|
const WorldRasterOptions& opt,
|
||||||
|
const OccupancyGrid& grid,
|
||||||
|
WorldSegments* out) {
|
||||||
|
if (out == nullptr) {
|
||||||
|
return StatusResponse::Error(StatusCode::kInvalidArgument, "out == null");
|
||||||
|
}
|
||||||
|
out->seg.clear();
|
||||||
|
out->cell_items.clear();
|
||||||
|
out->cell_start.assign(static_cast<size_t>(grid.width) * grid.height + 1, 0);
|
||||||
|
out->width = grid.width;
|
||||||
|
out->height = grid.height;
|
||||||
|
out->resolution = grid.resolution;
|
||||||
|
out->origin_x = grid.origin.position.x;
|
||||||
|
out->origin_y = grid.origin.position.y;
|
||||||
|
|
||||||
|
const double res = grid.resolution;
|
||||||
|
const double ox = out->origin_x, oy = out->origin_y;
|
||||||
|
const int W = static_cast<int>(grid.width), H = static_cast<int>(grid.height);
|
||||||
|
|
||||||
|
// --- Gom doan tu canh cua tam giac trong dai z ---
|
||||||
|
//
|
||||||
|
// Lay CA BA canh cua moi tam giac. Canh nam trong long vat the (vd canh cua
|
||||||
|
// tam giac mat tren chieu xuong) khong gay hai: chung luon nam XA hon mat
|
||||||
|
// truoc doc theo tia, va phep cat lay t NHO NHAT.
|
||||||
|
std::map<std::string, std::vector<Tri>> cache;
|
||||||
|
for (const WorldModel& m : world.models) {
|
||||||
|
if (m.collision_obj.empty()) continue;
|
||||||
|
auto it = cache.find(m.model_name);
|
||||||
|
if (it == cache.end()) {
|
||||||
|
std::vector<Tri> tris;
|
||||||
|
const bool ok = IsDae(m.collision_obj)
|
||||||
|
? ReadDaeTriangles(m.collision_obj, &tris)
|
||||||
|
: ReadObjTriangles(m.collision_obj, &tris);
|
||||||
|
if (!ok) tris.clear();
|
||||||
|
it = cache.emplace(m.model_name, std::move(tris)).first;
|
||||||
|
}
|
||||||
|
if (it->second.empty()) continue;
|
||||||
|
|
||||||
|
const double cy = std::cos(m.yaw), sny = std::sin(m.yaw);
|
||||||
|
for (const Tri& t0 : it->second) {
|
||||||
|
double X[3], Y[3], Z[3];
|
||||||
|
for (int k = 0; k < 3; ++k) {
|
||||||
|
const double sx = t0.x[k] * m.sx, sy = t0.y[k] * m.sy;
|
||||||
|
X[k] = sx * cy - sy * sny + m.x;
|
||||||
|
Y[k] = sx * sny + sy * cy + m.y;
|
||||||
|
Z[k] = t0.z[k] * m.sz + m.z;
|
||||||
|
}
|
||||||
|
const double zlo = std::min({Z[0], Z[1], Z[2]});
|
||||||
|
const double zhi = std::max({Z[0], Z[1], Z[2]});
|
||||||
|
if (zhi < opt.z_min || zlo > opt.z_max) continue;
|
||||||
|
for (int e = 0; e < 3; ++e) {
|
||||||
|
const int a = e, b = (e + 1) % 3;
|
||||||
|
out->seg.push_back(static_cast<float>(X[a]));
|
||||||
|
out->seg.push_back(static_cast<float>(Y[a]));
|
||||||
|
out->seg.push_back(static_cast<float>(X[b]));
|
||||||
|
out->seg.push_back(static_cast<float>(Y[b]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t n_seg = out->seg.size() / 4;
|
||||||
|
if (n_seg == 0) {
|
||||||
|
return StatusResponse::Error(StatusCode::kNotFound,
|
||||||
|
"khong dung duoc doan nao tu mesh va cham");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Chi muc CSR: hai luot, dem roi dien ---
|
||||||
|
//
|
||||||
|
// Moi doan duoc ghi vao MOI O no cat qua, di bang DDA supercover. Dung bao
|
||||||
|
// loi cua doan se re hon nhung mot buc tuong cheo dai 5 m se dinh vao hang
|
||||||
|
// nghin o no khong he cham.
|
||||||
|
auto walk = [&](size_t s, const std::function<void(int, int)>& visit) {
|
||||||
|
double ax = out->seg[s * 4], ay = out->seg[s * 4 + 1];
|
||||||
|
double bx = out->seg[s * 4 + 2], by = out->seg[s * 4 + 3];
|
||||||
|
double px = (ax - ox) / res, py = (ay - oy) / res;
|
||||||
|
const double qx = (bx - ox) / res, qy = (by - oy) / res;
|
||||||
|
int cx = static_cast<int>(std::floor(px));
|
||||||
|
int cyi = static_cast<int>(std::floor(py));
|
||||||
|
const int ex = static_cast<int>(std::floor(qx));
|
||||||
|
const int ey = static_cast<int>(std::floor(qy));
|
||||||
|
const double dx = qx - px, dy = qy - py;
|
||||||
|
const int sx = dx > 0 ? 1 : (dx < 0 ? -1 : 0);
|
||||||
|
const int sy = dy > 0 ? 1 : (dy < 0 ? -1 : 0);
|
||||||
|
const double inf = std::numeric_limits<double>::infinity();
|
||||||
|
const double tdx = dx != 0.0 ? std::fabs(1.0 / dx) : inf;
|
||||||
|
const double tdy = dy != 0.0 ? std::fabs(1.0 / dy) : inf;
|
||||||
|
double tmx = dx != 0.0 ? ((dx > 0 ? (cx + 1 - px) : (px - cx)) * tdx) : inf;
|
||||||
|
double tmy = dy != 0.0 ? ((dy > 0 ? (cyi + 1 - py) : (py - cyi)) * tdy) : inf;
|
||||||
|
for (int guard = 0; guard < 4096; ++guard) {
|
||||||
|
if (cx >= 0 && cyi >= 0 && cx < W && cyi < H) visit(cx, cyi);
|
||||||
|
if (cx == ex && cyi == ey) break;
|
||||||
|
if (tmx < tmy) { tmx += tdx; cx += sx; }
|
||||||
|
else { tmy += tdy; cyi += sy; }
|
||||||
|
if (tmx > 1.0 && tmy > 1.0) {
|
||||||
|
if (cx >= 0 && cyi >= 0 && cx < W && cyi < H) visit(cx, cyi);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t s = 0; s < n_seg; ++s) {
|
||||||
|
walk(s, [&](int cx, int cyi) {
|
||||||
|
out->cell_start[static_cast<size_t>(cyi) * grid.width + cx + 1]++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (size_t i = 1; i < out->cell_start.size(); ++i) {
|
||||||
|
out->cell_start[i] += out->cell_start[i - 1];
|
||||||
|
}
|
||||||
|
out->cell_items.assign(out->cell_start.back(), 0);
|
||||||
|
std::vector<uint32_t> fill(out->cell_start.begin(), out->cell_start.end() - 1);
|
||||||
|
for (size_t s = 0; s < n_seg; ++s) {
|
||||||
|
walk(s, [&](int cx, int cyi) {
|
||||||
|
out->cell_items[fill[static_cast<size_t>(cyi) * grid.width + cx]++] =
|
||||||
|
static_cast<uint32_t>(s);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
VSLAM_INFO("world -> doan: " << n_seg << " doan, " << out->cell_items.size()
|
||||||
|
<< " muc chi muc (" << (out->seg.size() * 4 +
|
||||||
|
out->cell_items.size() * 4) / 1048576.0
|
||||||
|
<< " MB)");
|
||||||
|
return StatusResponse::Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
StatusResponse ExportWorldMeshes(const GazeboWorld& world, bool visual,
|
StatusResponse ExportWorldMeshes(const GazeboWorld& world, bool visual,
|
||||||
WorldMeshes* out) {
|
WorldMeshes* out) {
|
||||||
if (out == nullptr) {
|
if (out == nullptr) {
|
||||||
|
|||||||
@@ -168,6 +168,10 @@ struct SimSource::Impl {
|
|||||||
SimConfig cfg;
|
SimConfig cfg;
|
||||||
OccupancyGrid map;
|
OccupancyGrid map;
|
||||||
GazeboWorld world;
|
GazeboWorld world;
|
||||||
|
// Doan 2D cua the gioi, de tra ve khoang cach TRUNG MAT TUONG thay vi trung
|
||||||
|
// bien o. Rong khi chay tu `--map` (chi co luoi, khong co mesh) -- khi do
|
||||||
|
// moi raycast giu nguyen ket qua luoi nhu cu.
|
||||||
|
WorldSegments segments;
|
||||||
|
|
||||||
SimLidar lidar;
|
SimLidar lidar;
|
||||||
SimMcu mcu;
|
SimMcu mcu;
|
||||||
@@ -213,6 +217,81 @@ struct SimSource::Impl {
|
|||||||
|
|
||||||
explicit Impl(SimConfig c) : cfg(std::move(c)) {}
|
explicit Impl(SimConfig c) : cfg(std::move(c)) {}
|
||||||
|
|
||||||
|
// --- Tinh chinh khoang cach bang doan 2D ----------------------------------
|
||||||
|
//
|
||||||
|
// ⚠️ DDA tra ve khoang cach toi MAT VAO cua o bi chiem, khong phai toi mat
|
||||||
|
// tuong. O do duoc danh dau khi tam giac di qua TAM o, nen mat vao ay nam
|
||||||
|
// lui vao trong tuong toi mot o day du.
|
||||||
|
//
|
||||||
|
// Do duoc o luoi 0.05 m: moi tia dung som, p50 = 3.7 cm, p90 = 5.6 cm so voi
|
||||||
|
// mat tuong nhin thay. Lam luoi min hon chi thu nho con so do chu khong xoa
|
||||||
|
// duoc no -- van la luong tu hoa.
|
||||||
|
//
|
||||||
|
// Nen: giu DDA de tim O trung (kinh, vuc, va cham deu van doc luoi), roi CAT
|
||||||
|
// chinh xac voi doan nam trong vung do.
|
||||||
|
//
|
||||||
|
// Tra ve NaN khi khong cat duoc gi -- khi do giu nguyen ket qua cua luoi.
|
||||||
|
// Do KHONG phai truong hop la: `--map` khong co mesh, va vai o bi chiem den
|
||||||
|
// tu `SetGlass`/tuong chen tay chu khong tu tam giac nao.
|
||||||
|
double RefineHit(double ox, double oy, double dx, double dy, double t_grid,
|
||||||
|
double max_range) const {
|
||||||
|
if (segments.empty()) return std::numeric_limits<double>::quiet_NaN();
|
||||||
|
const double res = segments.resolution;
|
||||||
|
const int W = static_cast<int>(segments.width);
|
||||||
|
const int H = static_cast<int>(segments.height);
|
||||||
|
|
||||||
|
// Quet vai o quanh cho DDA bao trung. Lui MOT o vi mat tuong that co the
|
||||||
|
// nam truoc mat vao (tuong cheo di qua o ma khong qua tam o do), va tien
|
||||||
|
// BA o vi no co the nam sau.
|
||||||
|
int cells[16][2];
|
||||||
|
int n_cells = 0;
|
||||||
|
for (int k = -2; k <= 6; ++k) {
|
||||||
|
const double t = t_grid + k * res * 0.5;
|
||||||
|
if (t < 0.0) continue;
|
||||||
|
const int cx = static_cast<int>(
|
||||||
|
std::floor((ox + dx * t - segments.origin_x) / res));
|
||||||
|
const int cy = static_cast<int>(
|
||||||
|
std::floor((oy + dy * t - segments.origin_y) / res));
|
||||||
|
if (cx < 0 || cy < 0 || cx >= W || cy >= H) continue;
|
||||||
|
bool dup = false;
|
||||||
|
for (int i = 0; i < n_cells; ++i) {
|
||||||
|
if (cells[i][0] == cx && cells[i][1] == cy) { dup = true; break; }
|
||||||
|
}
|
||||||
|
if (!dup && n_cells < 16) { cells[n_cells][0] = cx; cells[n_cells][1] = cy; n_cells++; }
|
||||||
|
}
|
||||||
|
|
||||||
|
double best = std::numeric_limits<double>::infinity();
|
||||||
|
for (int i = 0; i < n_cells; ++i) {
|
||||||
|
const size_t idx = static_cast<size_t>(cells[i][1]) * segments.width +
|
||||||
|
static_cast<size_t>(cells[i][0]);
|
||||||
|
for (uint32_t j = segments.cell_start[idx]; j < segments.cell_start[idx + 1];
|
||||||
|
++j) {
|
||||||
|
const uint32_t s = segments.cell_items[j];
|
||||||
|
const double ax = segments.seg[s * 4], ay = segments.seg[s * 4 + 1];
|
||||||
|
const double ex = segments.seg[s * 4 + 2] - ax;
|
||||||
|
const double ey = segments.seg[s * 4 + 3] - ay;
|
||||||
|
const double den = ex * dy - ey * dx;
|
||||||
|
if (std::fabs(den) < 1e-12) continue; // song song
|
||||||
|
const double wx = ax - ox, wy = ay - oy;
|
||||||
|
const double t = (ex * wy - ey * wx) / den;
|
||||||
|
if (t < 0.0 || t > max_range || t >= best) continue;
|
||||||
|
const double u = (dx * wy - dy * wx) / den;
|
||||||
|
if (u < 0.0 || u > 1.0) continue;
|
||||||
|
best = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!std::isfinite(best)) return std::numeric_limits<double>::quiet_NaN();
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ket qua da tinh chinh, hoac chinh `t_grid` neu khong tinh chinh duoc.
|
||||||
|
double Refined(double ox, double oy, double angle, double t_grid,
|
||||||
|
double max_range) const {
|
||||||
|
const double r = RefineHit(ox, oy, std::cos(angle), std::sin(angle), t_grid,
|
||||||
|
max_range);
|
||||||
|
return std::isnan(r) ? t_grid : r;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Raycast tren occupancy grid -----------------------------------------
|
// --- Raycast tren occupancy grid -----------------------------------------
|
||||||
// Thuat toan DDA: di tung o thay vi lay mau theo buoc co dinh. Lay mau theo
|
// Thuat toan DDA: di tung o thay vi lay mau theo buoc co dinh. Lay mau theo
|
||||||
// buoc co dinh se BO SOT tuong mong khi buoc lon hon mot o, va do la loi im
|
// buoc co dinh se BO SOT tuong mong khi buoc lon hon mot o, va do la loi im
|
||||||
@@ -260,7 +339,7 @@ struct SimSource::Impl {
|
|||||||
static_cast<size_t>(cx);
|
static_cast<size_t>(cx);
|
||||||
const bool is_glass = cidx < glass.size() && glass[cidx] != 0;
|
const bool is_glass = cidx < glass.size() && glass[cidx] != 0;
|
||||||
if (cell >= 50 && !is_glass) {
|
if (cell >= 50 && !is_glass) {
|
||||||
return t * res;
|
return Refined(ox, oy, angle, t * res, max_range);
|
||||||
}
|
}
|
||||||
if (t_max_x < t_max_y) {
|
if (t_max_x < t_max_y) {
|
||||||
t = t_max_x;
|
t = t_max_x;
|
||||||
@@ -393,7 +472,12 @@ struct SimSource::Impl {
|
|||||||
// KHONG kiem glass: sieu am thay moi vat can, ke ca kinh.
|
// KHONG kiem glass: sieu am thay moi vat can, ke ca kinh.
|
||||||
if (map.data[static_cast<size_t>(cy) * map.width +
|
if (map.data[static_cast<size_t>(cy) * map.width +
|
||||||
static_cast<size_t>(cx)] >= 50) {
|
static_cast<size_t>(cx)] >= 50) {
|
||||||
return t;
|
// Cung tinh chinh nhu LiDAR. Voi sieu am con quan trong hon theo ti
|
||||||
|
// le: nguong `us_stop_distance` chi 0.30 m, nen lech 3 cm la 10 %.
|
||||||
|
//
|
||||||
|
// Buc KINH do `--sim-glass-at` chen tay vao luoi khong co tam giac
|
||||||
|
// nao, nen RefineHit() tra NaN va ta giu ket qua luoi -- dung.
|
||||||
|
return Refined(ox, oy, angle, t, max_range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::numeric_limits<double>::infinity();
|
return std::numeric_limits<double>::infinity();
|
||||||
@@ -486,7 +570,12 @@ struct SimSource::Impl {
|
|||||||
const double lo = fz, hi = fz + cfg.wall_height;
|
const double lo = fz, hi = fz + cfg.wall_height;
|
||||||
if ((z_enter >= lo && z_enter <= hi) || (z_exit >= lo && z_exit <= hi) ||
|
if ((z_enter >= lo && z_enter <= hi) || (z_exit >= lo && z_exit <= hi) ||
|
||||||
(z_enter > hi && z_exit < lo) || (z_enter < lo && z_exit > hi)) {
|
(z_enter > hi && z_exit < lo) || (z_enter < lo && z_exit > hi)) {
|
||||||
return std::max(t_enter, 0.0) * res;
|
// Chi tinh chinh theo mat phang XY: tuong trong dai z la thang dung,
|
||||||
|
// nen cat trong mat bang la du. Nhanh cham SAN o duoi da noi suy
|
||||||
|
// dung tu truoc, khong can dong toi.
|
||||||
|
const double t_xy = std::max(t_enter, 0.0) * res;
|
||||||
|
const double r = RefineHit(ox, oy, dx, dy, t_xy, max_range);
|
||||||
|
return std::isnan(r) ? t_xy : r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,6 +1024,16 @@ StatusResponse SimSource::Open() {
|
|||||||
WorldRasterOptions wo;
|
WorldRasterOptions wo;
|
||||||
const StatusResponse rs = RasterizeGazeboWorld(impl_->world, wo, &impl_->map);
|
const StatusResponse rs = RasterizeGazeboWorld(impl_->world, wo, &impl_->map);
|
||||||
if (!rs.ok()) return rs;
|
if (!rs.ok()) return rs;
|
||||||
|
// Chi muc doan 2D, de khoang cach tra ve trung MAT TUONG chu khong trung
|
||||||
|
// bien o. Khong dung duoc thi van chay -- chi la moi tia dung som toi mot
|
||||||
|
// o, y nhu truoc day.
|
||||||
|
const StatusResponse ss =
|
||||||
|
BuildWorldSegments(impl_->world, wo, impl_->map, &impl_->segments);
|
||||||
|
if (!ss.ok()) {
|
||||||
|
VSLAM_WARN("sim: khong dung duoc chi muc doan (" << ss.message
|
||||||
|
<< ") -- raycast se luong tu hoa theo o "
|
||||||
|
<< impl_->map.resolution << " m");
|
||||||
|
}
|
||||||
} else if (impl_->cfg.map_yaml.empty()) {
|
} else if (impl_->cfg.map_yaml.empty()) {
|
||||||
impl_->map = MakeSyntheticWorld(impl_->cfg.synthetic_width,
|
impl_->map = MakeSyntheticWorld(impl_->cfg.synthetic_width,
|
||||||
impl_->cfg.synthetic_height,
|
impl_->cfg.synthetic_height,
|
||||||
@@ -986,6 +1085,10 @@ const std::vector<uint8_t>& SimSource::glass_mask() const { return impl_->glass;
|
|||||||
|
|
||||||
const GazeboWorld& SimSource::world() const { return impl_->world; }
|
const GazeboWorld& SimSource::world() const { return impl_->world; }
|
||||||
|
|
||||||
|
double SimSource::RangeForTest(double x, double y, double angle) const {
|
||||||
|
return impl_->Raycast(x, y, angle, impl_->cfg.lidar_range_max);
|
||||||
|
}
|
||||||
|
|
||||||
void SimSource::SetMapForTest(const OccupancyGrid& m) {
|
void SimSource::SetMapForTest(const OccupancyGrid& m) {
|
||||||
impl_->map = m;
|
impl_->map = m;
|
||||||
impl_->floor_z.assign(static_cast<size_t>(m.width) * m.height, 0.0f);
|
impl_->floor_z.assign(static_cast<size_t>(m.width) * m.height, 0.0f);
|
||||||
|
|||||||
@@ -76,6 +76,13 @@ struct RobotShape {
|
|||||||
double wheel_separation = 0.36;
|
double wheel_separation = 0.36;
|
||||||
double body_half_width = 0.17;
|
double body_half_width = 0.17;
|
||||||
|
|
||||||
|
// Khoi hop cua than, CHI de ve. `radius` van la thu dung cho va cham.
|
||||||
|
double body_length = 0.40;
|
||||||
|
double body_width = 0.34;
|
||||||
|
double body_height = 0.85;
|
||||||
|
double body_offset_x = -0.06;
|
||||||
|
double ground_clearance = 0.04;
|
||||||
|
|
||||||
// Vi tri cam bien trong base_link (met). z do tu TAM TRUC banh, khong tu
|
// Vi tri cam bien trong base_link (met). z do tu TAM TRUC banh, khong tu
|
||||||
// san -- trinh ve tu cong wheel_radius khi can toa do so voi san.
|
// san -- trinh ve tu cong wheel_radius khi can toa do so voi san.
|
||||||
double laser_x = 0.24, laser_y = 0.0, laser_z = 0.125;
|
double laser_x = 0.24, laser_y = 0.0, laser_z = 0.125;
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ void WriteStateJson(const WebSnapshot& s, std::string* out) {
|
|||||||
Num("wheel_radius", s.robot.wheel_radius, 4, out); Comma(out);
|
Num("wheel_radius", s.robot.wheel_radius, 4, out); Comma(out);
|
||||||
Num("wheel_sep", s.robot.wheel_separation, 4, out); Comma(out);
|
Num("wheel_sep", s.robot.wheel_separation, 4, out); Comma(out);
|
||||||
Num("half_width", s.robot.body_half_width, 4, out); Comma(out);
|
Num("half_width", s.robot.body_half_width, 4, out); Comma(out);
|
||||||
|
Num("body_l", s.robot.body_length, 4, out); Comma(out);
|
||||||
|
Num("body_w", s.robot.body_width, 4, out); Comma(out);
|
||||||
|
Num("body_h", s.robot.body_height, 4, out); Comma(out);
|
||||||
|
Num("body_off_x", s.robot.body_offset_x, 4, out); Comma(out);
|
||||||
|
Num("clearance", s.robot.ground_clearance, 4, out); Comma(out);
|
||||||
Num("laser_x", s.robot.laser_x, 4, out); Comma(out);
|
Num("laser_x", s.robot.laser_x, 4, out); Comma(out);
|
||||||
Num("laser_y", s.robot.laser_y, 4, out); Comma(out);
|
Num("laser_y", s.robot.laser_y, 4, out); Comma(out);
|
||||||
Num("laser_z", s.robot.laser_z, 4, out); Comma(out);
|
Num("laser_z", s.robot.laser_z, 4, out); Comma(out);
|
||||||
|
|||||||
@@ -12,7 +12,55 @@ const MAGIC = 0x314C5356; // 'VSL1' little-endian
|
|||||||
// Phien ban ma nguon giao dien. TANG khi doi app.js / app3d.js / style.css.
|
// 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
|
// Hien ngay tren thanh tren cung de phan biet "chua sua" voi "trinh duyet con
|
||||||
// cache ban cu".
|
// cache ban cu".
|
||||||
const UI_VERSION = '2026-09-18c';
|
const UI_VERSION = '2026-09-19f';
|
||||||
|
|
||||||
|
// ⚠️ HAI bang mau, mot cho moi khung. Chung KHONG duoc giong nhau.
|
||||||
|
//
|
||||||
|
// Ban truoc dung MOT bang cho ca hai: `free` gan trang (#ffffff) tren nen gan
|
||||||
|
// trang (#f3f6fa). Hai mau do cach nhau vai don vi, nen vung DA QUET va vung
|
||||||
|
// chua co gi trong y het nhau -- khong con biet quet toi dau.
|
||||||
|
//
|
||||||
|
// Gio moi khung mang tone cua cong cu no thay the:
|
||||||
|
//
|
||||||
|
// `world` -- khung THE GIOI, tone Gazebo: nen troi, san sang, tuong xam.
|
||||||
|
// `slam` -- khung SLAM, tone RViz: nen than chi, o TRONG sang bat len, o bi
|
||||||
|
// chiem gan den. Tuong phan nam giua `free` va `bg`, khong giua
|
||||||
|
// `occupied` va `bg` -- vi cai nguoi van hanh can thay la vung DA
|
||||||
|
// QUET lon den dau.
|
||||||
|
//
|
||||||
|
// Nguyen tac khong doi cho ca hai: CHUA BIET trong suot (xem rasterize()).
|
||||||
|
const PALETTE = {
|
||||||
|
world: {
|
||||||
|
bg: '#a9b8c6', // troi Gazebo
|
||||||
|
occupied: [86, 97, 108, 255], // tuong, xam dam
|
||||||
|
free: [232, 237, 241, 235], // san, sang
|
||||||
|
unknown: [0, 0, 0, 0],
|
||||||
|
path: '#1b5e8a',
|
||||||
|
scan: '#c0392b',
|
||||||
|
cloud: '#1f7a4d',
|
||||||
|
nose: '#eef2f6',
|
||||||
|
text: '#44505c',
|
||||||
|
robot: '#1a6ea8',
|
||||||
|
gt: '#0f9d58',
|
||||||
|
},
|
||||||
|
slam: {
|
||||||
|
// Nen RViz. Sang hon mot nac so voi ban dau (#2e3033): o do tuong gan
|
||||||
|
// den chi cach nen 29.5 don vi, nen mot o tuong le giua vung chua quet la
|
||||||
|
// vo hinh. Tuong phan chinh van la free-vs-bg, nhung occupied-vs-bg cung
|
||||||
|
// phai du.
|
||||||
|
bg: '#3c4046',
|
||||||
|
occupied: [18, 18, 20, 255], // tuong, gan den
|
||||||
|
free: [206, 208, 211, 235], // vung da quet, SANG -- day la tuong phan
|
||||||
|
unknown: [0, 0, 0, 0],
|
||||||
|
path: '#4fc3f7',
|
||||||
|
scan: '#ff5a4d',
|
||||||
|
cloud: '#34d17e',
|
||||||
|
nose: '#3c4046',
|
||||||
|
text: '#9aa3ad',
|
||||||
|
robot: '#42a5f5',
|
||||||
|
gt: '#2ee06a',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const T_SCAN = 1, T_CLOUD = 2, T_MAP_FULL = 3, T_MAP_PATCH = 4, T_PATH = 5;
|
const T_SCAN = 1, T_CLOUD = 2, T_MAP_FULL = 3, T_MAP_PATCH = 4, T_PATH = 5;
|
||||||
// Ban do THE GIOI cua bo mo phong -- khung nhin "Gazebo". Tinh: gui mot lan.
|
// Ban do THE GIOI cua bo mo phong -- khung nhin "Gazebo". Tinh: gui mot lan.
|
||||||
@@ -29,7 +77,10 @@ const state = {
|
|||||||
bytes: 0, lastBytes: 0, wireRate: 0,
|
bytes: 0, lastBytes: 0, wireRate: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const view = { x: 0, y: 0, scale: 40, init: false }; // scale = pixel/met
|
// `rot` = goc XOAY cua khung nhin, radian, nguoc chieu kim dong ho trong he
|
||||||
|
// the gioi. Hai khung dung CHUNG view nay nen chung luon thang hang -- doi
|
||||||
|
// chieu duoc hai ban do la ca ly do mo hai khung.
|
||||||
|
const view = { x: 0, y: 0, scale: 40, rot: 0, init: false }; // scale = pixel/met
|
||||||
|
|
||||||
// --- WebSocket -------------------------------------------------------------
|
// --- WebSocket -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -134,12 +185,12 @@ function onBinary(dv) {
|
|||||||
if (type === T_WORLD_MAP) {
|
if (type === T_WORLD_MAP) {
|
||||||
// Ban do THE GIOI: su that, de lai cho chuan. KHONG lan vao state.map.
|
// Ban do THE GIOI: su that, de lai cho chuan. KHONG lan vao state.map.
|
||||||
state.worldMap = grid;
|
state.worldMap = grid;
|
||||||
state.worldMapImage = rasterize(grid);
|
state.worldMapImage = rasterize(grid, PALETTE.world);
|
||||||
if (!view.init) centerOnMap(grid);
|
if (!view.init) centerOnMap(grid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.map = grid;
|
state.map = grid;
|
||||||
state.mapImage = rasterize(grid);
|
state.mapImage = rasterize(grid, PALETTE.slam);
|
||||||
// Can khung theo ban do THE GIOI neu co -- no la cai khong doi, con ban
|
// Can khung theo ban do THE GIOI neu co -- no la cai khong doi, con ban
|
||||||
// do SLAM lon dan khi quet va se keo khung nhin chay theo.
|
// do SLAM lon dan khi quet va se keo khung nhin chay theo.
|
||||||
if (!view.init && !state.worldMap) centerOnMap(grid);
|
if (!view.init && !state.worldMap) centerOnMap(grid);
|
||||||
@@ -161,7 +212,7 @@ function onBinary(dv) {
|
|||||||
|
|
||||||
// Giai RLE mot lan cho moi map_version roi blit -- moi khung chi con mot
|
// Giai RLE mot lan cho moi map_version roi blit -- moi khung chi con mot
|
||||||
// drawImage thay vi ve lai tung o.
|
// drawImage thay vi ve lai tung o.
|
||||||
function rasterize(map) {
|
function rasterize(map, pal) {
|
||||||
const img = new ImageData(map.w, map.h);
|
const img = new ImageData(map.w, map.h);
|
||||||
const d = img.data;
|
const d = img.data;
|
||||||
for (let i = 0; i < map.cells.length; i++) {
|
for (let i = 0; i < map.cells.length; i++) {
|
||||||
@@ -182,12 +233,12 @@ function rasterize(map) {
|
|||||||
// RViz ve chua-biet trong suot, va do la ly do ban do o do "lon dan" nhin
|
// RViz ve chua-biet trong suot, va do la ly do ban do o do "lon dan" nhin
|
||||||
// thay duoc.
|
// thay duoc.
|
||||||
//
|
//
|
||||||
// Mau cung dao lai cho nen TOI: bi chiem SANG (tuong noi len), trong thi
|
// Mau lay tu `CANVAS` o dau file, khong go tai cho: bang do phai doi cung
|
||||||
// mo. Ban truoc de bi chiem gan DEN tren nen den -- vo hinh.
|
// luc voi bien CSS, va de hai noi thi chac chan se lech.
|
||||||
let c;
|
let c;
|
||||||
if (v < 0) c = [0, 0, 0, 0]; // chua biet -> TRONG SUOT
|
if (v < 0) c = pal.unknown; // chua biet -> TRONG SUOT
|
||||||
else if (v < 50) c = [58, 70, 86, 170]; // trong, mo
|
else if (v < 50) c = pal.free;
|
||||||
else c = [222, 232, 244, 255]; // bi chiem, SANG
|
else c = pal.occupied;
|
||||||
d[j] = c[0]; d[j + 1] = c[1]; d[j + 2] = c[2]; d[j + 3] = c[3];
|
d[j] = c[0]; d[j + 1] = c[1]; d[j + 2] = c[2]; d[j + 3] = c[3];
|
||||||
}
|
}
|
||||||
const cv = document.createElement('canvas');
|
const cv = document.createElement('canvas');
|
||||||
@@ -271,6 +322,20 @@ function onState(s) {
|
|||||||
if (s.teleop) {
|
if (s.teleop) {
|
||||||
txt('linSpeed', fmt(s.teleop.linear_speed, 2));
|
txt('linSpeed', fmt(s.teleop.linear_speed, 2));
|
||||||
txt('angSpeed', fmt(s.teleop.angular_speed, 2));
|
txt('angSpeed', fmt(s.teleop.angular_speed, 2));
|
||||||
|
// Thanh truot: chi dong bo khi NGUOI DUNG khong dang keo, va lay tran
|
||||||
|
// tu server (`--max-speed` co the noi tran len cho mo phong).
|
||||||
|
syncRange('linRange', s.teleop.linear_speed, s.teleop.max_linear_speed);
|
||||||
|
syncRange('angRange', s.teleop.angular_speed, s.teleop.max_angular_speed);
|
||||||
|
}
|
||||||
|
// Toc do DO DUOC tu encoder, de canh gia tri dat.
|
||||||
|
//
|
||||||
|
// ⚠️ Dat 2.0 ma do duoc 0.98 KHONG phai loi: `accel_limit` 0.30 m/s^2 can
|
||||||
|
// 6.7 giay va ~6.7 m duong chay de len toi 2 m/s, ma cho rong nhat trong
|
||||||
|
// toa nha chi 4.75 m. Hai so nay canh nhau thi khac biet do nhin thay ngay
|
||||||
|
// thay vi thanh mot cau hoi.
|
||||||
|
if (s.odom) {
|
||||||
|
txt('linReal', fmt(Math.abs(s.odom.vx), 2));
|
||||||
|
txt('angReal', fmt(Math.abs(s.odom.vyaw), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
const btn = document.getElementById('estop');
|
const btn = document.getElementById('estop');
|
||||||
@@ -291,6 +356,11 @@ function fmt(v, d) {
|
|||||||
|
|
||||||
const cv = document.getElementById('main');
|
const cv = document.getElementById('main');
|
||||||
const ctx = cv.getContext('2d');
|
const ctx = cv.getContext('2d');
|
||||||
|
// ⚠️ Khai o DAY chu khong o cho dung dau tien: bo xu ly chuot ben duoi gan
|
||||||
|
// cho ca hai khung, va `const` khai muon hon cho dung se nem ReferenceError
|
||||||
|
// ngay luc nap trang.
|
||||||
|
const cvR = document.getElementById('mainR');
|
||||||
|
const ctxR = cvR.getContext('2d');
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
const dpr = window.devicePixelRatio || 1;
|
const dpr = window.devicePixelRatio || 1;
|
||||||
@@ -315,27 +385,47 @@ function centerOnMap(grid) {
|
|||||||
// y: hai ban do phai thang hang thi moi doi chieu duoc, ma doi chieu chinh la
|
// y: hai ban do phai thang hang thi moi doi chieu duoc, ma doi chieu chinh la
|
||||||
// ly do mo hai khung.
|
// ly do mo hai khung.
|
||||||
let curCv = null;
|
let curCv = null;
|
||||||
function sx(x) { return (x - view.x) * view.scale + curCv.clientWidth / 2; }
|
// The gioi -> man hinh, qua ba buoc: doi goc ve tam nhin, XOAY, roi doi ti le.
|
||||||
function sy(y) { return curCv.clientHeight / 2 - (y - view.y) * view.scale; }
|
// Truc y cua canvas nguoc voi truc y the gioi, nen moi phep xoay xuat hien o
|
||||||
|
// `ctx.rotate()` deu mang dau am.
|
||||||
|
function sx(x, y) {
|
||||||
|
const c = Math.cos(view.rot), s_ = Math.sin(view.rot);
|
||||||
|
const dx = x - view.x, dy = y - view.y;
|
||||||
|
return (dx * c - dy * s_) * view.scale + curCv.clientWidth / 2;
|
||||||
|
}
|
||||||
|
function sy(x, y) {
|
||||||
|
const c = Math.cos(view.rot), s_ = Math.sin(view.rot);
|
||||||
|
const dx = x - view.x, dy = y - view.y;
|
||||||
|
return curCv.clientHeight / 2 - (dx * s_ + dy * c) * view.scale;
|
||||||
|
}
|
||||||
|
|
||||||
function on(id) { return document.getElementById(id).checked; }
|
function on(id) { return document.getElementById(id).checked; }
|
||||||
|
|
||||||
// Tam giac chi huong. Mot ham cho ca pose uoc luong lan ground truth: hai ban
|
// Tam giac chi huong. Mot ham cho ca pose uoc luong lan ground truth: hai ban
|
||||||
// chep cua cung mot hinh se lech nhau ngay lan sua dau tien, va luc do khong ai
|
// chep cua cung mot hinh se lech nhau ngay lan sua dau tien, va luc do khong ai
|
||||||
// so sanh duoc hai cai nua.
|
// so sanh duoc hai cai nua.
|
||||||
function drawRobot(ctx, x, y, yaw, color, alpha) {
|
// Robot ve theo HINH HOP, dung kich thuoc that tu robot.yaml.
|
||||||
const L = 0.30 * view.scale, W = 0.17 * view.scale;
|
//
|
||||||
|
// ⚠️ Ban truoc ve tam giac voi hai hang so 0.30 va 0.17 go thang vao day. Do
|
||||||
|
// la dung lop bug "hai cho phai giu dong bo" ma `PROJECT_CONTEXT.md` da ghi
|
||||||
|
// giua URDF va launch param: doi hinh hoc trong robot.yaml thi hinh ve khong
|
||||||
|
// doi theo, va khong co gi bao.
|
||||||
|
//
|
||||||
|
// Hop mot minh thi khong doc duoc huong, nen them mot vach o dau mui.
|
||||||
|
function drawRobot(ctx, x, y, yaw, color, alpha, pal) {
|
||||||
|
const r = state.robot;
|
||||||
|
const L = (r && r.body_l ? r.body_l : 0.40) * view.scale;
|
||||||
|
const W = (r && r.body_w ? r.body_w : 0.34) * view.scale;
|
||||||
|
const off = (r && r.body_off_x ? r.body_off_x : 0) * view.scale;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.globalAlpha = alpha;
|
ctx.globalAlpha = alpha;
|
||||||
ctx.translate(sx(x), sy(y));
|
ctx.translate(sx(x, y), sy(x, y));
|
||||||
ctx.rotate(-yaw);
|
ctx.rotate(-yaw - view.rot);
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(L, 0);
|
|
||||||
ctx.lineTo(-L * 0.6, -W);
|
|
||||||
ctx.lineTo(-L * 0.6, W);
|
|
||||||
ctx.closePath();
|
|
||||||
ctx.fillStyle = color;
|
ctx.fillStyle = color;
|
||||||
ctx.fill();
|
ctx.fillRect(off - L / 2, -W / 2, L, W);
|
||||||
|
// Vach mui: chi ro dau la phia truoc.
|
||||||
|
ctx.fillStyle = pal.nose;
|
||||||
|
ctx.fillRect(off + L / 2 - L * 0.14, -W * 0.16, L * 0.14, W * 0.32);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,21 +438,21 @@ function drawRobot(ctx, x, y, yaw, color, alpha) {
|
|||||||
//
|
//
|
||||||
// Mot ham cho ca hai khung: hai ban chep se lech nhau ngay lan sua dau, va
|
// Mot ham cho ca hai khung: hai ban chep se lech nhau ngay lan sua dau, va
|
||||||
// luc do khong con doi chieu duoc nua.
|
// luc do khong con doi chieu duoc nua.
|
||||||
function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapToggle) {
|
function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapToggle, pal) {
|
||||||
curCv = targetCv;
|
curCv = targetCv;
|
||||||
const ctx = targetCtx;
|
const ctx = targetCtx;
|
||||||
const w = targetCv.clientWidth, h = targetCv.clientHeight;
|
const w = targetCv.clientWidth, h = targetCv.clientHeight;
|
||||||
if (targetCv.width !== w || targetCv.height !== h) {
|
if (targetCv.width !== w || targetCv.height !== h) {
|
||||||
targetCv.width = w; targetCv.height = h;
|
targetCv.width = w; targetCv.height = h;
|
||||||
}
|
}
|
||||||
ctx.fillStyle = '#12151a';
|
ctx.fillStyle = pal.bg;
|
||||||
ctx.fillRect(0, 0, w, h);
|
ctx.fillRect(0, 0, w, h);
|
||||||
|
|
||||||
// Mot khung den khong noi duoc vi sao no den. Neu day la khung SLAM va
|
// Mot khung den khong noi duoc vi sao no den. Neu day la khung SLAM va
|
||||||
// SLAM dang TAT, viet ra -- nguoi van hanh khong phai doan.
|
// SLAM dang TAT, viet ra -- nguoi van hanh khong phai doan.
|
||||||
if (!grid && mapToggle === 'lyMap' &&
|
if (!grid && mapToggle === 'lyMap' &&
|
||||||
(state.slamMode === 'off' || !state.slamMode)) {
|
(state.slamMode === 'off' || !state.slamMode)) {
|
||||||
ctx.fillStyle = '#7d8896';
|
ctx.fillStyle = pal.text;
|
||||||
ctx.font = '13px system-ui, sans-serif';
|
ctx.font = '13px system-ui, sans-serif';
|
||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.fillText('SLAM dang TAT', w / 2, h / 2 - 10);
|
ctx.fillText('SLAM dang TAT', w / 2, h / 2 - 10);
|
||||||
@@ -373,17 +463,24 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
|||||||
if (grid && gridImage && on(mapToggle || 'lyMap')) {
|
if (grid && gridImage && on(mapToggle || 'lyMap')) {
|
||||||
const m = grid;
|
const m = grid;
|
||||||
ctx.imageSmoothingEnabled = false;
|
ctx.imageSmoothingEnabled = false;
|
||||||
ctx.drawImage(gridImage,
|
// Goc TREN-TRAI cua anh trong he the gioi la (ox, oy + h*res). Dua goc do
|
||||||
sx(m.ox), sy(m.oy + m.h * m.res),
|
// vao dung cho roi xoay CA anh quanh no.
|
||||||
|
const gx = m.ox, gy = m.oy + m.h * m.res;
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(sx(gx, gy), sy(gx, gy));
|
||||||
|
ctx.rotate(-view.rot);
|
||||||
|
ctx.drawImage(gridImage, 0, 0,
|
||||||
m.w * m.res * view.scale, m.h * m.res * view.scale);
|
m.w * m.res * view.scale, m.h * m.res * view.scale);
|
||||||
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.path && on('lyPath')) {
|
if (state.path && on('lyPath')) {
|
||||||
ctx.strokeStyle = '#5aa9e6';
|
ctx.strokeStyle = pal.path;
|
||||||
ctx.lineWidth = 1.5;
|
ctx.lineWidth = 1.5;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
for (let i = 0; i < state.path.length; i += 2) {
|
for (let i = 0; i < state.path.length; i += 2) {
|
||||||
const X = sx(state.path[i]), Y = sy(state.path[i + 1]);
|
const X = sx(state.path[i], state.path[i + 1]);
|
||||||
|
const Y = sy(state.path[i], state.path[i + 1]);
|
||||||
i === 0 ? ctx.moveTo(X, Y) : ctx.lineTo(X, Y);
|
i === 0 ? ctx.moveTo(X, Y) : ctx.lineTo(X, Y);
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
@@ -397,7 +494,7 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
|||||||
// Ground truth ve TRUOC pose uoc luong, de pose ve de len tren: cai ta
|
// 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.
|
// dang danh gia phai nhin ro hon cai lam chuan.
|
||||||
if (showGt && state.gt && on('lyGt')) {
|
if (showGt && state.gt && on('lyGt')) {
|
||||||
drawRobot(ctx, state.gt.x, state.gt.y, state.gt.yaw, '#00c853', 0.45);
|
drawRobot(ctx, state.gt.x, state.gt.y, state.gt.yaw, pal.gt, 0.45, pal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.cloud && on('lyCloud')) {
|
if (state.cloud && on('lyCloud')) {
|
||||||
@@ -411,12 +508,12 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
|||||||
const t = Math.max(0, Math.min(1, z / 1.2));
|
const t = Math.max(0, Math.min(1, z / 1.2));
|
||||||
ctx.fillStyle = 'rgb(' + Math.round(80 + 175 * t) + ',' +
|
ctx.fillStyle = 'rgb(' + Math.round(80 + 175 * t) + ',' +
|
||||||
Math.round(200 - 90 * t) + ',' + Math.round(120 + 60 * t) + ')';
|
Math.round(200 - 90 * t) + ',' + Math.round(120 + 60 * t) + ')';
|
||||||
ctx.fillRect(sx(x) - 1, sy(y) - 1, 2, 2);
|
ctx.fillRect(sx(x, y) - 1, sy(x, y) - 1, 2, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.scan && on('lyScan')) {
|
if (state.scan && on('lyScan')) {
|
||||||
ctx.fillStyle = '#e2574c';
|
ctx.fillStyle = pal.scan;
|
||||||
const pts = state.scan;
|
const pts = state.scan;
|
||||||
// ⚠️ Scan trong frame LASER -- phai bu vi tri gan LiDAR truoc khi dua
|
// ⚠️ Scan trong frame LASER -- phai bu vi tri gan LiDAR truoc khi dua
|
||||||
// vao pose cua base. Xem ghi chu trong v3dSetScan().
|
// vao pose cua base. Xem ghi chu trong v3dSetScan().
|
||||||
@@ -426,11 +523,11 @@ function drawScene(targetCv, targetCtx, grid, gridImage, robotPose, showGt, mapT
|
|||||||
const bx = pts[i] + lx, by = pts[i + 1] + ly;
|
const bx = pts[i] + lx, by = pts[i + 1] + ly;
|
||||||
const x = p.x + c * bx - s * by;
|
const x = p.x + c * bx - s * by;
|
||||||
const y = p.y + s * bx + c * by;
|
const y = p.y + s * bx + c * by;
|
||||||
ctx.fillRect(sx(x) - 1.5, sy(y) - 1.5, 3, 3);
|
ctx.fillRect(sx(x, y) - 1.5, sy(x, y) - 1.5, 3, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawRobot(ctx, robotPose.x, robotPose.y, robotPose.yaw, '#4ec9a0', 1.0);
|
drawRobot(ctx, robotPose.x, robotPose.y, robotPose.yaw, pal.robot, 1.0, pal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,6 +557,9 @@ function updateSlamLabel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
// Goi o DAY chu khong trong draw3d(): o so sanh uoc luong voi ground truth
|
||||||
|
// phai chay ca khi dang xem khung 2D.
|
||||||
|
updateGapChip();
|
||||||
// ⚠️ 3D va CHIA DOI phai chay CUNG NHAU.
|
// ⚠️ 3D va CHIA DOI phai chay CUNG NHAU.
|
||||||
//
|
//
|
||||||
// Ban truoc viet `if (use3d) { draw3d(); return; }` -- tuc khi bat 3D thi
|
// Ban truoc viet `if (use3d) { draw3d(); return; }` -- tuc khi bat 3D thi
|
||||||
@@ -472,7 +572,8 @@ function draw() {
|
|||||||
// Khung phai VAN phai chay khi dang chia doi.
|
// Khung phai VAN phai chay khi dang chia doi.
|
||||||
if (split) {
|
if (split) {
|
||||||
updateSlamLabel();
|
updateSlamLabel();
|
||||||
drawScene(cvR, ctxR, state.map, state.mapImage, state.pose, true, 'lyMap');
|
drawScene(cvR, ctxR, state.map, state.mapImage, state.pose, true, 'lyMap',
|
||||||
|
PALETTE.slam);
|
||||||
}
|
}
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
return;
|
return;
|
||||||
@@ -481,17 +582,19 @@ function draw() {
|
|||||||
updateSlamLabel();
|
updateSlamLabel();
|
||||||
// TRAI = THE GIOI: ban do that + pose THAT. Day la khung de LAI.
|
// TRAI = THE GIOI: ban do that + pose THAT. Day la khung de LAI.
|
||||||
drawScene(cv, ctx, state.worldMap, state.worldMapImage,
|
drawScene(cv, ctx, state.worldMap, state.worldMapImage,
|
||||||
state.gt || state.pose, false, 'lyWorld');
|
state.gt || state.pose, false, 'lyWorld', PALETTE.world);
|
||||||
// PHAI = SLAM: ban do dang dung + pose UOC LUONG. Khung de xem quet toi
|
// PHAI = SLAM: ban do dang dung + pose UOC LUONG. Khung de xem quet toi
|
||||||
// dau, va lech bao nhieu so voi khung trai.
|
// 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.pose, true, 'lyMap',
|
||||||
|
PALETTE.slam);
|
||||||
} else {
|
} else {
|
||||||
// Mot khung: uu tien ban do SLAM neu co, khong thi ban do the gioi.
|
// Mot khung: uu tien ban do SLAM neu co, khong thi ban do the gioi.
|
||||||
const haveSlam = !!state.map;
|
const haveSlam = !!state.map;
|
||||||
drawScene(cv, ctx,
|
drawScene(cv, ctx,
|
||||||
haveSlam ? state.map : state.worldMap,
|
haveSlam ? state.map : state.worldMap,
|
||||||
haveSlam ? state.mapImage : state.worldMapImage,
|
haveSlam ? state.mapImage : state.worldMapImage,
|
||||||
state.pose, true, haveSlam ? 'lyMap' : 'lyWorld');
|
state.pose, true, haveSlam ? 'lyMap' : 'lyWorld',
|
||||||
|
haveSlam ? PALETTE.slam : PALETTE.world);
|
||||||
}
|
}
|
||||||
requestAnimationFrame(draw);
|
requestAnimationFrame(draw);
|
||||||
}
|
}
|
||||||
@@ -500,24 +603,48 @@ function draw() {
|
|||||||
|
|
||||||
let dragging = false, lastX = 0, lastY = 0;
|
let dragging = false, lastX = 0, lastY = 0;
|
||||||
|
|
||||||
cv.addEventListener('mousedown', (e) => {
|
// ⚠️ Gan cho CA HAI khung.
|
||||||
dragging = true; lastX = e.clientX; lastY = e.clientY;
|
//
|
||||||
});
|
// Truoc day chi khung trai nhan chuot, nen khung SLAM ben phai khong keo va
|
||||||
window.addEventListener('mouseup', () => { dragging = false; });
|
// khong phong to duoc -- ma do moi la khung nguoi dung nhin lau nhat khi quet.
|
||||||
window.addEventListener('mousemove', (e) => {
|
//
|
||||||
if (!dragging) return;
|
// Hai khung dung chung mot `view`, nen keo o khung nao thi ca hai cung di. Do
|
||||||
view.x -= (e.clientX - lastX) / view.scale;
|
// la co y: doi chieu duoc hai ban do la ca ly do mo hai khung.
|
||||||
view.y += (e.clientY - lastY) / view.scale;
|
for (const c of [cv, cvR]) {
|
||||||
|
c.addEventListener('mousedown', (e) => {
|
||||||
|
dragging = e.button === 2 ? 'rot' : 'pan';
|
||||||
lastX = e.clientX; lastY = e.clientY;
|
lastX = e.clientX; lastY = e.clientY;
|
||||||
view.init = true;
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
cv.addEventListener('wheel', (e) => {
|
c.addEventListener('contextmenu', (e) => e.preventDefault());
|
||||||
|
c.addEventListener('wheel', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
view.scale *= e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
view.scale *= e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
||||||
view.scale = Math.max(2, Math.min(400, view.scale));
|
view.scale = Math.max(2, Math.min(400, view.scale));
|
||||||
view.init = true;
|
view.init = true;
|
||||||
}, { passive: false });
|
}, { passive: false });
|
||||||
cv.addEventListener('dblclick', () => { centerOnMap(); });
|
c.addEventListener('dblclick', () => { view.rot = 0; centerOnMap(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('mouseup', () => { dragging = false; });
|
||||||
|
window.addEventListener('mousemove', (e) => {
|
||||||
|
if (!dragging) return;
|
||||||
|
const dx = e.clientX - lastX, dy = e.clientY - lastY;
|
||||||
|
lastX = e.clientX; lastY = e.clientY;
|
||||||
|
|
||||||
|
if (dragging === 'rot') {
|
||||||
|
// Keo ngang de xoay khung nhin. Keo sang PHAI thi canh quay sang phai.
|
||||||
|
view.rot -= dx * 0.005;
|
||||||
|
} else {
|
||||||
|
// Keo canh: canh phai di THEO tay, ke ca khi khung nhin dang xoay. Nen
|
||||||
|
// phai dua do doi man hinh NGUOC ve he the gioi truoc.
|
||||||
|
const c = Math.cos(view.rot), s_ = Math.sin(view.rot);
|
||||||
|
const wx = dx / view.scale, wy = -dy / view.scale;
|
||||||
|
view.x -= wx * c + wy * s_;
|
||||||
|
view.y -= -wx * s_ + wy * c;
|
||||||
|
}
|
||||||
|
view.init = true;
|
||||||
|
});
|
||||||
|
|
||||||
// --- Lenh ------------------------------------------------------------------
|
// --- Lenh ------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -671,6 +798,26 @@ function adjustSpeed(which, dir) {
|
|||||||
post('teleop/adjust', { axis: which, dir: dir });
|
post('teleop/adjust', { axis: which, dir: dir });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dong bo thanh truot voi gia tri server, TRU khi nguoi dung dang keo no.
|
||||||
|
// Ghi de giua luc keo lam thanh truot giat nguoc ve va khong dat duoc gia tri.
|
||||||
|
function syncRange(id, value, max) {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (!el || el === document.activeElement || el.dataset.drag === '1') return;
|
||||||
|
if (max && Number(el.max) !== max) el.max = String(max);
|
||||||
|
el.value = String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [id, axis] of [['linRange', 'lin'], ['angRange', 'ang']]) {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (!el) continue;
|
||||||
|
el.addEventListener('pointerdown', () => { el.dataset.drag = '1'; });
|
||||||
|
el.addEventListener('pointerup', () => { el.dataset.drag = '0'; });
|
||||||
|
el.addEventListener('input', () => {
|
||||||
|
txt(id === 'linRange' ? 'linSpeed' : 'angSpeed', Number(el.value).toFixed(2));
|
||||||
|
post('teleop/set', { axis: axis, value: Number(el.value) });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const b of document.querySelectorAll('.sbtn')) {
|
for (const b of document.querySelectorAll('.sbtn')) {
|
||||||
b.addEventListener('click', () => adjustSpeed(b.dataset.adj, Number(b.dataset.dir)));
|
b.addEventListener('click', () => adjustSpeed(b.dataset.adj, Number(b.dataset.dir)));
|
||||||
}
|
}
|
||||||
@@ -707,8 +854,6 @@ connect();
|
|||||||
// Tuong duong mo ca Gazebo lan RViz. Khung trai la SU THAT (de lai cho
|
// Tuong duong mo ca Gazebo lan RViz. Khung trai la SU THAT (de lai cho
|
||||||
// chuan), khung phai la cai SLAM dang dung (de biet quet toi dau). Hai khung
|
// chuan), khung phai la cai SLAM dang dung (de biet quet toi dau). Hai khung
|
||||||
// dung CHUNG `view`, nen pan/zoom khoa voi nhau va doi chieu duoc truc tiep.
|
// dung CHUNG `view`, nen pan/zoom khoa voi nhau va doi chieu duoc truc tiep.
|
||||||
const cvR = document.getElementById('mainR');
|
|
||||||
const ctxR = cvR.getContext('2d');
|
|
||||||
const btnSplit = document.getElementById('btnSplit');
|
const btnSplit = document.getElementById('btnSplit');
|
||||||
const labR = document.getElementById('labR');
|
const labR = document.getElementById('labR');
|
||||||
const wrap = document.querySelector('.canvas-wrap');
|
const wrap = document.querySelector('.canvas-wrap');
|
||||||
@@ -769,21 +914,27 @@ function loadWorldMeshes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
btn3d.addEventListener('click', () => {
|
// Bat/tat khung 3D. Tach ra khoi bo xu ly nut vi CAC NUT GOC NHIN cung goi
|
||||||
if (!use3d && !V3D.ready) {
|
// no: bam "tren" khi dang o 2D thi phai vao 3D roi moi dat goc, khong thi nut
|
||||||
|
// khong lam gi ca va nguoi dung tuong no hong.
|
||||||
|
function setThreeD(on) {
|
||||||
|
if (on && !V3D.ready) {
|
||||||
if (!v3dInit(cv3d)) {
|
if (!v3dInit(cv3d)) {
|
||||||
btn3d.textContent = '3D loi';
|
btn3d.textContent = '3D loi';
|
||||||
btn3d.classList.add('bad');
|
btn3d.classList.add('bad');
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!use3d) loadWorldMeshes();
|
if (on && !use3d) loadWorldMeshes();
|
||||||
use3d = !use3d;
|
use3d = on;
|
||||||
// Chi doi CLASS. Dat style inline o day se de bep quy tac .split trong
|
// Chi doi CLASS. Dat style inline o day se de bep quy tac .split trong
|
||||||
// stylesheet -- dung cai bay da lam khung phai den xi mot lan.
|
// stylesheet -- dung cai bay da lam khung phai den xi mot lan.
|
||||||
wrap.classList.toggle('three', use3d);
|
wrap.classList.toggle('three', use3d);
|
||||||
btn3d.textContent = use3d ? '2D' : '3D';
|
btn3d.textContent = use3d ? '2D' : '3D';
|
||||||
});
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
btn3d.addEventListener('click', () => { setThreeD(!use3d); });
|
||||||
|
|
||||||
// Khoang cach VE giua hai hinh robot -- do tren chinh hai doi tuong 3D, khong
|
// Khoang cach VE giua hai hinh robot -- do tren chinh hai doi tuong 3D, khong
|
||||||
// phai tinh lai tu du lieu.
|
// phai tinh lai tu du lieu.
|
||||||
@@ -795,12 +946,39 @@ btn3d.addEventListener('click', () => {
|
|||||||
function updateGapChip() {
|
function updateGapChip() {
|
||||||
const el = document.getElementById('gap');
|
const el = document.getElementById('gap');
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
// Sai so DU LIEU: khoang cach giua pose uoc luong va ground truth, tinh tu
|
||||||
|
// chinh hai con so server gui len.
|
||||||
|
let dData = null;
|
||||||
|
if (state.pose && state.gt) {
|
||||||
|
dData = Math.hypot(state.pose.x - state.gt.x, state.pose.y - state.gt.y);
|
||||||
|
}
|
||||||
|
// Khoang cach VE: do tren hai doi tuong 3D that su dang duoc ve.
|
||||||
|
let dDraw = null;
|
||||||
const a = V3D.robotGroup && V3D.robotGroup.position;
|
const a = V3D.robotGroup && V3D.robotGroup.position;
|
||||||
const b = V3D.gtGroup && V3D.gtGroup.position;
|
const b = V3D.gtGroup && V3D.gtGroup.position;
|
||||||
if (!a || !b || !V3D.gtGroup.visible) { el.textContent = 'gap --'; return; }
|
if (a && b && V3D.gtGroup.visible) {
|
||||||
const d = Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
|
dDraw = Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||||
el.textContent = 'gap ' + d.toFixed(3) + ' m';
|
}
|
||||||
el.classList.toggle('bad', d > 0.05);
|
if (dData === null) { el.textContent = 'gap --'; el.title = ''; return; }
|
||||||
|
// ⚠️ Hien CA HAI khi chung khac nhau.
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
el.textContent = 'gap ' + dData.toFixed(3) + ' m' +
|
||||||
|
(drift ? ' / ve ' + dDraw.toFixed(3) : '');
|
||||||
|
el.title = drift
|
||||||
|
? 'Sai so du lieu va khoang cach VE khac nhau -- con loi o tang hien thi.'
|
||||||
|
: 'Sai so uoc luong vs ground truth. Hinh ve trung thuc voi du lieu.';
|
||||||
|
el.classList.toggle('bad', dData > 0.05 || drift);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const b of document.querySelectorAll('.vbtn')) {
|
||||||
|
b.addEventListener('click', () => {
|
||||||
|
if (!setThreeD(true)) return;
|
||||||
|
v3dSetView(b.dataset.view);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw3d() {
|
function draw3d() {
|
||||||
@@ -813,7 +991,6 @@ function draw3d() {
|
|||||||
V3D.gtGroup.visible = false;
|
V3D.gtGroup.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGapChip();
|
|
||||||
v3dSetScan(on('lyScan') ? state.scan : null, state.pose, state.robot);
|
v3dSetScan(on('lyScan') ? state.scan : null, state.pose, state.robot);
|
||||||
v3dSetCloud(on('lyCloud') ? state.cloud : null, state.pose);
|
v3dSetCloud(on('lyCloud') ? state.cloud : null, state.pose);
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ function v3dInit(canvas) {
|
|||||||
// lai cua trang nay la nen toi, nhung khung 3D co bang mau RIENG -- vi muc
|
// lai cua trang nay la nen toi, nhung khung 3D co bang mau RIENG -- vi muc
|
||||||
// tieu cua no la trong giong Gazebo, va tuong trang tren nen toi doc rat te:
|
// tieu cua no la trong giong Gazebo, va tuong trang tren nen toi doc rat te:
|
||||||
// khong co bong, khong co chieu sau, moi khoi thanh mot mang bet.
|
// khong co bong, khong co chieu sau, moi khoi thanh mot mang bet.
|
||||||
V3D.scene.background = new THREE.Color(0xb8c6d4);
|
// ⚠️ Tone nay phai khop `PALETTE.world` trong app.js: hai khung cung the
|
||||||
|
// hien MOT the gioi, lech tone thi nhin nhu hai noi khac nhau.
|
||||||
|
V3D.scene.background = new THREE.Color(0xa9b8c6); // = PALETTE.world.bg
|
||||||
// Suong mu xa: ban do 2000x2000 o do phan giai 0.05 m la 100 m moi chieu,
|
// Suong mu xa: ban do 2000x2000 o do phan giai 0.05 m la 100 m moi chieu,
|
||||||
// ve het se thanh mot vung nhieu xam. Suong mu cat no mem hon la cat cung.
|
// ve het se thanh mot vung nhieu xam. Suong mu cat no mem hon la cat cung.
|
||||||
// Mau suong = mau nen, neu khong se thay mot duong chan troi gia.
|
// Mau suong = mau nen, neu khong se thay mot duong chan troi gia.
|
||||||
@@ -89,7 +91,7 @@ function v3dInit(canvas) {
|
|||||||
V3D.scene.add(V3D.root);
|
V3D.scene.add(V3D.root);
|
||||||
|
|
||||||
// Luoi san 1 m, va truc goc toa do map.
|
// Luoi san 1 m, va truc goc toa do map.
|
||||||
V3D.gridHelper = new THREE.GridHelper(40, 40, 0x93a3b3, 0xa9b6c4);
|
V3D.gridHelper = new THREE.GridHelper(40, 40, 0x93a2b0, 0xa6b3c0);
|
||||||
V3D.root.add(V3D.gridHelper);
|
V3D.root.add(V3D.gridHelper);
|
||||||
V3D.root.add(new THREE.AxesHelper(0.5));
|
V3D.root.add(new THREE.AxesHelper(0.5));
|
||||||
|
|
||||||
@@ -109,13 +111,41 @@ function v3dBindMouse(canvas) {
|
|||||||
const dx = e.clientX - V3D.dragging.x, dy = e.clientY - V3D.dragging.y;
|
const dx = e.clientX - V3D.dragging.x, dy = e.clientY - V3D.dragging.y;
|
||||||
V3D.dragging.x = e.clientX; V3D.dragging.y = e.clientY;
|
V3D.dragging.x = e.clientX; V3D.dragging.y = e.clientY;
|
||||||
if (V3D.dragging.btn === 0) {
|
if (V3D.dragging.btn === 0) {
|
||||||
|
// ⚠️ CANH DI THEO TAY, va DAU CUA HAI TRUC KHONG GIONG NHAU.
|
||||||
|
//
|
||||||
|
// Suy luan tay o day rat de sai: phep xoay lam ca VI TRI lan HE TRUC cua
|
||||||
|
// camera doi cung luc, va phan he truc moi la phan quyet dinh. Toi da
|
||||||
|
// suy sai mot lan va dao ca hai truc, lam hong truc ngang trong khi
|
||||||
|
// dang sua truc doc.
|
||||||
|
//
|
||||||
|
// Dau duoi day duoc CHOT BANG PHEP DO: `test/www/test_orbit_camera.js`
|
||||||
|
// chieu mot diem the gioi qua dung phep camera cua v3dRender() roi xem
|
||||||
|
// no di ve phia nao. Doi dau o day ma khong chay bai do lai la quay ve
|
||||||
|
// dung cho cu.
|
||||||
V3D.orbit.az -= dx * 0.006;
|
V3D.orbit.az -= dx * 0.006;
|
||||||
// Chan o hai dau: qua thien dinh thi khung nhin lat nguoc va nguoi dung
|
// Chan o hai dau: qua thien dinh thi khung nhin lat nguoc va nguoi dung
|
||||||
// mat phuong huong.
|
// mat phuong huong.
|
||||||
V3D.orbit.el = Math.max(0.05, Math.min(1.45, V3D.orbit.el + dy * 0.006));
|
V3D.orbit.el = Math.max(0.05, Math.min(1.45, V3D.orbit.el - dy * 0.006));
|
||||||
} else {
|
} else {
|
||||||
V3D.orbit.tx -= dx * 0.01;
|
// Keo canh: phai di theo HUONG NHIN, khong theo truc the gioi. Khong doi
|
||||||
V3D.orbit.ty += dy * 0.01;
|
// he thi o mot goc bat ky, keo sang phai lam canh di cheo.
|
||||||
|
//
|
||||||
|
// Dau tru: `tx`/`ty` la TAM NHIN. Canh di sang phai nghia la tam nhin
|
||||||
|
// di sang TRAI.
|
||||||
|
const c = Math.cos(V3D.orbit.az), s = Math.sin(V3D.orbit.az);
|
||||||
|
const k = V3D.orbit.dist * 0.0016;
|
||||||
|
// ⚠️ Truc DOC phai bu do rut ngan theo goc nhin.
|
||||||
|
//
|
||||||
|
// Mat san nhin cheo bi rut ngan mot he so sin(el): doi tam nhin 1 m ve
|
||||||
|
// phia truoc lam canh dich it hon nhieu so voi 1 m sang ngang. Dung
|
||||||
|
// chung mot he so cho ca hai truc lam canh KEO HUT theo chieu doc -- do
|
||||||
|
// duoc: ti le do doi 0.27 trong khi ti le keo la 0.63.
|
||||||
|
//
|
||||||
|
// Chan mau o 0.25 cho goc nhin "canh": o do sin(el) -> 0 va phep bu se
|
||||||
|
// no ra vo cuc.
|
||||||
|
const kf = k / Math.max(Math.sin(V3D.orbit.el), 0.25);
|
||||||
|
V3D.orbit.tx -= dx * s * k + dy * c * kf;
|
||||||
|
V3D.orbit.ty -= -dx * c * k + dy * s * kf;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
canvas.addEventListener('wheel', (e) => {
|
canvas.addEventListener('wheel', (e) => {
|
||||||
@@ -135,23 +165,36 @@ function v3dBuildRobot(r) {
|
|||||||
// toa do map voi san la 0.
|
// toa do map voi san la 0.
|
||||||
g.position.y = r.wheel_radius;
|
g.position.y = r.wheel_radius;
|
||||||
|
|
||||||
const bodyMat = new THREE.MeshLambertMaterial({ color: 0x3d6ea5 });
|
const bodyMat = new THREE.MeshLambertMaterial({ color: 0x1a6ea8 });
|
||||||
const darkMat = new THREE.MeshLambertMaterial({ color: 0x20262e });
|
const darkMat = new THREE.MeshLambertMaterial({ color: 0x20262e });
|
||||||
|
|
||||||
// Than: tru tron ban kinh `radius`. Chieu cao chon theo ban kinh, khong
|
// Than: KHOI HOP, dung kich thuoc that tu robot.yaml.
|
||||||
// phai mot hang so -- robot.yaml khong co chieu cao than.
|
//
|
||||||
const bodyH = r.radius * 1.2;
|
// Ban truoc ve hinh tru ban kinh `robot_radius` vi robot.yaml chua co chieu
|
||||||
|
// cao than. Nhung robot that la mot hop 0.40 x 0.34 x 0.85 m -- hinh tru
|
||||||
|
// 0.24 m lam no trong lun va tron, khong nhan ra duoc huong.
|
||||||
|
//
|
||||||
|
// `robot_radius` van la thu dung cho va cham: mot hinh tron bao ngoai hop.
|
||||||
|
// Khong dung kich thuoc hop cho va cham -- lam vay thi phep va cham phu
|
||||||
|
// thuoc goc quay, va do la mot lop bug moi.
|
||||||
|
const bodyL = r.body_l || r.radius * 1.6;
|
||||||
|
const bodyW = r.body_w || r.radius * 1.4;
|
||||||
|
const bodyH = r.body_h || r.radius * 1.2;
|
||||||
|
const clear = r.clearance || 0.0;
|
||||||
const body = new THREE.Mesh(
|
const body = new THREE.Mesh(
|
||||||
new THREE.CylinderGeometry(r.radius, r.radius, bodyH, 28), bodyMat);
|
new THREE.BoxGeometry(bodyL, bodyH, bodyW), bodyMat);
|
||||||
body.position.y = bodyH / 2;
|
// `base_link` o tam truc banh; day hop cach SAN dung `clearance`, nen tam
|
||||||
|
// hop nam tren base_link mot doan (clearance + bodyH/2 - wheel_radius).
|
||||||
|
body.position.set(r.body_off_x || 0, clear + bodyH / 2 - r.wheel_radius, 0);
|
||||||
g.add(body);
|
g.add(body);
|
||||||
|
|
||||||
// Mui chi huong +X, de nhin mot cai la biet dau la truoc.
|
// Mui chi huong +X, de nhin mot cai la biet dau la truoc.
|
||||||
const nose = new THREE.Mesh(
|
const nose = new THREE.Mesh(
|
||||||
new THREE.ConeGeometry(r.radius * 0.28, r.radius * 0.5, 16),
|
new THREE.ConeGeometry(bodyW * 0.16, bodyL * 0.22, 16),
|
||||||
new THREE.MeshLambertMaterial({ color: 0x8ec5ff }));
|
new THREE.MeshLambertMaterial({ color: 0x8ec5ff }));
|
||||||
nose.rotation.z = -Math.PI / 2;
|
nose.rotation.z = -Math.PI / 2;
|
||||||
nose.position.set(r.radius * 0.85, bodyH * 0.55, 0);
|
nose.position.set((r.body_off_x || 0) + bodyL / 2,
|
||||||
|
clear + bodyH * 0.85 - r.wheel_radius, 0);
|
||||||
g.add(nose);
|
g.add(nose);
|
||||||
|
|
||||||
// Hai banh chu dong, cach nhau `wheel_sep`.
|
// Hai banh chu dong, cach nhau `wheel_sep`.
|
||||||
@@ -402,7 +445,7 @@ function v3dSetGround(grid) {
|
|||||||
const fw = grid.w * r, fh = grid.h * r;
|
const fw = grid.w * r, fh = grid.h * r;
|
||||||
V3D.floorMesh = new THREE.Mesh(
|
V3D.floorMesh = new THREE.Mesh(
|
||||||
new THREE.PlaneGeometry(fw, fh),
|
new THREE.PlaneGeometry(fw, fh),
|
||||||
new THREE.MeshStandardMaterial({ color: 0x9aa5ad, roughness: 1.0 }));
|
new THREE.MeshStandardMaterial({ color: 0xe8edf1, roughness: 1.0 }));
|
||||||
V3D.floorMesh.rotation.x = -Math.PI / 2;
|
V3D.floorMesh.rotation.x = -Math.PI / 2;
|
||||||
V3D.floorMesh.position.set(grid.ox + fw / 2, -0.004, -(grid.oy + fh / 2));
|
V3D.floorMesh.position.set(grid.ox + fw / 2, -0.004, -(grid.oy + fh / 2));
|
||||||
V3D.floorMesh.receiveShadow = true;
|
V3D.floorMesh.receiveShadow = true;
|
||||||
@@ -416,7 +459,7 @@ function v3dSetGround(grid) {
|
|||||||
V3D.scene.fog.far = span * 1.4;
|
V3D.scene.fog.far = span * 1.4;
|
||||||
if (V3D.gridHelper) V3D.root.remove(V3D.gridHelper);
|
if (V3D.gridHelper) V3D.root.remove(V3D.gridHelper);
|
||||||
V3D.gridHelper = new THREE.GridHelper(Math.ceil(span), Math.ceil(span),
|
V3D.gridHelper = new THREE.GridHelper(Math.ceil(span), Math.ceil(span),
|
||||||
0x93a3b3, 0xa9b6c4);
|
0x93a2b0, 0xa6b3c0);
|
||||||
V3D.root.add(V3D.gridHelper);
|
V3D.root.add(V3D.gridHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,6 +726,27 @@ function v3dSetWorldVisible(on) {
|
|||||||
if (V3D.worldMesh) V3D.worldMesh.visible = on;
|
if (V3D.worldMesh) V3D.worldMesh.visible = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dat khung nhin ve mot goc chuan.
|
||||||
|
//
|
||||||
|
// Ba goc nay la ba cau hoi khac nhau: "mat bang the nao" (tren), "cao thap ra
|
||||||
|
// sao" (canh), va "tong the" (cheo). Xoay tay toi dung mot trong ba goc do rat
|
||||||
|
// kho, nen chung la nut.
|
||||||
|
function v3dSetView(name) {
|
||||||
|
if (!V3D.ready) return;
|
||||||
|
const o = V3D.orbit;
|
||||||
|
if (name === 'top') {
|
||||||
|
o.el = 1.45; // gan thien dinh; 1.5708 lam khung nhin suy bien
|
||||||
|
o.az = -Math.PI / 2; // +X sang phai, +Y len tren -- nhu khung 2D
|
||||||
|
} else if (name === 'side') {
|
||||||
|
o.el = 0.06; // sat mat san
|
||||||
|
o.az = -Math.PI / 2;
|
||||||
|
} else {
|
||||||
|
o.el = 0.55;
|
||||||
|
o.az = -2.2;
|
||||||
|
}
|
||||||
|
o.tx = 0; o.ty = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function v3dSetOverlays(on) {
|
function v3dSetOverlays(on) {
|
||||||
if (!V3D.ready || !V3D.root) return;
|
if (!V3D.ready || !V3D.root) return;
|
||||||
V3D.root.traverse((o) => {
|
V3D.root.traverse((o) => {
|
||||||
|
|||||||
@@ -20,6 +20,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<button id="btnSplit" class="chip" title="Hai khung: THE GIOI (de lai) va SLAM (de xem ban do dang dung)">chia doi</button>
|
<button id="btnSplit" class="chip" title="Hai khung: THE GIOI (de lai) va SLAM (de xem ban do dang dung)">chia doi</button>
|
||||||
<button id="btn3d" class="chip" title="Doi giua nhin tu tren (2D) va 3D">3D</button>
|
<button id="btn3d" class="chip" title="Doi giua nhin tu tren (2D) va 3D">3D</button>
|
||||||
|
<!-- Goc nhin chuan cho khung 3D. An khi dang o 2D. -->
|
||||||
|
<!-- LUON hien. An chung cho toi khi bam 3D lam chung khong tim thay duoc:
|
||||||
|
nguoi dung khong biet co thu do de ma di tim. Bam mot trong ba nut se
|
||||||
|
tu vao 3D. -->
|
||||||
|
<span id="viewBtns" class="viewgrp">
|
||||||
|
<button class="chip vbtn" data-view="top" title="Nhin tu tren xuong">tren</button>
|
||||||
|
<button class="chip vbtn" data-view="side" title="Nhin ngang, sat mat san">canh</button>
|
||||||
|
<button class="chip vbtn" data-view="iso" title="Goc cheo mac dinh">cheo</button>
|
||||||
|
</span>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<!-- ⚠️ O nay ton tai de tra loi MOT cau hoi: trinh duyet dang chay ban JS
|
<!-- ⚠️ O nay ton tai de tra loi MOT cau hoi: trinh duyet dang chay ban JS
|
||||||
nao. Sua o `www/` la sua file tinh, khong phai sua server, nen khoi
|
nao. Sua o `www/` la sua file tinh, khong phai sua server, nen khoi
|
||||||
@@ -126,20 +135,27 @@
|
|||||||
<tr><td>wz</td><td id="jwz">0.00</td></tr>
|
<tr><td>wz</td><td id="jwz">0.00</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!-- ⚠️ Thanh truot, khong phai hai nut +/-.
|
||||||
|
Buoc chinh la 0.05 m/s, nen tu 0.30 len tran 2.00 la 34 lan bam.
|
||||||
|
Nguoi van hanh bam vai cai, thay van cham, roi ket luan la lenh
|
||||||
|
khong an. `dat` hien gia tri DAT, `that` hien toc do DO DUOC tu
|
||||||
|
encoder -- hai so do khac nhau khi base con dang tang toc. -->
|
||||||
<div class="speed-row">
|
<div class="speed-row">
|
||||||
<button class="sbtn" data-adj="lin" data-dir="-1">−</button>
|
|
||||||
<span class="slabel">toc do</span>
|
<span class="slabel">toc do</span>
|
||||||
|
<input type="range" id="linRange" class="srange"
|
||||||
|
min="0.05" max="2.00" step="0.05" value="0.30">
|
||||||
<span id="linSpeed" class="sval">0.30</span>
|
<span id="linSpeed" class="sval">0.30</span>
|
||||||
<button class="sbtn" data-adj="lin" data-dir="1">+</button>
|
<span id="linReal" class="sreal">0.00</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="speed-row">
|
<div class="speed-row">
|
||||||
<button class="sbtn" data-adj="ang" data-dir="-1">−</button>
|
|
||||||
<span class="slabel">quay</span>
|
<span class="slabel">quay</span>
|
||||||
|
<input type="range" id="angRange" class="srange"
|
||||||
|
min="0.10" max="2.00" step="0.05" value="0.70">
|
||||||
<span id="angSpeed" class="sval">0.70</span>
|
<span id="angSpeed" class="sval">0.70</span>
|
||||||
<button class="sbtn" data-adj="ang" data-dir="1">+</button>
|
<span id="angReal" class="sreal">0.00</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hint-sm">keo joystick · phim mui ten · Space = dung<br>+ − hoac Q E de chinh toc do</div>
|
<div class="hint-sm">keo joystick · phim mui ten · Space = dung<br>keo thanh truot hoac Q E de chinh toc do · so mo la toc do DO DUOC</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="controls">
|
<section class="controls">
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
/* Mot trang, khong dependency. Muc tieu < 60 kB cho ca ba file. */
|
/* Mot trang, khong dependency. Muc tieu < 60 kB cho ca ba file. */
|
||||||
:root {
|
:root {
|
||||||
--bg: #12151a;
|
/* Tone SANG. Moi mau di theo cap voi mot mau tren canvas -- xem
|
||||||
--panel: #1a1f27;
|
`CANVAS` trong app.js. Doi mot ben ma quen ben kia se lam ban do chim
|
||||||
--line: #2a323d;
|
vao nen: o bi chiem tung duoc ve SANG cho nen toi. */
|
||||||
--fg: #d6dde7;
|
--bg: #eef1f6;
|
||||||
--dim: #7c8798;
|
--panel: #ffffff;
|
||||||
--ok: #4ec9a0;
|
--line: #ccd5e0;
|
||||||
--warn: #e0b34a;
|
--fg: #1c232c;
|
||||||
--bad: #e2574c;
|
--dim: #66717f;
|
||||||
--accent: #5aa9e6;
|
--ok: #157a56;
|
||||||
|
--warn: #8a6100;
|
||||||
|
--bad: #c0392b;
|
||||||
|
--accent: #1f6fb8;
|
||||||
|
--chip: #e3e9f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
* { box-sizing: border-box; }
|
* { box-sizing: border-box; }
|
||||||
@@ -31,10 +35,10 @@ header {
|
|||||||
|
|
||||||
.chip {
|
.chip {
|
||||||
padding: 3px 10px; border-radius: 3px;
|
padding: 3px 10px; border-radius: 3px;
|
||||||
background: #222a34; border: 1px solid var(--line);
|
background: var(--chip); border: 1px solid var(--line);
|
||||||
}
|
}
|
||||||
.chip.ok { color: var(--ok); border-color: #2c5b4c; }
|
.chip.ok { color: var(--ok); border-color: #9ccbb9; }
|
||||||
.chip.bad { color: var(--bad); border-color: #5b2f2c; }
|
.chip.bad { color: var(--bad); border-color: #e0a9a3; }
|
||||||
|
|
||||||
main { display: flex; height: calc(100% - 41px); }
|
main { display: flex; height: calc(100% - 41px); }
|
||||||
|
|
||||||
@@ -63,22 +67,22 @@ aside td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
|
|||||||
|
|
||||||
.state {
|
.state {
|
||||||
padding: 5px 8px; border-radius: 3px; text-align: center;
|
padding: 5px 8px; border-radius: 3px; text-align: center;
|
||||||
background: #222a34; border: 1px solid var(--line); margin-bottom: 4px;
|
background: var(--chip); border: 1px solid var(--line); margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
.state.ok { color: var(--ok); border-color: #2c5b4c; }
|
.state.ok { color: var(--ok); border-color: #9ccbb9; }
|
||||||
.state.warn { color: var(--warn); border-color: #5b4d2c; }
|
.state.warn { color: var(--warn); border-color: #d9c48a; }
|
||||||
.state.bad { color: var(--bad); border-color: #5b2f2c; }
|
.state.bad { color: var(--bad); border-color: #e0a9a3; }
|
||||||
.detail { color: var(--dim); font-size: 11px; min-height: 16px; margin-bottom: 4px; }
|
.detail { color: var(--dim); font-size: 11px; min-height: 16px; margin-bottom: 4px; }
|
||||||
|
|
||||||
.controls { display: flex; gap: 8px; }
|
.controls { display: flex; gap: 8px; }
|
||||||
button {
|
button {
|
||||||
flex: 1; padding: 9px; cursor: pointer;
|
flex: 1; padding: 9px; cursor: pointer;
|
||||||
background: #222a34; color: var(--fg);
|
background: var(--chip); color: var(--fg);
|
||||||
border: 1px solid var(--line); border-radius: 3px;
|
border: 1px solid var(--line); border-radius: 3px;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
button:hover { border-color: var(--accent); }
|
button:hover { border-color: var(--accent); }
|
||||||
button.danger { color: var(--bad); border-color: #5b2f2c; }
|
button.danger { color: var(--bad); border-color: #e0a9a3; }
|
||||||
button.danger:hover { background: var(--bad); color: #fff; }
|
button.danger:hover { background: var(--bad); color: #fff; }
|
||||||
|
|
||||||
/* --- Joystick ---
|
/* --- Joystick ---
|
||||||
@@ -90,7 +94,7 @@ button.danger:hover { background: var(--bad); color: #fff; }
|
|||||||
position: relative;
|
position: relative;
|
||||||
width: 160px; height: 160px;
|
width: 160px; height: 160px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: radial-gradient(circle at 50% 50%, #222a34 0%, #1a1f27 70%);
|
background: radial-gradient(circle at 50% 50%, #ffffff 0%, #dfe6ef 70%);
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
touch-action: none; /* tat pan/zoom cua trinh duyet khi keo */
|
touch-action: none; /* tat pan/zoom cua trinh duyet khi keo */
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@@ -166,3 +170,14 @@ button.danger:hover { background: var(--bad); color: #fff; }
|
|||||||
}
|
}
|
||||||
#labL { left: 8px; }
|
#labL { left: 8px; }
|
||||||
#labR { left: 50%; margin-left: 8px; }
|
#labR { left: 50%; margin-left: 8px; }
|
||||||
|
|
||||||
|
/* Thanh truot toc do. `sval` la gia tri DAT, `sreal` la toc do DO DUOC. */
|
||||||
|
.speed-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
|
||||||
|
.srange { flex: 1; min-width: 70px; accent-color: var(--accent); }
|
||||||
|
.sval { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
|
||||||
|
.sreal {
|
||||||
|
font-variant-numeric: tabular-nums; min-width: 34px; text-align: right;
|
||||||
|
color: var(--dim); font-size: 11px;
|
||||||
|
}
|
||||||
|
.viewgrp { display: inline-flex; gap: 4px; }
|
||||||
|
.viewgrp[hidden] { display: none; }
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ if(VSLAM_BUILD_SIM)
|
|||||||
vslam_add_test(test_sim_source LIBS vslam_sim vslam_drivers vslam_common)
|
vslam_add_test(test_sim_source LIBS vslam_sim vslam_drivers vslam_common)
|
||||||
# Doc `.world` cua Gazebo. Fixture rieng trong test/data/world -- KHONG can
|
# Doc `.world` cua Gazebo. Fixture rieng trong test/data/world -- KHONG can
|
||||||
# bo model 3 GB cua AWS, nen bai kiem nay chay duoc tren may sach.
|
# bo model 3 GB cua AWS, nen bai kiem nay chay duoc tren may sach.
|
||||||
vslam_add_test(test_gazebo_world LIBS vslam_sim vslam_common)
|
vslam_add_test(test_gazebo_world LIBS vslam_sim vslam_drivers vslam_common)
|
||||||
if(VSLAM_BUILD_ODOMETRY)
|
if(VSLAM_BUILD_ODOMETRY)
|
||||||
# Test TICH HOP: sim -> encoder -> wheel_odom -> EKF, do sai so so voi
|
# Test TICH HOP: sim -> encoder -> wheel_odom -> EKF, do sai so so voi
|
||||||
# ground truth. Day la bai L2 cua repo cu viet lai khong ROS.
|
# ground truth. Day la bai L2 cua repo cu viet lai khong ROS.
|
||||||
@@ -206,6 +206,21 @@ if(VSLAM_NODE_EXE AND TARGET vslam_world_export)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/www/test_robot_marker.js)
|
${CMAKE_CURRENT_SOURCE_DIR}/www/test_robot_marker.js)
|
||||||
set_tests_properties(www_robot_marker PROPERTIES
|
set_tests_properties(www_robot_marker PROPERTIES
|
||||||
PASS_REGULAR_EXPRESSION "=> DAT")
|
PASS_REGULAR_EXPRESSION "=> DAT")
|
||||||
|
# Phep bien doi cua khung 2D: xoay + keo canh. Bat bien duoc kiem la "diem
|
||||||
|
# duoi con tro o nguyen duoi con tro sau khi keo", dung o MOI goc xoay.
|
||||||
|
add_test(NAME www_view_transform
|
||||||
|
COMMAND ${VSLAM_NODE_EXE}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/www/test_view_transform.js)
|
||||||
|
set_tests_properties(www_view_transform PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION "=> DAT")
|
||||||
|
# Chieu keo chuot trong khung 3D. Suy luan tay o day rat de sai vi phep xoay
|
||||||
|
# doi CA vi tri lan he truc cua camera cung luc -- da sua sai mot lan. Bai
|
||||||
|
# kiem chieu mot diem the gioi qua dung phep camera roi DO xem no di dau.
|
||||||
|
add_test(NAME www_orbit_camera
|
||||||
|
COMMAND ${VSLAM_NODE_EXE}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/www/test_orbit_camera.js)
|
||||||
|
set_tests_properties(www_orbit_camera PROPERTIES
|
||||||
|
PASS_REGULAR_EXPRESSION "=> DAT")
|
||||||
else()
|
else()
|
||||||
message(STATUS "vslam: khong tim thay `node` -- bo qua bai kiem frontend")
|
message(STATUS "vslam: khong tim thay `node` -- bo qua bai kiem frontend")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -269,3 +269,87 @@ TEST(GazeboWorld, MaHoaGhiDeKhongNoiThem) {
|
|||||||
vslam::EncodeWorldMeshes(wm, &blob);
|
vslam::EncodeWorldMeshes(wm, &blob);
|
||||||
EXPECT_EQ(blob.size(), once);
|
EXPECT_EQ(blob.size(), once);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
// RAYCAST PHAI DUNG O MAT TUONG, KHONG O BIEN O LUOI
|
||||||
|
// ===========================================================================
|
||||||
|
//
|
||||||
|
// ⚠️ DDA tren luoi tra ve khoang cach toi MAT VAO cua o bi chiem dau tien, ma
|
||||||
|
// o do chi duoc danh dau khi tam giac di qua TAM o. Mat vao ay nam lui vao
|
||||||
|
// trong tuong toi mot o day du.
|
||||||
|
//
|
||||||
|
// Do tren the gioi benh vien, khoang cach tu diem quet toi mat tuong NHIN
|
||||||
|
// THAY: p50 = 3.7 cm, p90 = 5.6 cm. MOI tia deu dung som. Nguoi van hanh nhin
|
||||||
|
// thay vanh quet lo lung truoc tuong va tuong la robot bi troi -- trong khi
|
||||||
|
// sai so dinh vi that chi 0.9 cm.
|
||||||
|
//
|
||||||
|
// Loi nay khong lam gi hong theo nghia van hanh: dung so tia, dung nhip,
|
||||||
|
// khong mot ngoai le nao. Chi co hinh hoc moi phat hien duoc.
|
||||||
|
|
||||||
|
#include "vslam/sim_source.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Hop `box_m_1` trong mini.world: 2.0 x 1.0 x 0.5 m, tam o goc toa do.
|
||||||
|
// Mat x duong o x = +1.0, mat y duong o y = +0.5.
|
||||||
|
std::unique_ptr<vslam::SimSource> OpenMiniSim() {
|
||||||
|
vslam::SimConfig sc;
|
||||||
|
sc.world_path = DataDir() + "/world/mini.world";
|
||||||
|
sc.world_model_paths = {DataDir() + "/world/models"};
|
||||||
|
// Goc toa do nam TRONG hop `box_m_1`, nen phai xuat phat cho khac.
|
||||||
|
sc.start_x = 5.0;
|
||||||
|
sc.start_y = 3.0;
|
||||||
|
auto sim = std::unique_ptr<vslam::SimSource>(new vslam::SimSource(sc));
|
||||||
|
const vslam::StatusResponse st = sim->Open();
|
||||||
|
EXPECT_TRUE(st.ok()) << st.message;
|
||||||
|
return sim;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Bo tri mini.world:
|
||||||
|
// box_m_1 (0, 0) x [-1, 1] y [-0.5, 0.5]
|
||||||
|
// box_cm_1 (5, 0) box_mtx_1 (10, 0) box_zup_1 (15, 0)
|
||||||
|
// box_m_2 (0, 6) quay 90 do: x [-0.5, 0.5] y [5, 7]
|
||||||
|
// Luoi phu x [-2, 17], y [-1.5, 8]. Ban tu ngoai vung do la vo nghia.
|
||||||
|
TEST(GazeboWorld, RaycastDungOMatTuong) {
|
||||||
|
auto sim = OpenMiniSim();
|
||||||
|
|
||||||
|
// Tu (0, 3) ban xuong: cham mat tren cua box_m_1 o y = +0.5 -> 2.500 m.
|
||||||
|
EXPECT_NEAR(sim->RangeForTest(0.0, 3.0, -M_PI_2), 2.500, 0.002);
|
||||||
|
|
||||||
|
// Tu (0, 3) ban len: cham mat duoi cua box_m_2 o y = 5 -> 2.000 m.
|
||||||
|
EXPECT_NEAR(sim->RangeForTest(0.0, 3.0, M_PI_2), 2.000, 0.002);
|
||||||
|
|
||||||
|
// Tu (2.5, 0) ban sang trai: cham mat x = +1.0 -> 1.500 m.
|
||||||
|
EXPECT_NEAR(sim->RangeForTest(2.5, 0.0, M_PI), 1.500, 0.002);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tia CHEO la phep kiem that su.
|
||||||
|
//
|
||||||
|
// Tia truc chinh co the dung TINH CO: bien o thang hang voi mat tuong khi goc
|
||||||
|
// luoi roi dung cho. Tia cheo cham mat tuong o mot diem khong phai bien o nao,
|
||||||
|
// nen no chi dung khi da that su cat voi tam giac.
|
||||||
|
TEST(GazeboWorld, RaycastCheoCungDungOMatTuong) {
|
||||||
|
auto sim = OpenMiniSim();
|
||||||
|
|
||||||
|
// Tu (3, 3) ngam toi (0, 0.5) -- mot diem GIUA mat tren cua box_m_1.
|
||||||
|
const double dx = 0.0 - 3.0, dy = 0.5 - 3.0;
|
||||||
|
const double want = std::sqrt(dx * dx + dy * dy);
|
||||||
|
EXPECT_NEAR(sim->RangeForTest(3.0, 3.0, std::atan2(dy, dx)), want, 0.003);
|
||||||
|
|
||||||
|
// ⚠️ Dung sai 3 mm o tren la phep kiem: luoi 0.05 m, nen mot ket qua bi
|
||||||
|
// luong tu hoa se lech toi 50 mm. Khong the lot.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Khong co mesh (chay tu `--map`) thi phai giu nguyen duong cu, khong hong.
|
||||||
|
TEST(GazeboWorld, KhongCoMeshThiVanChay) {
|
||||||
|
vslam::SimConfig sc; // khong world_path, khong map_yaml
|
||||||
|
vslam::SimSource sim(sc);
|
||||||
|
ASSERT_TRUE(sim.Open().ok());
|
||||||
|
// The gioi tong hop: co tuong, nen phai do duoc mot cu ly huu han o dau do.
|
||||||
|
const double r = sim.RangeForTest(sim.ground_truth().x, sim.ground_truth().y,
|
||||||
|
0.0);
|
||||||
|
EXPECT_GT(r, 0.0);
|
||||||
|
EXPECT_TRUE(std::isfinite(r) || std::isinf(r));
|
||||||
|
}
|
||||||
|
|||||||
240
test/www/test_orbit_camera.js
Normal file
240
test/www/test_orbit_camera.js
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
// Chuot trong khung 3D: canh phai di THEO tay.
|
||||||
|
//
|
||||||
|
// ================== VI SAO CAN BAI KIEM NAY ==================
|
||||||
|
// Da sua chieu keo mot lan bang cach suy luan, va sai: dao dung truc azimuth
|
||||||
|
// thi dung, nhung dao ca truc elevation thi hong, va phep keo canh thi nguoc
|
||||||
|
// hoan toan. Khong mot loi nao -- canh van ve, chi la no di nguoc tay.
|
||||||
|
//
|
||||||
|
// Nen bai kiem nay khong doc ma nguon ma DO: chieu mot diem the gioi qua dung
|
||||||
|
// phep camera cua `v3dRender()`, keo chuot, roi xem diem do di ve phia nao
|
||||||
|
// tren man hinh.
|
||||||
|
//
|
||||||
|
// Bat bien: keo sang PHAI thi diem di sang PHAI; keo XUONG thi diem di XUONG.
|
||||||
|
// Voi phep KEO CANH con chat hon: diem duoi con tro phai O NGUYEN duoi con
|
||||||
|
// tro, y nhu khung 2D.
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const vm = require('vm');
|
||||||
|
|
||||||
|
// --- THREE gia: chi can du de app3d.js chay den cho gan chuot ---
|
||||||
|
class V3 {
|
||||||
|
constructor(x, y, z) { this.x = x || 0; this.y = y || 0; this.z = z || 0; }
|
||||||
|
set(x, y, z) { this.x = x; this.y = y; this.z = z; return this; }
|
||||||
|
copy(o) { this.x = o.x; this.y = o.y; this.z = o.z; return this; }
|
||||||
|
}
|
||||||
|
const node = () => ({ position: new V3(), rotation: { x: 0, y: 0, z: 0 },
|
||||||
|
userData: {}, visible: true });
|
||||||
|
class Grp {
|
||||||
|
constructor() { Object.assign(this, node()); this.children = []; }
|
||||||
|
add(c) { this.children.push(c); }
|
||||||
|
remove(c) { this.children = this.children.filter((x) => x !== c); }
|
||||||
|
traverse(f) { f(this); this.children.forEach((c) => (c.traverse ? c.traverse(f) : f(c))); }
|
||||||
|
}
|
||||||
|
const leafCls = () => class { constructor(g, m) { Object.assign(this, node());
|
||||||
|
this.geometry = g; this.material = m; } };
|
||||||
|
const matCls = () => class {
|
||||||
|
constructor(o) { Object.assign(this, o); this.color = { set() {}, setHSL() {} }; }
|
||||||
|
clone() { const c = Object.create(Object.getPrototypeOf(this));
|
||||||
|
Object.assign(c, this); c.color = { set() {}, setHSL() {} }; return c; }
|
||||||
|
dispose() {}
|
||||||
|
};
|
||||||
|
global.THREE = {
|
||||||
|
Group: Grp, Mesh: leafCls(), Line: leafCls(), LineLoop: leafCls(),
|
||||||
|
LineSegments: leafCls(), Points: leafCls(), Vector3: V3,
|
||||||
|
MeshLambertMaterial: matCls(), MeshStandardMaterial: matCls(),
|
||||||
|
LineBasicMaterial: matCls(), PointsMaterial: matCls(),
|
||||||
|
CylinderGeometry: class {}, ConeGeometry: class {}, BoxGeometry: class { dispose() {} },
|
||||||
|
PlaneGeometry: class { dispose() {} },
|
||||||
|
GridHelper: class { constructor() { Object.assign(this, node()); } },
|
||||||
|
BufferGeometry: class {
|
||||||
|
constructor() { this.attributes = {}; }
|
||||||
|
setAttribute(n, a) { this.attributes[n] = a; }
|
||||||
|
setFromPoints() { return this; } computeVertexNormals() {} dispose() {}
|
||||||
|
},
|
||||||
|
BufferAttribute: class { constructor(a, n) { this.array = a; this.itemSize = n; } },
|
||||||
|
InstancedMesh: class { constructor() { Object.assign(this, node());
|
||||||
|
this.instanceMatrix = {}; }
|
||||||
|
setMatrixAt() {} dispose() {} },
|
||||||
|
Matrix4: class { compose() {} }, Quaternion: class { setFromAxisAngle() {} },
|
||||||
|
Color: class { constructor() { this.set = () => {}; this.setHSL = () => {}; } },
|
||||||
|
Scene: class { constructor() { Object.assign(this, node()); this.fog = { near: 0, far: 0 }; } },
|
||||||
|
PerspectiveCamera: class { constructor() { Object.assign(this, node());
|
||||||
|
this.lookAt = () => {}; } },
|
||||||
|
WebGLRenderer: class { constructor() { this.shadowMap = {}; }
|
||||||
|
setPixelRatio() {} setSize() {} render() {} },
|
||||||
|
HemisphereLight: class { constructor() { Object.assign(this, node()); } },
|
||||||
|
DirectionalLight: class { constructor() { Object.assign(this, node());
|
||||||
|
this.shadow = { camera: {}, mapSize: {} }; } },
|
||||||
|
AmbientLight: class { constructor() { Object.assign(this, node()); } },
|
||||||
|
Fog: class {}, FogExp2: class {},
|
||||||
|
PCFSoftShadowMap: 1, DoubleSide: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- canvas + window gia, bat lay bo xu ly chuot ---
|
||||||
|
const H = { win: {}, cv: {} };
|
||||||
|
const canvas = {
|
||||||
|
clientWidth: 900, clientHeight: 600, width: 900, height: 600,
|
||||||
|
addEventListener(ev, fn) { H.cv[ev] = fn; },
|
||||||
|
getContext: () => new Proxy({}, { get: () => () => {} }),
|
||||||
|
};
|
||||||
|
const sandbox = {
|
||||||
|
THREE: global.THREE, console,
|
||||||
|
window: { addEventListener(ev, fn) { H.win[ev] = fn; }, devicePixelRatio: 1 },
|
||||||
|
document: { createElement: () => canvas },
|
||||||
|
};
|
||||||
|
vm.createContext(sandbox);
|
||||||
|
vm.runInContext(
|
||||||
|
fs.readFileSync(path.resolve(
|
||||||
|
'/home/quangtrung/projects/vslam_cpp/libs/vslam_web/www/app3d.js'), 'utf8') +
|
||||||
|
'\n;this.__V3D = V3D; this.__bind = v3dBindMouse; this.__setView = v3dSetView;',
|
||||||
|
sandbox);
|
||||||
|
|
||||||
|
const V3D = sandbox.__V3D;
|
||||||
|
V3D.ready = true;
|
||||||
|
V3D.root = new Grp();
|
||||||
|
sandbox.__bind(canvas);
|
||||||
|
|
||||||
|
// --- Chieu mot diem the gioi len man hinh, dung phep camera cua v3dRender ---
|
||||||
|
//
|
||||||
|
// Camera dat o goc cau quanh tam nhin, nhin ve tam, up = +Y. Day la copy
|
||||||
|
// nguyen van cong thuc trong v3dRender() -- neu cong thuc do doi ma o day
|
||||||
|
// khong doi, bai kiem se bao sai va do la dieu MONG MUON: hai noi phai khop.
|
||||||
|
function project(p) {
|
||||||
|
const o = V3D.orbit;
|
||||||
|
const cx = o.tx, cz = o.ty;
|
||||||
|
const cam = {
|
||||||
|
x: cx + o.dist * Math.cos(o.el) * Math.cos(o.az),
|
||||||
|
y: o.dist * Math.sin(o.el),
|
||||||
|
z: cz + o.dist * Math.cos(o.el) * Math.sin(o.az),
|
||||||
|
};
|
||||||
|
const tgt = { x: cx, y: 0.2, z: cz };
|
||||||
|
const sub = (a, b) => ({ x: a.x - b.x, y: a.y - b.y, z: a.z - b.z });
|
||||||
|
const norm = (v) => { const n = Math.hypot(v.x, v.y, v.z);
|
||||||
|
return { x: v.x / n, y: v.y / n, z: v.z / n }; };
|
||||||
|
const cross = (a, b) => ({ x: a.y * b.z - a.z * b.y,
|
||||||
|
y: a.z * b.x - a.x * b.z,
|
||||||
|
z: a.x * b.y - a.y * b.x });
|
||||||
|
const dot = (a, b) => a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
|
const fwd = norm(sub(tgt, cam)); // huong nhin
|
||||||
|
const right = norm(cross(fwd, { x: 0, y: 1, z: 0 }));
|
||||||
|
const up = cross(right, fwd);
|
||||||
|
const d = sub(p, cam);
|
||||||
|
const depth = dot(d, fwd);
|
||||||
|
if (depth <= 1e-6) return null; // sau lung camera
|
||||||
|
// Phoi canh: chia cho do sau. He so tieu cu khong doi ket qua ve CHIEU.
|
||||||
|
return { x: dot(d, right) / depth, y: dot(d, up) / depth, depth };
|
||||||
|
}
|
||||||
|
|
||||||
|
const bad = [];
|
||||||
|
const P = { x: 2.0, y: 0.0, z: 1.0 }; // mot diem co dinh trong canh
|
||||||
|
|
||||||
|
// --- TU KIEM phep chieu truoc khi tin no ---
|
||||||
|
//
|
||||||
|
// Mot bai kiem sai co the to cao code dung. Ba tinh huong duoi day co dap an
|
||||||
|
// biet truoc, khong phu thuoc vao app3d.js chut nao.
|
||||||
|
{
|
||||||
|
V3D.orbit.az = -2.2; V3D.orbit.el = 0.55; V3D.orbit.dist = 6.0;
|
||||||
|
V3D.orbit.tx = 0; V3D.orbit.ty = 0;
|
||||||
|
const o = V3D.orbit;
|
||||||
|
const cam = { x: o.dist * Math.cos(o.el) * Math.cos(o.az),
|
||||||
|
y: o.dist * Math.sin(o.el),
|
||||||
|
z: o.dist * Math.cos(o.el) * Math.sin(o.az) };
|
||||||
|
const fwd = { x: -cam.x, y: 0.2 - cam.y, z: -cam.z };
|
||||||
|
const n = Math.hypot(fwd.x, fwd.y, fwd.z);
|
||||||
|
const f = { x: fwd.x / n, y: fwd.y / n, z: fwd.z / n };
|
||||||
|
const rN = Math.hypot(-f.z, 0, f.x);
|
||||||
|
const right = { x: -f.z / rN, y: 0, z: f.x / rN };
|
||||||
|
|
||||||
|
const c0 = project({ x: 0, y: 0.2, z: 0 }); // dung tam nhin
|
||||||
|
const cR = project({ x: right.x, y: 0.2, z: right.z }); // lech sang PHAI 1 m
|
||||||
|
const cU = project({ x: 0, y: 1.2, z: 0 }); // cao hon 1 m
|
||||||
|
const good = Math.abs(c0.x) < 1e-9 && Math.abs(c0.y) < 1e-9 &&
|
||||||
|
cR.x > 0 && cU.y > 0;
|
||||||
|
console.log(` tu kiem: tam=(${c0.x.toFixed(3)}, ${c0.y.toFixed(3)}) ` +
|
||||||
|
`phai.x=${cR.x.toFixed(3)} cao.y=${cU.y.toFixed(3)}` +
|
||||||
|
(good ? '' : ' <-- PHEP CHIEU CUA BAI KIEM SAI'));
|
||||||
|
if (!good) { bad.push('tu kiem phep chieu'); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function drag(btn, dx, dy) {
|
||||||
|
H.cv.mousedown({ clientX: 100, clientY: 100, button: btn, preventDefault() {} });
|
||||||
|
H.win.mousemove({ clientX: 100 + dx, clientY: 100 + dy });
|
||||||
|
H.win.mouseup();
|
||||||
|
}
|
||||||
|
|
||||||
|
function check(label, btn, dx, dy, wantX, wantY) {
|
||||||
|
V3D.orbit.az = -2.2; V3D.orbit.el = 0.55; V3D.orbit.dist = 6.0;
|
||||||
|
V3D.orbit.tx = 0; V3D.orbit.ty = 0;
|
||||||
|
const a = project(P);
|
||||||
|
drag(btn, dx, dy);
|
||||||
|
const b = project(P);
|
||||||
|
if (!a || !b) { bad.push(label + ' (diem ra sau camera)'); return; }
|
||||||
|
const mx = b.x - a.x, my = b.y - a.y;
|
||||||
|
// Truc y cua MAN HINH huong xuong, con `up` cua camera huong len -> dao dau.
|
||||||
|
const sx = mx, sy = -my;
|
||||||
|
// ⚠️ `null` = KHONG XET. Phep xoay lam diem lech tam di theo cung, nen mot
|
||||||
|
// cu keo ngang cung sinh do doi doc -- doi truc kia bang 0 la doi sai.
|
||||||
|
const okx = wantX === null ? true : Math.sign(sx) === wantX;
|
||||||
|
const oky = wantY === null ? true : Math.sign(sy) === wantY;
|
||||||
|
const nm = (v) => (v > 0 ? 'phai/xuong' : v < 0 ? 'trai/len' : 'khong doi');
|
||||||
|
console.log(` ${label.padEnd(34)} diem di ${nm(sx).padEnd(11)} ` +
|
||||||
|
`${nm(sy).padEnd(11)} ${okx && oky ? '' : ' <-- SAI'}`);
|
||||||
|
if (!okx || !oky) bad.push(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(' --- keo TRAI (xoay) ---');
|
||||||
|
check('keo sang phai -> canh sang phai', 0, 60, 0, +1, null);
|
||||||
|
check('keo sang trai -> canh sang trai', 0, -60, 0, -1, null);
|
||||||
|
check('keo xuong -> canh xuong', 0, 0, 50, null, +1);
|
||||||
|
check('keo len -> canh len', 0, 0, -50, null, -1);
|
||||||
|
|
||||||
|
console.log(' --- keo PHAI (di chuyen canh) ---');
|
||||||
|
check('keo sang phai -> canh sang phai', 2, 60, 0, +1, null);
|
||||||
|
check('keo xuong -> canh xuong', 2, 0, 50, null, +1);
|
||||||
|
|
||||||
|
// ⚠️ Keo canh phai giu DIEM DUOI CON TRO. Chi kiem chieu thoi thi mot phep
|
||||||
|
// keo qua manh hay qua nhe van "dung chieu".
|
||||||
|
// Keo canh: HAI TRUC phai cung ti le.
|
||||||
|
//
|
||||||
|
// Khong doi khoa cung vao con tro -- phep chieu la phoi canh, muon khoa cung
|
||||||
|
// thi phai cat tia voi mat san. Gazebo cung khong khoa cung. Cai PHAI dung la
|
||||||
|
// hai truc cung ti le: keo cheo 40:25 thi canh cung phai di cheo xap xi 40:25,
|
||||||
|
// khong phai 40:11 nhu khi quen bu do rut ngan theo goc nhin.
|
||||||
|
console.log(' --- keo canh: hai truc cung ti le ---');
|
||||||
|
for (const az of [-2.2, 0.0, 1.1]) {
|
||||||
|
V3D.orbit.az = az; V3D.orbit.el = 0.55; V3D.orbit.dist = 6.0;
|
||||||
|
V3D.orbit.tx = 0; V3D.orbit.ty = 0;
|
||||||
|
// ⚠️ Do o DUNG TAM NHIN. Mot diem lech tam bi phoi canh lam meo ti le theo
|
||||||
|
// do sau, va do sau lai doi theo goc nhin -- do la bien so cua PHEP DO, chu
|
||||||
|
// khong phai cua code.
|
||||||
|
const Q = { x: 0, y: 0.2, z: 0 };
|
||||||
|
const a = project(Q);
|
||||||
|
drag(2, 40, 25);
|
||||||
|
const b = project(Q);
|
||||||
|
// Do doi tren man hinh, quy ve pixel bang cung mot he so cho ca hai truc.
|
||||||
|
const errx = (b.x - a.x), erry = -(b.y - a.y);
|
||||||
|
console.log(` az=${az.toFixed(1).padStart(5)} do doi = ` +
|
||||||
|
`(${errx.toFixed(4)}, ${erry.toFixed(4)}) ti le ` +
|
||||||
|
`${(errx === 0 ? 0 : erry / errx).toFixed(3)}`);
|
||||||
|
// Ti le do doi phai khop ti le keo (25/40 = 0.625), va cung dau.
|
||||||
|
const want = 25 / 40;
|
||||||
|
const got = erry / errx;
|
||||||
|
if (!(errx > 0 && erry > 0 && got > want / 1.7 && got < want * 1.7)) {
|
||||||
|
bad.push('keo canh @ az=' + az.toFixed(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Nut goc nhin ---
|
||||||
|
console.log(' --- nut goc nhin ---');
|
||||||
|
for (const [name, wantEl] of [['top', 1.45], ['side', 0.06], ['iso', 0.55]]) {
|
||||||
|
V3D.orbit.tx = 9; V3D.orbit.ty = 9;
|
||||||
|
sandbox.__setView(name);
|
||||||
|
const o = V3D.orbit;
|
||||||
|
const ok = Math.abs(o.el - wantEl) < 1e-9 && o.tx === 0 && o.ty === 0;
|
||||||
|
console.log(` ${name.padEnd(6)} el=${o.el.toFixed(2)} az=${o.az.toFixed(2)} ` +
|
||||||
|
`tx=${o.tx} ty=${o.ty}${ok ? '' : ' <-- SAI'}`);
|
||||||
|
if (!ok) bad.push('goc nhin ' + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(bad.length ? '\n => HONG: ' + bad.join(', ') : '\n => DAT');
|
||||||
|
process.exit(bad.length ? 1 : 0);
|
||||||
233
test/www/test_view_transform.js
Normal file
233
test/www/test_view_transform.js
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
// Phep bien doi cua khung 2D: xoay, keo canh, va hinh hop robot.
|
||||||
|
//
|
||||||
|
// ================== VI SAO CAN BAI KIEM NAY ==================
|
||||||
|
// Khung 2D vua co them phep XOAY. Ba thu phai dung cung luc: phep chieu
|
||||||
|
// (`sx`/`sy`), phep keo canh (phai nghich dao dung phep xoay), va hinh robot.
|
||||||
|
//
|
||||||
|
// Sai mot dau se khong gay loi nao: canh van ve, robot van hien, chi la keo
|
||||||
|
// chuot sang phai thi canh di cheo. Da co ba lan lien tiep loi nam o tang
|
||||||
|
// hien thi trong khi build sach va ctest xanh.
|
||||||
|
//
|
||||||
|
// Phep kiem manh nhat la BAT BIEN: diem the gioi nam duoi con tro phai O
|
||||||
|
// NGUYEN duoi con tro sau khi keo. Do la dinh nghia cua "canh di theo tay",
|
||||||
|
// va no dung o MOI goc xoay.
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const vm = require('vm');
|
||||||
|
|
||||||
|
// --- DOM gia: du de app.js chay het pham vi module ---
|
||||||
|
const handlers = { window: {}, el: {} };
|
||||||
|
function mkEl(id) {
|
||||||
|
const h = {};
|
||||||
|
return {
|
||||||
|
id, checked: true, value: '0', max: '2', dataset: {}, style: {}, hidden: false,
|
||||||
|
textContent: '', classList: { add() {}, remove() {}, toggle() {} },
|
||||||
|
clientWidth: 800, clientHeight: 600, width: 800, height: 600,
|
||||||
|
addEventListener(ev, fn) { (handlers.el[id] = handlers.el[id] || {})[ev] = fn; },
|
||||||
|
getContext() {
|
||||||
|
// ⚠️ Ghi LAI moi lenh ve. Mot ngu canh nuot het khong phan biet duoc
|
||||||
|
// "ve dung" voi "khong ve gi" -- ma "khong ve gi" chinh la trieu chung
|
||||||
|
// cua loi da xay ra: hai khung trang tinh trong khi du lieu van chay.
|
||||||
|
const calls = (this.calls = this.calls || {});
|
||||||
|
return new Proxy({}, {
|
||||||
|
get: (_, k) => (...a) => { calls[k] = (calls[k] || 0) + 1; return a[0]; },
|
||||||
|
set: () => true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getBoundingClientRect() { return { left: 0, top: 0, width: 800, height: 600 }; },
|
||||||
|
appendChild() {}, removeChild() {}, setAttribute() {}, focus() {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const els = {};
|
||||||
|
const doc = {
|
||||||
|
getElementById(id) { return (els[id] = els[id] || mkEl(id)); },
|
||||||
|
querySelectorAll() { return []; },
|
||||||
|
querySelector(sel) { return (els[sel] = els[sel] || mkEl(sel)); },
|
||||||
|
createElement(t) { return mkEl('#' + t); },
|
||||||
|
addEventListener(ev, fn) { handlers.window[ev] = fn; },
|
||||||
|
activeElement: null,
|
||||||
|
body: mkEl('body'),
|
||||||
|
};
|
||||||
|
const sandbox = {
|
||||||
|
document: doc, console,
|
||||||
|
window: { addEventListener(ev, fn) { handlers.window[ev] = fn; },
|
||||||
|
devicePixelRatio: 1, location: { search: '' } },
|
||||||
|
location: { search: '' },
|
||||||
|
requestAnimationFrame() {}, setInterval() {}, setTimeout() {},
|
||||||
|
fetch() { return Promise.resolve({ json: () => Promise.resolve({ code: 0 }) }); },
|
||||||
|
WebSocket: function () { this.send = () => {}; this.readyState = 0; },
|
||||||
|
ImageData: function (w, h) { this.width = w; this.height = h;
|
||||||
|
this.data = new Uint8ClampedArray(w * h * 4); },
|
||||||
|
URLSearchParams: function () { this.get = () => null; },
|
||||||
|
V3D: { ready: false },
|
||||||
|
};
|
||||||
|
sandbox.window.document = doc;
|
||||||
|
for (const k of ['v3dInit', 'v3dSetShape', 'v3dSetPose', 'v3dSetScan', 'v3dSetCloud',
|
||||||
|
'v3dSetWorld', 'v3dSetMap', 'v3dSetPath', 'v3dSetOverlays',
|
||||||
|
'v3dRender', 'v3dSetWorldMeshes', 'v3dSetWorldVisible',
|
||||||
|
'v3dSetView', 'v3dFrustum', 'v3dCliffRings']) {
|
||||||
|
sandbox[k] = () => {};
|
||||||
|
}
|
||||||
|
vm.createContext(sandbox);
|
||||||
|
const src = fs.readFileSync(
|
||||||
|
path.resolve('/home/quangtrung/projects/vslam_cpp/libs/vslam_web/www/app.js'), 'utf8');
|
||||||
|
vm.runInContext(src + '\n;this.__view = view; this.__sx = sx; this.__sy = sy;' +
|
||||||
|
'\n;this.__ver = UI_VERSION; this.__setCv = (c) => { curCv = c; };' +
|
||||||
|
'\n;this.__pal = PALETTE; this.__state = state;' +
|
||||||
|
'\n;this.__draw = draw; this.__rasterize = rasterize;', sandbox);
|
||||||
|
|
||||||
|
const view = sandbox.__view;
|
||||||
|
const sx = sandbox.__sx, sy = sandbox.__sy;
|
||||||
|
// `curCv` chi duoc dat trong drawScene(); dat tay de do phep chieu rieng le.
|
||||||
|
sandbox.__setCv(doc.getElementById('main'));
|
||||||
|
const bad = [];
|
||||||
|
const chk = (label, got, want, tol) => {
|
||||||
|
const ok = Math.abs(got - want) <= (tol === undefined ? 1e-9 : tol);
|
||||||
|
console.log(` ${label.padEnd(40)} ${got.toFixed(4)}${ok ? '' : ' != ' + want.toFixed(4)}`);
|
||||||
|
if (!ok) bad.push(label);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Canvas 800x600, tam o (400, 300).
|
||||||
|
view.x = 0; view.y = 0; view.scale = 50; view.rot = 0;
|
||||||
|
chk('rot=0: goc the gioi o tam man hinh (x)', sx(0, 0), 400);
|
||||||
|
chk('rot=0: goc the gioi o tam man hinh (y)', sy(0, 0), 300);
|
||||||
|
chk('rot=0: (1,0) sang PHAI', sx(1, 0), 450);
|
||||||
|
chk('rot=0: (0,1) LEN TREN', sy(0, 1), 250);
|
||||||
|
|
||||||
|
// Xoay 90 do: truc +X the gioi phai chi LEN TREN man hinh.
|
||||||
|
view.rot = Math.PI / 2;
|
||||||
|
chk('rot=90: (1,0) khong lech ngang', sx(1, 0), 400, 1e-9);
|
||||||
|
chk('rot=90: (1,0) di LEN', sy(1, 0), 250, 1e-9);
|
||||||
|
|
||||||
|
// ⚠️ BAT BIEN: diem duoi con tro phai O NGUYEN duoi con tro sau khi keo.
|
||||||
|
//
|
||||||
|
// Day la dinh nghia cua "canh di theo tay". No phai dung o MOI goc xoay --
|
||||||
|
// va chinh o goc khac 0 thi phep nghich dao sai moi lo ra.
|
||||||
|
const down = handlers.el['main'] && handlers.el['main'].mousedown;
|
||||||
|
const move = handlers.window.mousemove;
|
||||||
|
const up = handlers.window.mouseup;
|
||||||
|
if (!down || !move) {
|
||||||
|
console.log(' khong bat duoc bo xu ly chuot cua khung 2D');
|
||||||
|
bad.push('bo xu ly chuot');
|
||||||
|
} else {
|
||||||
|
for (const rot of [0, 0.7, Math.PI / 2, -1.3]) {
|
||||||
|
view.x = 3; view.y = -2; view.scale = 50; view.rot = rot;
|
||||||
|
// Diem the gioi dang nam duoi con tro tai (500, 250).
|
||||||
|
// Giai nguoc: tu man hinh ve the gioi.
|
||||||
|
const c = Math.cos(rot), s_ = Math.sin(rot);
|
||||||
|
const rx = (500 - 400) / 50, ry = (300 - 250) / 50;
|
||||||
|
const wx = view.x + rx * c + ry * s_;
|
||||||
|
const wy = view.y + -rx * s_ + ry * c;
|
||||||
|
// Kiem phep giai nguoc truoc.
|
||||||
|
if (Math.abs(sx(wx, wy) - 500) > 1e-6 || Math.abs(sy(wx, wy) - 250) > 1e-6) {
|
||||||
|
bad.push('giai nguoc rot=' + rot.toFixed(2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
down({ button: 0, clientX: 500, clientY: 250, preventDefault() {} });
|
||||||
|
move({ clientX: 560, clientY: 215 });
|
||||||
|
up();
|
||||||
|
const nx = sx(wx, wy), ny = sy(wx, wy);
|
||||||
|
const err = Math.hypot(nx - 560, ny - 215);
|
||||||
|
console.log(` keo theo tay @ rot=${rot.toFixed(2).padStart(5)}` +
|
||||||
|
` lech ${err.toFixed(4)} px`);
|
||||||
|
if (err > 1e-6) bad.push('keo @ rot=' + rot.toFixed(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Bang mau: hai mau canh nhau phai PHAN BIET DUOC ---
|
||||||
|
//
|
||||||
|
// ⚠️ Day la mot loi that, khong phai gia dinh. Ban truoc dung MOT bang cho ca
|
||||||
|
// hai khung, voi `free` = #ffffff tren `bg` = #f3f6fa. Hai mau cach nhau 12
|
||||||
|
// don vi -- vung DA QUET va vung chua co gi trong y het nhau, nen khong con
|
||||||
|
// biet quet toi dau. Khong loi, khong canh bao: ban do van ve du.
|
||||||
|
//
|
||||||
|
// Cap quan trong nhat la `free` voi `bg`: cai nguoi van hanh can thay la vung
|
||||||
|
// da quet LON DEN DAU, khong phai vi tri tung buc tuong.
|
||||||
|
console.log('\n --- bang mau: khoang cach giua cac mau ---');
|
||||||
|
const pal = sandbox.__pal;
|
||||||
|
function rgb(v) {
|
||||||
|
if (Array.isArray(v)) return v.slice(0, 3);
|
||||||
|
const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(v);
|
||||||
|
return m ? [1, 2, 3].map((i) => parseInt(m[i], 16)) : null;
|
||||||
|
}
|
||||||
|
// Khoang cach co trong so theo do nhay cua mat (xap xi Rec. 601).
|
||||||
|
function dist(a, b) {
|
||||||
|
const A = rgb(a), B = rgb(b);
|
||||||
|
const w = [0.30, 0.59, 0.11];
|
||||||
|
let d = 0;
|
||||||
|
for (let i = 0; i < 3; ++i) d += w[i] * (A[i] - B[i]) * (A[i] - B[i]);
|
||||||
|
return Math.sqrt(d);
|
||||||
|
}
|
||||||
|
const MIN_GAP = 40;
|
||||||
|
for (const name of ['world', 'slam']) {
|
||||||
|
const P = pal[name];
|
||||||
|
for (const [x, y] of [['free', 'bg'], ['occupied', 'free'], ['occupied', 'bg']]) {
|
||||||
|
const d = dist(P[x], P[y]);
|
||||||
|
const ok = d >= MIN_GAP;
|
||||||
|
console.log(` ${name}: ${(x + ' vs ' + y).padEnd(17)} ${d.toFixed(1).padStart(6)}` +
|
||||||
|
(ok ? '' : ` < ${MIN_GAP} <-- KHONG PHAN BIET DUOC`));
|
||||||
|
if (!ok) bad.push(`${name}.${x} vs ${y}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hai khung phai KHAC tone: cung tone thi khong biet dang nhin khung nao.
|
||||||
|
const dpane = dist(pal.world.bg, pal.slam.bg);
|
||||||
|
console.log(` nen hai khung khac nhau ${dpane.toFixed(1).padStart(6)}` +
|
||||||
|
(dpane >= 60 ? '' : ' <-- QUA GIONG'));
|
||||||
|
if (dpane < 60) bad.push('hai khung cung tone');
|
||||||
|
|
||||||
|
// --- CHAY THAT duong ve ---
|
||||||
|
//
|
||||||
|
// ⚠️ Bai kiem nay ton tai vi mot loi that: `drawRobot()` doc `pal.nose` nhung
|
||||||
|
// khong co tham so `pal`. ReferenceError ngay lan ve dau, va vi
|
||||||
|
// `requestAnimationFrame(draw)` nam o CUOI draw(), vong ve chet vinh vien.
|
||||||
|
// Ca hai khung trang tinh trong khi thanh ben van cap nhat binh thuong --
|
||||||
|
// WebSocket chay o duong khac.
|
||||||
|
//
|
||||||
|
// Cac bai kiem truoc do khong bat duoc vi chung khong lan nao GOI draw().
|
||||||
|
console.log('\n --- chay that duong ve ---');
|
||||||
|
{
|
||||||
|
const st = sandbox.__state;
|
||||||
|
const grid = { res: 0.05, w: 40, h: 30, ox: -1, oy: -1,
|
||||||
|
cells: new Int8Array(40 * 30) };
|
||||||
|
for (let i = 0; i < grid.cells.length; ++i) {
|
||||||
|
grid.cells[i] = i % 7 === 0 ? 100 : (i % 3 === 0 ? -1 : 0);
|
||||||
|
}
|
||||||
|
st.pose = { x: 0.5, y: 0.5, yaw: 0.3 };
|
||||||
|
st.gt = { x: 0.52, y: 0.5, yaw: 0.3, err: 0.02 };
|
||||||
|
st.robot = { radius: 0.24, wheel_radius: 0.075, wheel_sep: 0.36,
|
||||||
|
laser_x: 0.24, laser_y: 0, laser_z: 0.125,
|
||||||
|
body_l: 0.40, body_w: 0.34, body_h: 0.85, body_off_x: -0.06,
|
||||||
|
clearance: 0.04 };
|
||||||
|
st.scan = new Float32Array([1.0, 0.0, 0.0, 1.0, -1.0, 0.0]);
|
||||||
|
st.path = new Float32Array([0, 0, 0.5, 0.5, 1.0, 0.4]);
|
||||||
|
st.worldMap = grid;
|
||||||
|
st.worldMapImage = sandbox.__rasterize(grid, sandbox.__pal.world);
|
||||||
|
st.map = grid;
|
||||||
|
st.mapImage = sandbox.__rasterize(grid, sandbox.__pal.slam);
|
||||||
|
st.slamMode = 'mapping';
|
||||||
|
|
||||||
|
const main = doc.getElementById('main');
|
||||||
|
const mainR = doc.getElementById('mainR');
|
||||||
|
// ⚠️ XOA KHOA, dung thay object: Proxy trong getContext() da giu tham chieu
|
||||||
|
// toi object cu, nen gan mot object moi se cat mat duong ghi nhan.
|
||||||
|
for (const el of [main, mainR]) {
|
||||||
|
el.calls = el.calls || {};
|
||||||
|
for (const k of Object.keys(el.calls)) delete el.calls[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
let threw = null;
|
||||||
|
try { sandbox.__draw(); } catch (e) { threw = e; }
|
||||||
|
console.log(' goi draw() ' +
|
||||||
|
(threw ? 'NEM: ' + threw.message : 'khong nem'));
|
||||||
|
if (threw) bad.push('draw() nem ngoai le');
|
||||||
|
|
||||||
|
// Dem NOI DUNG: draw() co that su ve gi khong.
|
||||||
|
const n = (el) => Object.values(el.calls || {}).reduce((a, b) => a + b, 0);
|
||||||
|
console.log(` lenh ve tren khung trai ${n(main)}`);
|
||||||
|
if (n(main) < 5) bad.push('khung trai khong duoc ve');
|
||||||
|
if (!(main.calls && main.calls.drawImage)) bad.push('ban do khong duoc ve');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n UI_VERSION = ' + sandbox.__ver);
|
||||||
|
console.log(bad.length ? '\n => HONG: ' + bad.join(', ') : '\n => DAT');
|
||||||
|
process.exit(bad.length ? 1 : 0);
|
||||||
Reference in New Issue
Block a user