This commit is contained in:
trung09122002
2026-09-25 14:07:58 +07:00
parent 0093df0508
commit fe8b147c6a
21 changed files with 13992 additions and 9 deletions

View File

@@ -50,6 +50,19 @@ database_path: map.db
# Do duoc tren map_house.db (240 node): xem docs/SLAM.md.
optimizer_strategy: "1"
# ============ DO CHAC CUA ODOM ============
# Sigma MOI LIEN KET giua hai node (~0.1-0.3 m di chuyen) gui RTAB-Map.
#
# Mac dinh cu (khong dat) la 10 cm / 5.7 do moi lien ket -- te hon ICP
# (1.1 do) ~5 lan, nen toi uu do thi nghe ICP. Moi lien ket ICP sai rat it
# (TB 0.7 cm / 0.15 do) nhung 37 phut quet co 2542 lien ket, cong don thanh
# xoay ~3 do va lech 0.25 m (do tren DB 2026-09-25).
#
# ⚠️ ROBOT THAT: odom that TRUOT. Khai chac qua thi SLAM khong sua duoc troi
# that. 0.01 / 0.005 la uoc luong tu ~2% quang duong -- CHUA do tren robot.
odom_sigma_m: 0.01
odom_sigma_rad: 0.005
# ============ THI GIAC ============
# Kp/MaxFeatures: -1 khi false, 400 khi true.
#
@@ -216,3 +229,11 @@ rtabmap:
Rtabmap/TimeThr: "0"
Rtabmap/MemoryThr: "0"
Rtabmap/DetectionRate: "3"
# --- Luu DB ---
# Khong luu cac khung RTAB-Map da bo qua (khong nam trong do thi). Mac dinh
# RTAB-Map la true: 37 phut quet ra 17723 node ma chi 3192 trong do thi --
# 79% (1.7 GB) cua DB 2.16 GB la khung thua.
# ⚠️ Doi lai: DB khong con MOI khung, nen vslam_slam_bench chay lai tu no
# se thua hon phien goc. Quet de lam du lieu phan tich thi dat "true".
Mem/NotLinkedNodesKept: "false"

View File

@@ -39,6 +39,9 @@ struct RtabmapConfig {
// Gui depth vao RTAB-Map (luu trong DB) va bat ban do voxel 3D. KHONG doi
// luoi -- xem ghi chu trong BuildRtabmapParams.
bool camera_3d = false;
// Do chac cua odom MOI LIEN KET gui RTAB-Map. Xem slam.yaml.
double odom_sigma_m = 0.01;
double odom_sigma_rad = 0.005;
// Optimizer. "1" = g2o. KHONG dung "2" (GTSAM): apt jammy arm64 khong co
// GTSAM va PPA borglab khong publish arm64.

View File

@@ -29,8 +29,12 @@ struct SlamInput {
// odom -> base_footprint. Day la dau vao BAT BUOC: RTAB-Map o che do nay
// khong tu tinh odometry, no chinh odometry cua ta.
Pose2D odom;
double odom_linear_var = 0.01;
double odom_angular_var = 0.01;
// Phuong sai odom MOI LIEN KET. <= 0 = lay tu slam.yaml (odom_sigma_*).
// Mac dinh cu 0.01 / 0.01 (sigma 10 cm / 5.7 do) lam RTAB-Map tin ICP hon
// odom ~27 lan ve goc; 2542 lien ket ICP sai TB 0.15 do cong don thanh
// troi 0.25 m sau 37 phut quet (do tren DB 2026-09-25).
double odom_linear_var = -1.0;
double odom_angular_var = -1.0;
// Scan DA VE SINH (qua ScanSanitizer), trong frame laser.
const LaserScan* scan = nullptr;

View File

@@ -155,6 +155,8 @@ RtabmapConfig LoadRtabmapConfig(const ConfigNode& node) {
cfg.visual_loop = node.get<bool>("visual_loop", false);
cfg.camera_3d = node.get<bool>("camera_3d", false);
cfg.odom_sigma_m = node.get<double>("odom_sigma_m", cfg.odom_sigma_m);
cfg.odom_sigma_rad = node.get<double>("odom_sigma_rad", cfg.odom_sigma_rad);
cfg.optimizer_strategy = node.get<std::string>("optimizer_strategy", "1");
// Khoi `rtabmap:` di thang vao ParametersMap, giu nguyen van. Khong kiem

View File

@@ -96,6 +96,12 @@ StatusResponse RtabmapSlam::Init(const RtabmapConfig& cfg) {
}
impl_->cfg = cfg;
if (cfg.odom_sigma_m <= 0.0 || cfg.odom_sigma_rad <= 0.0) {
return StatusResponse::Error(
StatusCode::kInvalidArgument,
"slam.yaml: odom_sigma_m / odom_sigma_rad phai > 0");
}
// --- Giai duong dan DB: tuong doi -> MapDir(), no {stamp} ---
//
// Lam o DAY chu khong o app_config: duong `--check` khong dung toi
@@ -275,11 +281,19 @@ SlamOutput RtabmapSlam::Process(const SlamInput& in) {
: impl_->camera_to_base,
impl_->next_id++);
// Phuong sai odom: nguoi goi dat thi dung, khong thi lay tu slam.yaml.
const double lin_var = in.odom_linear_var > 0.0
? in.odom_linear_var
: impl_->cfg.odom_sigma_m * impl_->cfg.odom_sigma_m;
const double ang_var = in.odom_angular_var > 0.0
? in.odom_angular_var
: impl_->cfg.odom_sigma_rad * impl_->cfg.odom_sigma_rad;
bool ok = false;
try {
ok = impl_->rtabmap.process(data, ToRtabmap(in.odom),
static_cast<float>(in.odom_linear_var),
static_cast<float>(in.odom_angular_var));
static_cast<float>(lin_var),
static_cast<float>(ang_var));
} catch (const std::exception& e) {
VSLAM_ERROR("slam: process nem: " << e.what());
return out;

View File

@@ -388,5 +388,15 @@
198,
150,
83
],
"vslam_hospital_nam_floor": [
120,
135,
144
],
"vslam_hospital_nam_walls": [
86,
94,
98
]
}

View File

@@ -0,0 +1,14 @@
# aws_robomaker_hospital_floor_01_floor (collision) cat o y <= -10.12: 3 tam giac
# Z-UP, don vi MET, toa do THE GIOI. Sinh boi tools/cut_world.py.
v -0.5333 -10.1200 -0.0000
v -12.5014 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -10.1200 -0.0000
v -0.5333 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -35.0144 -0.0000
f 1 2 3
f 4 5 6
f 7 8 9

View File

@@ -0,0 +1,14 @@
# aws_robomaker_hospital_floor_01_floor (visual) cat o y <= -10.12: 3 tam giac
# Z-UP, don vi MET, toa do THE GIOI. Sinh boi tools/cut_world.py.
v -0.5333 -10.1200 -0.0000
v -12.5014 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -10.1200 -0.0000
v -0.5333 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -10.1200 -0.0000
v -12.5014 -35.0144 -0.0000
v 12.4986 -35.0144 -0.0000
f 1 2 3
f 4 5 6
f 7 8 9

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<model>
<name>vslam_hospital_nam_floor</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>
<author>
<name>vslam_cpp</name>
<email></email>
</author>
<description>
aws_robomaker_hospital_floor_01_floor cat o y &lt;= -10.12, toa do THE GIOI (dat model o goc).
Sinh boi tools/cut_world.py -- dung sua tay.
</description>
</model>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<model name="vslam_hospital_nam_floor">
<link name="link">
<visual name="visual">
<geometry>
<mesh>
<uri>model://vslam_hospital_nam_floor/meshes/visual.obj</uri>
</mesh>
</geometry>
</visual>
<collision name="collision">
<geometry>
<mesh>
<uri>model://vslam_hospital_nam_floor/meshes/collision.obj</uri>
</mesh>
</geometry>
</collision>
</link>
<static>1</static>
</model>
</sdf>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<model>
<name>vslam_hospital_nam_walls</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>
<author>
<name>vslam_cpp</name>
<email></email>
</author>
<description>
aws_robomaker_hospital_floor_01_walls cat o y &lt;= -10.12, toa do THE GIOI (dat model o goc).
Sinh boi tools/cut_world.py -- dung sua tay.
</description>
</model>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<model name="vslam_hospital_nam_walls">
<link name="link">
<visual name="visual">
<geometry>
<mesh>
<uri>model://vslam_hospital_nam_walls/meshes/visual.obj</uri>
</mesh>
</geometry>
</visual>
<collision name="collision">
<geometry>
<mesh>
<uri>model://vslam_hospital_nam_walls/meshes/collision.obj</uri>
</mesh>
</geometry>
</collision>
</link>
<static>1</static>
</model>
</sdf>

View File

@@ -0,0 +1,19 @@
# Tuong chan cat world: hop 27.4 x 0.2 x 2.5 m, tam day o goc model.
# Z-UP, don vi MET -- dung quy uoc .obj ma bo doc world gia dinh
# (libs/vslam_sim/src/gazebo_world.cc). Xem tools/cut_world.py.
v -13.7 -0.1 0.0
v 13.7 -0.1 0.0
v 13.7 0.1 0.0
v -13.7 0.1 0.0
v -13.7 -0.1 2.5
v 13.7 -0.1 2.5
v 13.7 0.1 2.5
v -13.7 0.1 2.5
# day, nap
f 1 4 3 2
f 5 6 7 8
# bon mat ben
f 1 2 6 5
f 2 3 7 6
f 3 4 8 7
f 4 1 5 8

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<model>
<name>vslam_tuong_cat</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>
<author>
<name>vslam_cpp</name>
<email></email>
</author>
<description>
Tuong chan 27.4 x 0.2 x 2.5 m de cat mot world thanh ban do nho hon.
Xem tools/cut_world.py.
</description>
</model>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<model name="vslam_tuong_cat">
<link name="link">
<visual name="visual">
<geometry>
<mesh>
<uri>model://vslam_tuong_cat/meshes/tuong_cat.obj</uri>
</mesh>
</geometry>
</visual>
<collision name="collision">
<geometry>
<mesh>
<uri>model://vslam_tuong_cat/meshes/tuong_cat.obj</uri>
</mesh>
</geometry>
</collision>
</link>
<static>1</static>
</model>
</sdf>

View File

@@ -0,0 +1,485 @@
<?xml version='1.0' encoding='utf-8'?>
<sdf version="1.6">
<world name="world">
<gravity>0 0 -9.8</gravity>
<physics default="0" name="default_physics" type="ode">
<max_step_size>0.001</max_step_size>
<real_time_factor>1</real_time_factor>
<real_time_update_rate>1000</real_time_update_rate>
</physics>
<scene>
<ambient>0.6 0.6 0.6 1</ambient>
<background>0.4 0.4 0.4 1</background>
<shadows>false</shadows>
</scene>
<include>
<uri>model://sun</uri>
</include>
<include>
<uri>model://ground_plane</uri>
<pose>0 0 -0.1 0 -0 0</pose>
</include>
<model name="vslam_hospital_nam_floor_1">
<include>
<uri>model://vslam_hospital_nam_floor</uri>
<static>true</static>
<pose>0 0 0 0 0 0</pose>
</include>
</model>
<model name="vslam_hospital_nam_walls_1">
<include>
<uri>model://vslam_hospital_nam_walls</uri>
<static>true</static>
<pose>0 0 0 0 0 0</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_1">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>-11.0216 -13.8069 0 0 -0 1.55358</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_2">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>11.1417 -21.4039 0 0 0 -1.55117</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_3">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>11.1068 -17.8472 0 0 0 -1.55117</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_4">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>11.1374 -14.1551 0 0 0 -1.55117</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_5">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>-11.0332 -17.61 0 0 -0 1.55358</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_half_open_01_6">
<include>
<uri>model://aws_robomaker_hospital_curtain_half_open_01</uri>
<static>true</static>
<pose>-11.0086 -21.7566 0 0 -0 1.55358</pose>
</include>
</model>
<model name="CGMClassic_1">
<include>
<uri>model://CGMClassic</uri>
<static>true</static>
<pose>11.1777 -18.4129 0 0 0 -3.13719</pose>
</include>
</model>
<model name="CGMClassic_2">
<include>
<uri>model://CGMClassic</uri>
<static>true</static>
<pose>11.1179 -14.6493 0 0 0 -3.13599</pose>
</include>
</model>
<model name="Scrubs_1">
<include>
<uri>model://Scrubs</uri>
<static>true</static>
<pose>-9.61916 -12.5112 0 0 0 -3.12353</pose>
</include>
</model>
<model name="CGMClassic_3">
<include>
<uri>model://CGMClassic</uri>
<static>true</static>
<pose>-11.2304 -21.1134 0 0 0 -3.11834</pose>
</include>
</model>
<model name="aws_robomaker_residential_CoffeeTable_01_1">
<include>
<uri>model://aws_robomaker_residential_CoffeeTable_01</uri>
<static>true</static>
<pose>-10.2383 -29.9144 0 0 -0 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_Sofa_01_1">
<include>
<uri>model://aws_robomaker_residential_Sofa_01</uri>
<static>true</static>
<pose>-11.077 -30.5544 -1e-05 2.6e-05 -3e-06 1.56984</pose>
</include>
</model>
<model name="aws_robomaker_residential_TV_02_1">
<include>
<uri>model://aws_robomaker_residential_TV_02</uri>
<static>true</static>
<pose>-12.4122 -28.4594 1.53211 0 -0 3.13999</pose>
</include>
</model>
<model name="aws_robomaker_residential_KitchenCabinet_01_1">
<include>
<uri>model://aws_robomaker_residential_KitchenCabinet_01</uri>
<static>true</static>
<pose>-11.1379 -25.6941 0 0 -0 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_Refrigerator_01_1">
<include>
<uri>model://aws_robomaker_residential_Refrigerator_01</uri>
<static>true</static>
<pose>-9.28238 -24.5015 0 0 -0 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_SofaB_01_1">
<include>
<uri>model://aws_robomaker_residential_SofaB_01</uri>
<static>true</static>
<pose>-10.8238 -28.6662 -5e-06 -1.3e-05 -2e-06 -1.56116</pose>
</include>
</model>
<model name="aws_robomaker_residential_SofaB_01_2">
<include>
<uri>model://aws_robomaker_residential_SofaB_01</uri>
<static>true</static>
<pose>-9.73697 -28.6538 -3e-06 1.3e-05 -4e-06 -1.56077</pose>
</include>
</model>
<model name="ElderLadyPatient_2">
<include>
<uri>model://ElderLadyPatient</uri>
<static>true</static>
<pose>-10.8133 -13.5925 0.001657 0 -2e-06 -0.025052</pose>
</include>
</model>
<model name="aws_robomaker_residential_Trash_01_3">
<include>
<uri>model://aws_robomaker_residential_Trash_01</uri>
<static>true</static>
<pose>-12.1773 -27.6293 0.000894 -1e-06 -1e-06 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitE_01_1">
<include>
<uri>model://aws_robomaker_residential_PortraitE_01</uri>
<static>true</static>
<pose>-9.06141 -31.9238 1.38136 0 -0 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitE_01_2">
<include>
<uri>model://aws_robomaker_residential_PortraitE_01</uri>
<static>true</static>
<pose>-11.7398 -31.9011 1.38136 0 -0 0</pose>
</include>
</model>
<model name="InstrumentCart1_1">
<include>
<uri>model://InstrumentCart1</uri>
<static>true</static>
<pose>-11.8071 -16.1825 0 0 -0 1.56702</pose>
</include>
</model>
<model name="ElderMalePatient_1">
<include>
<uri>model://ElderMalePatient</uri>
<static>true</static>
<pose>-11.1165 -17.2377 0.001656 0 3e-06 0</pose>
</include>
</model>
<model name="aws_robomaker_residential_Carpet_01_1">
<include>
<uri>model://aws_robomaker_residential_Carpet_01</uri>
<static>true</static>
<pose>-10.7338 -29.9243 0 0 -0 0</pose>
</include>
</model>
<model name="BedTable_2">
<include>
<uri>model://BedTable</uri>
<static>true</static>
<pose>-10.5874 -12.5084 0.001189 0 -0 3.11588</pose>
</include>
</model>
<model name="AnesthesiaMachine_1">
<include>
<uri>model://AnesthesiaMachine</uri>
<static>true</static>
<pose>-1.28478 -21.1127 0 0 0 -3.12971</pose>
</include>
</model>
<model name="TrolleyBedPatient_1">
<include>
<uri>model://TrolleyBedPatient</uri>
<static>true</static>
<pose>-1.83202 -19.2612 0 0 -0 0</pose>
</include>
</model>
<model name="Scrubs_4">
<include>
<uri>model://Scrubs</uri>
<static>true</static>
<pose>-0.93616 -18.2252 0 0 -0 1.62572</pose>
</include>
</model>
<model name="Shower_1">
<include>
<uri>model://Shower</uri>
<static>true</static>
<pose>-1.07422 -16.1332 0 0 -0 0</pose>
</include>
</model>
<model name="Shower_2">
<include>
<uri>model://Shower</uri>
<static>true</static>
<pose>0.853327 -16.1492 0 0 -0 0</pose>
</include>
</model>
<model name="SurgicalTrolley_2">
<include>
<uri>model://SurgicalTrolley</uri>
<static>true</static>
<pose>-0.411421 -22.2085 0 0 0 -1.58175</pose>
</include>
</model>
<model name="SurgicalTrolley_3">
<include>
<uri>model://SurgicalTrolley</uri>
<static>true</static>
<pose>3.11747 -19.6565 0 0 -0 1.57031</pose>
</include>
</model>
<model name="SurgicalTrolleyMed_1">
<include>
<uri>model://SurgicalTrolleyMed</uri>
<static>true</static>
<pose>0.770804 -19.7749 0 0 0 -1.56798</pose>
</include>
</model>
<model name="Scrubs_5">
<include>
<uri>model://Scrubs</uri>
<static>true</static>
<pose>-2.66657 -18.3733 0 -0.002221 -0.006608 -1.24025</pose>
</include>
</model>
<model name="InstrumentCart1_2">
<include>
<uri>model://InstrumentCart1</uri>
<static>true</static>
<pose>-11.8071 -16.1825 0 0 -0 1.56702</pose>
</include>
</model>
<model name="InstrumentCart2_3">
<include>
<uri>model://InstrumentCart2</uri>
<static>true</static>
<pose>-0.869537 -17.7436 0 0 0 -0.002595</pose>
</include>
</model>
<model name="StorageRackCovered_1">
<include>
<uri>model://StorageRackCovered</uri>
<static>true</static>
<pose>0.546476 -18.3985 -0 0 -0 1.56584</pose>
</include>
</model>
<model name="StorageRack_2">
<include>
<uri>model://StorageRack</uri>
<static>true</static>
<pose>-2.69866 -22.4178 -8e-06 0 4e-06 0</pose>
</include>
</model>
<model name="KitchenSink_1">
<include>
<uri>model://KitchenSink</uri>
<static>true</static>
<pose>3.06236 -11.8809 -0.001614 0 -0 3.1391</pose>
</include>
</model>
<model name="KitchenSink_2">
<include>
<uri>model://KitchenSink</uri>
<static>true</static>
<pose>-3.09305 -11.8988 -0.001609 0 -0 0</pose>
</include>
</model>
<model name="Toilet_1">
<include>
<uri>model://Toilet</uri>
<static>true</static>
<pose>0.464522 -11.8023 0.005252 0 0.016801 0</pose>
</include>
</model>
<model name="Toilet_2">
<include>
<uri>model://Toilet</uri>
<static>true</static>
<pose>-0.54552 -11.8033 0.000387 0 0 -3.139</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitD_01_3">
<include>
<uri>model://aws_robomaker_residential_PortraitD_01</uri>
<static>true</static>
<pose>1.2703 -12.9084 1.57344 0 0 -3.14134</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitD_01_4">
<include>
<uri>model://aws_robomaker_residential_PortraitD_01</uri>
<static>true</static>
<pose>-1.06108 -12.9155 1.57344 0 0 -3.14134</pose>
</include>
</model>
<model name="Toilet_5">
<include>
<uri>model://Toilet</uri>
<static>true</static>
<pose>-7.02851 -12.7728 0.000377 0 0 -3.13589</pose>
</include>
</model>
<model name="Toilet_6">
<include>
<uri>model://Toilet</uri>
<static>true</static>
<pose>7.48696 -12.617 0.000386 0 0 -3.13589</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitD_02_3">
<include>
<uri>model://aws_robomaker_residential_PortraitD_02</uri>
<static>true</static>
<pose>7.89294 -13.6155 1.54508 0 0 -1.57619</pose>
</include>
</model>
<model name="aws_robomaker_residential_PortraitD_02_6">
<include>
<uri>model://aws_robomaker_residential_PortraitD_02</uri>
<static>true</static>
<pose>-7.90937 -13.3417 1.54508 0 -0 1.57083</pose>
</include>
</model>
<model name="ParkingTrolleyMin_1">
<include>
<uri>model://ParkingTrolleyMin</uri>
<static>true</static>
<pose>0.715846 -17.1496 -0.000121 -1e-06 -0 0</pose>
</include>
</model>
<model name="Scrubs_6">
<include>
<uri>model://Scrubs</uri>
<static>true</static>
<pose>-1.29468 -20.4093 0 0 0 -1.51066</pose>
</include>
</model>
<model name="CGMClassic_9">
<include>
<uri>model://CGMClassic</uri>
<static>true</static>
<pose>11.3613 -21.8867 0 0 0 -3.12292</pose>
</include>
</model>
<model name="StorageRack_3">
<include>
<uri>model://StorageRack</uri>
<static>true</static>
<pose>-10.1178 -10.4694 -0 0 -0 0</pose>
</include>
</model>
<model name="StorageRackCovered_2">
<include>
<uri>model://StorageRackCovered</uri>
<static>true</static>
<pose>10.294 -10.577 -7e-06 3e-06 -0 3.13389</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_closed_01_4">
<include>
<uri>model://aws_robomaker_hospital_curtain_closed_01</uri>
<static>true</static>
<pose>10.9819 -26.2149 0 0 0 -1.58306</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_closed_01_5">
<include>
<uri>model://aws_robomaker_hospital_curtain_closed_01</uri>
<static>true</static>
<pose>1.31506 -30.5771 0 0 -0 3.1401</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_closed_01_6">
<include>
<uri>model://aws_robomaker_hospital_curtain_closed_01</uri>
<static>true</static>
<pose>5.49659 -30.5364 0 0 -0 3.1401</pose>
</include>
</model>
<model name="aws_robomaker_hospital_curtain_closed_01_7">
<include>
<uri>model://aws_robomaker_hospital_curtain_closed_01</uri>
<static>true</static>
<pose>9.80048 -30.5918 0 0 -0 3.1401</pose>
</include>
</model>
<model name="InstrumentCart1_3">
<include>
<uri>model://InstrumentCart1</uri>
<static>true</static>
<pose>-1.83539 -17.5879 0 0 -0 0</pose>
</include>
</model>
<model name="ParkingTrolleyMax_1">
<include>
<uri>model://ParkingTrolleyMax</uri>
<static>true</static>
<pose>7.71054 -25.1326 -0.000121 1e-06 -0 -1.59536</pose>
</include>
</model>
<model name="XRayMachine_1">
<include>
<uri>model://XRayMachine</uri>
<static>true</static>
<pose>1.79424 -21.3329 0 0 -0 0</pose>
</include>
</model>
<model name="IVStand_1">
<include>
<uri>model://IVStand</uri>
<static>true</static>
<pose>-11.0966 -16.4963 0 0 -0 0</pose>
</include>
</model>
<model name="BloodPressureMonitor_1">
<include>
<uri>model://BloodPressureMonitor</uri>
<static>true</static>
<pose>-9.96258 -11.9361 0 0 -0 0</pose>
</include>
</model>
<model name="IVStand_2">
<include>
<uri>model://IVStand</uri>
<static>true</static>
<pose>-2.30593 -20.2447 0 0 -0 0</pose>
</include>
</model>
<model name="vslam_tuong_cat_1">
<include>
<uri>model://vslam_tuong_cat</uri>
<static>true</static>
<pose>0.0 -10.12 0 0 0 0</pose>
</include>
</model>
</world>
</sdf>

Binary file not shown.

275
tools/cut_world.py Normal file
View File

@@ -0,0 +1,275 @@
#!/usr/bin/env python3
"""Cat mot world Gazebo theo truc y: giu phan y < --y-max, bo han phan con lai.
Dung de co mot ban do VUA -- lon hon nha hang (12x10 m), nho hon ca benh vien
(25x51 m) -- quet tron duoc trong 10-15 phut.
Ba buoc:
1. LOC MODEL: giu khoi `<model name="...">` co pose y < y-max - margin.
Bo doc world (libs/vslam_sim/src/gazebo_world.cc) tach khoi tu
`<model name="` den `</model>` GAN NHAT, lay `<uri>` va `<pose>` DAU TIEN
-- script nay loc dung theo cach tach do.
2. CAT MESH (--clip): tuong va san cua benh vien la MOT mesh .dae cho ca toa
nha. Khong sua .dae (de hong) -- lay CHINH tam giac ma bo doc world tao ra
(`vslam_world_export --meshes`), cat o y = y-max (tam giac vat qua duong
cat bi cat doi chinh xac, nen tuong doc chay suot toa nha van con phan
phia nam), ghi thanh model .obj moi va thay vao world.
3. TUONG CHAN: duong cat di qua loi hanh lang, nen chen
resources/models/vslam_tuong_cat o y = y-max de bit lai.
Tai tao resources/worlds/hospital_nam.world (chay tu goc repo):
GAZEBO_MODEL_PATH=$PWD/resources/models ./build/tools/vslam_world_export \\
--world ../vSLAM_ws/src/robot_sim/worlds/hospital.world --meshes /tmp/c.bin
GAZEBO_MODEL_PATH=$PWD/resources/models ./build/tools/vslam_world_export \\
--world ../vSLAM_ws/src/robot_sim/worlds/hospital.world --meshes /tmp/v.bin \\
--meshes-visual
python3 tools/cut_world.py \\
--in ../vSLAM_ws/src/robot_sim/worlds/hospital.world \\
--out resources/worlds/hospital_nam.world --y-max -10.12 \\
--meshes-bin /tmp/c.bin --meshes-visual-bin /tmp/v.bin \\
--clip aws_robomaker_hospital_floor_01_walls=vslam_hospital_nam_walls \\
--clip aws_robomaker_hospital_floor_01_floor=vslam_hospital_nam_floor \\
--colors resources/model_colors.json
Chay node voi GAZEBO_MODEL_PATH=$PWD/resources/models de tim thay cac model moi.
y = -10.12 chon tu ban do raster hoa (vslam_world_export): duong ngang o do chi
cat 7.7 m san trong (cac loi hanh lang), con lai trung tuong co san.
⚠️ Chay lai tools/gen_model_colors.py se ghi de model_colors.json va mat mau
cua model moi -- chay lai script nay sau do.
"""
import argparse
import json
import math
import os
import re
import struct
import sys
WALL_BLOCK = """ <model name="vslam_tuong_cat_1">
<include>
<uri>model://vslam_tuong_cat</uri>
<static>true</static>
<pose>{x} {y} 0 0 0 0</pose>
</include>
</model>
"""
CLIP_BLOCK = """ <model name="{name}_1">
<include>
<uri>model://{name}</uri>
<static>true</static>
<pose>0 0 0 0 0 0</pose>
</include>
</model>
"""
MODEL_CONFIG = """<?xml version="1.0" ?>
<model>
<name>{name}</name>
<version>1.0</version>
<sdf version="1.6">model.sdf</sdf>
<author>
<name>vslam_cpp</name>
<email></email>
</author>
<description>
{src} cat o y &lt;= {y_max}, toa do THE GIOI (dat model o goc).
Sinh boi tools/cut_world.py -- dung sua tay.
</description>
</model>
"""
MODEL_SDF = """<?xml version="1.0" ?>
<sdf version="1.6">
<model name="{name}">
<link name="link">
<visual name="visual">
<geometry>
<mesh>
<uri>model://{name}/meshes/visual.obj</uri>
</mesh>
</geometry>
</visual>
<collision name="collision">
<geometry>
<mesh>
<uri>model://{name}/meshes/collision.obj</uri>
</mesh>
</geometry>
</collision>
</link>
<static>1</static>
</model>
</sdf>
"""
def read_meshes(path):
"""Doc khoi "VSLW" cua EncodeWorldMeshes (gazebo_world.h).
Tra ve (geoms, instances): geoms[i] = (ten, [9 float moi tam giac] trong he
MODEL), instances = [(geom, x, y, z, yaw)].
"""
b = open(path, "rb").read()
if b[:4] != b"VSLW":
sys.exit(f"{path}: khong phai khoi VSLW")
_, ng, ni = struct.unpack_from("<III", b, 4)
o = 16
geoms = []
for _ in range(ng):
(n,) = struct.unpack_from("<I", b, o)
o += 4
name = b[o:o + n].decode()
o += n + 3 # bo qua r,g,b
(nt,) = struct.unpack_from("<I", b, o)
o += 4
geoms.append((name, struct.unpack_from(f"<{nt * 9}f", b, o)))
o += nt * 9 * 4
insts = []
for _ in range(ni):
insts.append(struct.unpack_from("<Iffff", b, o))
o += 20
return geoms, insts
def clip_poly(poly, y_max):
"""Sutherland-Hodgman voi mot nua mat phang y <= y_max. Giu thu tu dinh."""
out = []
for i, cur in enumerate(poly):
prev = poly[i - 1]
cin, pin = cur[1] <= y_max, prev[1] <= y_max
if cin != pin:
t = (y_max - prev[1]) / (cur[1] - prev[1])
out.append(tuple(p + t * (c - p) for p, c in zip(prev, cur)))
if cin:
out.append(cur)
return out
def world_triangles(geoms, insts, model_name, y_max):
"""Moi the hien cua `model_name` -> tam giac TOA DO THE GIOI, da cat."""
idx = [i for i, g in enumerate(geoms) if g[0] == model_name]
if not idx:
sys.exit(f"khong co mesh '{model_name}' trong file .bin")
tris = []
for g, x, y, z, yaw in insts:
if g not in idx:
continue
c, s = math.cos(yaw), math.sin(yaw)
t = geoms[g][1]
for k in range(0, len(t), 9):
poly = [(c * t[k + 3 * j] - s * t[k + 3 * j + 1] + x,
s * t[k + 3 * j] + c * t[k + 3 * j + 1] + y,
t[k + 3 * j + 2] + z) for j in range(3)]
poly = clip_poly(poly, y_max)
for j in range(2, len(poly)): # quat tam giac
tris.append((poly[0], poly[j - 1], poly[j]))
return tris
def write_obj(path, tris, header):
with open(path, "w") as f:
f.write(f"# {header}\n# Z-UP, don vi MET, toa do THE GIOI. Sinh boi tools/cut_world.py.\n")
for tri in tris:
for p in tri:
f.write(f"v {p[0]:.4f} {p[1]:.4f} {p[2]:.4f}\n")
for i in range(len(tris)):
f.write(f"f {3 * i + 1} {3 * i + 2} {3 * i + 3}\n")
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--in", dest="src", required=True, help="world goc")
ap.add_argument("--out", required=True, help="world da cat")
ap.add_argument("--y-max", type=float, required=True,
help="giu phan y < y-max; tuong chan dat o y-max")
ap.add_argument("--margin", type=float, default=0.3,
help="model co pose trong khoang nay quanh duong cat bi bo (m)")
ap.add_argument("--keep", action="append", default=[],
help="uri chua chuoi nay thi LUON giu nguyen (khong cat)")
ap.add_argument("--clip", action="append", default=[],
help="MODEL=MOI: cat mesh MODEL, ghi thanh model MOI, thay vao world")
ap.add_argument("--meshes-bin", help="vslam_world_export --meshes (va cham)")
ap.add_argument("--meshes-visual-bin", help="vslam_world_export --meshes --meshes-visual")
ap.add_argument("--models-dir", default="resources/models",
help="noi ghi model moi")
ap.add_argument("--colors", help="model_colors.json: chep mau MODEL sang MOI")
ap.add_argument("--wall-x", type=float, default=0.0,
help="tam x cua tuong chan (mesh rong 27.4 m quanh tam)")
a = ap.parse_args()
clips = dict(c.split("=", 1) for c in a.clip)
if clips and not (a.meshes_bin and a.meshes_visual_bin):
sys.exit("--clip can ca --meshes-bin lan --meshes-visual-bin")
# --- 2. Cat mesh, ghi model moi ---
if clips:
col = read_meshes(a.meshes_bin)
vis = read_meshes(a.meshes_visual_bin)
for src_name, new_name in clips.items():
d = os.path.join(a.models_dir, new_name)
os.makedirs(os.path.join(d, "meshes"), exist_ok=True)
for kind, data in (("collision", col), ("visual", vis)):
tris = world_triangles(*data, src_name, a.y_max)
write_obj(os.path.join(d, "meshes", kind + ".obj"), tris,
f"{src_name} ({kind}) cat o y <= {a.y_max}: {len(tris)} tam giac")
print(f"{new_name}/{kind}.obj: {len(tris)} tam giac")
with open(os.path.join(d, "model.config"), "w") as f:
f.write(MODEL_CONFIG.format(name=new_name, src=src_name, y_max=a.y_max))
with open(os.path.join(d, "model.sdf"), "w") as f:
f.write(MODEL_SDF.format(name=new_name))
if a.colors:
colors = json.load(open(a.colors))
for src_name, new_name in clips.items():
if src_name in colors:
colors[new_name] = colors[src_name]
with open(a.colors, "w") as f:
json.dump(colors, f, indent=0, sort_keys=True)
f.write("\n") # giu dung dinh dang gen_model_colors.py ghi ra
# --- 1 + 3. Loc model, thay model da cat, chen tuong chan ---
src = open(a.src).read()
if src.count("</world>") != 1:
sys.exit("world phai co dung mot </world>")
kept, dropped, replaced = [], [], []
def filt(m):
body = m.group(2)
uri = re.search(r"<uri>([^<]+)</uri>", body)
pose = re.search(r"<pose>([^<]+)</pose>", body)
# Khong co uri: bo doc world cung bo qua, de nguyen cho Gazebo that.
if uri is None:
kept.append(m.group(1))
return m.group(0)
model = uri.group(1).split("://", 1)[-1].split("/", 1)[0]
if model in clips:
replaced.append(m.group(1))
return CLIP_BLOCK.format(name=clips[model])
if any(k in uri.group(1) for k in a.keep):
kept.append(m.group(1))
return m.group(0)
y = float(pose.group(1).split()[1]) if pose else 0.0
if y < a.y_max - a.margin:
kept.append(m.group(1))
return m.group(0)
dropped.append(m.group(1))
return ""
# Non-greedy toi </model> GAN NHAT -- dung cach gazebo_world.cc tach khoi.
out = re.sub(r'[ \t]*<model name="([^"]+)">(.*?)</model>[ \t]*\n?', filt, src,
flags=re.S)
out = re.sub(r"[ \t]*</world>",
lambda _: WALL_BLOCK.format(x=a.wall_x, y=a.y_max) + " </world>",
out, count=1)
with open(a.out, "w") as f:
f.write(out)
print(f"giu {len(kept)}, thay {len(replaced)} (da cat mesh), bo {len(dropped)} model; "
f"tuong chan o y = {a.y_max}")
print(f"-> {a.out}")
if __name__ == "__main__":
main()

View File

@@ -175,6 +175,16 @@ double AteAligned(const std::vector<vslam::Pose2D>& est,
return std::sqrt(sum / static_cast<double>(n));
}
// Sai so LON NHAT, khong can chinh. Troi tich luy hien o day ro hon RMSE: phan
// lon quy dao tot keo RMSE xuong trong khi mot doan cuoi lech 0.25 m.
double MaxErr(const std::vector<vslam::Pose2D>& a,
const std::vector<vslam::Pose2D>& b) {
double m = 0.0;
const size_t n = std::min(a.size(), b.size());
for (size_t i = 0; i < n; ++i) m = std::max(m, vslam::Distance2D(a[i], b[i]));
return m;
}
} // namespace
int main(int argc, char** argv) {
@@ -189,6 +199,13 @@ int main(int argc, char** argv) {
bool trace = false;
bool with_images = false;
std::string ref_db;
// Moc so: "opt" = pose toi uu trong DB (nhu cu); "odom" = pose odom cua
// node. Trong MO PHONG odom ~ ground truth, nen "odom" do sai so do CHINH
// SLAM gay ra.
std::string ref_kind = "opt";
// Sigma odom moi lien ket gui RTAB-Map (m, rad). <0 = mac dinh SlamInput
// (0.1 m / 0.1 rad) -- dung cai runtime dang gui.
double odom_sigma_lin = -1.0, odom_sigma_ang = -1.0;
std::map<std::string, std::string> extra;
for (int i = 1; i < argc; ++i) {
@@ -204,6 +221,13 @@ int main(int argc, char** argv) {
else if (a == "--trace") trace = true;
else if (a == "--with-images") with_images = true;
else if (a == "--ref-db") ref_db = next();
else if (a == "--ref") ref_kind = next();
else if (a == "--odom-sigma") { // "LIN_M,ANG_RAD"
const std::string v = next();
const size_t c = v.find(',');
odom_sigma_lin = std::atof(v.substr(0, c).c_str());
if (c != std::string::npos) odom_sigma_ang = std::atof(v.substr(c + 1).c_str());
}
else if (a == "--param") {
// --param Key/Name=value. Di thang vao khoi overrides, tuc la CUNG
// duong ma slam.yaml di -- ke ca phep kiem ten key.
@@ -220,7 +244,8 @@ int main(int argc, char** argv) {
} else if (a == "--help") {
std::printf(
"cach dung: %s --db X.db [--localize] [--kidnap M,DEG]\n"
" [--limit N] [--optimizer 0|1|2|3] [--export-map out.pgm]\n",
" [--limit N] [--optimizer 0|1|2|3] [--export-map out.pgm]\n"
" [--ref opt|odom] [--odom-sigma LIN_M,ANG_RAD]\n",
argv[0]);
return 0;
}
@@ -451,6 +476,26 @@ int main(int argc, char** argv) {
const vslam::Pose2D kidnap_offset; // odom khong bi dong toi
// Moc cua PHIEN GOC: pose toi uu ma lan chay that luu trong DB, so voi odom.
// Lan chay lai phai so voi con so nay chu khong phai voi 0.
if (ref_kind == "odom") {
std::vector<vslam::Pose2D> opt, odo;
for (const Frame& f : frames) {
if (!f.has_optimized) continue;
opt.push_back(f.optimized);
odo.push_back(f.odom);
}
std::printf("phien goc (pose toi uu trong DB vs odom): %zu node, RMSE %.4f m, "
"max %.4f m\n", opt.size(), Rmse(opt, odo), MaxErr(opt, odo));
}
std::printf("odom sigma gui RTAB-Map: %s\n",
odom_sigma_lin > 0.0
? (std::to_string(odom_sigma_lin) + " m, " +
std::to_string(odom_sigma_ang) + " rad").c_str()
: ("mac dinh slam.yaml (" + std::to_string(cfg.odom_sigma_m) + " m, " +
std::to_string(cfg.odom_sigma_rad) + " rad)").c_str());
std::fflush(stdout);
std::vector<vslam::Pose2D> est, ref;
est.reserve(frames.size());
ref.reserve(frames.size());
@@ -459,10 +504,14 @@ int main(int argc, char** argv) {
double converge_s = -1.0;
const double t_start = frames.front().stamp;
size_t i_frame = 0;
for (const Frame& f : frames) {
++i_frame;
vslam::SlamInput in;
in.stamp = vslam::UnixTime::fromSec(f.stamp);
in.odom = vslam::Pose2DCompose(kidnap_offset, f.odom);
if (odom_sigma_lin > 0.0) in.odom_linear_var = odom_sigma_lin * odom_sigma_lin;
if (odom_sigma_ang > 0.0) in.odom_angular_var = odom_sigma_ang * odom_sigma_ang;
in.scan = &f.scan;
if (f.has_image) {
in.depth = &f.depth_pod;
@@ -476,14 +525,21 @@ int main(int argc, char** argv) {
if (o.loop_closure_id > 0) loops++;
if (o.proximity_id > 0) prox++;
if (f.has_optimized) {
if (ref_kind == "odom") {
est.push_back(o.pose_map);
ref.push_back(f.odom);
} else if (f.has_optimized) {
est.push_back(o.pose_map);
ref.push_back(f.optimized);
}
if (trace && (processed % 20 == 0)) {
std::printf(" [%4d] ms %7.1f wm %4d loop %d prox %d\n", processed,
o.process_ms, o.nodes_wm, o.loop_closure_id, o.proximity_id);
std::printf(" [%4d] khung %zu/%zu ms %7.1f wm %4d loop %d prox %d\n",
processed, i_frame, frames.size(), o.process_ms, o.nodes_wm,
o.loop_closure_id, o.proximity_id);
// Qua `| tee` stdout bi dem theo khoi 4 kB: khong xa thi terminal im
// lang hang chuc phut va nguoi chay tuong da treo.
std::fflush(stdout);
}
if (localize && converge_s < 0.0 && o.localized && f.has_optimized &&
vslam::Distance2D(o.pose_map, f.optimized) < 0.30) {
@@ -498,10 +554,12 @@ int main(int argc, char** argv) {
std::printf(" vong dong / lan can: %d / %d\n", loops, prox);
std::printf(" process_ms : cuoi %.1f, max %.1f, p95 %.1f\n", s.last_ms,
s.max_ms, s.p95_ms);
std::printf(" cap so sanh : %zu (node co pose toi uu)\n", est.size());
std::printf(" cap so sanh : %zu (moc: %s)\n", est.size(),
ref_kind == "odom" ? "odom" : "node co pose toi uu");
const double ate_raw = Rmse(est, ref);
const double ate = AteAligned(est, ref);
std::printf(" ATE RMSE (tho) : %.4f m\n", ate_raw);
std::printf(" sai so lon nhat : %.4f m (tho)\n", MaxErr(est, ref));
std::printf(" ATE RMSE (can chinh): %.4f m <-- chi tieu < 0.10\n", ate);
if (converge_s >= 0.0) std::printf(" hoi tu sau : %.2f s\n", converge_s);
else if (localize) std::printf(" hoi tu sau : KHONG hoi tu\n");