154 lines
6.5 KiB
C++
154 lines
6.5 KiB
C++
#ifndef VSLAM_RTABMAP_SLAM_H
|
|
#define VSLAM_RTABMAP_SLAM_H
|
|
|
|
// Boc `rtabmap::Rtabmap`.
|
|
//
|
|
// ================== BA DIEU PHAI NHO ==================
|
|
//
|
|
// 1. `Process()` CHAN 100-600 ms. Luong goi no KHONG duoc chia se mutex nao
|
|
// voi luong safety. Trong ban ROS dieu nay duoc bao dam mien phi boi tien
|
|
// trinh rieng + respawn="true"; o day no la quy tac review.
|
|
//
|
|
// 2. RTAB-Map luu du lieu NEN. `gridGroundCellsRaw()` tra ma tran RONG, im
|
|
// lang, cho toi khi goi `uncompressDataConst()`. Da mac loi nay mot lan
|
|
// khi do `tools/probe_rtabmap` tren map_hospital.db.
|
|
//
|
|
// 3. DB hien co luu `Optimizer/Strategy=2` (GTSAM). Tren Jetson build voi
|
|
// -DWITH_GTSAM=OFF ma de RTAB-Map doc tham so tu DB thi no chon lai GTSAM
|
|
// va crash thieu symbol. `Init()` luon goi
|
|
// `init(params, db, loadDatabaseParameters=false)` VA assert sau do.
|
|
|
|
#include <memory>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <opencv2/core.hpp>
|
|
|
|
#include "vslam/height_map.h"
|
|
#include "vslam/rtabmap_params.h"
|
|
#include "vslam/slam_types.h"
|
|
#include "vslam/voxel_export.h"
|
|
#include "vslam/vslam_common.h"
|
|
|
|
namespace vslam {
|
|
|
|
class RtabmapSlamImpl; // o namespace scope, KHONG long trong class
|
|
// (pimpl long private khong goi duoc tu .cc -- da
|
|
// mac loi nay o ConfigNode va WebServer)
|
|
|
|
// Anh cua mot node ban do, cho dinh vi lai bang camera (vslam/visual_verifier.h).
|
|
struct NodeView {
|
|
cv::Mat gray; // anh IR (kenh "rgb" luc quet), 8 bit
|
|
cv::Mat depth; // CV_16UC1 (mm); rong neu with_depth = false
|
|
cv::Matx33d K; // DA bu binning -- dung nhu luc luu
|
|
cv::Matx44d T_base_optical; // base (z tu san, gom nghieng luc chup) <- optical
|
|
cv::Matx44d T_map_base; // pose TOI UU cua node
|
|
};
|
|
|
|
class RtabmapSlam {
|
|
public:
|
|
RtabmapSlam();
|
|
~RtabmapSlam();
|
|
|
|
RtabmapSlam(const RtabmapSlam&) = delete;
|
|
RtabmapSlam& operator=(const RtabmapSlam&) = delete;
|
|
|
|
// Mo DB va khoi tao. Tra loi (khong nem) de nguoi goi quyet dinh chay tiep
|
|
// o che do khong-SLAM hay dung han.
|
|
//
|
|
// Kiem truoc khi chay, KHONG phai sau:
|
|
// - optimizer da yeu cau co duoc build vao khong;
|
|
// - visual_loop=true ma DB khong co tu vung (SELECT COUNT(*) FROM Word
|
|
// = 0) -> tra FAILED_PRECONDITION thay vi am tham ton CPU ma khong bao
|
|
// gio dong duoc vong nao;
|
|
// - localization ma DB rong -> khong co gi de dinh vi vao.
|
|
StatusResponse Init(const RtabmapConfig& cfg);
|
|
|
|
// Phep bien doi TINH tu cam bien ve base_footprint, doc tu robot.yaml.
|
|
//
|
|
// PHAI goi truoc Process(). Mac dinh la dong nhat, va dong nhat la SAI:
|
|
// laser tren robot nay o xyz = (0.24, 0, 0.20). Bo qua no thi moi scan bi
|
|
// dat lech 24 cm so voi pose, ICP van hoi tu (no chi thay ca the gioi dich
|
|
// di) nhung do thi tich luy sai so -- da do: ATE 0.2378 m thay vi 0.0074 m
|
|
// tren map_house.db. Khong co gi bao loi.
|
|
void SetExtrinsics(const Transform& laser_to_base, const Transform& camera_to_base);
|
|
|
|
// Mot khung. Tra `processed=false` neu RTAB-Map bo qua (chua du chuyen dong
|
|
// theo RGBD/LinearUpdate) -- do KHONG phai loi.
|
|
SlamOutput Process(const SlamInput& in);
|
|
|
|
// map -> odom gan nhat. An toan goi tu luong khac (doc duoi mutex rieng,
|
|
// khong phai mutex ma Process() giu).
|
|
Pose2D map_correction() const;
|
|
bool localized() const;
|
|
uint64_t map_version() const;
|
|
|
|
// Dat lai pose (thay cho /initialpose). Chi co nghia o che do localization.
|
|
StatusResponse SetInitialPose(const Pose2D& pose);
|
|
|
|
// Xuat occupancy grid hien tai. Dat, goi khi map_version doi.
|
|
StatusResponse ExportMap(OccupancyGrid* out);
|
|
|
|
// Xuat ban do VOXEL 3D. Dat hon ExportMap: no quet lai o bi chiem cua moi
|
|
// node. Goi cung nhip va cung ngan sach voi ExportMap -- xem Runtime::SlamLoop.
|
|
//
|
|
// `out->epoch` khong duoc dat o day: vong doi epoch la viec cua nguoi goi,
|
|
// chi ho moi biet tap truoc do la gi.
|
|
StatusResponse ExportVoxels(const VoxelExportOptions& opt, VoxelGrid* out);
|
|
|
|
// Node co pose toi uu (ban do dang dung), va anh + hinh hoc camera cua mot node -- DUNG
|
|
// nhu RTAB-Map da luu (K da bu binning, T gom nghieng luc chup). CHI luong slam goi (cung
|
|
// luong Process()): doc thang Memory cua RTAB-Map.
|
|
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;
|
|
|
|
// Vong dong XA: node vua tao vs node CU (cach >= min_graph_gap buoc trong do
|
|
// thi) nam trong ban kinh `radius_m` theo do thi da toi uu -- tuc lan di
|
|
// TRUOC qua cung cho. Dang ky ICP giua hai scan (tham so Icp/* cua chinh ban
|
|
// do); nhan neu ICP dat va chinh so voi do thi < max_corr; them lien ket.
|
|
//
|
|
// KHONG ghep node cung mot luot di: lien ket ICP trong hanh lang khong rang
|
|
// buoc doc truc va keo ban do truot (do trong sim 04/10: detectMoreLoopClosures
|
|
// cua RTAB-Map them hang tram lien ket nhu vay, sai 12 cm -> 33 cm).
|
|
// Tra 1 = da them, 0 = khong co ung vien / ICP khong dat, -1 = loi. `detail`:
|
|
// ly do. CHI luong slam, CHI che do mapping.
|
|
int TryFarLoopClosure(double radius_m, int min_graph_gap, double max_corr_m,
|
|
double max_corr_rad, std::string* detail);
|
|
|
|
StatusResponse Close(bool save_database);
|
|
|
|
const SlamStats& stats() const;
|
|
SlamMode mode() const;
|
|
|
|
// Duong dan DB DA GIAI (tuong doi -> MapDir(), {stamp} da no).
|
|
// Rong = DB trong RAM. Chi co nghia sau Init().
|
|
const std::string& database_path() const;
|
|
|
|
// Tham so RTAB-Map DANG CHAY (slam.yaml + mac dinh). Dung lai GridGlobal/*
|
|
// khi dung luoi tu DB (ExportOccupancyGridFromDb) cho cung cach cap nhat o
|
|
// voi ban do dang hien.
|
|
std::map<std::string, std::string> rtabmap_parameters() const;
|
|
|
|
private:
|
|
std::unique_ptr<RtabmapSlamImpl> impl_;
|
|
};
|
|
|
|
} // namespace vslam
|
|
|
|
#endif // VSLAM_RTABMAP_SLAM_H
|