Files
vslam_cpp/libs/vslam_perception/include/vslam/perception_pipeline.h
trung09122002 48bd5377dc upload
2026-09-18 18:14:42 +07:00

90 lines
2.8 KiB
C++

#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