Log chi in n_cliff gop. Diem khong co so do do sau bi tinh la ung vien vuc -- dung voi cau thang toi, nhung san phang KHONG VAN nhin o goc luot cung cho ra y het nhu vay (pipeline.yaml da ghi ro: cang luot thi stereo cang khong bat duoc gi tren san phang khong van). Hai thu do can hai cach sua khac han nhau, ma gop lam mot con so thi khong phan biet duoc tu log. In them n_hole, n_drop, n_inwin va dai r_min..r_max de biet camera thuc su thay san o dau.
148 lines
5.8 KiB
C++
148 lines
5.8 KiB
C++
#include "vslam/perception_pipeline.h"
|
|
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
|
|
#include "vslam/depth_to_cloud.h"
|
|
#include "vslam/geometry.h"
|
|
#include <cmath>
|
|
|
|
#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);
|
|
|
|
// Bao LY DO ra log, khong chi ra web.
|
|
//
|
|
// cliff_detected = true co HAI nghia rat khac nhau:
|
|
// judged -> that su thay vuc
|
|
// <bail> -> detector khong phan xet duoc va fail_safe bat len
|
|
// Lop safety in cung mot cau cho ca hai, nen khong phan biet duoc tu log.
|
|
// Da mat nhieu thoi gian vi dieu do tren robot: "VUC phia truoc" lien tuc
|
|
// trong khi truoc mat trong khong.
|
|
if (cr.detected) {
|
|
VSLAM_WARN_THROTTLE(5.0,
|
|
"cliff: bao VUC, ly do=" << out.cliff_detail
|
|
<< (cr.judged ? " (thay vuc THAT)"
|
|
: " (KHONG phan xet duoc -> fail_safe)")
|
|
<< " -- mu lien tuc " << cr.bail_held << " s, n_cliff=" << cr.n_cliff
|
|
// Tach LO khoi HUT. Diem khong co so do do sau bi tinh la ung vien
|
|
// vuc (cliff_detect.cc: "le ra phai thay san o day ma khong co so do
|
|
// nao") -- dung voi cau thang toi, nhung san phang KHONG VAN nhin o
|
|
// goc luot cung cho ra y het nhu vay, va pipeline.yaml da ghi ro dieu
|
|
// do. Gop hai thu vao mot con so thi khong the phan biet tu log, ma
|
|
// chung can hai cach sua khac han nhau.
|
|
<< " (lo=" << cr.n_hole << " hut=" << cr.n_drop
|
|
<< ", trong cua so=" << cr.n_inwin
|
|
<< ", san thay o " << cr.r_min << ".." << cr.r_max << " m)");
|
|
|
|
// Mat phang san khop duoc, quy ve he base. Hai so nay CHINH LA sai so
|
|
// ngoai lai cua camera, nen in kem ca hieu chinh suy ra tu chung:
|
|
//
|
|
// lvl_z0 = do cao cua mat phang tai chan robot. Dung ra ~0. Lech
|
|
// bao nhieu thi camera_link.z trong robot.yaml sai bay
|
|
// nhieu (nguoc dau).
|
|
// lvl_slope = do doc cua mat phang trong he base. Dung ra ~0. Doc
|
|
// bao nhieu thi goc chuc camera sai bay nhieu.
|
|
//
|
|
// In o day thay vi bat nguoi doc mo web: `offset_large` mot minh chi
|
|
// noi "sai", khong noi sai bao nhieu va sai o dau.
|
|
// In cho CA `judged`, khong chi cho bail.
|
|
//
|
|
// Khi detector bao "thay vuc THAT" thi cau hoi tiep theo luon la "mat
|
|
// phang quy chieu no dung co dung khong". Neu z0 hay do doc lech thi
|
|
// "vuc" do chi la san that bi doc lech xuong -- va khong co cach nao
|
|
// phan biet neu ba so nay khong ra log.
|
|
if (cr.judged ||
|
|
out.cliff_detail == std::string("offset_large") ||
|
|
out.cliff_detail == std::string("residual_large") ||
|
|
out.cliff_detail == std::string("slope_clamped")) {
|
|
const double pitch_err_deg = std::atan(cr.lvl_slope) * 180.0 / M_PI;
|
|
VSLAM_WARN_THROTTLE(5.0,
|
|
"cliff: mat phang khop duoc: z0=" << cr.lvl_z0 << " m (dung ra ~0), "
|
|
<< "doc=" << cr.lvl_slope << " (" << pitch_err_deg << " do), mad="
|
|
<< cr.lvl_mad << " m.\n"
|
|
" -> camera_link.z trong robot.yaml lech " << -cr.lvl_z0 << " m\n"
|
|
" -> goc chuc camera lech " << pitch_err_deg << " do"
|
|
" (rpy pitch hien tai co the sai)");
|
|
}
|
|
}
|
|
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
|