upload
This commit is contained in:
223
libs/vslam_perception/include/vslam/cliff_detect.h
Normal file
223
libs/vslam_perception/include/vslam/cliff_detect.h
Normal file
@@ -0,0 +1,223 @@
|
||||
#ifndef VSLAM_CLIFF_DETECT_H
|
||||
#define VSLAM_CLIFF_DETECT_H
|
||||
|
||||
// Phat hien vuc / bac thang xuong bang anh DEPTH.
|
||||
//
|
||||
// Port tu perception_3d/src/cliff_detect_nodelet.cpp (~450 dong, doan thuat
|
||||
// toan day nhat cua repo cu).
|
||||
//
|
||||
// ============ VI SAO CHAY TREN ANH DEPTH CHU KHONG PHAI POINT CLOUD ============
|
||||
// 1. Bac thang TOI tra ve LO (NaN / 0), khong tra ve diem thap.
|
||||
// pcl::PassThrough loai NaN => chinh cai tin hieu can tim bi xoa sach.
|
||||
// Tren anh depth, mot pixel le ra phai thay san ma khong co so do LA bang
|
||||
// chung cua vuc.
|
||||
// 2. Tia biet minh di huong nao. Voi moi pixel tinh duoc "san LE RA phai o
|
||||
// depth bao nhieu" (giao tia voi mat phang san). Cloud da mat thong tin do.
|
||||
// 3. Danh dau tai P_floor = giao tia voi mat san, tuc la MEP vuc, chu khong
|
||||
// phai tai diem tra ve (nam sau duoi day vuc, hoac khong ton tai).
|
||||
//
|
||||
// ============ VUNG MU 0 - 1.1 m ============
|
||||
// Camera cao 0.803 m nghieng xuong: tia cham san gan nhat o ~1.07 m. Duoi
|
||||
// nguong do khong tia nao cham san, detector khong the biet gi. Do la ly do
|
||||
// min_dist mac dinh 1.10 m, va la ly do BAT BUOC phai co cam bien khac (cliff
|
||||
// IR / bumper) cho vung gan.
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/perception_types.h"
|
||||
#include "vslam/unix_time.h"
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
struct CliffDetectConfig {
|
||||
bool enabled = true;
|
||||
|
||||
// Cua so xet, tinh theo ban kinh tren mat san (m). Duoi min_dist la vung mu
|
||||
// hinh hoc, khong phai lua chon tuy y.
|
||||
double min_dist = 1.10;
|
||||
double max_dist = 2.50;
|
||||
|
||||
// Be mat phai thap hon san tham chieu bao nhieu moi tinh la vuc (m).
|
||||
double cliff_margin = 0.05;
|
||||
|
||||
// Sai so pitch con lai sau tu hieu chuan. Nguong no ra theo tam:
|
||||
// thr = z_ref - (cliff_margin + r * tan(pitch_uncertainty))
|
||||
double pitch_uncertainty_deg = 2.0;
|
||||
|
||||
int pixel_step = 4; // lay mau thua: 1/16 so pixel
|
||||
int min_neighbors = 3; // trong 8 lang gieng, de loai pixel le
|
||||
int min_cluster = 12; // so diem toi thieu de bao vuc
|
||||
|
||||
double imu_timeout = 0.5;
|
||||
// Bail khi gravity_align dang khong neo duoc vao trong luc. Pitch luc do la
|
||||
// gyro thuan va dang troi -> hinh hoc cat tia x san khong dung tin.
|
||||
bool require_accel_ok = true;
|
||||
|
||||
// --- Tu hieu chuan mat san ---
|
||||
bool self_level = true;
|
||||
int min_level_samples = 40;
|
||||
// Cong nay loai CA vat the (mat ban 0.7 m) LAN vuc that (z ~ -1 m) khoi phep
|
||||
// khop. Nho ve thu hai ma khop duoc tren TOAN cua so ma khong nuot mat chinh
|
||||
// cai vuc dang can tim.
|
||||
double level_gate = 0.25;
|
||||
// Doc vuot tran = dau hieu phep khop hong, KHONG phai san doc that. Ramp la
|
||||
// san doc THAT va robot phai di duoc -- cong phan biet ramp/vuc la MAD.
|
||||
double max_level_slope = 0.20;
|
||||
double max_level_residual = 0.05;
|
||||
|
||||
// Mat phang san khop duoc, NGOAI SUY ve r = 0, phai di qua chinh cho robot
|
||||
// dang dung -- vi robot DANG DUNG TREN no. Mot phep khop noi "san duoi banh
|
||||
// xe toi thap hon 25 cm" la mot menh de vat ly sai, khong phai mot nguong
|
||||
// can chinh.
|
||||
//
|
||||
// Day la cong bat duoc kieu hong ma `max_obstructed_frac` KHONG bat duoc:
|
||||
// hanh lang 2.5-3.0 m, tuong cach 1.25-1.5 m. Chi ~9% tia tra ve diem cao
|
||||
// hon level_gate (xa cong 0.60), nhung diem tuong o r lon van lot cong va
|
||||
// KEO DOC duong khop len +0.19 -- vua du duoi tran max_level_slope 0.20.
|
||||
// Sau do san THAT o r ~ 2 m bi do voi z_ref = +0.13 -> roi duoi nguong ->
|
||||
// vuc gia. Do duoc: 6/210 khung o be rong 3.0 m.
|
||||
//
|
||||
// Vi sao KHONG ha max_level_slope thay vi the: 0.20 duoc chon de HAP THU
|
||||
// dao dong pitch +-8.5 do do duoc tren robot that; ha xuong se vo hieu hoa
|
||||
// co che bu va tat phat hien vuc khi robot dang chay. Xem ghi chu trong
|
||||
// depth_filter.yaml cua repo cu.
|
||||
//
|
||||
// Vi sao 0.15: sai so cua z_ref(0) chi den tu sai so pitch va sai so chieu
|
||||
// cao camera, ma ca hai deu da bi chan boi max_tz_dev = 0.08. Mot ramp that
|
||||
// 8% bat dau o 1.5 m cho z0 = -0.096 -- van lot.
|
||||
double max_level_offset = 0.15;
|
||||
|
||||
// Camera lech khoi chieu cao danh dinh => robot dang nghieng / da nhoai len
|
||||
// vat gi do. Luc do phep khop mat san se bam theo TANG DUOI va bao "khong co
|
||||
// vuc" -- nguy hiem hon la im lang.
|
||||
// ⚠️ PHAI dat tu `RobotModel::camera_height_above_floor()`, khong go tay.
|
||||
// No la camera_link.z CONG wheel_radius -- mot he qua, khong phai mot so
|
||||
// doc lap. Mac dinh 0.803 o day tung LECH voi 0.80 ma bo mo phong dung, va
|
||||
// khong co gi bao. Gio mac dinh khop, nhung van phai dat tu RobotModel vi
|
||||
// robot.yaml moi la nguon.
|
||||
double nominal_tz = 0.80;
|
||||
double max_tz_dev = 0.08;
|
||||
|
||||
// Ti le toi da tia trong cua so duoc phep tra ve diem CAO hon level_gate
|
||||
// truoc khi coi nhu "dang nhin vao vat can, khong nhin thay san".
|
||||
//
|
||||
// KHONG co trong ban ROS goc, va no bit mot lo hong THAT cua ban do.
|
||||
// Trong hanh lang hep hon 2 x min_dist, tuong nam GAN HON vung mu 1.10 m:
|
||||
// hau het tia dap vao tuong chu khong toi san. Mot so it diem tuong co
|
||||
// z < level_gate van duoc nhan vao phep khop, va mat san tham chieu bi keo
|
||||
// LEN theo chung. Sau do san THAT o xa hon bi do voi mat phang bi keo len
|
||||
// do -> roi duoi nguong -> BAO VUC GIA giua hanh lang phang.
|
||||
//
|
||||
// Do duoc trong mo phong (hanh lang 1.6 m, robot quay tai cho): z0 khop
|
||||
// thanh +0.24 m, MAD chi 0.046 nen lot ca cong MAD, roi 46 tia san that
|
||||
// roi duoi nguong. Hong kieu nay la hong KHONG AN TOAN -- no bao CO vuc
|
||||
// chu khong bao "khong biet".
|
||||
//
|
||||
// Vi sao dem diem CAO chu khong phai be rong dai mau: be rong la proxy yeu
|
||||
// (da do: dai mau van trai 50% cua so ma van bao gia). Con dem diem cao thi
|
||||
// KHONG BAO GIO che duoc vuc that: vuc lam diem THAP hoac MAT HAN, khong
|
||||
// bao gio lam diem cao. Cong nay chi co the bien "co vuc" thanh "khong
|
||||
// biet", khong bao gio bien thanh "khong co vuc".
|
||||
double max_obstructed_frac = 0.60;
|
||||
|
||||
bool fail_safe = true;
|
||||
double fail_safe_after = 1.0; // mu LIEN TUC bao lau thi bao nguy
|
||||
|
||||
double wheel_radius = 0.075;
|
||||
};
|
||||
|
||||
// Vi sao khung nay khong phan xet duoc. Gia tri duoc dua ra ngoai de web UI
|
||||
// hien duoc -- bao "khong biet" khac han bao "khong co vuc".
|
||||
enum class CliffBail : uint8_t {
|
||||
kNone = 0,
|
||||
kDisabled,
|
||||
kNoRollPitch,
|
||||
kAccelGated, // robot dang tang/giam toc
|
||||
kBadGeometry, // tz <= 0
|
||||
kTzDeviation, // robot khong bang phang
|
||||
kFewSamples, // khong du mau san de khop
|
||||
kSlopeClamped, // doc cham tran -> khop hong
|
||||
kResidualLarge, // MAD lon -> khung nhin khong phai mot mat phang
|
||||
kBadEncoding,
|
||||
kObstructed, // phan lon tia dap vao vat can, khong thay san
|
||||
kOffsetLarge, // mat phang khop duoc khong di qua cho robot dang dung
|
||||
};
|
||||
|
||||
const char* CliffBailName(CliffBail b);
|
||||
|
||||
struct CliffResult {
|
||||
bool detected = false;
|
||||
bool judged = false; // false = khong phan xet duoc (bail)
|
||||
CliffBail bail = CliffBail::kNone;
|
||||
double bail_held = 0.0; // da mu lien tuc bao lau (s)
|
||||
|
||||
// Mep vuc trong base_footprint. z giu AM co y (xem ghi chu trong .cc).
|
||||
PointCloudXYZ edge_cloud;
|
||||
|
||||
// Chan doan -- lam nen cho khoi debug throttle cua ban ROS.
|
||||
int64_t n_total = 0, n_up = 0, n_zneg = 0, n_range = 0, n_inwin = 0;
|
||||
int64_t n_hole = 0, n_drop = 0;
|
||||
int n_cliff = 0;
|
||||
double r_min = 0.0, r_max = 0.0, z_lowest = 0.0;
|
||||
double lvl_z0 = 0.0, lvl_slope = 0.0, lvl_slope_raw = 0.0, lvl_mad = 0.0;
|
||||
int64_t lvl_samples = 0; // so mau vao phep khop mat san
|
||||
int64_t lvl_high = 0; // tia trong cua so tra ve diem CAO hon level_gate
|
||||
int64_t lvl_window = 0; // tong tia trong cua so o luot do muc san
|
||||
double lvl_r_lo = 0.0; // ban kinh nho nhat / lon nhat trong so mau do
|
||||
double lvl_r_hi = 0.0;
|
||||
bool leveled = false;
|
||||
double tz = 0.0;
|
||||
};
|
||||
|
||||
struct CliffDetectStats {
|
||||
uint64_t frames = 0;
|
||||
uint64_t judged = 0;
|
||||
uint64_t detected = 0;
|
||||
uint64_t bailed = 0;
|
||||
uint64_t bail_by[12] = {0};
|
||||
};
|
||||
|
||||
class CliffDetect {
|
||||
public:
|
||||
explicit CliffDetect(CliffDetectConfig cfg);
|
||||
|
||||
// roll/pitch tu GravityAlign. accel_ok = bo loc co dang neo duoc vao trong
|
||||
// luc khong, hay chi dang tich phan gyro.
|
||||
void SetTilt(UnixTime stamp, double roll, double pitch, bool accel_ok);
|
||||
|
||||
// `cam_to_base` la phep bien doi TINH camera -> base_link (tu robot.yaml);
|
||||
// nghieng do duoc se duoc ap them, giong het GravityAlign.
|
||||
CliffResult Process(const Image& depth, const CameraInfo& info,
|
||||
const Transform& cam_to_base, UnixTime now);
|
||||
|
||||
void Reset();
|
||||
const CliffDetectStats& stats() const { return stats_; }
|
||||
|
||||
private:
|
||||
CliffResult Bail(CliffBail why, bool immediate, UnixTime now);
|
||||
|
||||
CliffDetectConfig cfg_;
|
||||
|
||||
bool have_rp_ = false;
|
||||
double roll_ = 0.0, pitch_ = 0.0;
|
||||
bool accel_ok_ = true;
|
||||
UnixTime last_rp_;
|
||||
|
||||
bool bailing_ = false;
|
||||
UnixTime bail_since_;
|
||||
|
||||
// Bo dem tai su dung giua cac khung: 30 Hz x 4800 o, cap phat moi khung la
|
||||
// lang phi va la nguon jitter.
|
||||
std::vector<uint8_t> cand_;
|
||||
std::vector<double> pos_x_, pos_y_;
|
||||
std::vector<std::pair<double, double>> rz_;
|
||||
|
||||
CliffDetectStats stats_;
|
||||
};
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_CLIFF_DETECT_H
|
||||
81
libs/vslam_perception/include/vslam/depth_filter.h
Normal file
81
libs/vslam_perception/include/vslam/depth_filter.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef VSLAM_DEPTH_FILTER_H
|
||||
#define VSLAM_DEPTH_FILTER_H
|
||||
|
||||
// Loc point cloud tu camera depth.
|
||||
//
|
||||
// Port tu perception_3d/src/depth_filter_nodelet.cpp. Chuoi:
|
||||
// PassThrough(z) -> VoxelGrid -> (tuy chon) xac nhan theo thoi gian
|
||||
//
|
||||
// KHONG dung PCL. Ba bo loc nay cong lai khoang 100 dong, va giu
|
||||
// vslam_perception khong phu thuoc PCL nghia la P5 build va test duoc trên
|
||||
// may chua co PCL -- cung ly do voi vslam_odometry.
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "vslam/unix_time.h"
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
struct DepthFilterConfig {
|
||||
double min_range = 0.22; // Min-Z cua D410
|
||||
double max_range = 4.0;
|
||||
double voxel_size = 0.03;
|
||||
double max_rate = 10.0; // gioi han tan so dau ra, Hz
|
||||
|
||||
// Xac nhan theo thoi gian: mot voxel phai duoc thay `min_hits` lan trong
|
||||
// `temporal_window` giay moi duoc xuat. Loc nhieu nhap nhay cua depth.
|
||||
bool enable_temporal = false;
|
||||
int min_hits = 3;
|
||||
double temporal_window = 0.5;
|
||||
};
|
||||
|
||||
struct DepthFilterStats {
|
||||
uint64_t frames_in = 0;
|
||||
uint64_t frames_out = 0;
|
||||
uint64_t frames_rate_limited = 0;
|
||||
uint64_t points_in = 0;
|
||||
uint64_t points_after_range = 0;
|
||||
uint64_t points_after_voxel = 0;
|
||||
uint64_t points_out = 0;
|
||||
};
|
||||
|
||||
class DepthFilter {
|
||||
public:
|
||||
explicit DepthFilter(DepthFilterConfig cfg);
|
||||
|
||||
// Tra false neu khung bi bo vi gioi han tan so. `out` khong duoc ghi.
|
||||
//
|
||||
// `stamp` dung STAMP CUA BAN TIN, khong phai dong ho tuong: gioi han tan so
|
||||
// theo dong ho tuong se bop nham khi phat lai ban ghi nhanh.
|
||||
bool Apply(const PointCloudXYZ& in, UnixTime stamp, PointCloudXYZ* out);
|
||||
|
||||
void Reset();
|
||||
const DepthFilterStats& stats() const { return stats_; }
|
||||
|
||||
private:
|
||||
struct VoxelHit {
|
||||
int hits = 0;
|
||||
UnixTime last_seen;
|
||||
PointXYZ centroid;
|
||||
int count = 0;
|
||||
};
|
||||
|
||||
DepthFilterConfig cfg_;
|
||||
UnixTime last_output_;
|
||||
bool have_output_ = false;
|
||||
std::unordered_map<int64_t, VoxelHit> voxels_;
|
||||
DepthFilterStats stats_;
|
||||
};
|
||||
|
||||
// Khoa voxel: goi ba chi so 21 bit vao mot int64.
|
||||
//
|
||||
// 21 bit moi truc -> dai +-1048575 voxel. Voi voxel 3 cm do la +-31 km, thua
|
||||
// xa moi ban do trong nha. Goi vao mot int64 cho phep dung unordered_map ma
|
||||
// khong phai bam mot tuple.
|
||||
int64_t VoxelKey(double x, double y, double z, double size);
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_DEPTH_FILTER_H
|
||||
41
libs/vslam_perception/include/vslam/depth_to_cloud.h
Normal file
41
libs/vslam_perception/include/vslam/depth_to_cloud.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef VSLAM_DEPTH_TO_CLOUD_H
|
||||
#define VSLAM_DEPTH_TO_CLOUD_H
|
||||
|
||||
// Anh depth -> point cloud. Thay depth_image_proc/point_cloud_xyz.
|
||||
//
|
||||
// Cong thuc da XAC MINH tu
|
||||
// /opt/ros/noetic/include/depth_image_proc/depth_conversions.h:52-100:
|
||||
//
|
||||
// constant_x = unit_scaling / fx (uint16 -> 0.001 m moi don vi)
|
||||
// constant_y = unit_scaling / fy
|
||||
// x = (u - cx) * depth * constant_x
|
||||
// y = (v - cy) * depth * constant_y
|
||||
// z = depth
|
||||
// depth khong hop le (0 voi uint16, NaN voi float) -> diem = NaN
|
||||
//
|
||||
// fx/cx lay TU CameraInfo DA BU BINNING. crop_decimate cap nhat binning chu
|
||||
// khong chia lai K, nen quen bu la moi diem lech theo he so decimate -- va
|
||||
// cloud van "trong nhu that", chi la sai ti le.
|
||||
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
// `out` duoc ghi de. Diem khong hop le duoc giu lai duoi dang NaN de cloud
|
||||
// van TO CHUC THEO ANH (width x height) -- buoc sau can dieu do.
|
||||
// Doc mot diem anh depth ra met. Tra NaN neu khong do duoc.
|
||||
// Cong khai vi CliffDetect phai doc CHINH cung mot cach -- no lam viec trong
|
||||
// khong gian anh chu khong qua cloud, va hai cach doc lech nhau (nhat la quy
|
||||
// uoc 0 = khong do duoc) se sinh vuc gia.
|
||||
double DepthAtMeters(const Image& img, uint32_t u, uint32_t v);
|
||||
|
||||
void DepthToCloud(const Image& depth, const CameraInfo& info, PointCloudXYZ* out);
|
||||
|
||||
// Ban KHONG to chuc: bo luon diem khong hop le. Nhanh hon va nho hon khi
|
||||
// buoc sau khong can cau truc anh.
|
||||
void DepthToCloudDense(const Image& depth, const CameraInfo& info,
|
||||
PointCloudXYZ* out);
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_DEPTH_TO_CLOUD_H
|
||||
128
libs/vslam_perception/include/vslam/gravity_align.h
Normal file
128
libs/vslam_perception/include/vslam/gravity_align.h
Normal file
@@ -0,0 +1,128 @@
|
||||
#ifndef VSLAM_GRAVITY_ALIGN_H
|
||||
#define VSLAM_GRAVITY_ALIGN_H
|
||||
|
||||
// Uoc luong roll/pitch tu IMU va xoay point cloud ve mat phang ngang.
|
||||
//
|
||||
// Port tu perception_3d/src/gravity_align_nodelet.cpp.
|
||||
//
|
||||
// ================== VAN DE COT LOI ==================
|
||||
// Gia toc ke KHONG phan biet duoc nghieng voi tang toc. No do TONG cua:
|
||||
// 1. trong luc chieu xuong ba truc cua than (phu thuoc roll/pitch)
|
||||
// 2. gia toc rieng cua robot (tinh tien + huong tam)
|
||||
//
|
||||
// Mot robot tang toc 0.3 m/s^2 tren san phang cho ra doc cung gia toc ke nhu
|
||||
// mot robot dung yen nghieng 1.75 do. Khong co cach nao tach hai truong hop
|
||||
// bang rieng gia toc ke.
|
||||
//
|
||||
// Cach lam: TRU gia toc rieng truoc khi coi phan con lai la trong luc.
|
||||
// axc = ax - a_lin (gia toc tinh tien, tu dao ham van toc odom)
|
||||
// ayc = ay - v * omega (gia toc huong tam khi quay)
|
||||
// Roi chi hieu chinh khi |a| con lai gan g -- tuc la dang gan trang thai tinh.
|
||||
//
|
||||
// ================== VI SAO PHAI LOC THONG THAP TRUOC ==================
|
||||
// Gia toc ke tho dao dong manh do rung tiep xuc banh-san (san gach + banh
|
||||
// cung). Ap cong |a| ~ g len mau tho se tu choi gan nhu moi mau, va bo loc
|
||||
// chi con lai phan tich phan gyro -- tuc la troi tu do.
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "vslam/unix_time.h"
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
// base_footprint <- base_link voi nghieng da do. Ca GravityAlign lan
|
||||
// CliffDetect deu phai dung CHINH ham nay -- hai ban sao hinh hoc lech nhau
|
||||
// la lop loi da co trong repo cu (URDF vs base_tilt_tf.py).
|
||||
Transform TiltLift(double roll, double pitch, double wheel_radius);
|
||||
|
||||
struct GravityAlignConfig {
|
||||
// He so bo loc bu: 1 = chi tin gyro, 0 = chi tin accel.
|
||||
// 0.98 nghia la gyro cho ngan han, accel keo ve dai han.
|
||||
double alpha = 0.98;
|
||||
|
||||
// LPF cho gia toc ke truoc khi dung. Nho = loc manh.
|
||||
double accel_lpf_alpha = 0.05;
|
||||
|
||||
// |a| duoc coi la "gan tinh" khi lech khoi g duoi nguong nay (m/s^2).
|
||||
double accel_gate = 1.0;
|
||||
|
||||
double imu_timeout = 0.5;
|
||||
double odom_timeout = 0.2;
|
||||
|
||||
// Tru gia toc rieng cua robot truoc khi hieu chinh. TAT cai nay la bo loc
|
||||
// se hieu moi lan tang toc thanh mot cu nghieng.
|
||||
bool use_odom_accel = true;
|
||||
double odom_accel_alpha = 0.3; // LPF cho dao ham van toc
|
||||
|
||||
// Cat dai chieu cao sau khi xoay ve base_footprint.
|
||||
double min_height = 0.06;
|
||||
double max_height = 1.20;
|
||||
|
||||
// Chieu cao banh xe: base_footprint o mat dat, base_link o tam truc.
|
||||
double wheel_radius = 0.075;
|
||||
};
|
||||
|
||||
struct GravityAlignStats {
|
||||
uint64_t imu_samples = 0;
|
||||
uint64_t accel_accepted = 0; // so lan cong |a| ~ g mo
|
||||
uint64_t accel_rejected = 0;
|
||||
uint64_t clouds_in = 0;
|
||||
uint64_t clouds_out = 0;
|
||||
uint64_t points_in = 0;
|
||||
uint64_t points_out = 0;
|
||||
double last_accel_norm = 0.0;
|
||||
};
|
||||
|
||||
class GravityAlign {
|
||||
public:
|
||||
explicit GravityAlign(GravityAlignConfig cfg);
|
||||
|
||||
// Goi moi mau IMU (200 Hz).
|
||||
void FeedImu(const Imu& imu);
|
||||
|
||||
// Goi moi ban tin odometry. Dung de tinh gia toc rieng cua robot.
|
||||
void FeedOdom(UnixTime stamp, double vx, double vyaw);
|
||||
|
||||
// Xoay cloud tu frame quang hoc cua camera ve base_footprint, da bu nghieng.
|
||||
//
|
||||
// `cam_to_base` la phep bien doi TINH tu camera toi base_link (tu robot.yaml).
|
||||
// Nghieng do bo loc uoc luong duoc ap THEM vao.
|
||||
//
|
||||
// Tra false neu chua co uoc luong nghieng nao.
|
||||
bool Align(const PointCloudXYZ& in, const Transform& cam_to_base,
|
||||
UnixTime stamp, PointCloudXYZ* out) const;
|
||||
|
||||
double roll() const { return roll_; }
|
||||
double pitch() const { return pitch_; }
|
||||
bool valid() const { return initialized_; }
|
||||
// true neu mau accel gan nhat duoc chap nhan (dang gan trang thai tinh).
|
||||
bool accel_ok() const { return accel_ok_; }
|
||||
|
||||
void Reset();
|
||||
const GravityAlignStats& stats() const { return stats_; }
|
||||
|
||||
private:
|
||||
GravityAlignConfig cfg_;
|
||||
|
||||
bool initialized_ = false;
|
||||
double roll_ = 0.0, pitch_ = 0.0;
|
||||
UnixTime last_imu_;
|
||||
|
||||
bool lpf_init_ = false;
|
||||
double ax_f_ = 0.0, ay_f_ = 0.0, az_f_ = 0.0;
|
||||
bool accel_ok_ = false;
|
||||
|
||||
bool have_odom_ = false;
|
||||
UnixTime last_odom_;
|
||||
double v_prev_ = 0.0, w_ = 0.0, a_lin_ = 0.0;
|
||||
|
||||
// mutable: Align() la const ve mat logic (khong doi uoc luong nghieng)
|
||||
// nhung van phai dem. const_cast o day se la mot loi cho, khong phai giai
|
||||
// phap.
|
||||
mutable GravityAlignStats stats_;
|
||||
};
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_GRAVITY_ALIGN_H
|
||||
89
libs/vslam_perception/include/vslam/perception_pipeline.h
Normal file
89
libs/vslam_perception/include/vslam/perception_pipeline.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifndef VSLAM_PERCEPTION_PIPELINE_H
|
||||
#define VSLAM_PERCEPTION_PIPELINE_H
|
||||
|
||||
// Chuoi depth_to_cloud -> depth_filter -> gravity_align -> cliff_detect,
|
||||
// chay INLINE trong mot loi goi tren chinh luong camera.
|
||||
//
|
||||
// Thay cho ba nodelet chung mot manager trong ban ROS. Tot hon: khong
|
||||
// intrusive_ptr, khong dispatch theo topic, khong nodelet loader, va thu tu
|
||||
// cac buoc la thu tu dong lenh -- khong con phu thuoc vao thu tu remap trong
|
||||
// launch file.
|
||||
//
|
||||
// Doi tuong nay KHONG tu khoa. No thuoc ve dung mot luong (camera_rx). Ket
|
||||
// qua di ra ngoai bang shared_ptr<const> qua Channel.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "vslam/cliff_detect.h"
|
||||
#include "vslam/clock.h"
|
||||
#include "vslam/depth_filter.h"
|
||||
#include "vslam/gravity_align.h"
|
||||
#include "vslam/perception_types.h"
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
struct PerceptionConfig {
|
||||
DepthFilterConfig filter;
|
||||
GravityAlignConfig gravity;
|
||||
CliffDetectConfig cliff;
|
||||
|
||||
// Bo qua buoc dung cloud va loc -- chi chay cliff_detect. Cliff chay tren
|
||||
// anh depth nen khong can cloud; tren Jetson day la cach ha tai khi chi can
|
||||
// an toan chu khong can cloud cho SLAM.
|
||||
bool enable_cloud = true;
|
||||
bool enable_cliff = true;
|
||||
};
|
||||
|
||||
struct PerceptionStats {
|
||||
uint64_t frames_in = 0;
|
||||
uint64_t frames_out = 0;
|
||||
double last_ms = 0.0;
|
||||
double max_ms = 0.0;
|
||||
double avg_ms = 0.0;
|
||||
};
|
||||
|
||||
class PerceptionPipeline {
|
||||
public:
|
||||
// `clock` chi dung cho do thoi gian xu ly va cho timeout cua cliff_detect.
|
||||
// Moi dau thoi gian tren du lieu lay tu stamp cua ban tin -- day la dieu
|
||||
// kien de phat lai ban ghi cho ket qua y het chay that.
|
||||
PerceptionPipeline(PerceptionConfig cfg, const Clock& clock);
|
||||
|
||||
// Dat phep bien doi TINH camera_depth_optical_frame -> base_link, doc tu
|
||||
// robot.yaml. Goi mot lan luc khoi tao.
|
||||
void SetCameraExtrinsic(const Transform& cam_to_base);
|
||||
|
||||
// IMU 200 Hz. Goi truc tiep tu luong mcu_rx.
|
||||
void FeedImu(const Imu& imu);
|
||||
// Odometry 50 Hz -- can de TRU gia toc rieng cua robot khoi gia toc ke.
|
||||
void FeedOdom(UnixTime stamp, double vx, double vyaw);
|
||||
|
||||
// Mot khung depth. Tra ve ket qua day du; nguoi goi quyet dinh publish gi.
|
||||
PerceptionOutput Process(const Image& depth, const CameraInfo& info);
|
||||
|
||||
const GravityAlign& gravity() const { return gravity_; }
|
||||
const CliffDetect& cliff() const { return cliff_; }
|
||||
const PerceptionStats& stats() const { return stats_; }
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
PerceptionConfig cfg_;
|
||||
const Clock& clock_;
|
||||
Transform cam_to_base_;
|
||||
|
||||
GravityAlign gravity_;
|
||||
DepthFilter filter_;
|
||||
CliffDetect cliff_;
|
||||
|
||||
// Tai su dung giua cac khung. 30 Hz x ~300k diem: cap phat moi khung la
|
||||
// nguon jitter lon hon ban than phep tinh.
|
||||
PointCloudXYZ buf_raw_, buf_filt_, buf_align_;
|
||||
|
||||
PerceptionStats stats_;
|
||||
};
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_PERCEPTION_PIPELINE_H
|
||||
35
libs/vslam_perception/include/vslam/perception_types.h
Normal file
35
libs/vslam_perception/include/vslam/perception_types.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef VSLAM_PERCEPTION_TYPES_H
|
||||
#define VSLAM_PERCEPTION_TYPES_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/vslam_common.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
// Ket qua cua mot vong perception. Moi truong deu co the null/rong neu buoc
|
||||
// tuong ung khong chay hoac khong co du lieu.
|
||||
struct PerceptionOutput {
|
||||
UnixTime stamp;
|
||||
|
||||
PointCloudXYZPtr cloud_raw; // sau depth_to_cloud
|
||||
PointCloudXYZPtr cloud_filtered; // sau depth_filter
|
||||
PointCloudXYZPtr cloud_aligned; // sau gravity_align, trong base_footprint
|
||||
PointCloudXYZPtr cloud_cliff; // diem danh dau mep vuc
|
||||
|
||||
// gravity_align
|
||||
double roll = 0.0;
|
||||
double pitch = 0.0;
|
||||
bool tilt_valid = false;
|
||||
bool accel_ok = false; // accel co dang gan trang thai tinh khong
|
||||
|
||||
// cliff_detect
|
||||
bool cliff_detected = false;
|
||||
std::string cliff_detail;
|
||||
};
|
||||
|
||||
} // namespace vslam
|
||||
|
||||
#endif // VSLAM_PERCEPTION_TYPES_H
|
||||
Reference in New Issue
Block a user