diff --git a/app/src/runtime.cc b/app/src/runtime.cc index 1d4ab0b..7962a47 100644 --- a/app/src/runtime.cc +++ b/app/src/runtime.cc @@ -87,6 +87,9 @@ StatusResponse Runtime::OpenSource() { Transform t; if (cfg_->robot.StaticTransform(kBaseLinkFrame, kLaserFrame, &t)) { sc.lidar_x = t.translation.x; + // Do cao LiDAR tren TAM TRUC. Duong 2D cu khong dung; dia hinh 3D thi + // can de tia o dung 0.2165 m tren san. + sc.lidar_z = t.translation.z; } if (cfg_->robot.StaticTransform(kBaseLinkFrame, kCameraFrame, &t)) { sc.camera_x = t.translation.x; @@ -2121,6 +2124,9 @@ void Runtime::WebLoop() { snap.ground_truth = have_gt_latched ? gt_latched : source_->sim->ground_truth(); source_->sim->true_tilt(&snap.gt_roll, &snap.gt_pitch); + // Do cao san THAT duoi robot. Chi khac 0 khi world co dia hinh (doc, + // san cao); uoc luong hien van la 2D nen day la thuoc do cho no. + snap.gt_z = source_->sim->ground_truth_3d().z; } // pose_map = map_correction * pose_odom. diff --git a/libs/vslam_sim/include/vslam/gazebo_world.h b/libs/vslam_sim/include/vslam/gazebo_world.h index 3e55bc1..388a7e7 100644 --- a/libs/vslam_sim/include/vslam/gazebo_world.h +++ b/libs/vslam_sim/include/vslam/gazebo_world.h @@ -57,8 +57,17 @@ struct WorldModel { // `CGMClassic` mot minh ra bao loi 239 x 111 m, va ca the gioi phinh tu // 25x51 m len 263x146 m. double sx = 1.0, sy = 1.0, sz = 1.0; + + // Model DIA HINH: mat robot di LEN duoc (san, doc, chieu nghi), khong phai + // vat can. Nhan bang TEN model (`kTerrainModelPrefix`), KHONG bang phap + // tuyen: mat ban, mat giuong, mat ghe cung huong len, va lay theo phap + // tuyen la cho robot leo len ban. + bool terrain = false; }; +// Model co ten bat dau bang chuoi nay la dia hinh. Xem `WorldModel::terrain`. +constexpr const char* kTerrainModelPrefix = "vslam_terrain_"; + struct GazeboWorld { std::string world_path; std::vector models; @@ -80,9 +89,13 @@ StatusResponse LoadGazeboWorld(const std::string& world_path, // Raster hoa mesh VA CHAM cua world thanh luoi chiem dung 2D. // -// Chi lay tam giac nam trong dai do cao [z_min, z_max] so voi SAN: do la dai -// ma LiDAR 2D thuc su quet. Lay het moi do cao se bien ca mat san thanh vat -// can, va lay qua cao se bo lot ban ghe. +// Chi lay tam giac nam trong dai do cao [z_min, z_max] tinh tu MAT SAN CUC BO +// cua tung o: do la dai ma LiDAR 2D thuc su quet. Lay het moi do cao se bien +// ca mat san thanh vat can, va lay qua cao se bo lot ban ghe. +// +// World khong co model dia hinh thi mat san o moi o la 0 -- dung y het truoc +// day. Co dia hinh (san cao, doc) thi dai z TRUOT theo san: mot cai tu dung +// tren san tang 2 cao 1.5 m van la vat can, va mat doc KHONG thanh tuong. // // `resolution` met/o. `pad` la vien trong them quanh bao loi, tinh bang met. struct WorldRasterOptions { @@ -92,10 +105,28 @@ struct WorldRasterOptions { double pad = 1.0; }; +// Dia hinh rut tu world, cung kich thuoc va goc voi luoi. +struct WorldTerrain { + // Do cao mat tren cua dia hinh tai TAM moi o (m, he world). O khong co dia + // hinh = 0. Nhieu tam giac chong nhau thi lay cao nhat (mat tren). + std::vector floor_z; + // Dinh cua vat can cao nhat trong moi o bi chiem (m, he world); 0 = o + // trong. Cho phep raycast 3D biet tuong cao toi dau thay vi gia dinh mot + // chieu cao chung. + std::vector wall_top; + size_t terrain_cells = 0; // so o co dia hinh; 0 = world phang + float floor_min = 0.0f, floor_max = 0.0f; +}; + StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, const WorldRasterOptions& opt, OccupancyGrid* out); +// Nhu tren, va tra them dia hinh. `terrain` co the null. +StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, + const WorldRasterOptions& opt, + OccupancyGrid* out, WorldTerrain* terrain); + // --------------------------------------------------------------------------- // Chi muc doan 2D, de raycast trung MAT TUONG chu khong trung bien o // --------------------------------------------------------------------------- @@ -135,10 +166,15 @@ struct WorldSegments { // 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. +// +// Model dia hinh khong sinh doan nao (no la san, khong phai tuong). `floor_z` +// (tu `WorldTerrain`, cung kich thuoc `grid`) dua dai z ve mat san cuc bo; +// null = san phang o 0, y het truoc day. StatusResponse BuildWorldSegments(const GazeboWorld& world, const WorldRasterOptions& opt, const OccupancyGrid& grid, - WorldSegments* out); + WorldSegments* out, + const std::vector* floor_z = nullptr); // --------------------------------------------------------------------------- // Xuat hinh hoc cho khung 3D diff --git a/libs/vslam_sim/include/vslam/sim_source.h b/libs/vslam_sim/include/vslam/sim_source.h index c3dce7c..0faddc8 100644 --- a/libs/vslam_sim/include/vslam/sim_source.h +++ b/libs/vslam_sim/include/vslam/sim_source.h @@ -210,6 +210,29 @@ struct SimConfig { bool follow_terrain_slope = true; double wheelbase_for_slope = 0.44; // khoang cach truoc-sau de do doc + // ================== DIA HINH 3D (DOC, SAN NHIEU TANG) ================== + // Tat = hanh vi cu, giu NGUYEN tung byte: robot o z = 0, LiDAR quet mat + // phang ngang, camera o do cao co dinh. Do cao san chi de camera thay vuc. + // + // Bat thi robot di TREN mat san: + // * z = san duoi robot; roll/pitch theo dia hinh (truoc-sau, trai-phai); + // * lenh v la toc do BANH doc mat doc: di ngang v*cos(pitch), encoder + // dem quang duong doc doc; + // * LiDAR quet tia 3D nghieng theo than, cham doc/san/tuong that -- nen + // "tuong gia" o chan doc hien ra dung cho (0.2165 / tan(goc)); + // * camera dat theo tu the 6-DoF; gyro thay toc do doi nghieng do dia hinh; + // * chenh san giua hai o ke nhau > max_step la vat can (mep bac, mep san + // cao) -- robot khong roi khoi mep doc. + // + // kAuto: bat khi world co model dia hinh (`vslam_terrain_*`). + enum class TerrainMode { kAuto, kOff, kOn }; + TerrainMode terrain = TerrainMode::kAuto; + double max_step = 0.05; // m, chenh san toi da giua hai o ke nhau + // LiDAR nghieng theo CA lo xo giam xoc (mac dinh chi theo dia hinh). Than + // ngoc 2 do khi tang toc la tia cham san phang o ~6 m -- that, nhung lam + // nhieu moi bai do doc, nen de nut rieng. + bool lidar_follow_suspension = false; + double encoder_rate_hz = 50.0; // ================== HAI LOAI TRUOT, RAT KHAC NHAU ================== @@ -251,6 +274,16 @@ struct SimConfig { double speed = 1.0; }; +// Tu the that 6-DoF cua robot (chi de danh gia). +// +// (x, y, z) la `base_footprint`: diem tren MAT SAN duoi tam robot, z la do +// cao san o do. roll/pitch la nghieng THAT cua than (dia hinh + lo xo), cung +// quy uoc voi `true_tilt` (pitch duong = mui chuc xuong). +struct SimPose3 { + double x = 0.0, y = 0.0, z = 0.0; + double roll = 0.0, pitch = 0.0, yaw = 0.0; +}; + // So huu ca bon nguon, y het ReplaySource. class SimSource { public: @@ -281,6 +314,17 @@ class SimSource { // z am = bac hut xuong / cau thang di xuong. void SetFloorHeight(double x0, double y0, double x1, double y1, float z); + // Doc TUYEN TINH theo x: san tang deu tu `z_at_x0` (o x0) toi `z_at_x1` (o + // x1), khong doi theo y. Cho bai kiem dia hinh 3D khong can file world. + void SetFloorRamp(double x0, double y0, double x1, double y1, float z_at_x0, + float z_at_x1); + + // Dia hinh 3D dang bat chua (sau Open(); xem SimConfig::terrain). + bool terrain_active() const; + + // Tu the that 6-DoF. CHI de danh gia, nhu `ground_truth()`. + SimPose3 ground_truth_3d() const; + // Danh dau mot vung hinh chu nhat (toa do THE GIOI, met) la KINH. // // O kinh phai la o BI CHIEM trong ban do (data >= 50) -- kinh la vat can diff --git a/libs/vslam_sim/src/gazebo_world.cc b/libs/vslam_sim/src/gazebo_world.cc index 316fdf9..3162524 100644 --- a/libs/vslam_sim/src/gazebo_world.cc +++ b/libs/vslam_sim/src/gazebo_world.cc @@ -155,6 +155,7 @@ StatusResponse LoadGazeboWorld(const std::string& world_path, if (uri.empty()) { skip++; continue; } m.model_name = uri.substr(uri.rfind('/') + 1); + m.terrain = m.model_name.rfind(kTerrainModelPrefix, 0) == 0; std::string root; const std::string dir = ResolveModelUri(uri, roots, &root); @@ -597,6 +598,12 @@ bool ReadObjTriangles(const std::string& path, std::vector* out) { StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, const WorldRasterOptions& opt, OccupancyGrid* out) { + return RasterizeGazeboWorld(world, opt, out, nullptr); +} + +StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, + const WorldRasterOptions& opt, + OccupancyGrid* out, WorldTerrain* terrain) { if (!(opt.resolution > 0.0)) { return StatusResponse::Error(StatusCode::kInvalidArgument, "resolution phai duong"); @@ -675,15 +682,70 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, // o deu da biet -- cai chua duoc quet la chuyen cua ban do SLAM. out->data.assign(static_cast(w) * h, 0); - // --- Luot 2: to tam giac trong dai do cao --- + // --- Luot 1.5: dia hinh -> do cao san --- + // + // Do cao mat tren tai TAM o, noi suy trong tam giac. Tam giac dung thang + // (suy bien tren mat bang) la mat ben cua doc/bac, khong dinh nghia san nen + // bo qua. Chong nhau thi lay CAO NHAT: mot hop kin co ca mat day lan mat tren. + const size_t n_cells = static_cast(w) * h; + std::vector ground(n_cells, 0.0f); + std::vector covered(n_cells, 0); + size_t n_terrain_models = 0, n_terrain_cells = 0; + for (const Loaded& L : loaded) { + if (!L.m->terrain) continue; + n_terrain_models++; + for (const Tri& t : L.tris) { + const double ax = t.x[0], ay = t.y[0]; + const double bx = t.x[1], by = t.y[1]; + const double cx = t.x[2], cy = t.y[2]; + const double den = (by - cy) * (ax - cx) + (cx - bx) * (ay - cy); + if (std::fabs(den) < 1e-12) continue; + const int cx0 = std::max(0, static_cast((std::min({ax, bx, cx}) - minx) / res)); + const int cx1 = std::min(static_cast(w) - 1, + static_cast((std::max({ax, bx, cx}) - minx) / res)); + const int cy0 = std::max(0, static_cast((std::min({ay, by, cy}) - miny) / res)); + const int cy1 = std::min(static_cast(h) - 1, + static_cast((std::max({ay, by, cy}) - miny) / res)); + for (int gy = cy0; gy <= cy1; ++gy) { + for (int gx = cx0; gx <= cx1; ++gx) { + const double px = minx + (gx + 0.5) * res; + const double py = miny + (gy + 0.5) * res; + const double l1 = ((by - cy) * (px - cx) + (cx - bx) * (py - cy)) / den; + const double l2 = ((cy - ay) * (px - cx) + (ax - cx) * (py - cy)) / den; + const double l3 = 1.0 - l1 - l2; + if (l1 < -1e-9 || l2 < -1e-9 || l3 < -1e-9) continue; + const float z = static_cast(l1 * t.z[0] + l2 * t.z[1] + l3 * t.z[2]); + const size_t idx = static_cast(gy) * w + gx; + if (!covered[idx]) { + covered[idx] = 1; + ground[idx] = z; + n_terrain_cells++; + } else if (z > ground[idx]) { + ground[idx] = z; + } + } + } + } + } + // O khong co dia hinh la san 0, nen min/max luon tinh ca 0. World phang: + // fmin = fmax = 0 va luot 2 duoi day y het truoc. + float fmin = 0.0f, fmax = 0.0f; + for (float f : ground) { fmin = std::min(fmin, f); fmax = std::max(fmax, f); } + + // --- Luot 2: to tam giac VAT CAN trong dai do cao, tinh tu san cuc bo --- + std::vector top(n_cells, 0.0f); size_t n_used = 0; for (const Loaded& L : loaded) { + if (L.m->terrain) continue; // dia hinh la san, khong phai vat can for (const Tri& t : L.tris) { // Tam giac nam hoan toan ngoai dai thi bo. Cat dung tam giac la thua: // mesh day dac nen mot tam giac bien bi bo van con hang xom phu. + // + // Day la phep loc THO theo dai cua ca ban do; dai dung cua tung o kiem + // ben duoi, theo san cua chinh o do. const double tz0 = std::min({t.z[0], t.z[1], t.z[2]}); const double tz1 = std::max({t.z[0], t.z[1], t.z[2]}); - if (tz1 < opt.z_min || tz0 > opt.z_max) continue; + if (tz1 < fmin + opt.z_min || tz0 > fmax + opt.z_max) continue; n_used++; // Bao loi cua tam giac, roi kiem tung o bang toa do trong tam. @@ -721,7 +783,13 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, inside = l1 >= -1e-9 && l2 >= -1e-9 && l3 >= -1e-9; } if (inside) { - out->data[static_cast(gy) * w + gx] = 100; + const size_t idx = static_cast(gy) * w + gx; + // Dai z cua RIENG o nay. World phang: san 0, trung phep loc tho + // o tren nen khong bo them o nao. + const double f = ground[idx]; + if (tz1 < f + opt.z_min || tz0 > f + opt.z_max) continue; + out->data[idx] = 100; + if (tz1 > top[idx]) top[idx] = static_cast(tz1); } } } @@ -734,6 +802,18 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, << minx << ", " << miny << "), " << n_mesh << " mesh, " << n_tri << " tam giac (" << n_used << " trong dai z [" << opt.z_min << ", " << opt.z_max << "]), " << occ << " o bi chiem"); + if (n_terrain_models > 0) { + VSLAM_INFO("world -> dia hinh: " << n_terrain_models << " model, " + << n_terrain_cells << " o, san tu " << fmin << " den " << fmax + << " m; dai z cua vat can tinh tu san cuc bo"); + } + if (terrain != nullptr) { + terrain->floor_z = std::move(ground); + terrain->wall_top = std::move(top); + terrain->terrain_cells = n_terrain_cells; + terrain->floor_min = fmin; + terrain->floor_max = fmax; + } return StatusResponse::Ok(); } @@ -742,7 +822,8 @@ StatusResponse RasterizeGazeboWorld(const GazeboWorld& world, StatusResponse BuildWorldSegments(const GazeboWorld& world, const WorldRasterOptions& opt, const OccupancyGrid& grid, - WorldSegments* out) { + WorldSegments* out, + const std::vector* floor_z) { if (out == nullptr) { return StatusResponse::Error(StatusCode::kInvalidArgument, "out == null"); } @@ -759,6 +840,18 @@ StatusResponse BuildWorldSegments(const GazeboWorld& world, const double ox = out->origin_x, oy = out->origin_y; const int W = static_cast(grid.width), H = static_cast(grid.height); + // San cuc bo tai mot diem, de dai z truot theo dia hinh. Khong co ban do + // san thi la 0 -- y het truoc. + const bool have_floor = + floor_z != nullptr && floor_z->size() == static_cast(W) * H; + auto floor_at = [&](double x, double y) -> double { + if (!have_floor) return 0.0; + const int fx = static_cast(std::floor((x - ox) / res)); + const int fy = static_cast(std::floor((y - oy) / res)); + if (fx < 0 || fy < 0 || fx >= W || fy >= H) return 0.0; + return (*floor_z)[static_cast(fy) * grid.width + fx]; + }; + // --- 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 @@ -767,6 +860,7 @@ StatusResponse BuildWorldSegments(const GazeboWorld& world, std::map> cache; for (const WorldModel& m : world.models) { if (m.collision_obj.empty()) continue; + if (m.terrain) continue; // dia hinh la san: tia cham no o raycast 3D auto it = cache.find(m.model_name); if (it == cache.end()) { std::vector tris; @@ -789,7 +883,8 @@ StatusResponse BuildWorldSegments(const GazeboWorld& world, } 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; + const double f = floor_at((X[0] + X[1] + X[2]) / 3.0, (Y[0] + Y[1] + Y[2]) / 3.0); + if (zhi < f + opt.z_min || zlo > f + 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(X[a])); diff --git a/libs/vslam_sim/src/sim_source.cc b/libs/vslam_sim/src/sim_source.cc index 817046b..401cc89 100644 --- a/libs/vslam_sim/src/sim_source.cc +++ b/libs/vslam_sim/src/sim_source.cc @@ -1,10 +1,12 @@ #include "vslam/sim_source.h" +#include #include #include #include #include #include +#include #include "vslam/geometry.h" #include "vslam/log.h" @@ -16,6 +18,33 @@ namespace vslam { namespace { +// Raycast dia hinh 3D: chi noi suy san khi tia da xuong trong dai nay tren +// mat san cua o. Lon hon nhieu sai khac giua gia tri o va gia tri noi suy +// (o doc 30 do: < 1.5 cm), nho hon do cao LiDAR (0.2165 m). +constexpr double kSmoothFloorBand = 0.15; + +// Ma tran xoay R = Rz(yaw) * Ry(pitch) * Rx(roll), REP-103: than -> the gioi. +// pitch DUONG = mui chuc xuong, roll DUONG = ben trai nhac len. Tinh MOT lan +// cho moi scan / moi khung anh, khong goi sin/cos cho tung tia. +struct Rot3 { + double m[9]; + static Rot3 FromRPY(double roll, double pitch, double yaw) { + const double cr = std::cos(roll), sr = std::sin(roll); + const double cp = std::cos(pitch), sp = std::sin(pitch); + const double cy = std::cos(yaw), sy = std::sin(yaw); + Rot3 r; + r.m[0] = cy * cp; r.m[1] = cy * sp * sr - sy * cr; r.m[2] = cy * sp * cr + sy * sr; + r.m[3] = sy * cp; r.m[4] = sy * sp * sr + cy * cr; r.m[5] = sy * sp * cr - cy * sr; + r.m[6] = -sp; r.m[7] = cp * sr; r.m[8] = cp * cr; + return r; + } + void Apply(double x, double y, double z, double* ox, double* oy, double* oz) const { + *ox = m[0] * x + m[1] * y + m[2] * z; + *oy = m[3] * x + m[4] * y + m[5] * z; + *oz = m[6] * x + m[7] * y + m[8] * z; + } +}; + // Bon lop nay la interface driver THAT, y het ReplaySource. vslam_node khong // phan biet duoc phan cung / file .vsr / mo phong. @@ -204,6 +233,21 @@ struct SimSource::Impl { double terrain_pitch = 0.0; // nghieng do DIA HINH, cong vao than double last_accel = 0.0; + // --- Dia hinh 3D (SimConfig::terrain). Tat thi khong truong nao duoi day + // duoc doc, va moi duong cu giu nguyen tung byte. --- + bool terrain_on = false; // chot o Open() + double ground_z = 0.0; // san duoi tam robot (base_footprint) + double terrain_roll = 0.0; // nghieng ngang do dia hinh + double terrain_pitch_rate = 0.0, terrain_roll_rate = 0.0; + // Goc dia hinh da co gia tri dau chua. Chua thi lan tinh dau KHONG sinh toc + // do goc -- neu khong, robot dat san tren doc se "quay" 10 do trong 5 ms. + bool terrain_ready = false; + bool steps_dirty = true; // san vua doi -> tinh lai mat na bac + std::vector step_block; // o sat mep bac (chenh > max_step) + // Dinh vat can cao nhat moi o (he world, tu mesh). 0 = khong biet -> dung + // `wall_height` nhu cu. + std::vector wall_top; + std::atomic stop{false}; mutable std::mutex state_mu; Stats stats; @@ -354,6 +398,82 @@ struct SimSource::Impl { return inf; } + // Do cao san NOI SUY SONG TUYEN giua tam cac o (chi dia hinh 3D). + // + // Gia tri tung o la bac thang 5 cm: o doc 30 do moi o nhay 2.9 cm, va + // robot / tia doc san se thay rang cua thay vi mat doc. Ngoai ban do kep vao + // o bien -- robot khong ra duoc ngoai (va cham), con tia ra ngoai thi raycast + // da dung tu truoc. + double FloorAtSmooth(double wx, double wy) const { + if (floor_z.empty() || !std::isfinite(wx) || !std::isfinite(wy)) return 0.0; + const int W = static_cast(map.width), H = static_cast(map.height); + const double fx = std::min( + std::max((wx - map.origin.position.x) / map.resolution - 0.5, 0.0), W - 1.0); + const double fy = std::min( + std::max((wy - map.origin.position.y) / map.resolution - 0.5, 0.0), H - 1.0); + const int x0 = static_cast(fx), y0 = static_cast(fy); + const int x1 = std::min(x0 + 1, W - 1), y1 = std::min(y0 + 1, H - 1); + const double tx = fx - x0, ty = fy - y0; + auto at = [&](int cx, int cy) { + return static_cast( + floor_z[static_cast(cy) * map.width + static_cast(cx)]); + }; + const double a = at(x0, y0) * (1.0 - tx) + at(x1, y0) * tx; + const double b = at(x0, y1) * (1.0 - tx) + at(x1, y1) * tx; + return a * (1.0 - ty) + b * ty; + } + + // O nao sat mep bac -- chenh san voi mot o ke > max_step. Danh dau CA HAI + // phia mep, va CellBlocked() coi chung nhu tuong: robot khong leo duoc + // len bac, cung khong roi khoi mep san cao. + void RebuildStepMask() { + const uint32_t W = map.width, H = map.height; + step_block.assign(static_cast(W) * H, 0); + const float lim = static_cast(cfg.max_step); + size_t n = 0; + for (uint32_t cy = 0; cy < H; ++cy) { + for (uint32_t cx = 0; cx < W; ++cx) { + const size_t i = static_cast(cy) * W + cx; + const float f = floor_z[i]; + const bool step = (cx + 1 < W && std::fabs(floor_z[i + 1] - f) > lim) || + (cx > 0 && std::fabs(floor_z[i - 1] - f) > lim) || + (cy + 1 < H && std::fabs(floor_z[i + W] - f) > lim) || + (cy > 0 && std::fabs(floor_z[i - W] - f) > lim); + if (step) { step_block[i] = 1; n++; } + } + } + steps_dirty = false; + VSLAM_DEBUG("sim: mat na bac: " << n << " o chenh > " << cfg.max_step << " m"); + } + + // z, pitch, roll do DIA HINH tai tu the hien tai, va toc do doi cua chung + // (cho gyro). Bon diem do: truoc/sau cach nhau `wheelbase_for_slope`, + // trai/phai cach nhau `wheel_separation`. + void UpdateTerrainPose(double dt) { + const double hl = cfg.wheelbase_for_slope / 2.0; + const double hw = cfg.wheel_separation / 2.0; + const double c = std::cos(yaw), s = std::sin(yaw); + const double ff = FloorAtSmooth(x + hl * c, y + hl * s); + const double fb = FloorAtSmooth(x - hl * c, y - hl * s); + const double fl = FloorAtSmooth(x - hw * s, y + hw * c); + const double fr = FloorAtSmooth(x + hw * s, y - hw * c); + // Doc len phia truoc -> mui ngoc len -> pitch AM (quy uoc cu). Ben TRAI + // cao hon -> roll DUONG (quay quanh +X dua +Y len). + const double np = -std::atan2(ff - fb, 2.0 * hl); + const double nr = std::atan2(fl - fr, 2.0 * hw); + if (terrain_ready && dt > 0.0) { + terrain_pitch_rate = (np - terrain_pitch) / dt; + terrain_roll_rate = (nr - terrain_roll) / dt; + } else { + terrain_pitch_rate = 0.0; + terrain_roll_rate = 0.0; + terrain_ready = true; + } + terrain_pitch = np; + terrain_roll = nr; + ground_z = FloorAtSmooth(x, y); + } + // Do cao san tai mot diem the gioi. Ngoai ban do coi nhu phang. float FloorAt(double wx, double wy) const { const int cx = static_cast( @@ -567,7 +687,13 @@ struct SimSource::Impl { // depth camera. Mot robot dich vu di vao cua kinh la truong hop that, // va no la ly do nhanh US_BLOCKED cua FSM ton tai. if (map.data[idx] >= 50 && !(idx < glass.size() && glass[idx])) { - const double lo = fz, hi = fz + cfg.wall_height; + const double lo = fz; + double hi = fz + cfg.wall_height; + // Dia hinh 3D: vat can cao dung bang mesh cua no. Tuong 4 m ben doc + // khong duoc thanh tuong 2 m chi vi san o day bang 0. + if (terrain_on && idx < wall_top.size() && wall_top[idx] > lo) { + hi = wall_top[idx]; + } 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)) { // Chi tinh chinh theo mat phang XY: tuong trong dai z la thang dung, @@ -581,8 +707,18 @@ struct SimSource::Impl { // Cham san: tia tut xuong duoi mat san trong o nay. Noi suy tuyen tinh // giua hai dau o de khong luong tu hoa khoang cach theo kich thuoc o. - const double gap_enter = z_enter - fz; - const double gap_exit = z_exit - fz; + // + // Dia hinh 3D: san tai hai dau o lay NOI SUY, de mat doc la mat phang + // chu khong phai bac thang. Chi tinh khi tia da xuong gan san -- tia + // LiDAR cach san 0.22 m bay qua hang tram o, va noi suy o moi o la + // phi. + double f_in = fz, f_out = fz; + if (terrain_on && std::min(z_enter, z_exit) < fz + kSmoothFloorBand) { + f_in = FloorAtSmooth(ox + dx * t_enter * res, oy + dy * t_enter * res); + f_out = FloorAtSmooth(ox + dx * t_exit * res, oy + dy * t_exit * res); + } + const double gap_enter = z_enter - f_in; + const double gap_exit = z_exit - f_out; if (gap_enter > 0.0 && gap_exit <= 0.0) { const double frac = gap_enter / (gap_enter - gap_exit); return (t_enter + frac * (t_exit - t_enter)) * res; @@ -614,8 +750,10 @@ struct SimSource::Impl { cy >= static_cast(map.height)) { return true; } - return map.data[static_cast(cy) * map.width + - static_cast(cx)] >= 50; + const size_t idx = static_cast(cy) * map.width + static_cast(cx); + if (map.data[idx] >= 50) return true; + // Dia hinh 3D: mep bac / mep san cao cung chan nhu tuong. + return terrain_on && idx < step_block.size() && step_block[idx] != 0; } // Kiem va cham: lay 8 diem tren vanh robot. @@ -649,11 +787,24 @@ struct SimSource::Impl { prev_v = v; // Tich phan pose THAT. - const double nx = x + v * std::cos(yaw) * dt; - const double ny = y + v * std::sin(yaw) * dt; - const double nyaw = NormalizeAngle(yaw + w * dt); + double nx, ny, nyaw; + if (terrain_on) { + // Lenh v la toc do BANH, doc mat san: di NGANG v*cos(pitch). Than quay + // quanh truc z CUA NO (dang nghieng), nen huong tren mat bang doi + // w*cos(roll)/cos(pitch) -- bo qua thi sai 15% o doc 30 do. + const double ct = std::cos(terrain_pitch); + const double cr = std::cos(terrain_roll); + nx = x + v * ct * std::cos(yaw) * dt; + ny = y + v * ct * std::sin(yaw) * dt; + nyaw = NormalizeAngle(yaw + w * cr / std::max(ct, 0.1) * dt); + } else { + nx = x + v * std::cos(yaw) * dt; + ny = y + v * std::sin(yaw) * dt; + nyaw = NormalizeAngle(yaw + w * dt); + } std::lock_guard lk(state_mu); + if (terrain_on && steps_dirty) RebuildStepMask(); if (Collides(nx, ny)) { // Dung tai cho. Robot that se truot va quay, nhung "dung han" la mo // hinh trung thuc hon voi mot robot dich vu co bumper cat nguon. @@ -690,7 +841,10 @@ struct SimSource::Impl { roll += roll_rate * dt; // Nghieng do DIA HINH: do chenh lech do cao san giua truoc va sau robot. - if (cfg.follow_terrain_slope) { + if (terrain_on) { + // Ca z, pitch va roll, voi toc do doi cho gyro. + UpdateTerrainPose(dt); + } else if (cfg.follow_terrain_slope) { const double half = cfg.wheelbase_for_slope / 2.0; const double fz = FloorAt(x + half * std::cos(yaw), y + half * std::sin(yaw)); const double bz = FloorAt(x - half * std::cos(yaw), y - half * std::sin(yaw)); @@ -728,6 +882,45 @@ struct SimSource::Impl { right_rad += vr / cfg.wheel_radius * dt; } + // LiDAR tren dia hinh 3D: MOT mat phang quet gan cung vao than, nghieng + // theo dia hinh (va theo lo xo neu `lidar_follow_suspension`). Moi tia la + // tia 3D, cham tuong / vat can / MAT SAN that. + // + // Day la thu cho thay loi cua SLAM 2D tren doc: dung o san phang nhin vao + // chan doc goc t, tia ngang cham mat doc o 0.2165 / tan(t) -- mot "tuong" + // khong co that, va no lui dan khi robot tien len. + void FillScan3D(LaserScan* s) { + double rx, ry, rz, ryaw, rroll, rpitch; + { + std::lock_guard lk(state_mu); + rx = x; ry = y; rz = ground_z; ryaw = yaw; + rroll = terrain_roll; + rpitch = terrain_pitch; + if (cfg.lidar_follow_suspension) { rroll += roll; rpitch += pitch; } + } + const Rot3 R = Rot3::FromRPY(rroll, rpitch, ryaw); + // Goc tia: base_footprint (tren san) + R * (lidar_x, 0, r_banh + lidar_z). + // `lidar_z` do tu TAM TRUC banh, nhu laser_link trong robot.yaml. + double ox, oy, oz; + R.Apply(cfg.lidar_x, 0.0, cfg.wheel_radius + cfg.lidar_z, &ox, &oy, &oz); + ox += rx; oy += ry; oz += rz; + + std::normal_distribution noise(0.0, cfg.lidar_noise_stddev); + for (uint32_t i = 0; i < cfg.lidar_samples; ++i) { + const double a = s->angle_min + i * s->angle_increment; + double dx, dy, dz; + R.Apply(std::cos(a), std::sin(a), 0.0, &dx, &dy, &dz); + const double r = RaycastDepth(ox, oy, oz, dx, dy, dz, cfg.lidar_range_max); + if (std::isinf(r)) { + s->ranges[i] = std::numeric_limits::infinity(); + } else { + const double rn = r + noise(rng); + s->ranges[i] = static_cast( + rn < cfg.lidar_range_min ? cfg.lidar_range_min : rn); + } + } + } + LaserScanPtr MakeScan(UnixTime stamp) { auto s = std::make_shared(); s->header.stamp = stamp; @@ -742,6 +935,11 @@ struct SimSource::Impl { s->range_max = static_cast(cfg.lidar_range_max); s->ranges.resize(cfg.lidar_samples); + if (terrain_on) { + FillScan3D(s.get()); + return s; + } + double rx, ry, ryaw; { std::lock_guard lk(state_mu); @@ -782,18 +980,20 @@ struct SimSource::Impl { depth_buf.assign(static_cast(w) * h * 2, 0); // 16UC1 } - double rx, ry, ryaw; + double rx, ry, rz, ryaw; { std::lock_guard lk(state_mu); rx = x; ry = y; + rz = ground_z; ryaw = yaw; } - // Vi tri camera trong the gioi. - const double cx_w = rx + cfg.camera_x * std::cos(ryaw); - const double cy_w = ry + cfg.camera_x * std::sin(ryaw); - const double cz_w = cfg.camera_z; + // Vi tri camera trong the gioi. Dia hinh 3D tinh lai ben duoi, theo tu the + // 6-DoF cua than. + double cx_w = rx + cfg.camera_x * std::cos(ryaw); + double cy_w = ry + cfg.camera_x * std::sin(ryaw); + double cz_w = cfg.camera_z; // Noi suy tu HFOV. Anh da decimate nen fx/fy tinh theo kich thuoc DA // giam; binning trong CameraInfo bao cho consumer biet dieu do. @@ -810,12 +1010,25 @@ struct SimSource::Impl { std::lock_guard lk(state_mu); body_roll = roll; body_pitch = pitch + terrain_pitch; + if (terrain_on) body_roll += terrain_roll; } const double total_pitch = cfg.camera_pitch + body_pitch; const double cp = std::cos(total_pitch), sp = std::sin(total_pitch); const double cr_b = std::cos(body_roll), sr_b = std::sin(body_roll); const double cy_r = std::cos(ryaw), sy_r = std::sin(ryaw); + // Dia hinh 3D: than xoay du ba goc, camera chuc `camera_pitch` TREN than. + // (Duong cu cong camera_pitch vao pitch cua than va xoay roll truoc -- + // chi dung khi roll = 0, du cho san phang.) + const Rot3 R_body = Rot3::FromRPY(body_roll, body_pitch, ryaw); + const double ccp = std::cos(cfg.camera_pitch), csp = std::sin(cfg.camera_pitch); + if (terrain_on) { + R_body.Apply(cfg.camera_x, 0.0, cfg.camera_z, &cx_w, &cy_w, &cz_w); + cx_w += rx; + cy_w += ry; + cz_w += rz; + } + // Khong dung mot `normal_distribution` chung: sigma phu thuoc KHOANG // CACH cua tung diem anh, nen phan phoi duoc dung ngay trong vong lap. std::uniform_real_distribution uni01(0.0, 1.0); @@ -831,15 +1044,23 @@ struct SimSource::Impl { // Quang hoc -> than robot: +Z_quang = +X_than, +X_quang = -Y_than, // +Y_quang = -Z_than. Roi chuc xuong `camera_pitch`, roi xoay theo yaw. const double bx0 = oz * inv, by0 = -ox * inv, bz0 = -oy * inv; - // Nghieng ngang cua than (roll) truoc, roi chuc xuong (pitch). - const double by1 = by0 * cr_b - bz0 * sr_b; - const double bz1 = by0 * sr_b + bz0 * cr_b; - const double px = bx0 * cp + bz1 * sp; - const double pz = -bx0 * sp + bz1 * cp; - const double py = by1; + double wx, wy, pz; + if (terrain_on) { + // Chuc camera tren than (quanh y than), roi xoay theo than. + const double mx = bx0 * ccp + bz0 * csp; + const double mz = -bx0 * csp + bz0 * ccp; + R_body.Apply(mx, by0, mz, &wx, &wy, &pz); + } else { + // Nghieng ngang cua than (roll) truoc, roi chuc xuong (pitch). + const double by1 = by0 * cr_b - bz0 * sr_b; + const double bz1 = by0 * sr_b + bz0 * cr_b; + const double px = bx0 * cp + bz1 * sp; + pz = -bx0 * sp + bz1 * cp; + const double py = by1; - const double wx = px * cy_r - py * sy_r; - const double wy = px * sy_r + py * cy_r; + wx = px * cy_r - py * sy_r; + wy = px * sy_r + py * cy_r; + } double d = RaycastDepth(cx_w, cy_w, cz_w, wx, wy, pz, cfg.depth_far); uint16_t mm = 0; // 0 = khong do duoc, dung quy uoc cua RealSense @@ -966,6 +1187,14 @@ struct SimSource::Impl { cur_rr = roll_rate; cur_pr = pitch_rate; cur_accel = last_accel; + if (terrain_on) { + // Than nghieng theo dia hinh thi gyro PHAI thay luc no nghieng -- + // khong thi gia toc ke bao "dang tren doc" con gyro bao "chua he xoay", + // va moi bo loc (gravity_align, VIO) bi hai cam bien cai nhau. + cur_roll += terrain_roll; + cur_rr += terrain_roll_rate; + cur_pr += terrain_pitch_rate; + } } // Con quay do van toc goc THAT tren ca ba truc. @@ -1017,18 +1246,21 @@ StatusResponse SimSource::Open() { // chuoi do phai giong nhau giua hai lan ghi cung mot kich ban. impl_->rng.seed(impl_->cfg.seed); + WorldTerrain terr; if (!impl_->cfg.world_path.empty()) { const StatusResponse st = LoadGazeboWorld( impl_->cfg.world_path, impl_->cfg.world_model_paths, &impl_->world); if (!st.ok()) return st; WorldRasterOptions wo; - const StatusResponse rs = RasterizeGazeboWorld(impl_->world, wo, &impl_->map); + const StatusResponse rs = + RasterizeGazeboWorld(impl_->world, wo, &impl_->map, &terr); 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); + const StatusResponse ss = BuildWorldSegments( + impl_->world, wo, impl_->map, &impl_->segments, + terr.terrain_cells > 0 ? &terr.floor_z : nullptr); if (!ss.ok()) { VSLAM_WARN("sim: khong dung duoc chi muc doan (" << ss.message << ") -- raycast se luong tu hoa theo o " @@ -1048,13 +1280,37 @@ StatusResponse SimSource::Open() { } // San phang mac dinh. SetFloorHeight() tao bac hut xuong. - impl_->floor_z.assign(static_cast(impl_->map.width) * impl_->map.height, 0.0f); - impl_->glass.assign(static_cast(impl_->map.width) * impl_->map.height, 0); + const size_t n_cells = static_cast(impl_->map.width) * impl_->map.height; + impl_->floor_z.assign(n_cells, 0.0f); + impl_->glass.assign(n_cells, 0); + impl_->wall_top.clear(); + impl_->step_block.clear(); + // World co dia hinh (san cao, doc): san lay tu mesh dia hinh. + if (terr.terrain_cells > 0 && terr.floor_z.size() == n_cells) { + impl_->floor_z = terr.floor_z; + } + if (terr.wall_top.size() == n_cells) impl_->wall_top = terr.wall_top; + + const SimConfig::TerrainMode tm = impl_->cfg.terrain; + impl_->terrain_on = tm == SimConfig::TerrainMode::kOn || + (tm == SimConfig::TerrainMode::kAuto && terr.terrain_cells > 0); + if (impl_->terrain_on) { + VSLAM_INFO("sim: dia hinh 3D BAT -- " << terr.terrain_cells << " o dia hinh, san tu " + << terr.floor_min << " den " << terr.floor_max + << " m. Robot di tren mat san, LiDAR quet tia 3D, chenh san > " + << impl_->cfg.max_step << " m la vat can."); + } impl_->x = impl_->cfg.start_x; impl_->y = impl_->cfg.start_y; impl_->yaw = impl_->cfg.start_yaw; + if (impl_->terrain_on) { + impl_->RebuildStepMask(); + impl_->terrain_ready = false; + impl_->UpdateTerrainPose(0.0); + } + if (impl_->Collides(impl_->x, impl_->y)) { // Bao NGAY thay vi de robot ket ngay tu khung dau tien va nguoi dung ngoi // doan tai sao no khong nhuc nhich. @@ -1093,6 +1349,10 @@ void SimSource::SetMapForTest(const OccupancyGrid& m) { impl_->map = m; impl_->floor_z.assign(static_cast(m.width) * m.height, 0.0f); impl_->glass.assign(static_cast(m.width) * m.height, 0); + impl_->wall_top.clear(); + impl_->step_block.clear(); + impl_->steps_dirty = true; + impl_->terrain_ready = false; } bool SimSource::true_bumper() const { return impl_->bumper_now; } @@ -1143,16 +1403,67 @@ void SimSource::SetFloorHeight(double x0, double y0, double x1, double y1, float impl_->floor_z[static_cast(cy) * m.width + static_cast(cx)] = z; } } + // Dia hinh 3D: mat na bac tinh lai o buoc vat ly sau, va goc dia hinh lay + // lai tu dau (khong sinh toc do goc gia). + impl_->steps_dirty = true; + impl_->terrain_ready = false; VSLAM_INFO("sim: dat do cao san " << z << " m cho vung (" << x0 << ", " << y0 << ") - (" << x1 << ", " << y1 << ")"); } +void SimSource::SetFloorRamp(double x0, double y0, double x1, double y1, + float z_at_x0, float z_at_x1) { + const OccupancyGrid& m = impl_->map; + if (x1 == x0) return; + auto to_cell = [&](double w, double origin) { + return static_cast(std::floor((w - origin) / m.resolution)); + }; + const int cx0 = std::max(0, to_cell(std::min(x0, x1), m.origin.position.x)); + const int cy0 = std::max(0, to_cell(std::min(y0, y1), m.origin.position.y)); + const int cx1 = std::min(static_cast(m.width) - 1, + to_cell(std::max(x0, x1), m.origin.position.x)); + const int cy1 = std::min(static_cast(m.height) - 1, + to_cell(std::max(y0, y1), m.origin.position.y)); + + std::lock_guard lk(impl_->state_mu); + for (int cy = cy0; cy <= cy1; ++cy) { + for (int cx = cx0; cx <= cx1; ++cx) { + // Do cao tai TAM o, cung quy uoc voi raster dia hinh tu world. + const double wx = m.origin.position.x + (cx + 0.5) * m.resolution; + const double t = std::min(1.0, std::max(0.0, (wx - x0) / (x1 - x0))); + impl_->floor_z[static_cast(cy) * m.width + static_cast(cx)] = + static_cast(z_at_x0 + t * (z_at_x1 - z_at_x0)); + } + } + impl_->steps_dirty = true; + impl_->terrain_ready = false; + VSLAM_INFO("sim: doc tu x = " << x0 << " (" << z_at_x0 << " m) toi x = " << x1 + << " (" << z_at_x1 << " m)"); +} + +bool SimSource::terrain_active() const { return impl_->terrain_on; } + void SimSource::true_tilt(double* roll_out, double* pitch_out) const { std::lock_guard lk(impl_->state_mu); - *roll_out = impl_->roll; + // Tat dia hinh 3D thi KHONG cong (ke ca 0.0): giu dung tung bit nhu cu. + *roll_out = impl_->terrain_on ? impl_->roll + impl_->terrain_roll : impl_->roll; *pitch_out = impl_->pitch + impl_->terrain_pitch; } +SimPose3 SimSource::ground_truth_3d() const { + std::lock_guard lk(impl_->state_mu); + SimPose3 p; + p.x = impl_->x; + p.y = impl_->y; + p.yaw = impl_->yaw; + // Tat dia hinh 3D thi robot luon o z = 0, ke ca khi SetFloorHeight tao vuc: + // do cao san luc do chi de camera NHIN thay, robot khong di len no. + p.z = impl_->terrain_on ? impl_->ground_z : 0.0; + p.roll = impl_->terrain_on ? impl_->roll + impl_->terrain_roll : impl_->roll; + p.pitch = impl_->pitch + impl_->terrain_pitch; + return p; +} + Pose2D SimSource::ground_truth() const { std::lock_guard lk(impl_->state_mu); return Pose2D{impl_->x, impl_->y, impl_->yaw}; diff --git a/libs/vslam_web/include/vslam/web_snapshot.h b/libs/vslam_web/include/vslam/web_snapshot.h index 344e47a..81647f1 100644 --- a/libs/vslam_web/include/vslam/web_snapshot.h +++ b/libs/vslam_web/include/vslam/web_snapshot.h @@ -151,6 +151,7 @@ struct WebSnapshot { Pose2D ground_truth; double gt_roll = 0.0; // nghieng THAT, de doi chung gravity_align double gt_pitch = 0.0; + double gt_z = 0.0; // do cao san THAT duoi robot (world co doc) SafetySnapshot safety; SlamSnapshot slam; diff --git a/libs/vslam_web/src/json_writer.cc b/libs/vslam_web/src/json_writer.cc index 460342b..b5a3288 100644 --- a/libs/vslam_web/src/json_writer.cc +++ b/libs/vslam_web/src/json_writer.cc @@ -141,6 +141,7 @@ void WriteStateJson(const WebSnapshot& s, std::string* out) { Num("yaw", s.ground_truth.theta, 4, out); Comma(out); Num("roll", s.gt_roll, 4, out); Comma(out); Num("pitch", s.gt_pitch, 4, out); Comma(out); + Num("z", s.gt_z, 3, out); Comma(out); // Sai so vi tri cua uoc luong so voi su that. Tinh o day thay vi de // client tu tru: neu sau nay map va gt khac goc toa do thi phep tru // ngay tren client se sai am tham. diff --git a/libs/vslam_web/www/app.js b/libs/vslam_web/www/app.js index 738e60d..745835d 100644 --- a/libs/vslam_web/www/app.js +++ b/libs/vslam_web/www/app.js @@ -394,6 +394,8 @@ function onState(s) { // khong phan biet duoc "dung o goc" voi "khong biet". state.gt = s.gt || null; txt('gtErr', s.gt ? fmt(s.gt.err, 3) + ' m' : '--'); + // Do cao san THAT (sim co doc). Pose uoc luong hien la 2D: chua co z. + txt('gtZ', s.gt && s.gt.z !== undefined ? fmt(s.gt.z, 3) + ' m' : '--'); state.slamMode = s.slam.mode; txt('mode', s.slam.mode); diff --git a/libs/vslam_web/www/app3d.js b/libs/vslam_web/www/app3d.js index 64b0677..a758723 100644 --- a/libs/vslam_web/www/app3d.js +++ b/libs/vslam_web/www/app3d.js @@ -425,6 +425,19 @@ function v3dSetPose(group, p) { group.position.x = p.x; group.position.z = -p.y; group.rotation.y = p.yaw; + // Cao do va nghieng CHI khi pose mang chung -- hien chi ground truth cua sim + // (`gt.z/roll/pitch`). Pose uoc luong la 2D: KHONG dong vao y, de hop dong + // o tren van dung (test/www/test_robot_marker.js muc 4). + // + // Nhom NGOAI duoc dat cao do san (`z`), phep nang wheel_radius van o tang + // trong. Goc: ROS R = Rz(yaw) Ry(pitch) Rx(roll); three.js y-len, z = -y_ros + // -> Ry(yaw) Rz(-pitch) Rx(roll), tuc thu tu 'YZX'. + if (p.z !== undefined) group.position.y = p.z; + if (p.roll !== undefined || p.pitch !== undefined) { + group.rotation.order = 'YZX'; + group.rotation.x = p.roll || 0; + group.rotation.z = -(p.pitch || 0); + } } // scan: mang [x0,y0, x1,y1, ...] trong frame LASER (xem ghi chu ben trong). diff --git a/libs/vslam_web/www/index.html b/libs/vslam_web/www/index.html index 84a87ec..70151b3 100644 --- a/libs/vslam_web/www/index.html +++ b/libs/vslam_web/www/index.html @@ -73,6 +73,8 @@ sai so-- + + z that-- diff --git a/resources/models/vslam_slope_test_walls/meshes/walls.obj b/resources/models/vslam_slope_test_walls/meshes/walls.obj new file mode 100644 index 0000000..55d8ae0 --- /dev/null +++ b/resources/models/vslam_slope_test_walls/meshes/walls.obj @@ -0,0 +1,842 @@ +# Tuong va cot cua world doc. Z-UP, met. +# Sinh boi tools/gen_slope_world.py -- dung sua tay. +v -0.2000 -0.2000 4.0000 +vt -0.2000 -0.2000 +v 0.0000 -0.2000 4.0000 +vt 0.0000 -0.2000 +v 0.0000 33.7000 4.0000 +vt 0.0000 33.7000 +v -0.2000 33.7000 4.0000 +vt -0.2000 33.7000 +f 1/1 2/2 3/3 +f 1/1 3/3 4/4 +v -0.2000 33.7000 0.0000 +vt -0.2000 33.7000 +v 0.0000 33.7000 0.0000 +vt 0.0000 33.7000 +v 0.0000 -0.2000 0.0000 +vt 0.0000 -0.2000 +v -0.2000 -0.2000 0.0000 +vt -0.2000 -0.2000 +f 5/5 6/6 7/7 +f 5/5 7/7 8/8 +v -0.2000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 0.0000 -0.2000 0.0000 +vt 0.0000 0.0000 +v 0.0000 -0.2000 4.0000 +vt 0.0000 4.0000 +v -0.2000 -0.2000 4.0000 +vt -0.2000 4.0000 +f 9/9 10/10 11/11 +f 9/9 11/11 12/12 +v 0.0000 33.7000 0.0000 +vt 0.0000 0.0000 +v -0.2000 33.7000 0.0000 +vt -0.2000 0.0000 +v -0.2000 33.7000 4.0000 +vt -0.2000 4.0000 +v 0.0000 33.7000 4.0000 +vt 0.0000 4.0000 +f 13/13 14/14 15/15 +f 13/13 15/15 16/16 +v -0.2000 33.7000 0.0000 +vt 33.7000 0.0000 +v -0.2000 -0.2000 0.0000 +vt -0.2000 0.0000 +v -0.2000 -0.2000 4.0000 +vt -0.2000 4.0000 +v -0.2000 33.7000 4.0000 +vt 33.7000 4.0000 +f 17/17 18/18 19/19 +f 17/17 19/19 20/20 +v 0.0000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 0.0000 33.7000 0.0000 +vt 33.7000 0.0000 +v 0.0000 33.7000 4.0000 +vt 33.7000 4.0000 +v 0.0000 -0.2000 4.0000 +vt -0.2000 4.0000 +f 21/21 22/22 23/23 +f 21/21 23/23 24/24 +v 12.8000 -0.2000 4.0000 +vt 12.8000 -0.2000 +v 13.0000 -0.2000 4.0000 +vt 13.0000 -0.2000 +v 13.0000 33.7000 4.0000 +vt 13.0000 33.7000 +v 12.8000 33.7000 4.0000 +vt 12.8000 33.7000 +f 25/25 26/26 27/27 +f 25/25 27/27 28/28 +v 12.8000 33.7000 0.0000 +vt 12.8000 33.7000 +v 13.0000 33.7000 0.0000 +vt 13.0000 33.7000 +v 13.0000 -0.2000 0.0000 +vt 13.0000 -0.2000 +v 12.8000 -0.2000 0.0000 +vt 12.8000 -0.2000 +f 29/29 30/30 31/31 +f 29/29 31/31 32/32 +v 12.8000 -0.2000 0.0000 +vt 12.8000 0.0000 +v 13.0000 -0.2000 0.0000 +vt 13.0000 0.0000 +v 13.0000 -0.2000 4.0000 +vt 13.0000 4.0000 +v 12.8000 -0.2000 4.0000 +vt 12.8000 4.0000 +f 33/33 34/34 35/35 +f 33/33 35/35 36/36 +v 13.0000 33.7000 0.0000 +vt 13.0000 0.0000 +v 12.8000 33.7000 0.0000 +vt 12.8000 0.0000 +v 12.8000 33.7000 4.0000 +vt 12.8000 4.0000 +v 13.0000 33.7000 4.0000 +vt 13.0000 4.0000 +f 37/37 38/38 39/39 +f 37/37 39/39 40/40 +v 12.8000 33.7000 0.0000 +vt 33.7000 0.0000 +v 12.8000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 12.8000 -0.2000 4.0000 +vt -0.2000 4.0000 +v 12.8000 33.7000 4.0000 +vt 33.7000 4.0000 +f 41/41 42/42 43/43 +f 41/41 43/43 44/44 +v 13.0000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 13.0000 33.7000 0.0000 +vt 33.7000 0.0000 +v 13.0000 33.7000 4.0000 +vt 33.7000 4.0000 +v 13.0000 -0.2000 4.0000 +vt -0.2000 4.0000 +f 45/45 46/46 47/47 +f 45/45 47/47 48/48 +v -0.2000 -0.2000 4.0000 +vt -0.2000 -0.2000 +v 13.0000 -0.2000 4.0000 +vt 13.0000 -0.2000 +v 13.0000 0.0000 4.0000 +vt 13.0000 0.0000 +v -0.2000 0.0000 4.0000 +vt -0.2000 0.0000 +f 49/49 50/50 51/51 +f 49/49 51/51 52/52 +v -0.2000 0.0000 0.0000 +vt -0.2000 0.0000 +v 13.0000 0.0000 0.0000 +vt 13.0000 0.0000 +v 13.0000 -0.2000 0.0000 +vt 13.0000 -0.2000 +v -0.2000 -0.2000 0.0000 +vt -0.2000 -0.2000 +f 53/53 54/54 55/55 +f 53/53 55/55 56/56 +v -0.2000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 13.0000 -0.2000 0.0000 +vt 13.0000 0.0000 +v 13.0000 -0.2000 4.0000 +vt 13.0000 4.0000 +v -0.2000 -0.2000 4.0000 +vt -0.2000 4.0000 +f 57/57 58/58 59/59 +f 57/57 59/59 60/60 +v 13.0000 0.0000 0.0000 +vt 13.0000 0.0000 +v -0.2000 0.0000 0.0000 +vt -0.2000 0.0000 +v -0.2000 0.0000 4.0000 +vt -0.2000 4.0000 +v 13.0000 0.0000 4.0000 +vt 13.0000 4.0000 +f 61/61 62/62 63/63 +f 61/61 63/63 64/64 +v -0.2000 0.0000 0.0000 +vt 0.0000 0.0000 +v -0.2000 -0.2000 0.0000 +vt -0.2000 0.0000 +v -0.2000 -0.2000 4.0000 +vt -0.2000 4.0000 +v -0.2000 0.0000 4.0000 +vt 0.0000 4.0000 +f 65/65 66/66 67/67 +f 65/65 67/67 68/68 +v 13.0000 -0.2000 0.0000 +vt -0.2000 0.0000 +v 13.0000 0.0000 0.0000 +vt 0.0000 0.0000 +v 13.0000 0.0000 4.0000 +vt 0.0000 4.0000 +v 13.0000 -0.2000 4.0000 +vt -0.2000 4.0000 +f 69/69 70/70 71/71 +f 69/69 71/71 72/72 +v -0.2000 33.5000 4.0000 +vt -0.2000 33.5000 +v 13.0000 33.5000 4.0000 +vt 13.0000 33.5000 +v 13.0000 33.7000 4.0000 +vt 13.0000 33.7000 +v -0.2000 33.7000 4.0000 +vt -0.2000 33.7000 +f 73/73 74/74 75/75 +f 73/73 75/75 76/76 +v -0.2000 33.7000 0.0000 +vt -0.2000 33.7000 +v 13.0000 33.7000 0.0000 +vt 13.0000 33.7000 +v 13.0000 33.5000 0.0000 +vt 13.0000 33.5000 +v -0.2000 33.5000 0.0000 +vt -0.2000 33.5000 +f 77/77 78/78 79/79 +f 77/77 79/79 80/80 +v -0.2000 33.5000 0.0000 +vt -0.2000 0.0000 +v 13.0000 33.5000 0.0000 +vt 13.0000 0.0000 +v 13.0000 33.5000 4.0000 +vt 13.0000 4.0000 +v -0.2000 33.5000 4.0000 +vt -0.2000 4.0000 +f 81/81 82/82 83/83 +f 81/81 83/83 84/84 +v 13.0000 33.7000 0.0000 +vt 13.0000 0.0000 +v -0.2000 33.7000 0.0000 +vt -0.2000 0.0000 +v -0.2000 33.7000 4.0000 +vt -0.2000 4.0000 +v 13.0000 33.7000 4.0000 +vt 13.0000 4.0000 +f 85/85 86/86 87/87 +f 85/85 87/87 88/88 +v -0.2000 33.7000 0.0000 +vt 33.7000 0.0000 +v -0.2000 33.5000 0.0000 +vt 33.5000 0.0000 +v -0.2000 33.5000 4.0000 +vt 33.5000 4.0000 +v -0.2000 33.7000 4.0000 +vt 33.7000 4.0000 +f 89/89 90/90 91/91 +f 89/89 91/91 92/92 +v 13.0000 33.5000 0.0000 +vt 33.5000 0.0000 +v 13.0000 33.7000 0.0000 +vt 33.7000 0.0000 +v 13.0000 33.7000 4.0000 +vt 33.7000 4.0000 +v 13.0000 33.5000 4.0000 +vt 33.5000 4.0000 +f 93/93 94/94 95/95 +f 93/93 95/95 96/96 +v 2.4000 8.0000 4.0000 +vt 2.4000 8.0000 +v 2.6000 8.0000 4.0000 +vt 2.6000 8.0000 +v 2.6000 25.5000 4.0000 +vt 2.6000 25.5000 +v 2.4000 25.5000 4.0000 +vt 2.4000 25.5000 +f 97/97 98/98 99/99 +f 97/97 99/99 100/100 +v 2.4000 25.5000 0.0000 +vt 2.4000 25.5000 +v 2.6000 25.5000 0.0000 +vt 2.6000 25.5000 +v 2.6000 8.0000 0.0000 +vt 2.6000 8.0000 +v 2.4000 8.0000 0.0000 +vt 2.4000 8.0000 +f 101/101 102/102 103/103 +f 101/101 103/103 104/104 +v 2.4000 8.0000 0.0000 +vt 2.4000 0.0000 +v 2.6000 8.0000 0.0000 +vt 2.6000 0.0000 +v 2.6000 8.0000 4.0000 +vt 2.6000 4.0000 +v 2.4000 8.0000 4.0000 +vt 2.4000 4.0000 +f 105/105 106/106 107/107 +f 105/105 107/107 108/108 +v 2.6000 25.5000 0.0000 +vt 2.6000 0.0000 +v 2.4000 25.5000 0.0000 +vt 2.4000 0.0000 +v 2.4000 25.5000 4.0000 +vt 2.4000 4.0000 +v 2.6000 25.5000 4.0000 +vt 2.6000 4.0000 +f 109/109 110/110 111/111 +f 109/109 111/111 112/112 +v 2.4000 25.5000 0.0000 +vt 25.5000 0.0000 +v 2.4000 8.0000 0.0000 +vt 8.0000 0.0000 +v 2.4000 8.0000 4.0000 +vt 8.0000 4.0000 +v 2.4000 25.5000 4.0000 +vt 25.5000 4.0000 +f 113/113 114/114 115/115 +f 113/113 115/115 116/116 +v 2.6000 8.0000 0.0000 +vt 8.0000 0.0000 +v 2.6000 25.5000 0.0000 +vt 25.5000 0.0000 +v 2.6000 25.5000 4.0000 +vt 25.5000 4.0000 +v 2.6000 8.0000 4.0000 +vt 8.0000 4.0000 +f 117/117 118/118 119/119 +f 117/117 119/119 120/120 +v 5.0000 8.0000 4.0000 +vt 5.0000 8.0000 +v 5.2000 8.0000 4.0000 +vt 5.2000 8.0000 +v 5.2000 25.5000 4.0000 +vt 5.2000 25.5000 +v 5.0000 25.5000 4.0000 +vt 5.0000 25.5000 +f 121/121 122/122 123/123 +f 121/121 123/123 124/124 +v 5.0000 25.5000 0.0000 +vt 5.0000 25.5000 +v 5.2000 25.5000 0.0000 +vt 5.2000 25.5000 +v 5.2000 8.0000 0.0000 +vt 5.2000 8.0000 +v 5.0000 8.0000 0.0000 +vt 5.0000 8.0000 +f 125/125 126/126 127/127 +f 125/125 127/127 128/128 +v 5.0000 8.0000 0.0000 +vt 5.0000 0.0000 +v 5.2000 8.0000 0.0000 +vt 5.2000 0.0000 +v 5.2000 8.0000 4.0000 +vt 5.2000 4.0000 +v 5.0000 8.0000 4.0000 +vt 5.0000 4.0000 +f 129/129 130/130 131/131 +f 129/129 131/131 132/132 +v 5.2000 25.5000 0.0000 +vt 5.2000 0.0000 +v 5.0000 25.5000 0.0000 +vt 5.0000 0.0000 +v 5.0000 25.5000 4.0000 +vt 5.0000 4.0000 +v 5.2000 25.5000 4.0000 +vt 5.2000 4.0000 +f 133/133 134/134 135/135 +f 133/133 135/135 136/136 +v 5.0000 25.5000 0.0000 +vt 25.5000 0.0000 +v 5.0000 8.0000 0.0000 +vt 8.0000 0.0000 +v 5.0000 8.0000 4.0000 +vt 8.0000 4.0000 +v 5.0000 25.5000 4.0000 +vt 25.5000 4.0000 +f 137/137 138/138 139/139 +f 137/137 139/139 140/140 +v 5.2000 8.0000 0.0000 +vt 8.0000 0.0000 +v 5.2000 25.5000 0.0000 +vt 25.5000 0.0000 +v 5.2000 25.5000 4.0000 +vt 25.5000 4.0000 +v 5.2000 8.0000 4.0000 +vt 8.0000 4.0000 +f 141/141 142/142 143/143 +f 141/141 143/143 144/144 +v 7.6000 8.0000 4.0000 +vt 7.6000 8.0000 +v 7.8000 8.0000 4.0000 +vt 7.8000 8.0000 +v 7.8000 25.5000 4.0000 +vt 7.8000 25.5000 +v 7.6000 25.5000 4.0000 +vt 7.6000 25.5000 +f 145/145 146/146 147/147 +f 145/145 147/147 148/148 +v 7.6000 25.5000 0.0000 +vt 7.6000 25.5000 +v 7.8000 25.5000 0.0000 +vt 7.8000 25.5000 +v 7.8000 8.0000 0.0000 +vt 7.8000 8.0000 +v 7.6000 8.0000 0.0000 +vt 7.6000 8.0000 +f 149/149 150/150 151/151 +f 149/149 151/151 152/152 +v 7.6000 8.0000 0.0000 +vt 7.6000 0.0000 +v 7.8000 8.0000 0.0000 +vt 7.8000 0.0000 +v 7.8000 8.0000 4.0000 +vt 7.8000 4.0000 +v 7.6000 8.0000 4.0000 +vt 7.6000 4.0000 +f 153/153 154/154 155/155 +f 153/153 155/155 156/156 +v 7.8000 25.5000 0.0000 +vt 7.8000 0.0000 +v 7.6000 25.5000 0.0000 +vt 7.6000 0.0000 +v 7.6000 25.5000 4.0000 +vt 7.6000 4.0000 +v 7.8000 25.5000 4.0000 +vt 7.8000 4.0000 +f 157/157 158/158 159/159 +f 157/157 159/159 160/160 +v 7.6000 25.5000 0.0000 +vt 25.5000 0.0000 +v 7.6000 8.0000 0.0000 +vt 8.0000 0.0000 +v 7.6000 8.0000 4.0000 +vt 8.0000 4.0000 +v 7.6000 25.5000 4.0000 +vt 25.5000 4.0000 +f 161/161 162/162 163/163 +f 161/161 163/163 164/164 +v 7.8000 8.0000 0.0000 +vt 8.0000 0.0000 +v 7.8000 25.5000 0.0000 +vt 25.5000 0.0000 +v 7.8000 25.5000 4.0000 +vt 25.5000 4.0000 +v 7.8000 8.0000 4.0000 +vt 8.0000 4.0000 +f 165/165 166/166 167/167 +f 165/165 167/167 168/168 +v 10.2000 8.0000 4.0000 +vt 10.2000 8.0000 +v 10.4000 8.0000 4.0000 +vt 10.4000 8.0000 +v 10.4000 25.5000 4.0000 +vt 10.4000 25.5000 +v 10.2000 25.5000 4.0000 +vt 10.2000 25.5000 +f 169/169 170/170 171/171 +f 169/169 171/171 172/172 +v 10.2000 25.5000 0.0000 +vt 10.2000 25.5000 +v 10.4000 25.5000 0.0000 +vt 10.4000 25.5000 +v 10.4000 8.0000 0.0000 +vt 10.4000 8.0000 +v 10.2000 8.0000 0.0000 +vt 10.2000 8.0000 +f 173/173 174/174 175/175 +f 173/173 175/175 176/176 +v 10.2000 8.0000 0.0000 +vt 10.2000 0.0000 +v 10.4000 8.0000 0.0000 +vt 10.4000 0.0000 +v 10.4000 8.0000 4.0000 +vt 10.4000 4.0000 +v 10.2000 8.0000 4.0000 +vt 10.2000 4.0000 +f 177/177 178/178 179/179 +f 177/177 179/179 180/180 +v 10.4000 25.5000 0.0000 +vt 10.4000 0.0000 +v 10.2000 25.5000 0.0000 +vt 10.2000 0.0000 +v 10.2000 25.5000 4.0000 +vt 10.2000 4.0000 +v 10.4000 25.5000 4.0000 +vt 10.4000 4.0000 +f 181/181 182/182 183/183 +f 181/181 183/183 184/184 +v 10.2000 25.5000 0.0000 +vt 25.5000 0.0000 +v 10.2000 8.0000 0.0000 +vt 8.0000 0.0000 +v 10.2000 8.0000 4.0000 +vt 8.0000 4.0000 +v 10.2000 25.5000 4.0000 +vt 25.5000 4.0000 +f 185/185 186/186 187/187 +f 185/185 187/187 188/188 +v 10.4000 8.0000 0.0000 +vt 8.0000 0.0000 +v 10.4000 25.5000 0.0000 +vt 25.5000 0.0000 +v 10.4000 25.5000 4.0000 +vt 25.5000 4.0000 +v 10.4000 8.0000 4.0000 +vt 8.0000 4.0000 +f 189/189 190/190 191/191 +f 189/189 191/191 192/192 +v 2.3000 3.8000 4.0000 +vt 2.3000 3.8000 +v 2.7000 3.8000 4.0000 +vt 2.7000 3.8000 +v 2.7000 4.2000 4.0000 +vt 2.7000 4.2000 +v 2.3000 4.2000 4.0000 +vt 2.3000 4.2000 +f 193/193 194/194 195/195 +f 193/193 195/195 196/196 +v 2.3000 4.2000 0.0000 +vt 2.3000 4.2000 +v 2.7000 4.2000 0.0000 +vt 2.7000 4.2000 +v 2.7000 3.8000 0.0000 +vt 2.7000 3.8000 +v 2.3000 3.8000 0.0000 +vt 2.3000 3.8000 +f 197/197 198/198 199/199 +f 197/197 199/199 200/200 +v 2.3000 3.8000 0.0000 +vt 2.3000 0.0000 +v 2.7000 3.8000 0.0000 +vt 2.7000 0.0000 +v 2.7000 3.8000 4.0000 +vt 2.7000 4.0000 +v 2.3000 3.8000 4.0000 +vt 2.3000 4.0000 +f 201/201 202/202 203/203 +f 201/201 203/203 204/204 +v 2.7000 4.2000 0.0000 +vt 2.7000 0.0000 +v 2.3000 4.2000 0.0000 +vt 2.3000 0.0000 +v 2.3000 4.2000 4.0000 +vt 2.3000 4.0000 +v 2.7000 4.2000 4.0000 +vt 2.7000 4.0000 +f 205/205 206/206 207/207 +f 205/205 207/207 208/208 +v 2.3000 4.2000 0.0000 +vt 4.2000 0.0000 +v 2.3000 3.8000 0.0000 +vt 3.8000 0.0000 +v 2.3000 3.8000 4.0000 +vt 3.8000 4.0000 +v 2.3000 4.2000 4.0000 +vt 4.2000 4.0000 +f 209/209 210/210 211/211 +f 209/209 211/211 212/212 +v 2.7000 3.8000 0.0000 +vt 3.8000 0.0000 +v 2.7000 4.2000 0.0000 +vt 4.2000 0.0000 +v 2.7000 4.2000 4.0000 +vt 4.2000 4.0000 +v 2.7000 3.8000 4.0000 +vt 3.8000 4.0000 +f 213/213 214/214 215/215 +f 213/213 215/215 216/216 +v 10.1000 3.8000 4.0000 +vt 10.1000 3.8000 +v 10.5000 3.8000 4.0000 +vt 10.5000 3.8000 +v 10.5000 4.2000 4.0000 +vt 10.5000 4.2000 +v 10.1000 4.2000 4.0000 +vt 10.1000 4.2000 +f 217/217 218/218 219/219 +f 217/217 219/219 220/220 +v 10.1000 4.2000 0.0000 +vt 10.1000 4.2000 +v 10.5000 4.2000 0.0000 +vt 10.5000 4.2000 +v 10.5000 3.8000 0.0000 +vt 10.5000 3.8000 +v 10.1000 3.8000 0.0000 +vt 10.1000 3.8000 +f 221/221 222/222 223/223 +f 221/221 223/223 224/224 +v 10.1000 3.8000 0.0000 +vt 10.1000 0.0000 +v 10.5000 3.8000 0.0000 +vt 10.5000 0.0000 +v 10.5000 3.8000 4.0000 +vt 10.5000 4.0000 +v 10.1000 3.8000 4.0000 +vt 10.1000 4.0000 +f 225/225 226/226 227/227 +f 225/225 227/227 228/228 +v 10.5000 4.2000 0.0000 +vt 10.5000 0.0000 +v 10.1000 4.2000 0.0000 +vt 10.1000 0.0000 +v 10.1000 4.2000 4.0000 +vt 10.1000 4.0000 +v 10.5000 4.2000 4.0000 +vt 10.5000 4.0000 +f 229/229 230/230 231/231 +f 229/229 231/231 232/232 +v 10.1000 4.2000 0.0000 +vt 4.2000 0.0000 +v 10.1000 3.8000 0.0000 +vt 3.8000 0.0000 +v 10.1000 3.8000 4.0000 +vt 3.8000 4.0000 +v 10.1000 4.2000 4.0000 +vt 4.2000 4.0000 +f 233/233 234/234 235/235 +f 233/233 235/235 236/236 +v 10.5000 3.8000 0.0000 +vt 3.8000 0.0000 +v 10.5000 4.2000 0.0000 +vt 4.2000 0.0000 +v 10.5000 4.2000 4.0000 +vt 4.2000 4.0000 +v 10.5000 3.8000 4.0000 +vt 3.8000 4.0000 +f 237/237 238/238 239/239 +f 237/237 239/239 240/240 +v 4.6000 5.0000 4.0000 +vt 4.6000 5.0000 +v 5.6000 5.0000 4.0000 +vt 5.6000 5.0000 +v 5.6000 5.2000 4.0000 +vt 5.6000 5.2000 +v 4.6000 5.2000 4.0000 +vt 4.6000 5.2000 +f 241/241 242/242 243/243 +f 241/241 243/243 244/244 +v 4.6000 5.2000 0.0000 +vt 4.6000 5.2000 +v 5.6000 5.2000 0.0000 +vt 5.6000 5.2000 +v 5.6000 5.0000 0.0000 +vt 5.6000 5.0000 +v 4.6000 5.0000 0.0000 +vt 4.6000 5.0000 +f 245/245 246/246 247/247 +f 245/245 247/247 248/248 +v 4.6000 5.0000 0.0000 +vt 4.6000 0.0000 +v 5.6000 5.0000 0.0000 +vt 5.6000 0.0000 +v 5.6000 5.0000 4.0000 +vt 5.6000 4.0000 +v 4.6000 5.0000 4.0000 +vt 4.6000 4.0000 +f 249/249 250/250 251/251 +f 249/249 251/251 252/252 +v 5.6000 5.2000 0.0000 +vt 5.6000 0.0000 +v 4.6000 5.2000 0.0000 +vt 4.6000 0.0000 +v 4.6000 5.2000 4.0000 +vt 4.6000 4.0000 +v 5.6000 5.2000 4.0000 +vt 5.6000 4.0000 +f 253/253 254/254 255/255 +f 253/253 255/255 256/256 +v 4.6000 5.2000 0.0000 +vt 5.2000 0.0000 +v 4.6000 5.0000 0.0000 +vt 5.0000 0.0000 +v 4.6000 5.0000 4.0000 +vt 5.0000 4.0000 +v 4.6000 5.2000 4.0000 +vt 5.2000 4.0000 +f 257/257 258/258 259/259 +f 257/257 259/259 260/260 +v 5.6000 5.0000 0.0000 +vt 5.0000 0.0000 +v 5.6000 5.2000 0.0000 +vt 5.2000 0.0000 +v 5.6000 5.2000 4.0000 +vt 5.2000 4.0000 +v 5.6000 5.0000 4.0000 +vt 5.0000 4.0000 +f 261/261 262/262 263/263 +f 261/261 263/263 264/264 +v 4.9000 29.3000 4.0000 +vt 4.9000 29.3000 +v 5.3000 29.3000 4.0000 +vt 5.3000 29.3000 +v 5.3000 29.7000 4.0000 +vt 5.3000 29.7000 +v 4.9000 29.7000 4.0000 +vt 4.9000 29.7000 +f 265/265 266/266 267/267 +f 265/265 267/267 268/268 +v 4.9000 29.7000 1.5000 +vt 4.9000 29.7000 +v 5.3000 29.7000 1.5000 +vt 5.3000 29.7000 +v 5.3000 29.3000 1.5000 +vt 5.3000 29.3000 +v 4.9000 29.3000 1.5000 +vt 4.9000 29.3000 +f 269/269 270/270 271/271 +f 269/269 271/271 272/272 +v 4.9000 29.3000 1.5000 +vt 4.9000 1.5000 +v 5.3000 29.3000 1.5000 +vt 5.3000 1.5000 +v 5.3000 29.3000 4.0000 +vt 5.3000 4.0000 +v 4.9000 29.3000 4.0000 +vt 4.9000 4.0000 +f 273/273 274/274 275/275 +f 273/273 275/275 276/276 +v 5.3000 29.7000 1.5000 +vt 5.3000 1.5000 +v 4.9000 29.7000 1.5000 +vt 4.9000 1.5000 +v 4.9000 29.7000 4.0000 +vt 4.9000 4.0000 +v 5.3000 29.7000 4.0000 +vt 5.3000 4.0000 +f 277/277 278/278 279/279 +f 277/277 279/279 280/280 +v 4.9000 29.7000 1.5000 +vt 29.7000 1.5000 +v 4.9000 29.3000 1.5000 +vt 29.3000 1.5000 +v 4.9000 29.3000 4.0000 +vt 29.3000 4.0000 +v 4.9000 29.7000 4.0000 +vt 29.7000 4.0000 +f 281/281 282/282 283/283 +f 281/281 283/283 284/284 +v 5.3000 29.3000 1.5000 +vt 29.3000 1.5000 +v 5.3000 29.7000 1.5000 +vt 29.7000 1.5000 +v 5.3000 29.7000 4.0000 +vt 29.7000 4.0000 +v 5.3000 29.3000 4.0000 +vt 29.3000 4.0000 +f 285/285 286/286 287/287 +f 285/285 287/287 288/288 +v 7.5000 29.3000 4.0000 +vt 7.5000 29.3000 +v 7.9000 29.3000 4.0000 +vt 7.9000 29.3000 +v 7.9000 29.7000 4.0000 +vt 7.9000 29.7000 +v 7.5000 29.7000 4.0000 +vt 7.5000 29.7000 +f 289/289 290/290 291/291 +f 289/289 291/291 292/292 +v 7.5000 29.7000 1.5000 +vt 7.5000 29.7000 +v 7.9000 29.7000 1.5000 +vt 7.9000 29.7000 +v 7.9000 29.3000 1.5000 +vt 7.9000 29.3000 +v 7.5000 29.3000 1.5000 +vt 7.5000 29.3000 +f 293/293 294/294 295/295 +f 293/293 295/295 296/296 +v 7.5000 29.3000 1.5000 +vt 7.5000 1.5000 +v 7.9000 29.3000 1.5000 +vt 7.9000 1.5000 +v 7.9000 29.3000 4.0000 +vt 7.9000 4.0000 +v 7.5000 29.3000 4.0000 +vt 7.5000 4.0000 +f 297/297 298/298 299/299 +f 297/297 299/299 300/300 +v 7.9000 29.7000 1.5000 +vt 7.9000 1.5000 +v 7.5000 29.7000 1.5000 +vt 7.5000 1.5000 +v 7.5000 29.7000 4.0000 +vt 7.5000 4.0000 +v 7.9000 29.7000 4.0000 +vt 7.9000 4.0000 +f 301/301 302/302 303/303 +f 301/301 303/303 304/304 +v 7.5000 29.7000 1.5000 +vt 29.7000 1.5000 +v 7.5000 29.3000 1.5000 +vt 29.3000 1.5000 +v 7.5000 29.3000 4.0000 +vt 29.3000 4.0000 +v 7.5000 29.7000 4.0000 +vt 29.7000 4.0000 +f 305/305 306/306 307/307 +f 305/305 307/307 308/308 +v 7.9000 29.3000 1.5000 +vt 29.3000 1.5000 +v 7.9000 29.7000 1.5000 +vt 29.7000 1.5000 +v 7.9000 29.7000 4.0000 +vt 29.7000 4.0000 +v 7.9000 29.3000 4.0000 +vt 29.3000 4.0000 +f 309/309 310/310 311/311 +f 309/309 311/311 312/312 +v 9.7000 30.5000 4.0000 +vt 9.7000 30.5000 +v 10.9000 30.5000 4.0000 +vt 10.9000 30.5000 +v 10.9000 30.7000 4.0000 +vt 10.9000 30.7000 +v 9.7000 30.7000 4.0000 +vt 9.7000 30.7000 +f 313/313 314/314 315/315 +f 313/313 315/315 316/316 +v 9.7000 30.7000 1.5000 +vt 9.7000 30.7000 +v 10.9000 30.7000 1.5000 +vt 10.9000 30.7000 +v 10.9000 30.5000 1.5000 +vt 10.9000 30.5000 +v 9.7000 30.5000 1.5000 +vt 9.7000 30.5000 +f 317/317 318/318 319/319 +f 317/317 319/319 320/320 +v 9.7000 30.5000 1.5000 +vt 9.7000 1.5000 +v 10.9000 30.5000 1.5000 +vt 10.9000 1.5000 +v 10.9000 30.5000 4.0000 +vt 10.9000 4.0000 +v 9.7000 30.5000 4.0000 +vt 9.7000 4.0000 +f 321/321 322/322 323/323 +f 321/321 323/323 324/324 +v 10.9000 30.7000 1.5000 +vt 10.9000 1.5000 +v 9.7000 30.7000 1.5000 +vt 9.7000 1.5000 +v 9.7000 30.7000 4.0000 +vt 9.7000 4.0000 +v 10.9000 30.7000 4.0000 +vt 10.9000 4.0000 +f 325/325 326/326 327/327 +f 325/325 327/327 328/328 +v 9.7000 30.7000 1.5000 +vt 30.7000 1.5000 +v 9.7000 30.5000 1.5000 +vt 30.5000 1.5000 +v 9.7000 30.5000 4.0000 +vt 30.5000 4.0000 +v 9.7000 30.7000 4.0000 +vt 30.7000 4.0000 +f 329/329 330/330 331/331 +f 329/329 331/331 332/332 +v 10.9000 30.5000 1.5000 +vt 30.5000 1.5000 +v 10.9000 30.7000 1.5000 +vt 30.7000 1.5000 +v 10.9000 30.7000 4.0000 +vt 30.7000 4.0000 +v 10.9000 30.5000 4.0000 +vt 30.5000 4.0000 +f 333/333 334/334 335/335 +f 333/333 335/335 336/336 diff --git a/resources/models/vslam_slope_test_walls/model.config b/resources/models/vslam_slope_test_walls/model.config new file mode 100644 index 0000000..9db4d5e --- /dev/null +++ b/resources/models/vslam_slope_test_walls/model.config @@ -0,0 +1,14 @@ + + + vslam_slope_test_walls + 1.0 + model.sdf + + vslam_cpp + + + + Tuong bao, tuong ngan lan va cot. + Sinh boi tools/gen_slope_world.py. + + diff --git a/resources/models/vslam_slope_test_walls/model.sdf b/resources/models/vslam_slope_test_walls/model.sdf new file mode 100644 index 0000000..c603b8a --- /dev/null +++ b/resources/models/vslam_slope_test_walls/model.sdf @@ -0,0 +1,22 @@ + + + + + + + + model://vslam_slope_test_walls/meshes/walls.obj + + + + + + + model://vslam_slope_test_walls/meshes/walls.obj + + + + + 1 + + diff --git a/resources/models/vslam_terrain_slope_test/meshes/terrain.obj b/resources/models/vslam_terrain_slope_test/meshes/terrain.obj new file mode 100644 index 0000000..daf3aa3 --- /dev/null +++ b/resources/models/vslam_terrain_slope_test/meshes/terrain.obj @@ -0,0 +1,122 @@ +# Dia hinh world doc: san duoi z=0, san tren z=1.50, 5 lan doc. +# Z-UP, met. Sinh boi tools/gen_slope_world.py -- dung sua tay. +v 0.0000 0.0000 0.0000 +vt 0.0000 0.0000 +v 12.8000 0.0000 0.0000 +vt 12.8000 0.0000 +v 12.8000 8.0000 0.0000 +vt 12.8000 8.0000 +v 0.0000 8.0000 0.0000 +vt 0.0000 8.0000 +f 1/1 2/2 3/3 +f 1/1 3/3 4/4 +v 0.0000 25.5000 1.5000 +vt 0.0000 25.5000 +v 12.8000 25.5000 1.5000 +vt 12.8000 25.5000 +v 12.8000 33.5000 1.5000 +vt 12.8000 33.5000 +v 0.0000 33.5000 1.5000 +vt 0.0000 33.5000 +f 5/5 6/6 7/7 +f 5/5 7/7 8/8 +v 0.0000 8.0000 0.0000 +vt 0.0000 8.0000 +v 2.4000 8.0000 0.0000 +vt 2.4000 8.0000 +v 2.4000 25.1451 1.5000 +vt 2.4000 25.1451 +v 0.0000 25.1451 1.5000 +vt 0.0000 25.1451 +f 9/9 10/10 11/11 +f 9/9 11/11 12/12 +v 0.0000 25.1451 1.5000 +vt 0.0000 25.1451 +v 2.4000 25.1451 1.5000 +vt 2.4000 25.1451 +v 2.4000 25.5000 1.5000 +vt 2.4000 25.5000 +v 0.0000 25.5000 1.5000 +vt 0.0000 25.5000 +f 13/13 14/14 15/15 +f 13/13 15/15 16/16 +v 2.6000 8.0000 0.0000 +vt 2.6000 8.0000 +v 5.0000 8.0000 0.0000 +vt 5.0000 8.0000 +v 5.0000 16.5069 1.5000 +vt 5.0000 16.5069 +v 2.6000 16.5069 1.5000 +vt 2.6000 16.5069 +f 17/17 18/18 19/19 +f 17/17 19/19 20/20 +v 2.6000 16.5069 1.5000 +vt 2.6000 16.5069 +v 5.0000 16.5069 1.5000 +vt 5.0000 16.5069 +v 5.0000 25.5000 1.5000 +vt 5.0000 25.5000 +v 2.6000 25.5000 1.5000 +vt 2.6000 25.5000 +f 21/21 22/22 23/23 +f 21/21 23/23 24/24 +v 5.2000 8.0000 0.0000 +vt 5.2000 8.0000 +v 7.6000 8.0000 0.0000 +vt 7.6000 8.0000 +v 7.6000 13.5981 1.5000 +vt 7.6000 13.5981 +v 5.2000 13.5981 1.5000 +vt 5.2000 13.5981 +f 25/25 26/26 27/27 +f 25/25 27/27 28/28 +v 5.2000 13.5981 1.5000 +vt 5.2000 13.5981 +v 7.6000 13.5981 1.5000 +vt 7.6000 13.5981 +v 7.6000 25.5000 1.5000 +vt 7.6000 25.5000 +v 5.2000 25.5000 1.5000 +vt 5.2000 25.5000 +f 29/29 30/30 31/31 +f 29/29 31/31 32/32 +v 7.8000 8.0000 0.0000 +vt 7.8000 8.0000 +v 10.2000 8.0000 0.0000 +vt 10.2000 8.0000 +v 10.2000 12.1212 1.5000 +vt 10.2000 12.1212 +v 7.8000 12.1212 1.5000 +vt 7.8000 12.1212 +f 33/33 34/34 35/35 +f 33/33 35/35 36/36 +v 7.8000 12.1212 1.5000 +vt 7.8000 12.1212 +v 10.2000 12.1212 1.5000 +vt 10.2000 12.1212 +v 10.2000 25.5000 1.5000 +vt 10.2000 25.5000 +v 7.8000 25.5000 1.5000 +vt 7.8000 25.5000 +f 37/37 38/38 39/39 +f 37/37 39/39 40/40 +v 10.4000 8.0000 0.0000 +vt 10.4000 8.0000 +v 12.8000 8.0000 0.0000 +vt 12.8000 8.0000 +v 12.8000 10.5981 1.5000 +vt 12.8000 10.5981 +v 10.4000 10.5981 1.5000 +vt 10.4000 10.5981 +f 41/41 42/42 43/43 +f 41/41 43/43 44/44 +v 10.4000 10.5981 1.5000 +vt 10.4000 10.5981 +v 12.8000 10.5981 1.5000 +vt 12.8000 10.5981 +v 12.8000 25.5000 1.5000 +vt 12.8000 25.5000 +v 10.4000 25.5000 1.5000 +vt 10.4000 25.5000 +f 45/45 46/46 47/47 +f 45/45 47/47 48/48 diff --git a/resources/models/vslam_terrain_slope_test/model.config b/resources/models/vslam_terrain_slope_test/model.config new file mode 100644 index 0000000..261b4fa --- /dev/null +++ b/resources/models/vslam_terrain_slope_test/model.config @@ -0,0 +1,14 @@ + + + vslam_terrain_slope_test + 1.0 + model.sdf + + vslam_cpp + + + + San, chieu nghi va 5 lan doc (dia hinh). + Sinh boi tools/gen_slope_world.py. + + diff --git a/resources/models/vslam_terrain_slope_test/model.sdf b/resources/models/vslam_terrain_slope_test/model.sdf new file mode 100644 index 0000000..f45491b --- /dev/null +++ b/resources/models/vslam_terrain_slope_test/model.sdf @@ -0,0 +1,22 @@ + + + + + + + + model://vslam_terrain_slope_test/meshes/terrain.obj + + + + + + + model://vslam_terrain_slope_test/meshes/terrain.obj + + + + + 1 + + diff --git a/resources/worlds/slope_test.world b/resources/worlds/slope_test.world new file mode 100644 index 0000000..cede22f --- /dev/null +++ b/resources/worlds/slope_test.world @@ -0,0 +1,95 @@ + + + + + model://ground_plane + model://sun + + + model://vslam_terrain_slope_test + true + 0.000 0.000 0.000 0 0 0.0000 + + + + + model://vslam_slope_test_walls + true + 0.000 0.000 0.000 0 0 0.0000 + + + + + model://MetalCabinet + true + 0.600 1.000 0.000 0 0 0.0000 + + + + + model://StorageRack + true + 3.000 0.600 0.000 0 0 0.0000 + + + + + model://IVStand + true + 5.100 1.000 0.000 0 0 0.0000 + + + + + model://PatientWheelChair + true + 7.700 1.000 0.000 0 0 0.0000 + + + + + model://BedTable + true + 9.500 0.800 0.000 0 0 0.0000 + + + + + model://VendingMachine + true + 12.100 1.200 0.000 0 0 -1.5708 + + + + + model://MetalCabinet + true + 0.600 32.600 1.500 0 0 0.0000 + + + + + model://IVStand + true + 5.100 32.800 1.500 0 0 0.0000 + + + + + model://StorageRack + true + 6.400 32.900 1.500 0 0 3.1416 + + + + + model://BedTable + true + 11.800 32.600 1.500 0 0 0.0000 + + + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f267ed3..c9af098 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -87,6 +87,9 @@ if(VSLAM_BUILD_SIM) # 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. vslam_add_test(test_gazebo_world LIBS vslam_sim vslam_drivers vslam_common) + # Dia hinh 3D: doc, san cao, robot di tren mat san, LiDAR tia 3D. Fixture + # test/data/world/ramp.world (mot doc 10 do). + vslam_add_test(test_sim_terrain LIBS vslam_sim vslam_drivers vslam_common) if(VSLAM_BUILD_ODOMETRY) # 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. diff --git a/test/data/world/models/pillar_upper/meshes/pillar.obj b/test/data/world/models/pillar_upper/meshes/pillar.obj new file mode 100644 index 0000000..ccb62d5 --- /dev/null +++ b/test/data/world/models/pillar_upper/meshes/pillar.obj @@ -0,0 +1,22 @@ +# cot 0.4 x 0.4 x 1.0 m, day o goc model. Dat tren san cao 1.5 m: z the gioi 1.5..2.5, +# NGOAI dai z tuyet doi [0.05, 1.2] cu nhung TRONG dai tinh tu san cuc bo. +v -0.200 -0.200 0.000 +v 0.200 -0.200 0.000 +v 0.200 0.200 0.000 +v -0.200 0.200 0.000 +v -0.200 -0.200 1.000 +v 0.200 -0.200 1.000 +v 0.200 0.200 1.000 +v -0.200 0.200 1.000 +f 1 2 3 +f 1 3 4 +f 5 6 7 +f 5 7 8 +f 1 2 6 +f 1 6 5 +f 3 4 8 +f 3 8 7 +f 2 3 7 +f 2 7 6 +f 4 1 5 +f 4 5 8 diff --git a/test/data/world/models/pillar_upper/model.sdf b/test/data/world/models/pillar_upper/model.sdf new file mode 100644 index 0000000..763211b --- /dev/null +++ b/test/data/world/models/pillar_upper/model.sdf @@ -0,0 +1,9 @@ + +true + + model://pillar_upper/meshes/pillar.obj + + + model://pillar_upper/meshes/pillar.obj + + diff --git a/test/data/world/models/table_slab/meshes/slab.obj b/test/data/world/models/table_slab/meshes/slab.obj new file mode 100644 index 0000000..40e7f65 --- /dev/null +++ b/test/data/world/models/table_slab/meshes/slab.obj @@ -0,0 +1,22 @@ +# mat ban 0.8 x 0.6 x 0.05 m o do cao 0.70..0.75 m. Mat tren huong LEN nhung +# KHONG phai dia hinh: phai la vat can, va san duoi no van la 0. +v -0.400 -0.300 0.700 +v 0.400 -0.300 0.700 +v 0.400 0.300 0.700 +v -0.400 0.300 0.700 +v -0.400 -0.300 0.750 +v 0.400 -0.300 0.750 +v 0.400 0.300 0.750 +v -0.400 0.300 0.750 +f 1 2 3 +f 1 3 4 +f 5 6 7 +f 5 7 8 +f 1 2 6 +f 1 6 5 +f 3 4 8 +f 3 8 7 +f 2 3 7 +f 2 7 6 +f 4 1 5 +f 4 5 8 diff --git a/test/data/world/models/table_slab/model.sdf b/test/data/world/models/table_slab/model.sdf new file mode 100644 index 0000000..02a411e --- /dev/null +++ b/test/data/world/models/table_slab/model.sdf @@ -0,0 +1,9 @@ + +true + + model://table_slab/meshes/slab.obj + + + model://table_slab/meshes/slab.obj + + diff --git a/test/data/world/models/vslam_terrain_ramp/meshes/ramp.obj b/test/data/world/models/vslam_terrain_ramp/meshes/ramp.obj new file mode 100644 index 0000000..ce5e4f6 --- /dev/null +++ b/test/data/world/models/vslam_terrain_ramp/meshes/ramp.obj @@ -0,0 +1,21 @@ +# Fixture dia hinh: san duoi z=0 (x -4..0), doc 10 do len 1.5 m (x 0..8.5069), +# san tren z=1.5 (x 8.5069..12.5069). y -1.5..1.5. Z-UP, met. Ten model bat dau +# bang vslam_terrain_ nen bo mo phong coi day la SAN, khong phai vat can. +v -4.00000 -1.50000 0.00000 +v 0.00000 -1.50000 0.00000 +v 0.00000 1.50000 0.00000 +v -4.00000 1.50000 0.00000 +f 1 2 3 +f 1 3 4 +v 0.00000 -1.50000 0.00000 +v 8.50692 -1.50000 1.50000 +v 8.50692 1.50000 1.50000 +v 0.00000 1.50000 0.00000 +f 5 6 7 +f 5 7 8 +v 8.50692 -1.50000 1.50000 +v 12.50692 -1.50000 1.50000 +v 12.50692 1.50000 1.50000 +v 8.50692 1.50000 1.50000 +f 9 10 11 +f 9 11 12 diff --git a/test/data/world/models/vslam_terrain_ramp/model.sdf b/test/data/world/models/vslam_terrain_ramp/model.sdf new file mode 100644 index 0000000..f9a11e9 --- /dev/null +++ b/test/data/world/models/vslam_terrain_ramp/model.sdf @@ -0,0 +1,9 @@ + +true + + model://vslam_terrain_ramp/meshes/ramp.obj + + + model://vslam_terrain_ramp/meshes/ramp.obj + + diff --git a/test/data/world/ramp.world b/test/data/world/ramp.world new file mode 100644 index 0000000..6d44460 --- /dev/null +++ b/test/data/world/ramp.world @@ -0,0 +1,21 @@ + + + + + model://vslam_terrain_ramptrue + 0 0 0 0 0 0 + + + model://pillar_uppertrue + 10.5 0 1.5 0 0 0 + + + model://table_slabtrue + -2.5 1.0 0 0 0 0 + + diff --git a/test/test_sim_terrain.cc b/test/test_sim_terrain.cc new file mode 100644 index 0000000..9659e60 --- /dev/null +++ b/test/test_sim_terrain.cc @@ -0,0 +1,311 @@ +// Dia hinh 3D trong bo mo phong: doc, san cao, robot di TREN mat san. +// +// ================== VI SAO BAI KIEM NAY TON TAI ================== +// Truoc day bo mo phong phang hoan toan: robot o z = 0, LiDAR quet mat phang +// ngang, mat doc trong world thanh TUONG. Du an phuc vu robot di giua cac toa +// nha qua doc, va moi phep do tren doc (SLAM, VO, z) deu dua vao viec bo mo +// phong noi dung su that. Bai nay khoa cac su that do bang so tinh tay: +// +// * mat doc la SAN, do cao tai x bang x*tan(goc); +// * vat tren san cao van la vat can; mat ban KHONG thanh san; +// * robot len doc: z = x*tan, pitch = -goc, encoder dem quang duong DOC doc; +// * LiDAR dung o san phang thay "tuong gia" o chan doc cach 0.2165/tan(goc); +// * tich phan gyro bang dung goc nghieng that (khong thi VIO vo nghia); +// * mep bac chan robot. +// +// Fixture: test/data/world/ramp.world -- MOT doc 10 do len san cao 1.5 m. + +#include + +#include +#include +#include +#include + +#include "vslam/gazebo_world.h" +#include "vslam/sim_source.h" + +using namespace vslam; + +namespace { + +constexpr double kDeg = M_PI / 180.0; +constexpr double kH = 1.5; // san tren cua fixture +constexpr double kRampDeg = 10.0; +const double kTan = std::tan(kRampDeg * kDeg); +const double kRampLen = kH / kTan; // 8.507 m + +// LiDAR robot that: tam truc + 0.13 m, banh r = 0.0865 m (robot.yaml). +constexpr double kLidarAboveFloor = 0.0865 + 0.13; + +std::string WorldDir() { + const char* e = std::getenv("VSLAM_TEST_DATA_DIR"); + return (e != nullptr ? std::string(e) : std::string("test/data")) + "/world"; +} + +GazeboWorld LoadRamp() { + GazeboWorld w; + const StatusResponse st = LoadGazeboWorld(WorldDir() + "/ramp.world", + {WorldDir() + "/models"}, &w); + EXPECT_TRUE(st.ok()) << st.message; + return w; +} + +size_t CellOf(const OccupancyGrid& g, double x, double y) { + const int cx = static_cast(std::floor((x - g.origin.position.x) / g.resolution)); + const int cy = static_cast(std::floor((y - g.origin.position.y) / g.resolution)); + return static_cast(cy) * g.width + static_cast(cx); +} + +double CellCenterX(const OccupancyGrid& g, double x) { + const double c = std::floor((x - g.origin.position.x) / g.resolution); + return g.origin.position.x + (c + 0.5) * g.resolution; +} + +SimConfig RampCfg() { + SimConfig c; + c.speed = 0.0; + c.enable_depth_camera = false; + c.world_path = WorldDir() + "/ramp.world"; + c.world_model_paths = {WorldDir() + "/models"}; + c.wheel_radius = 0.0865; + c.wheel_separation = 0.40; + c.lidar_x = 0.0; + c.lidar_z = 0.13; + c.lidar_noise_stddev = 0.0; + c.gyro_noise_stddev = 0.0; + c.accel_noise_stddev = 0.0; + c.start_x = -2.0; + c.start_y = 0.0; + c.start_yaw = 0.0; + return c; +} + +// Lai thang cho toi khi x vuot `x_stop`, hoac het `max_s` giay mo phong. +void DriveUntilX(SimSource* sim, double v, double x_stop, double max_s = 80.0) { + for (double t = 0.0; t < max_s; t += 0.05) { + sim->base()->SetVelocity(v, 0.0); + sim->RunFor(0.05); + if (sim->ground_truth().x >= x_stop) return; + } +} + +// Tia thang truoc (goc 0) cua mot scan. +double FrontRange(const LaserScan& s) { + const int i = static_cast(std::lround(-s.angle_min / s.angle_increment)); + return s.ranges[static_cast(i)]; +} + +} // namespace + +// --- Raster world ------------------------------------------------------------ + +TEST(GazeboTerrain, DocLaSanKhongPhaiTuong) { + const GazeboWorld w = LoadRamp(); + OccupancyGrid g; + WorldTerrain t; + ASSERT_TRUE(RasterizeGazeboWorld(w, WorldRasterOptions{}, &g, &t).ok()); + ASSERT_EQ(t.floor_z.size(), static_cast(g.width) * g.height); + EXPECT_GT(t.terrain_cells, 0u); + EXPECT_NEAR(t.floor_max, kH, 1e-3); + + // Gia tri lay tai TAM o: so voi x tam o, khong voi x hoi. + for (double x : {1.0, 3.0, 5.0, 7.0}) { + const size_t i = CellOf(g, x, 0.0); + EXPECT_NEAR(t.floor_z[i], CellCenterX(g, x) * kTan, 1e-3) << "x = " << x; + EXPECT_LT(g.data[i], 50) << "mat doc thanh VAT CAN o x = " << x; + } + EXPECT_NEAR(t.floor_z[CellOf(g, 10.0, 0.0)], kH, 1e-4); + EXPECT_NEAR(t.floor_z[CellOf(g, -2.0, 0.0)], 0.0, 1e-6); +} + +TEST(GazeboTerrain, VatTrenSanCaoVanLaVatCan) { + // Cot z 1.5..2.5 dung tren san cao. Dai z tuyet doi cu [0.05, 1.2] bo no -- + // robot se di xuyen qua. Tinh tu san cuc bo thi no la vat can. + const GazeboWorld w = LoadRamp(); + OccupancyGrid g; + WorldTerrain t; + ASSERT_TRUE(RasterizeGazeboWorld(w, WorldRasterOptions{}, &g, &t).ok()); + const size_t i = CellOf(g, 10.5, 0.0); + EXPECT_GE(g.data[i], 50); + EXPECT_NEAR(t.wall_top[i], 2.5, 1e-3); +} + +TEST(GazeboTerrain, MatBanKhongThanhSan) { + // Mat ban huong LEN nhung khong phai dia hinh: van la vat can, san duoi = 0. + const GazeboWorld w = LoadRamp(); + OccupancyGrid g; + WorldTerrain t; + ASSERT_TRUE(RasterizeGazeboWorld(w, WorldRasterOptions{}, &g, &t).ok()); + const size_t i = CellOf(g, -2.5, 1.0); + EXPECT_GE(g.data[i], 50); + EXPECT_NEAR(t.floor_z[i], 0.0, 1e-6); +} + +TEST(GazeboTerrain, WorldPhangRaLuoiNhuCu) { + // World khong co model dia hinh: hai ban ham phai ra CUNG mot luoi -- day la + // dieu kien de ban ghi hoi quy cu khong doi. + GazeboWorld w; + ASSERT_TRUE(LoadGazeboWorld(WorldDir() + "/mini.world", {WorldDir() + "/models"}, &w).ok()); + OccupancyGrid a, b; + WorldTerrain t; + ASSERT_TRUE(RasterizeGazeboWorld(w, WorldRasterOptions{}, &a).ok()); + ASSERT_TRUE(RasterizeGazeboWorld(w, WorldRasterOptions{}, &b, &t).ok()); + EXPECT_EQ(t.terrain_cells, 0u); + ASSERT_EQ(a.width, b.width); + ASSERT_EQ(a.height, b.height); + EXPECT_EQ(a.data, b.data); +} + +// --- Bo mo phong ------------------------------------------------------------- + +TEST(SimTerrain, TuBatKhiWorldCoDiaHinh) { + { + SimSource sim(RampCfg()); + ASSERT_TRUE(sim.Open().ok()); + EXPECT_TRUE(sim.terrain_active()); + } + { + SimConfig c = RampCfg(); + c.terrain = SimConfig::TerrainMode::kOff; + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + EXPECT_FALSE(sim.terrain_active()); + EXPECT_EQ(sim.ground_truth_3d().z, 0.0); + } +} + +TEST(SimTerrain, LenDocZVaPitchDung) { + SimSource sim(RampCfg()); + ASSERT_TRUE(sim.Open().ok()); + sim.base()->Open(); + + DriveUntilX(&sim, 0.35, 4.0); + const SimPose3 p = sim.ground_truth_3d(); + ASSERT_GE(p.x, 4.0); + EXPECT_NEAR(p.z, p.x * kTan, 0.01); + // Pitch AM = mui ngoc len. Toc do da on dinh, lo xo giam xoc da tat dao dong. + EXPECT_NEAR(p.pitch, -kRampDeg * kDeg, 0.2 * kDeg); + EXPECT_NEAR(p.roll, 0.0, 1e-6); + + // Len het doc: san tren phang. + DriveUntilX(&sim, 0.35, kRampLen + 1.0); + const SimPose3 q = sim.ground_truth_3d(); + EXPECT_NEAR(q.z, kH, 0.01); + EXPECT_NEAR(q.pitch, 0.0, 0.2 * kDeg); +} + +TEST(SimTerrain, EncoderDemQuangDuongDocMatDoc) { + // Banh lan TREN mat doc: encoder dem quang duong doc doc, dai hon quang + // duong ngang 1/cos(goc). Odometry 2D cong thang so nay vao ban do ngang la + // sai 1.5% o 10 do, 15% o 30 do. + SimSource sim(RampCfg()); + ASSERT_TRUE(sim.Open().ok()); + EncoderReading last; + sim.base()->SetEncoderCallback([&](const EncoderReading& e) { last = e; }); + sim.base()->Open(); + + DriveUntilX(&sim, 0.30, 2.0); + const double x1 = sim.ground_truth().x; + const double e1 = (last.left_rad + last.right_rad) / 2.0; + DriveUntilX(&sim, 0.30, 6.0); + const double x2 = sim.ground_truth().x; + const double e2 = (last.left_rad + last.right_rad) / 2.0; + + const double along = (e2 - e1) * 0.0865; + EXPECT_NEAR(along / (x2 - x1), 1.0 / std::cos(kRampDeg * kDeg), 0.003) + << "doc doc " << along << " m, ngang " << (x2 - x1) << " m"; +} + +TEST(SimTerrain, LidarThayTuongGiaOChanDoc) { + // Dung o san phang, cach chan doc 1.5 m, nhin vao doc. Tia ngang o + // 0.2165 m cham mat doc o 0.2165 / tan(10 do) = 1.228 m sau chan doc. + SimConfig c = RampCfg(); + c.start_x = -1.5; + { + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + LaserScanPtr scan; + sim.lidar()->SetCallback([&](LaserScanPtr s) { scan = s; }); + sim.lidar()->Open(); + sim.RunFor(0.1); + ASSERT_TRUE(scan != nullptr); + EXPECT_NEAR(FrontRange(*scan), 1.5 + kLidarAboveFloor / kTan, 0.02); + } + { + // Tat dia hinh 3D: LiDAR 2D cu khong thay doc (doc la san), chi thay cot + // tren san cao o x = 10.3. + c.terrain = SimConfig::TerrainMode::kOff; + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + LaserScanPtr scan; + sim.lidar()->SetCallback([&](LaserScanPtr s) { scan = s; }); + sim.lidar()->Open(); + sim.RunFor(0.1); + ASSERT_TRUE(scan != nullptr); + EXPECT_GT(FrontRange(*scan), 5.0); + } +} + +TEST(SimTerrain, TichPhanGyroBangGocNghiengThat) { + // Gyro va gia toc ke phai noi CUNG mot chuyen. Truoc day pitch do dia hinh + // vao trong luc nhung khong vao gyro: tich phan gyro bao "chua he nghieng" + // trong khi gia toc ke bao "dang len doc 10 do". + SimConfig c = RampCfg(); + c.start_x = -1.0; + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + double integ = 0.0; + const double dt = 1.0 / c.imu_rate_hz; + sim.mcu()->SetImuCallback([&](ImuPtr m) { integ += m->angular_velocity.y * dt; }); + sim.mcu()->Open(); + sim.base()->Open(); + + const double p0 = sim.ground_truth_3d().pitch; + DriveUntilX(&sim, 0.35, 2.0); + const double p1 = sim.ground_truth_3d().pitch; + ASSERT_LT(p1, -5.0 * kDeg) << "chua len doc"; + EXPECT_NEAR(integ, p1 - p0, 1e-3); +} + +TEST(SimTerrain, MepBacChanRobot) { + // Bac cao 0.3 m truoc mat: khong leo duoc, robot dung truoc mep, van o z = 0. + SimConfig c; + c.speed = 0.0; + c.enable_depth_camera = false; + c.terrain = SimConfig::TerrainMode::kOn; + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + sim.SetFloorHeight(1.0, -3.0, 3.0, 3.0, 0.3f); + sim.base()->Open(); + + for (int i = 0; i < 100; ++i) { sim.base()->SetVelocity(0.3, 0.0); sim.RunFor(0.05); } + const SimPose3 p = sim.ground_truth_3d(); + EXPECT_LT(p.x, 1.0 - c.robot_radius + 0.05); + EXPECT_NEAR(p.z, 0.0, 1e-6); + EXPECT_GT(sim.stats().collisions, 0u); +} + +TEST(SimTerrain, DocTongHopKhongCanWorld) { + // SetFloorRamp: doc tuyen tinh cho bai kiem khong co file world. + SimConfig c; + c.speed = 0.0; + c.enable_depth_camera = false; + c.terrain = SimConfig::TerrainMode::kOn; + c.wheel_separation = 0.40; + SimSource sim(c); + ASSERT_TRUE(sim.Open().ok()); + // 15 do: len 0.536 m tren 2 m. + const double tan15 = std::tan(15.0 * kDeg); + sim.SetFloorRamp(1.0, -3.0, 3.0, 3.0, 0.0f, static_cast(2.0 * tan15)); + sim.base()->Open(); + + for (int i = 0; i < 200 && sim.ground_truth().x < 2.0; ++i) { + sim.base()->SetVelocity(0.3, 0.0); + sim.RunFor(0.05); + } + const SimPose3 p = sim.ground_truth_3d(); + ASSERT_GE(p.x, 2.0); + EXPECT_NEAR(p.z, (p.x - 1.0) * tan15, 0.01); + EXPECT_NEAR(p.pitch, -15.0 * kDeg, 0.3 * kDeg); +} diff --git a/tools/gen_slope_world.py b/tools/gen_slope_world.py new file mode 100644 index 0000000..fde0f35 --- /dev/null +++ b/tools/gen_slope_world.py @@ -0,0 +1,267 @@ +#!/usr/bin/env python3 +"""Sinh world mo phong co DOC: resources/worlds/slope_test.world + hai model. + +Bo cuc (nhin tu tren xuong, x sang phai, y len tren; met): + + y=33.5 +--------------------------------------------------+ + | SANH TREN (san cao H = 1.5 m) | + y=25.5 +---------+---------+---------+---------+----------+ + | 5 do | 10 do | 15 do | 20 do | 30 do | + | | | | | | lan rong 2.4 m, + | doc | doc | doc | doc | doc | ngan boi tuong + | dai | | | | ngan | 0.2 m + y=8 +---------+---------+---------+---------+----------+ + | SANH DUOI (z = 0) | + y=0 +--------------------------------------------------+ + x=0 x=12.8 + +Moi lan: doc bat dau o y = 8 (z = 0) va len toi H, roi di phang o H toi sanh +tren. Nam doc CUNG noi hai mat bang, nen di len lan nay xuong lan kia la mot +vong khep kin -- dung thu SLAM can thu: khep vong ca x, y LAN z. + +Do dai doc = H / tan(goc): 17.1 m (5 do), 8.5 (10), 5.6 (15), 4.1 (20), +2.6 m (30 do). + +Model `vslam_terrain_slope_test` la DIA HINH: bo mo phong coi mat cua no la +SAN robot di len, khong phai vat can (xem libs/vslam_sim/include/vslam/ +gazebo_world.h, `kTerrainModelPrefix`). Mesh co toa do texture (vt) theo met, +de giai doan render GPU dan texture ma khong phai sinh lai. + +Do dac co texture lay tu ~/gazebo_models/aws_hospital_fuel; thieu thi bo doc +world bo qua (khong loi), chi mat vai vat cho camera bam. + +Chay tu goc repo: + + python3 tools/gen_slope_world.py + export GAZEBO_MODEL_PATH=$PWD/resources/models + ./build/app/vslam_node --sim --world resources/worlds/slope_test.world \\ + --x 6.4 --y 4 --yaw 1.5708 --token t +""" +import argparse +import math +import os + +H = 1.5 # chenh hai mat bang, m +ANGLES = [5, 10, 15, 20, 30] # do, tu trai sang phai +LANE_W = 2.4 # be rong long lan +WALL_T = 0.2 # be day tuong +HALL_D = 8.0 # chieu sau moi sanh +LANE_LEN = 17.5 # chieu dai lan (>= doc 5 do dai nhat) +WALL_H = H + 2.5 # tuong cao toi day, du che ca tang tren + +XI = len(ANGLES) * LANE_W + (len(ANGLES) - 1) * WALL_T # be rong long nha +Y_LANE0 = HALL_D +Y_LANE1 = HALL_D + LANE_LEN +Y_TOP = Y_LANE1 + HALL_D + +TERRAIN = 'vslam_terrain_slope_test' +WALLS = 'vslam_slope_test_walls' + +# Do dac co texture: (model, x, y, z, yaw). Chi dat sat tuong dau/cuoi va o +# KHE GIUA cac duong vao lan (tam lan x = 1.2, 3.8, 6.4, 9.0, 11.6, moi ben +# 0.6 m) -- dat chan duong vao lan nao la lan do khong chay thu duoc: lop an +# toan dung xe truoc khi toi doc (da mac: xe lan o (12.0, 6.6) chan lan 30 do). +FURNITURE = [ + ('MetalCabinet', 0.6, 1.0, 0.0, 0.0), + ('StorageRack', 3.0, 0.6, 0.0, 0.0), + ('IVStand', 5.1, 1.0, 0.0, 0.0), + ('PatientWheelChair', 7.7, 1.0, 0.0, 0.0), + ('BedTable', 9.5, 0.8, 0.0, 0.0), + ('VendingMachine', 12.1, 1.2, 0.0, -math.pi / 2), + ('MetalCabinet', 0.6, 32.6, H, 0.0), + ('IVStand', 5.1, 32.8, H, 0.0), + ('StorageRack', 6.4, 32.9, H, math.pi), + ('BedTable', 11.8, 32.6, H, 0.0), +] + + +class Obj: + """Mesh OBJ: Z-up, met. Mat huong LEN khi dinh di nguoc kim dong ho tu tren.""" + + def __init__(self, header): + self.lines = ['# ' + l for l in header.splitlines()] + self.nv = 0 + + def quad(self, p, uv=None): + """p: 4 dinh (x, y, z) theo thu tu vong. uv mac dinh = (x, y) met.""" + base = self.nv + for i, (x, y, z) in enumerate(p): + self.lines.append('v %.4f %.4f %.4f' % (x, y, z)) + u, w = uv[i] if uv else (x, y) + self.lines.append('vt %.4f %.4f' % (u, w)) + self.nv += 4 + a, b, c, d = (base + k + 1 for k in range(4)) + self.lines.append('f %d/%d %d/%d %d/%d' % (a, a, b, b, c, c)) + self.lines.append('f %d/%d %d/%d %d/%d' % (a, a, c, c, d, d)) + + def box(self, x0, y0, z0, x1, y1, z1): + """Hop kin, mat huong RA ngoai. uv cua mat dung theo (doc tuong, z).""" + self.quad([(x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)]) # tren + self.quad([(x0, y1, z0), (x1, y1, z0), (x1, y0, z0), (x0, y0, z0)]) # day + self.quad([(x0, y0, z0), (x1, y0, z0), (x1, y0, z1), (x0, y0, z1)], + [(x0, z0), (x1, z0), (x1, z1), (x0, z1)]) # -y + self.quad([(x1, y1, z0), (x0, y1, z0), (x0, y1, z1), (x1, y1, z1)], + [(x1, z0), (x0, z0), (x0, z1), (x1, z1)]) # +y + self.quad([(x0, y1, z0), (x0, y0, z0), (x0, y0, z1), (x0, y1, z1)], + [(y1, z0), (y0, z0), (y0, z1), (y1, z1)]) # -x + self.quad([(x1, y0, z0), (x1, y1, z0), (x1, y1, z1), (x1, y0, z1)], + [(y0, z0), (y1, z0), (y1, z1), (y0, z1)]) # +x + + def text(self): + return '\n'.join(self.lines) + '\n' + + +def lane_x(i): + x0 = i * (LANE_W + WALL_T) + return x0, x0 + LANE_W + + +def terrain_mesh(): + m = Obj('Dia hinh world doc: san duoi z=0, san tren z=%.2f, %d lan doc.\n' + 'Z-UP, met. Sinh boi tools/gen_slope_world.py -- dung sua tay.' + % (H, len(ANGLES))) + m.quad([(0, 0, 0), (XI, 0, 0), (XI, Y_LANE0, 0), (0, Y_LANE0, 0)]) + m.quad([(0, Y_LANE1, H), (XI, Y_LANE1, H), (XI, Y_TOP, H), (0, Y_TOP, H)]) + for i, deg in enumerate(ANGLES): + x0, x1 = lane_x(i) + y_top = Y_LANE0 + H / math.tan(math.radians(deg)) + m.quad([(x0, Y_LANE0, 0), (x1, Y_LANE0, 0), (x1, y_top, H), (x0, y_top, H)]) + if y_top < Y_LANE1 - 1e-6: + m.quad([(x0, y_top, H), (x1, y_top, H), (x1, Y_LANE1, H), (x0, Y_LANE1, H)]) + return m.text() + + +def walls_mesh(): + m = Obj('Tuong va cot cua world doc. Z-UP, met.\n' + 'Sinh boi tools/gen_slope_world.py -- dung sua tay.') + t = WALL_T + # Vong ngoai. + m.box(-t, -t, 0, 0, Y_TOP + t, WALL_H) + m.box(XI, -t, 0, XI + t, Y_TOP + t, WALL_H) + m.box(-t, -t, 0, XI + t, 0, WALL_H) + m.box(-t, Y_TOP, 0, XI + t, Y_TOP + t, WALL_H) + # Tuong ngan lan. + for i in range(len(ANGLES) - 1): + _, x1 = lane_x(i) + m.box(x1, Y_LANE0, 0, x1 + t, Y_LANE1, WALL_H) + # Vai cot va mau tuong de LiDAR co cho bam trong hai sanh rong. Dat o KHE + # giua cac duong vao/ra lan (xem FURNITURE), khong chan lan nao. + m.box(2.3, 3.8, 0, 2.7, 4.2, WALL_H) + m.box(10.1, 3.8, 0, 10.5, 4.2, WALL_H) + m.box(4.6, 5.0, 0, 5.6, 5.2, WALL_H) + m.box(4.9, 29.3, H, 5.3, 29.7, WALL_H) + m.box(7.5, 29.3, H, 7.9, 29.7, WALL_H) + m.box(9.7, 30.5, H, 10.9, 30.7, WALL_H) + return m.text() + + +SDF = ''' + + + + + + + model://{name}/meshes/{mesh} + + + + + + + model://{name}/meshes/{mesh} + + + + + 1 + + +''' + +CONFIG = ''' + + {name} + 1.0 + model.sdf + + vslam_cpp + + + + {desc} + Sinh boi tools/gen_slope_world.py. + + +''' + + +def include(name, uri, x, y, z, yaw): + return (' \n' + ' \n' + ' model://%s\n' + ' true\n' + ' %.3f %.3f %.3f 0 0 %.4f\n' + ' \n' + ' \n' % (name, uri, x, y, z, yaw)) + + +def world_text(): + parts = ['\n', + '\n', + '\n \n', + ' model://ground_plane\n', + ' model://sun\n', + include(TERRAIN + '_1', TERRAIN, 0, 0, 0, 0), + include(WALLS + '_1', WALLS, 0, 0, 0, 0)] + count = {} + for name, x, y, z, yaw in FURNITURE: + count[name] = count.get(name, 0) + 1 + parts.append(include('%s_%d' % (name, count[name]), name, x, y, z, yaw)) + parts.append(' \n\n') + return ''.join(parts) + + +def write(path, text): + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, 'w') as f: + f.write(text) + print('ghi', path) + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument('--root', default=os.path.dirname(here), + help='goc repo (mac dinh: thu muc cha cua tools/)') + a = ap.parse_args() + models = os.path.join(a.root, 'resources', 'models') + + write(os.path.join(models, TERRAIN, 'meshes', 'terrain.obj'), terrain_mesh()) + write(os.path.join(models, TERRAIN, 'model.sdf'), + SDF.format(name=TERRAIN, mesh='terrain.obj')) + write(os.path.join(models, TERRAIN, 'model.config'), + CONFIG.format(name=TERRAIN, desc='San, chieu nghi va 5 lan doc (dia hinh).')) + write(os.path.join(models, WALLS, 'meshes', 'walls.obj'), walls_mesh()) + write(os.path.join(models, WALLS, 'model.sdf'), + SDF.format(name=WALLS, mesh='walls.obj')) + write(os.path.join(models, WALLS, 'model.config'), + CONFIG.format(name=WALLS, desc='Tuong bao, tuong ngan lan va cot.')) + write(os.path.join(a.root, 'resources', 'worlds', 'slope_test.world'), world_text()) + + for i, deg in enumerate(ANGLES): + x0, x1 = lane_x(i) + print('lan %2d do: x %.1f-%.1f, doc dai %.2f m, chan doc y = %.1f, ' + 'tuong gia o chan doc cach %.2f m' % + (deg, x0, x1, H / math.tan(math.radians(deg)), Y_LANE0, + 0.2165 / math.tan(math.radians(deg)))) + + +if __name__ == '__main__': + main()