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:
60
libs/vslam_odometry/src/height_estimator.cc
Normal file
60
libs/vslam_odometry/src/height_estimator.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "vslam/height_estimator.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
namespace vslam {
|
||||
|
||||
HeightEstimator::HeightEstimator(HeightEstimatorConfig cfg) : cfg_(std::move(cfg)) {}
|
||||
|
||||
void HeightEstimator::Reset(double z, double sigma) {
|
||||
z_ = z;
|
||||
P_base_ = sigma * sigma;
|
||||
climb_ = 0.0;
|
||||
dist_ = 0.0;
|
||||
}
|
||||
|
||||
double HeightEstimator::P() const {
|
||||
const double rel = cfg_.sigma_rel * climb_;
|
||||
return P_base_ + rel * rel + cfg_.sigma_flat * cfg_.sigma_flat * dist_;
|
||||
}
|
||||
|
||||
double HeightEstimator::sigma() const { return std::sqrt(P()); }
|
||||
|
||||
void HeightEstimator::OnWheelStep(double ds, double pitch) {
|
||||
stats_.steps++;
|
||||
pitch_ = pitch;
|
||||
on_slope_ = std::fabs(pitch) >= cfg_.clamp_rad;
|
||||
double dz = 0.0;
|
||||
if (on_slope_) {
|
||||
dz = -ds * std::sin(pitch);
|
||||
} else {
|
||||
stats_.clamped++;
|
||||
}
|
||||
z_ += dz;
|
||||
stats_.climbed += std::fabs(dz);
|
||||
climb_ += std::fabs(dz);
|
||||
dist_ += std::fabs(ds);
|
||||
}
|
||||
|
||||
bool HeightEstimator::Anchor(double z_ref) {
|
||||
const double err = z_ref - z_;
|
||||
stats_.last_anchor_err = err;
|
||||
const double R = cfg_.sigma_anchor * cfg_.sigma_anchor;
|
||||
const double P_now = P();
|
||||
const double gate = std::max(cfg_.gate_min, cfg_.gate_sigma * std::sqrt(P_now + R));
|
||||
if (std::fabs(err) > gate) {
|
||||
stats_.anchors_rejected++;
|
||||
return false;
|
||||
}
|
||||
const double K = P_now / (P_now + R);
|
||||
z_ += K * err;
|
||||
P_base_ = (1.0 - K) * P_now;
|
||||
climb_ = 0.0;
|
||||
dist_ = 0.0;
|
||||
stats_.anchors++;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace vslam
|
||||
Reference in New Issue
Block a user