slam,odometry,perception: di tren doc (G4, slam.yaml slope.enabled, mac dinh tat) -- z robot = tich -ds*sin(pitch IMU) kep phang < 1.5 do va neo vao ban do (HeightEstimator), odometry ngang, scan cho SLAM bu nghieng + bo tia cham san/doc theo ban do do cao tu depth (ScanLeveler, ElevationMap), z/roll/pitch luu vao node + do thi z 1-D + mat san theo node (height_map), voxel dat o z that va vat can tinh tu san cuc bo, xoa tuong gia LiDAR tren doc noi camera da thay mat san, web z uoc luong, --sim-imu-hz

This commit is contained in:
trung09122002
2026-10-04 00:03:02 +07:00
parent 6735b53423
commit f064dcf3ec
32 changed files with 1799 additions and 10 deletions

View File

@@ -624,6 +624,45 @@ StatusResponse LoadAppConfig(const std::string& dir, AppConfig* out) {
"slam.yaml voxel: obstacle_z_min phai nho hon obstacle_z_max");
}
}
// Khoi `slope:` -- di tren doc. Vang mat = tat.
if (!root["slope"].IsNull()) {
const ConfigNode v = root["slope"];
const StatusResponse r = Reject(
v, "slam.yaml slope",
{"enabled", "clamp_deg", "sigma_rel", "sigma_flat", "sigma_anchor", "anchor_radius_m",
"horizontal_odom", "level_scan", "floor_margin_m", "below_ground_m",
"elevation_cell_m", "elevation_radius_m", "elevation_max_depth_m", "depth_stride"});
if (!r.ok()) return r;
SlopeConfig& c = out->slope;
c.enabled = v.get<bool>("enabled", c.enabled);
c.clamp_deg = v.get<double>("clamp_deg", c.clamp_deg);
c.sigma_rel = v.get<double>("sigma_rel", c.sigma_rel);
c.sigma_flat = v.get<double>("sigma_flat", c.sigma_flat);
c.sigma_anchor = v.get<double>("sigma_anchor", c.sigma_anchor);
c.anchor_radius_m = v.get<double>("anchor_radius_m", c.anchor_radius_m);
c.horizontal_odom = v.get<bool>("horizontal_odom", c.horizontal_odom);
c.level_scan = v.get<bool>("level_scan", c.level_scan);
c.floor_margin_m = v.get<double>("floor_margin_m", c.floor_margin_m);
c.below_ground_m = v.get<double>("below_ground_m", c.below_ground_m);
c.elevation_cell_m = v.get<double>("elevation_cell_m", c.elevation_cell_m);
c.elevation_radius_m = v.get<double>("elevation_radius_m", c.elevation_radius_m);
c.elevation_max_depth_m = v.get<double>("elevation_max_depth_m", c.elevation_max_depth_m);
c.depth_stride = v.get<int>("depth_stride", c.depth_stride);
if (c.clamp_deg < 0.0 || c.clamp_deg > 10.0) {
return StatusResponse::Error(StatusCode::kInvalidArgument,
"slam.yaml slope.clamp_deg phai trong [0, 10]");
}
if (c.sigma_rel < 0.0 || c.sigma_flat < 0.0 || c.sigma_anchor <= 0.0) {
return StatusResponse::Error(StatusCode::kInvalidArgument,
"slam.yaml slope: sigma_rel/sigma_flat >= 0, sigma_anchor > 0");
}
if (c.elevation_cell_m <= 0.0 || c.elevation_radius_m <= 0.0 || c.depth_stride < 1) {
return StatusResponse::Error(
StatusCode::kInvalidArgument,
"slam.yaml slope: elevation_cell_m, elevation_radius_m > 0, depth_stride >= 1");
}
}
}
#endif

View File

@@ -66,6 +66,30 @@ struct VoxelConfig {
size_t min_node_hits = 1;
};
// Di tren doc (G4). Doc tu khoi `slope:` trong slam.yaml. enabled = false thi
// moi duong cu giu nguyen tung byte -- xem slam.yaml.
struct SlopeConfig {
bool enabled = false;
// z = tich -ds*sin(pitch IMU); |pitch| < clamp -> coi la phang (dz = 0).
double clamp_deg = 1.5;
double sigma_rel = 0.05;
double sigma_flat = 0.005;
double sigma_anchor = 0.03;
// Neo z vao node ban do trong ban kinh nay (che do localization).
double anchor_radius_m = 0.6;
// Quang duong banh x cos(pitch) truoc khi vao EKF (doc 15 do: -3.4%).
bool horizontal_odom = true;
// Bu nghieng scan + bo tia cham san cho SLAM / dinh vi lai (KHONG cho an toan).
bool level_scan = true;
double floor_margin_m = 0.08;
double below_ground_m = 0.05;
// Ban do do cao san cuc bo tu depth camera.
double elevation_cell_m = 0.10;
double elevation_radius_m = 8.0;
double elevation_max_depth_m = 4.0;
int depth_stride = 4;
};
struct ThreadConfig {
int safety_priority = 50;
int driver_priority = 45;
@@ -127,6 +151,7 @@ struct AppConfig {
ThreadConfig threads;
SlamRuntimeConfig slam_runtime;
VoxelConfig voxel;
SlopeConfig slope;
RecordConfig record;
std::string log_level = "info";

View File

@@ -59,6 +59,8 @@ void Usage(const char* argv0) {
" --no-gamepad tat tay cam du system.yaml co bat\n"
" --sim-gl ve camera mo phong bang GPU: depth + anh IR co\n"
" texture (can --world, build VSLAM_SIM_WITH_GL=ON)\n"
" --sim-imu-hz N IMU mo phong phat N Hz (mac dinh moi buoc vat ly,\n"
" 200 Hz). 100 = WT61PC sau khi doi 115200 baud.\n"
" --sim-glass-at X dat buc KINH ngang hanh lang o x = X m.\n"
" LiDAR/depth KHONG thay; chi sieu am + bumper.\n"
" --max-speed V ghi de tran toc do (m/s). CHI CHO MO PHONG --\n"
@@ -166,6 +168,7 @@ int main(int argc, char** argv) {
else if (a == "--no-gamepad") opts.gamepad_override = -1;
else if (a == "--sim-glass-at") opts.sim_glass_at = std::atof(next().c_str());
else if (a == "--sim-gl") opts.sim_gl = true;
else if (a == "--sim-imu-hz") opts.sim_imu_hz = std::atof(next().c_str());
else if (a == "--max-speed") opts.max_speed_override = std::atof(next().c_str());
else if (a == "--slam") opts.force_slam = true;
else if (a == "--slam-db") { opts.slam_db = next(); opts.have_slam_db = true; }

View File

@@ -81,6 +81,7 @@ StatusResponse Runtime::OpenSource() {
sc.lidar_rate_hz = cfg_->sensors.lidar_hz;
sc.camera_rate_hz = cfg_->sensors.camera_hz;
sc.imu_rate_hz = cfg_->sensors.imu_hz;
sc.imu_output_hz = opts_.sim_imu_hz;
sc.enable_depth_camera = cfg_->sensors.camera_enable;
source_->sim.reset(new SimSource(sc));
@@ -629,6 +630,39 @@ StatusResponse Runtime::Start() {
}
#endif
// ---- Di tren doc (slam.yaml `slope:`) ----
// Tat thi khong tao gi: moi duong ben duoi kiem `slope_on_` truoc.
slope_on_ = cfg_->slope.enabled;
if (slope_on_) {
const SlopeConfig& sp = cfg_->slope;
HeightEstimatorConfig hc;
hc.clamp_rad = sp.clamp_deg * M_PI / 180.0;
hc.sigma_rel = sp.sigma_rel;
hc.sigma_flat = sp.sigma_flat;
hc.sigma_anchor = sp.sigma_anchor;
height_.reset(new HeightEstimator(hc));
ElevationMapConfig ec;
ec.cell_m = sp.elevation_cell_m;
ec.radius_m = sp.elevation_radius_m;
elev_.reset(new ElevationMap(ec));
level_cfg_.floor_margin = sp.floor_margin_m;
level_cfg_.below_ground = sp.below_ground_m;
if (!cfg_->robot.StaticTransform(kBaseLinkFrame, kLaserFrame, &laser_to_base_static_)) {
return StatusResponse::Error(StatusCode::kInvalidArgument,
"slope: robot.yaml khong co duong laser -> base_link");
}
have_cam_to_base_ = cfg_->robot.StaticTransform(kBaseLinkFrame, kCameraDepthOpticalFrame,
&cam_to_base_static_);
#ifdef VSLAM_HAVE_SLAM
if (slam_) slam_->SetUseHeights(true);
#endif
VSLAM_INFO("slope: BAT -- z = tich -ds*sin(pitch IMU), kep phang < " << sp.clamp_deg
<< " do, neo vao node trong " << sp.anchor_radius_m << " m; odometry ngang "
<< (sp.horizontal_odom ? "BAT" : "tat") << "; bu nghieng scan cho SLAM "
<< (sp.level_scan ? "BAT" : "tat") << " (an toan van dung scan tho). "
<< "Can IMU >= 100 Hz -- 10 Hz cho sai ~19 cm moi doc 1.5 m (sim G3).");
}
{
const StatusResponse st = Wire();
if (!st.ok()) return st;
@@ -1080,12 +1114,15 @@ void Runtime::SlamLoop() {
LaserScanPtr scan;
{
std::lock_guard<std::mutex> lk(scan_mu_);
scan = latest_scan_; // chi copy shared_ptr
// Ban cho SLAM: bu nghieng khi di tren doc, con lai CHINH latest_scan_.
scan = latest_slam_scan_; // chi copy shared_ptr
}
Pose2D odom;
bool have_odom = false;
double z_now = 0.0;
{
std::lock_guard<std::mutex> lk(odom_mu_);
if (slope_on_) z_now = height_->z();
// ⚠️ Dua cho SLAM pose cua EKF, KHONG phai cua wheel_odom.
//
// `map_correction` ma RTAB-Map tra ve la phep bien doi
@@ -1167,10 +1204,53 @@ void Runtime::SlamLoop() {
in.depth_info = depth_info.get();
in.infra1 = infra1.get();
in.camera_to_base = depth ? &cam_now : nullptr;
if (slope_on_) {
in.has_height = true;
in.z = z_now;
in.roll = tilt_roll_.load(std::memory_order_relaxed);
in.pitch = tilt_pitch_.load(std::memory_order_relaxed);
}
// --- KHONG MOT MUTEX NAO duoc giu qua dong nay ---
const SlamOutput out = slam_->Process(in);
// --- Di tren doc: z ban do + neo z robot ---
// Do thi z giai lai khi do thi doi (theo nhip, toi da 1 lan/giay -- getGraph
// va giai Cholesky vai ms cho ca nghin node). Neo: z robot keo ve mat san
// cua node gan nhat. O mapping node gan nhat thuong la chinh node vua tao
// (neo khong doi gi) -- co tac dung sau mot lan dong vong lam z do thi doi.
if (slope_on_) {
const auto now_h = std::chrono::steady_clock::now();
if (out.map_version != heights_version_ &&
std::chrono::duration<double>(now_h - heights_at_).count() >= 1.0) {
ZGraphConfig zc;
zc.clamp_rad = cfg_->slope.clamp_deg * M_PI / 180.0;
zc.sigma_rel = cfg_->slope.sigma_rel;
size_t nz = 0;
if (slam_->UpdateHeights(zc, &nz).ok()) {
heights_version_ = out.map_version;
heights_at_ = now_h;
VSLAM_INFO_THROTTLE(30.0, "slope: do thi z " << nz << " node");
}
}
double z_ref = 0.0;
if (out.localized &&
slam_->HeightAt(out.pose_map.x, out.pose_map.y, cfg_->slope.anchor_radius_m, &z_ref)) {
std::lock_guard<std::mutex> lk(odom_mu_);
if (!height_anchored_) {
// Lan dau: robot co the dung o tang tren (z 1.5 m) trong khi uoc
// luong bat dau tu 0 -- cong cua Anchor() se tu choi mai.
height_->Reset(z_ref, cfg_->slope.sigma_anchor);
height_anchored_ = true;
VSLAM_INFO("slope: z robot = " << z_ref << " m theo ban do tai ("
<< out.pose_map.x << ", " << out.pose_map.y << ")");
} else if (!height_->Anchor(z_ref)) {
VSLAM_WARN_THROTTLE(10.0, "slope: bo neo z -- ban do " << z_ref << " m, uoc luong "
<< height_->z() << " m (node sai tang / sai cho?)");
}
}
}
bool need_map = false;
{
std::lock_guard<std::mutex> lk(slam_mu_);
@@ -1325,8 +1405,20 @@ void Runtime::SlamLoop() {
// Grid/* cua RTAB-Map keo pose lech (do 2026-09-24: TB 0.020 ->
// 0.052 m). Phai lam TRUOC khi `vg` bi move ben duoi.
if (st.ok()) {
// Di tren doc: do cao tinh tu SAN tai cho (mat doc khong la tuong).
const FloorModel* floor =
slope_on_ && !slam_->floor_model().empty() ? &slam_->floor_model() : nullptr;
if (floor != nullptr) {
// Tren doc lop LiDAR nhuong cho camera: tuong gia (LiDAR thay mat
// doc tu xa) xoa di noi camera da thay mat san. TRUOC lop vat
// can camera, de vat can that tren doc duoc danh lai.
const size_t nc = ClearLidarOnSeenRamps(
&grid, slam_->floor_cells(), cfg_->voxel.emit_size_m, *floor,
cfg_->slope.clamp_deg * M_PI / 180.0, 1.0);
VSLAM_INFO_THROTTLE(30.0, "slope: xoa " << nc << " o LiDAR tren doc (camera thay mat san)");
}
const size_t n = MarkVoxelObstacles(vg, cfg_->voxel.obstacle_z_min,
cfg_->voxel.obstacle_z_max, &grid);
cfg_->voxel.obstacle_z_max, &grid, floor);
VSLAM_INFO_THROTTLE(30.0, "slam: " << n << " o vat can tu camera ("
<< cfg_->voxel.obstacle_z_min << "-"
<< cfg_->voxel.obstacle_z_max
@@ -1932,6 +2024,25 @@ void Runtime::RelocFinish(const Pose2D& map_from_odom, const Pose2D& odom,
return;
}
reloc_active_ = false;
if (slope_on_) {
// z robot theo ban do tai pose vua chot. Do thi z chua giai (RTAB-Map chua
// nhan khung nao trong luc dinh vi) thi giai ngay.
if (slam_->floor_model().empty()) {
ZGraphConfig zc;
zc.clamp_rad = cfg_->slope.clamp_deg * M_PI / 180.0;
zc.sigma_rel = cfg_->slope.sigma_rel;
slam_->UpdateHeights(zc);
}
double z_ref = 0.0;
if (slam_->HeightAt(pose.x, pose.y, 2.0, &z_ref)) {
std::lock_guard<std::mutex> lk(odom_mu_);
height_->Reset(z_ref, cfg_->slope.sigma_anchor);
height_anchored_ = true;
VSLAM_INFO("slope: z robot = " << z_ref << " m theo ban do sau dinh vi lai");
} else {
height_anchored_ = false;
}
}
if (opts_.slam_reloc_auto && reloc_exec_ != RelocExec::kOff) {
// Chot roi thi DUNG HAN tu chay, ke ca dang nhuong nguoi.
if (reloc_exec_ != RelocExec::kHalted) RelocCommand(0.0, 0.0);
@@ -2106,6 +2217,13 @@ void Runtime::WebLoop() {
snap.roll = tilt_roll_.load(std::memory_order_relaxed);
snap.pitch = tilt_pitch_.load(std::memory_order_relaxed);
snap.accel_ok = tilt_accel_ok_.load(std::memory_order_relaxed);
if (slope_on_) {
std::lock_guard<std::mutex> lk(odom_mu_);
snap.have_height = true;
snap.height_z = height_->z();
snap.height_sigma = height_->sigma();
snap.on_slope = height_->on_slope();
}
{
std::lock_guard<std::mutex> lk(safety_mu_);

View File

@@ -39,9 +39,12 @@
#include "app_config.h"
#include "vslam/driver_interfaces.h"
#include "vslam/ekf_se2.h"
#include "vslam/elevation_map.h"
#include "vslam/gamepad.h"
#include "vslam/geometry.h"
#include "vslam/height_estimator.h"
#include "vslam/perception_pipeline.h"
#include "vslam/scan_leveler.h"
#include "vslam/safety_monitor.h"
#include "vslam/scan_sanitizer.h"
#include "vslam/teleop_model.h"
@@ -93,6 +96,8 @@ struct RuntimeOptions {
// Ve camera mo phong bang GPU (vslam_sim_gl): depth + anh IR co texture.
// Can --world va node build voi -DVSLAM_SIM_WITH_GL=ON.
bool sim_gl = false;
// Tan so PHAT IMU cua sim (SimConfig::imu_output_hz). 0 = moi buoc vat ly.
double sim_imu_hz = 0.0;
bool force_slam = false; // --slam: ghi de slam.yaml enabled
bool have_slam_db = false; // --slam-db "" nghia la DB trong RAM
std::string slam_db;
@@ -130,6 +135,8 @@ class Runtime {
// wiring.cc -- noi duy nhat noi nguon voi stage. Tuong duong toan bo 20
// file .launch cua ban ROS.
StatusResponse Wire();
// Di tren doc: mot khung depth -> ban do do cao san cuc bo (luong camera).
void AddDepthToElevation(const CameraFrame& f);
// runtime.cc
StatusResponse OpenSource();
@@ -231,6 +238,9 @@ class Runtime {
// web_tx doc.
mutable std::mutex scan_mu_;
LaserScanPtr latest_scan_;
// Scan cho SLAM / dinh vi lai / canh lac: BU NGHIENG khi slope_on_ (xem
// ScanLeveler), con lai CHINH la latest_scan_. An toan + web dung ban tho.
LaserScanPtr latest_slam_scan_;
// odom_mu_: wheel_odom_ va ekf_. CHI luong source cham vao chung; hai luong
// kia chi doc ban sao pose.
@@ -476,6 +486,29 @@ class Runtime {
std::atomic<double> tilt_pitch_{0.0};
std::atomic<bool> tilt_accel_ok_{false};
// ---- Di tren doc (slam.yaml `slope:`) ----
// slope_on_ doc-only sau Start(). Tat thi KHONG doi tuong nao duoi day
// duoc tao, va moi duong cu giu nguyen.
bool slope_on_ = false;
// Duoi odom_mu_: luong encoder cong buoc, luong slam neo.
std::unique_ptr<HeightEstimator> height_;
// elev_mu_: ban do do cao san cuc bo + thong ke bu nghieng scan. THU TU
// KHOA: odom_mu_ roi moi elev_mu_, KHONG BAO GIO nguoc lai.
mutable std::mutex elev_mu_;
std::unique_ptr<ElevationMap> elev_;
ScanLevelerConfig level_cfg_;
ScanLevelStats level_stats_;
UnixTime elev_pruned_;
// Tinh, doc-only sau Start(): base_link <- laser_link / camera optical.
Transform laser_to_base_static_ = TransformIdentity();
Transform cam_to_base_static_ = TransformIdentity();
bool have_cam_to_base_ = false;
// CHI luong slam: lan giai do thi z cuoi; da neo z lan nao chua (lan DAU
// sau khoi dong / dinh vi lai thi DAT THANG z ban do, khong qua cong).
bool height_anchored_ = false;
uint64_t heights_version_ = 0;
std::chrono::steady_clock::time_point heights_at_{};
std::atomic<bool> estop_{false};
std::atomic<bool> stop_{false};

View File

@@ -18,10 +18,14 @@
#include "runtime.h"
#include "vslam/geometry.h"
#include "vslam/gravity_align.h"
#include "vslam/json_parse.h"
#include "vslam/log.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
namespace vslam {
@@ -36,8 +40,32 @@ StatusResponse Runtime::Wire() {
// rieng thi "cai nao chay truoc" la mot bay co that.
auto copy = std::make_shared<LaserScan>(*s);
sanitizer_->Apply(copy.get());
// Di tren doc: ban BU NGHIENG + bo tia cham san cho SLAM / dinh vi lai.
// An toan va web giu ban tho. Tat thi hai con tro la MOT.
LaserScanPtr slam_scan = copy;
if (slope_on_ && cfg_->slope.level_scan) {
Pose2D od;
double z = 0.0;
{
std::lock_guard<std::mutex> lk(odom_mu_);
od = ekf_->pose();
z = height_->z();
}
const double roll = tilt_roll_.load(std::memory_order_relaxed);
const double pitch = tilt_pitch_.load(std::memory_order_relaxed);
auto lv = std::make_shared<LaserScan>();
{
std::lock_guard<std::mutex> lk(elev_mu_);
LevelScan(*copy, laser_to_base_static_, roll, pitch,
cfg_->robot.geometry().wheel_radius, od, z, elev_.get(), level_cfg_,
lv.get(), &level_stats_);
}
slam_scan = lv;
}
std::lock_guard<std::mutex> lk(scan_mu_);
latest_scan_ = copy;
latest_slam_scan_ = slam_scan;
});
}
@@ -162,8 +190,23 @@ StatusResponse Runtime::Wire() {
gyro_ok ? std::max(2.4e-7 * dt, 1e-12) : 1e9;
const double var_tr = std::max(o.twist.covariance[0] * dt * dt, 1e-12);
ekf_->UpdateOdomDelta(e.stamp, d_trans, d_theta, d_theta_gyro,
// Di tren doc: z cong tu quang duong DOC mat doc; EKF (SE(2)) nhan
// quang duong NGANG -- doc 15 do ma khong chieu thi ban do gian 3.4%.
double d_trans_ekf = d_trans;
if (slope_on_) {
const double pitch = tilt_pitch_.load(std::memory_order_relaxed);
height_->OnWheelStep(d_trans, pitch);
if (cfg_->slope.horizontal_odom) d_trans_ekf = d_trans * std::cos(pitch);
}
ekf_->UpdateOdomDelta(e.stamp, d_trans_ekf, d_theta, d_theta_gyro,
var_tr, var_th_enc, var_th_gyro);
if (slope_on_) {
// Vet banh: san duoi robot o dung z robot. Thu tu khoa odom_mu_ ->
// elev_mu_ (xem runtime.h).
const Pose2D p = ekf_->pose();
std::lock_guard<std::mutex> lk2(elev_mu_);
elev_->AddFootprint(p.x, p.y, height_->z(), 0.15, e.stamp);
}
}
gyro_dtheta_ = 0.0;
gyro_dt_ = 0.0;
@@ -234,6 +277,9 @@ StatusResponse Runtime::Wire() {
have_depth_ = true;
}
// Di tren doc: depth -> ban do do cao san cuc bo (cho ScanLeveler).
if (slope_on_ && have_cam_to_base_) AddDepthToElevation(f);
// Ca chuoi perception chay INLINE o day: depth -> cloud -> loc ->
// can trong luc -> phat hien vuc. Mot loi goi ham, tren chinh luong
// camera.
@@ -397,4 +443,62 @@ StatusResponse Runtime::Wire() {
return StatusResponse::Ok();
}
void Runtime::AddDepthToElevation(const CameraFrame& f) {
const Image& d = *f.depth;
if (d.data == nullptr || d.width == 0 || d.height == 0) return;
const CameraInfo& ci = f.depth_info;
const double fx = ci.fx_binned(), fy = ci.fy_binned();
const double cx = ci.cx_binned(), cy = ci.cy_binned();
if (fx <= 0.0 || fy <= 0.0) return;
Pose2D od;
double z = 0.0;
{
std::lock_guard<std::mutex> lk(odom_mu_);
od = ekf_->pose();
z = height_->z();
}
const double roll = tilt_roll_.load(std::memory_order_relaxed);
const double pitch = tilt_pitch_.load(std::memory_order_relaxed);
// base_footprint DA CAN <- optical: CHUNG TiltLift voi GravityAlign va
// ScanLeveler -- ba ban hinh hoc lech nhau la lop loi da co trong repo cu.
const Transform fp_from_cam = TransformCompose(
TiltLift(roll, pitch, cfg_->robot.geometry().wheel_radius), cam_to_base_static_);
const double c = std::cos(od.theta), s = std::sin(od.theta);
const int stride = std::max(1, cfg_->slope.depth_stride);
const double dmax = cfg_->slope.elevation_max_depth_m;
std::vector<PointXYZ> pts;
pts.reserve((d.width / stride + 1) * (d.height / stride + 1));
for (uint32_t v = 0; v < d.height; v += static_cast<uint32_t>(stride)) {
const uint8_t* row = d.data + static_cast<size_t>(v) * d.step;
for (uint32_t u = 0; u < d.width; u += static_cast<uint32_t>(stride)) {
double depth = 0.0;
if (d.format == PixelFormat::kMono16) {
uint16_t raw;
std::memcpy(&raw, row + 2 * u, 2);
depth = raw * static_cast<double>(d.depth_scale);
} else if (d.format == PixelFormat::kFloat32) {
float raw;
std::memcpy(&raw, row + 4 * u, 4);
depth = raw;
} else {
return;
}
if (!(depth > 0.2) || depth > dmax) continue;
const Point p = TransformPoint(
fp_from_cam, Point{(u - cx) / fx * depth, (v - cy) / fy * depth, depth});
pts.push_back(PointXYZ{static_cast<float>(od.x + c * p.x - s * p.y),
static_cast<float>(od.y + s * p.x + c * p.y),
static_cast<float>(z + p.z)});
}
}
std::lock_guard<std::mutex> lk(elev_mu_);
elev_->AddPoints(pts, f.header.stamp);
if (SecondsBetween(f.header.stamp, elev_pruned_) > 1.0) {
elev_->Prune(od.x, od.y, f.header.stamp);
elev_pruned_ = f.header.stamp;
}
}
} // namespace vslam