upload
This commit is contained in:
89
libs/vslam_perception/src/perception_pipeline.cc
Normal file
89
libs/vslam_perception/src/perception_pipeline.cc
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "vslam/perception_pipeline.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include "vslam/depth_to_cloud.h"
|
||||
#include "vslam/geometry.h"
|
||||
#include "vslam/log.h"
|
||||
|
||||
namespace vslam {
|
||||
|
||||
PerceptionPipeline::PerceptionPipeline(PerceptionConfig cfg, const Clock& clock)
|
||||
: cfg_(std::move(cfg)),
|
||||
clock_(clock),
|
||||
cam_to_base_(TransformIdentity()),
|
||||
gravity_(cfg_.gravity),
|
||||
filter_(cfg_.filter),
|
||||
cliff_(cfg_.cliff) {}
|
||||
|
||||
void PerceptionPipeline::SetCameraExtrinsic(const Transform& cam_to_base) {
|
||||
cam_to_base_ = cam_to_base;
|
||||
}
|
||||
|
||||
void PerceptionPipeline::FeedImu(const Imu& imu) { gravity_.FeedImu(imu); }
|
||||
|
||||
void PerceptionPipeline::FeedOdom(UnixTime stamp, double vx, double vyaw) {
|
||||
gravity_.FeedOdom(stamp, vx, vyaw);
|
||||
}
|
||||
|
||||
void PerceptionPipeline::Reset() {
|
||||
gravity_.Reset();
|
||||
filter_.Reset();
|
||||
cliff_.Reset();
|
||||
stats_ = PerceptionStats{};
|
||||
}
|
||||
|
||||
PerceptionOutput PerceptionPipeline::Process(const Image& depth, const CameraInfo& info) {
|
||||
// steady_clock cho do thoi gian -- KHONG dung UnixTime. Mot buoc NTP giua
|
||||
// hai moc se cho ra "khung xu ly het -3 giay".
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
stats_.frames_in++;
|
||||
|
||||
PerceptionOutput out;
|
||||
out.stamp = depth.header.stamp;
|
||||
out.roll = gravity_.roll();
|
||||
out.pitch = gravity_.pitch();
|
||||
out.tilt_valid = gravity_.valid();
|
||||
out.accel_ok = gravity_.accel_ok();
|
||||
|
||||
// --- Duong cliff: chay tren ANH DEPTH, khong qua cloud ---
|
||||
// Dat TRUOC duong cloud vi no la duong an toan. Neu duong cloud nem hay
|
||||
// cham, cliff van da chay xong.
|
||||
if (cfg_.enable_cliff) {
|
||||
cliff_.SetTilt(depth.header.stamp, gravity_.roll(), gravity_.pitch(),
|
||||
gravity_.accel_ok());
|
||||
CliffResult cr = cliff_.Process(depth, info, cam_to_base_, clock_.Now());
|
||||
out.cliff_detected = cr.detected;
|
||||
out.cliff_detail = cr.judged ? "judged" : CliffBailName(cr.bail);
|
||||
if (!cr.edge_cloud.points.empty()) {
|
||||
out.cloud_cliff = std::make_shared<const PointCloudXYZ>(std::move(cr.edge_cloud));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Duong cloud: cho SLAM va cho hien thi ---
|
||||
if (cfg_.enable_cloud) {
|
||||
DepthToCloudDense(depth, info, &buf_raw_);
|
||||
out.cloud_raw = std::make_shared<const PointCloudXYZ>(buf_raw_);
|
||||
|
||||
if (filter_.Apply(buf_raw_, depth.header.stamp, &buf_filt_)) {
|
||||
out.cloud_filtered = std::make_shared<const PointCloudXYZ>(buf_filt_);
|
||||
|
||||
if (gravity_.Align(buf_filt_, cam_to_base_, depth.header.stamp, &buf_align_)) {
|
||||
out.cloud_aligned = std::make_shared<const PointCloudXYZ>(buf_align_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const double ms = std::chrono::duration<double, std::milli>(
|
||||
std::chrono::steady_clock::now() - t0)
|
||||
.count();
|
||||
stats_.frames_out++;
|
||||
stats_.last_ms = ms;
|
||||
stats_.max_ms = std::max(stats_.max_ms, ms);
|
||||
// Trung binh truot: du de bao cao, khong giu lich su.
|
||||
stats_.avg_ms += (ms - stats_.avg_ms) * 0.05;
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace vslam
|
||||
Reference in New Issue
Block a user