slam,odometry,perception: di tren doc (G4, slam.yaml slope.enabled, mac dinh tat) -- z robot = tich -ds*sin(pitch IMU) kep phang < 1.5 do va neo vao ban do (HeightEstimator), odometry ngang, scan cho SLAM bu nghieng + bo tia cham san/doc theo ban do do cao tu depth (ScanLeveler, ElevationMap), z/roll/pitch luu vao node + do thi z 1-D + mat san theo node (height_map), voxel dat o z that va vat can tinh tu san cuc bo, xoa tuong gia LiDAR tren doc noi camera da thay mat san, web z uoc luong, --sim-imu-hz
This commit is contained in:
98
libs/vslam_slam/include/vslam/height_map.h
Normal file
98
libs/vslam_slam/include/vslam/height_map.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef VSLAM_HEIGHT_MAP_H
|
||||
#define VSLAM_HEIGHT_MAP_H
|
||||
|
||||
// z cua ban do khi pose SLAM la SE(2): do cao tung node va mat san quanh no.
|
||||
//
|
||||
// ================== NGUON ==================
|
||||
// Moi node mang z / roll / pitch DO luc tao (HeightEstimator + GravityAlign),
|
||||
// luu trong userData cua RTAB-Map. z do co troi (truot banh, sai pitch), va
|
||||
// do thi SE(2) cua RTAB-Map khong biet gi ve no.
|
||||
//
|
||||
// ================== DO THI z 1-D ==================
|
||||
// Sau moi lan toi uu cua RTAB-Map, giai lai z bang binh phuong toi thieu:
|
||||
// * lien ket LANG GIENG (node lien tiep): z_j - z_i = z_do_j - z_do_i,
|
||||
// sigma = min + rel * |dz| (sai he thong ti le voi do cao leo);
|
||||
// * lien ket VONG / lan can (cung cho, hai lan qua): z_j - z_i = mat phang
|
||||
// doc cua node i keo toi node j. Ca hai node PHANG (|pitch| < clamp) ->
|
||||
// 0, chat (3 cm). Tren doc -> theo pitch, long hon (hai node cach 1 m tren
|
||||
// doc 30 do lech 0.58 m -- dz = 0 o day la SAI);
|
||||
// * node dau tien neo o z do cua no; moi node co mot prior rat long ve z do
|
||||
// de do thi khong lien thong van giai duoc.
|
||||
// Nho vay khi robot quay ve cho cu sau mot vong co doc, sai z don ra deu
|
||||
// tren vong thay vi don het vao mot cho.
|
||||
//
|
||||
// ================== MAT SAN ==================
|
||||
// FloorModel: do cao san tai (x, y) = MAT PHANG cua node GAN NHAT (z, pitch,
|
||||
// roll cua no) keo toi do. Dung cho: cat voxel theo do cao TREN san, lop vat
|
||||
// can tinh theo san cuc bo (doc khong con la tuong), va neo z robot luc dinh
|
||||
// vi. Node gan nhat chu khong trung binh: canh dinh doc, trung binh hai mat
|
||||
// phang (doc + chieu nghi) cho ra mot san khong co that.
|
||||
//
|
||||
// Khong phu thuoc RTAB-Map -- test duoc rieng.
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace vslam {
|
||||
|
||||
struct NodeHeight {
|
||||
double z = 0.0; // do cao base_footprint (mat san duoi robot), m
|
||||
double roll = 0.0; // nghieng than luc tao node (ROS: duong = trai len)
|
||||
double pitch = 0.0; // duong = mui chuc xuong
|
||||
};
|
||||
|
||||
struct ZGraphLink {
|
||||
int from = 0;
|
||||
int to = 0;
|
||||
bool neighbor = false; // lien tiep (odometry) hay vong / lan can
|
||||
// Vi tri node `to` trong frame node `from` (mat phang ngang), m.
|
||||
double dx = 0.0;
|
||||
double dy = 0.0;
|
||||
};
|
||||
|
||||
struct ZGraphConfig {
|
||||
double clamp_rad = 0.0261799; // 1.5 do: duoi nguong = phang
|
||||
double sigma_neighbor = 0.01;
|
||||
double sigma_rel = 0.05;
|
||||
double sigma_loop_flat = 0.03;
|
||||
double sigma_loop_slope = 0.10;
|
||||
double sigma_first = 0.01;
|
||||
double sigma_prior = 2.0; // prior long ve z do cua MOI node
|
||||
};
|
||||
|
||||
// Tra z da toi uu cho moi node trong `meas`. Lien ket toi node khong co trong
|
||||
// `meas` bi bo qua.
|
||||
std::map<int, double> SolveZGraph(const std::map<int, NodeHeight>& meas,
|
||||
const std::vector<ZGraphLink>& links,
|
||||
const ZGraphConfig& cfg = {});
|
||||
|
||||
struct FloorNode {
|
||||
double x = 0.0, y = 0.0, theta = 0.0; // pose (da toi uu) trong frame map
|
||||
double z = 0.0, roll = 0.0, pitch = 0.0;
|
||||
};
|
||||
|
||||
class FloorModel {
|
||||
public:
|
||||
// radius: chi dung node trong ban kinh nay (camera thay toi ~4 m).
|
||||
void Build(const std::vector<FloorNode>& nodes, double radius = 4.0, double cell = 0.25);
|
||||
// Do cao san tai (x, y) theo mat phang node gan nhat; false neu khong node
|
||||
// nao trong ban kinh. `dist`: khoang cach toi node do.
|
||||
bool FloorAt(double x, double y, double* z, double* dist = nullptr) const;
|
||||
// Node gan nhat (trong ban kinh) cua (x, y); false neu khong co.
|
||||
bool NearestNode(double x, double y, FloorNode* node, double* dist = nullptr) const;
|
||||
bool empty() const { return nodes_.empty(); }
|
||||
size_t size() const { return nodes_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<FloorNode> nodes_;
|
||||
double radius_ = 4.0, cell_ = 0.25, x0_ = 0.0, y0_ = 0.0;
|
||||
int w_ = 0, h_ = 0;
|
||||
std::vector<int> nearest_; // moi o: chi so node gan nhat, -1 = khong co
|
||||
};
|
||||
|
||||
// Do cao mat phang cua node n tai (x, y).
|
||||
double PlaneZ(const FloorNode& n, double x, double y);
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_HEIGHT_MAP_H
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include "vslam/height_map.h"
|
||||
#include "vslam/rtabmap_params.h"
|
||||
#include "vslam/slam_types.h"
|
||||
#include "vslam/voxel_export.h"
|
||||
@@ -101,6 +102,20 @@ class RtabmapSlam {
|
||||
std::vector<int> MapNodeIds() const;
|
||||
StatusResponse GetNodeView(int id, bool with_depth, NodeView* out);
|
||||
|
||||
// ---- z ban do khi di tren doc (height_map.h) ----
|
||||
// Giai lai do thi z tu z DO cua node (userData) va lien ket cua do thi,
|
||||
// dung lai mat san. Node chua co z do thi nap tu DB (ban do quet truoc).
|
||||
// CHI luong slam goi. `nodes_out`: so node co z.
|
||||
StatusResponse UpdateHeights(const ZGraphConfig& cfg, size_t* nodes_out = nullptr);
|
||||
// Do cao san tai (x, y) frame map theo mat phang node gan nhat, chi khi
|
||||
// node do trong `radius`. false neu khong co. CHI luong slam goi.
|
||||
bool HeightAt(double x, double y, double radius, double* z) const;
|
||||
const FloorModel& floor_model() const;
|
||||
// Bat dung z node + mat san cho ban do voxel (sau UpdateHeights).
|
||||
void SetUseHeights(bool on);
|
||||
// O 2D noi camera thay mat san trong lan ExportVoxels cuoi (che do doc).
|
||||
const std::vector<uint64_t>& floor_cells() const;
|
||||
|
||||
StatusResponse Close(bool save_database);
|
||||
|
||||
const SlamStats& stats() const;
|
||||
|
||||
@@ -51,6 +51,13 @@ struct SlamInput {
|
||||
// Than robot chuc len/xuong khi tang/giam toc. Coi camera nam ngang thi san
|
||||
// o 3 m bi day len ~0.2 m va thanh vat can gia trong ban do 3D.
|
||||
const Transform* camera_to_base = nullptr;
|
||||
|
||||
// Di tren doc (slam.yaml `slope:`): do cao base_footprint va nghieng than
|
||||
// luc nay. Co thi luu vao node (userData cua RTAB-Map) -- xem height_map.h.
|
||||
bool has_height = false;
|
||||
double z = 0.0;
|
||||
double roll = 0.0;
|
||||
double pitch = 0.0;
|
||||
};
|
||||
|
||||
struct SlamOutput {
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/height_map.h"
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace rtabmap {
|
||||
@@ -65,13 +67,32 @@ struct VoxelExportOptions {
|
||||
// nhieu depth va nguoi di ngang chi o 1-2 khung; tuong, ban ghe dung yen
|
||||
// thi nhieu node thay. 1 = giu moi voxel (hanh vi cu).
|
||||
size_t min_node_hits = 1;
|
||||
|
||||
// Di tren doc: z cua tung node (do thi z) + mat san. Co ca hai thi diem dat
|
||||
// o z THAT (z node + z cuc bo), va dai z_min..z_max tinh tu SAN tai cho diem
|
||||
// do (mat doc khong lot vao ban do nhu vat can). Null = duong cu (moi node
|
||||
// o z = 0, dai tinh tu san duoi node).
|
||||
const std::map<int, double>* node_z = nullptr;
|
||||
const FloorModel* floor = nullptr;
|
||||
// Che do doc: thu cac o 2D (kich thuoc emit_size_m, khoa PackFloorCell) noi
|
||||
// camera THAY MAT SAN (|cao - san| <= floor_band). Dung cho
|
||||
// ClearLidarOnSeenRamps. Null = khong thu.
|
||||
std::vector<uint64_t>* floor_cells = nullptr;
|
||||
double floor_band = 0.05;
|
||||
};
|
||||
|
||||
// Khoa o 2D (ix, iy) cua floor_cells.
|
||||
inline uint64_t PackFloorCell(int32_t ix, int32_t iy) {
|
||||
return (static_cast<uint64_t>(static_cast<uint32_t>(ix)) << 32) | static_cast<uint32_t>(iy);
|
||||
}
|
||||
|
||||
// Diem cua tung node, o frame CUA NODE, da gom voxel. Tinh MOT lan roi giu:
|
||||
// depth cua node khong doi, chi pose cua no doi sau moi lan toi uu.
|
||||
// CHI luong slam cham vao.
|
||||
struct VoxelNodeCache {
|
||||
std::unordered_map<int, std::vector<float>> nodes; // id -> x,y,z,x,y,z...
|
||||
// Diem node da cat theo dai z RONG (che do doc). Doi che do thi xoa cache.
|
||||
bool wide = false;
|
||||
};
|
||||
|
||||
// Gom diem -> tap voxel. KHONG chua kieu nao cua RTAB-Map, nen test duoc ma
|
||||
@@ -156,8 +177,26 @@ void NodeCloudFromSensorData(const rtabmap::SensorData& data,
|
||||
// mat san). La LOP VAT CAN tu camera cho nhung thu LiDAR (0.22 m) khong cat
|
||||
// ngang: mat ghe, khung giuong, ke thap. Chi THEM o bi chiem, khong xoa.
|
||||
// Tra ve so o moi danh dau (truoc do trong/chua biet).
|
||||
//
|
||||
// `floor` (di tren doc): do cao tinh tu SAN TAI CHO voxel (FloorModel) thay vi
|
||||
// tu z = 0 -- mat doc va san tang tren khong con bi danh la tuong. Null =
|
||||
// duong cu.
|
||||
size_t MarkVoxelObstacles(const VoxelGrid& vg, double z_min, double z_max,
|
||||
OccupancyGrid* grid);
|
||||
OccupancyGrid* grid, const FloorModel* floor = nullptr);
|
||||
|
||||
// Di tren doc: TREN DOC, lop LiDAR nhuong cho camera.
|
||||
//
|
||||
// LiDAR ngang thay mat doc len tu xa (> 4 m, ngoai tam depth) nhu mot buc
|
||||
// tuong -- tuong gia vao node TRUOC khi camera kip thay mat doc, va cac scan
|
||||
// sau BO tia cham doc (NaN) nen khong tia nao xoa duoc no. O day: o LiDAR bi
|
||||
// chiem ma (1) node ban do gan nhat (trong `max_node_dist`) dang TREN DOC
|
||||
// (|pitch| >= clamp) va (2) camera da THAY MAT SAN o do (floor_cells) -> tra
|
||||
// ve trong. Vat can THAT tren doc van duoc MarkVoxelObstacles danh lai (goi
|
||||
// SAU ham nay). Camera chua thay thi giu nguyen -- khong co bang chung.
|
||||
// Tra ve so o da xoa.
|
||||
size_t ClearLidarOnSeenRamps(OccupancyGrid* grid, const std::vector<uint64_t>& floor_cells,
|
||||
double cell_size, const FloorModel& floor, double clamp_rad,
|
||||
double max_node_dist);
|
||||
|
||||
// Hieu hai tap DA SAP XEP: `added` co trong `now` ma khong co trong `prev`,
|
||||
// `removed` thi nguoc lai. O(n + m), mot luot.
|
||||
|
||||
Reference in New Issue
Block a user